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 --- a/include/net/page_pool.h
19 +++ b/include/net/page_pool.h
20 @@ -115,6 +115,10 @@ struct page_pool_stats {
21 struct page_pool_recycle_stats recycle_stats;
24 +int page_pool_ethtool_stats_get_count(void);
25 +u8 *page_pool_ethtool_stats_get_strings(u8 *data);
26 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats);
29 * Drivers that wish to harvest page pool stats and report them to users
30 * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
31 @@ -122,6 +126,23 @@ struct page_pool_stats {
33 bool page_pool_get_stats(struct page_pool *pool,
34 struct page_pool_stats *stats);
37 +static inline int page_pool_ethtool_stats_get_count(void)
42 +static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)
47 +static inline u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
55 --- a/net/core/page_pool.c
56 +++ b/net/core/page_pool.c
58 #include <linux/page-flags.h>
59 #include <linux/mm.h> /* for __put_page() */
60 #include <linux/poison.h>
61 +#include <linux/ethtool.h>
63 #include <trace/events/page_pool.h>
66 this_cpu_add(s->__stat, val); \
69 +static const char pp_stats[][ETH_GSTRING_LEN] = {
72 + "rx_pp_alloc_slow_ho",
73 + "rx_pp_alloc_empty",
74 + "rx_pp_alloc_refill",
75 + "rx_pp_alloc_waive",
76 + "rx_pp_recycle_cached",
77 + "rx_pp_recycle_cache_full",
78 + "rx_pp_recycle_ring",
79 + "rx_pp_recycle_ring_full",
80 + "rx_pp_recycle_released_ref",
83 bool page_pool_get_stats(struct page_pool *pool,
84 struct page_pool_stats *stats)
86 @@ -50,7 +65,13 @@ bool page_pool_get_stats(struct page_poo
90 - memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
91 + /* The caller is responsible to initialize stats. */
92 + stats->alloc_stats.fast += pool->alloc_stats.fast;
93 + stats->alloc_stats.slow += pool->alloc_stats.slow;
94 + stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
95 + stats->alloc_stats.empty += pool->alloc_stats.empty;
96 + stats->alloc_stats.refill += pool->alloc_stats.refill;
97 + stats->alloc_stats.waive += pool->alloc_stats.waive;
99 for_each_possible_cpu(cpu) {
100 const struct page_pool_recycle_stats *pcpu =
101 @@ -66,6 +87,46 @@ bool page_pool_get_stats(struct page_poo
104 EXPORT_SYMBOL(page_pool_get_stats);
106 +u8 *page_pool_ethtool_stats_get_strings(u8 *data)
110 + for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
111 + memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
112 + data += ETH_GSTRING_LEN;
117 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
119 +int page_pool_ethtool_stats_get_count(void)
121 + return ARRAY_SIZE(pp_stats);
123 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
125 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
127 + struct page_pool_stats *pool_stats = stats;
129 + *data++ = pool_stats->alloc_stats.fast;
130 + *data++ = pool_stats->alloc_stats.slow;
131 + *data++ = pool_stats->alloc_stats.slow_high_order;
132 + *data++ = pool_stats->alloc_stats.empty;
133 + *data++ = pool_stats->alloc_stats.refill;
134 + *data++ = pool_stats->alloc_stats.waive;
135 + *data++ = pool_stats->recycle_stats.cached;
136 + *data++ = pool_stats->recycle_stats.cache_full;
137 + *data++ = pool_stats->recycle_stats.ring;
138 + *data++ = pool_stats->recycle_stats.ring_full;
139 + *data++ = pool_stats->recycle_stats.released_refcnt;
143 +EXPORT_SYMBOL(page_pool_ethtool_stats_get);
146 #define alloc_stat_inc(pool, __stat)
147 #define recycle_stat_inc(pool, __stat)