1 From f3c5264f452a5b0ac1de1f2f657efbabdea3c76a Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Tue, 12 Apr 2022 18:31:58 +0200
4 Subject: [PATCH] net: page_pool: introduce ethtool stats
6 Introduce page_pool APIs to report stats through ethtool and reduce
7 duplicated code in each driver.
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Reviewed-by: Jakub Kicinski <kuba@kernel.org>
11 Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
14 include/net/page_pool.h | 21 ++++++++++++++
15 net/core/page_pool.c | 63 ++++++++++++++++++++++++++++++++++++++++-
16 2 files changed, 83 insertions(+), 1 deletion(-)
18 diff --git a/include/net/page_pool.h b/include/net/page_pool.h
19 index ea5fb70e5101..813c93499f20 100644
20 --- a/include/net/page_pool.h
21 +++ b/include/net/page_pool.h
22 @@ -115,6 +115,10 @@ struct page_pool_stats {
23 struct page_pool_recycle_stats recycle_stats;
26 +int page_pool_ethtool_stats_get_count(void);
27 +u8 *page_pool_ethtool_stats_get_strings(u8 *data);
28 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats);
31 * Drivers that wish to harvest page pool stats and report them to users
32 * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
33 @@ -122,6 +126,23 @@ struct page_pool_stats {
35 bool page_pool_get_stats(struct page_pool *pool,
36 struct page_pool_stats *stats);
39 +static inline int page_pool_ethtool_stats_get_count(void)
44 +static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)
49 +static inline u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
57 --- a/net/core/page_pool.c
58 +++ b/net/core/page_pool.c
60 #include <linux/page-flags.h>
61 #include <linux/mm.h> /* for __put_page() */
62 #include <linux/poison.h>
63 +#include <linux/ethtool.h>
65 #include <trace/events/page_pool.h>
68 this_cpu_add(s->__stat, val); \
71 +static const char pp_stats[][ETH_GSTRING_LEN] = {
74 + "rx_pp_alloc_slow_ho",
75 + "rx_pp_alloc_empty",
76 + "rx_pp_alloc_refill",
77 + "rx_pp_alloc_waive",
78 + "rx_pp_recycle_cached",
79 + "rx_pp_recycle_cache_full",
80 + "rx_pp_recycle_ring",
81 + "rx_pp_recycle_ring_full",
82 + "rx_pp_recycle_released_ref",
85 bool page_pool_get_stats(struct page_pool *pool,
86 struct page_pool_stats *stats)
88 @@ -50,7 +65,13 @@ bool page_pool_get_stats(struct page_poo
92 - memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
93 + /* The caller is responsible to initialize stats. */
94 + stats->alloc_stats.fast += pool->alloc_stats.fast;
95 + stats->alloc_stats.slow += pool->alloc_stats.slow;
96 + stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
97 + stats->alloc_stats.empty += pool->alloc_stats.empty;
98 + stats->alloc_stats.refill += pool->alloc_stats.refill;
99 + stats->alloc_stats.waive += pool->alloc_stats.waive;
101 for_each_possible_cpu(cpu) {
102 const struct page_pool_recycle_stats *pcpu =
103 @@ -66,6 +87,46 @@ bool page_pool_get_stats(struct page_poo
106 EXPORT_SYMBOL(page_pool_get_stats);
108 +u8 *page_pool_ethtool_stats_get_strings(u8 *data)
112 + for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
113 + memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
114 + data += ETH_GSTRING_LEN;
119 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
121 +int page_pool_ethtool_stats_get_count(void)
123 + return ARRAY_SIZE(pp_stats);
125 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
127 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
129 + struct page_pool_stats *pool_stats = stats;
131 + *data++ = pool_stats->alloc_stats.fast;
132 + *data++ = pool_stats->alloc_stats.slow;
133 + *data++ = pool_stats->alloc_stats.slow_high_order;
134 + *data++ = pool_stats->alloc_stats.empty;
135 + *data++ = pool_stats->alloc_stats.refill;
136 + *data++ = pool_stats->alloc_stats.waive;
137 + *data++ = pool_stats->recycle_stats.cached;
138 + *data++ = pool_stats->recycle_stats.cache_full;
139 + *data++ = pool_stats->recycle_stats.ring;
140 + *data++ = pool_stats->recycle_stats.ring_full;
141 + *data++ = pool_stats->recycle_stats.released_refcnt;
145 +EXPORT_SYMBOL(page_pool_ethtool_stats_get);
148 #define alloc_stat_inc(pool, __stat)
149 #define recycle_stat_inc(pool, __stat)