generic: Convert incorrect generic/5.10 patches
[openwrt/staging/ansuel.git] / target / linux / generic / backport-5.15 / 604-v5.19-net-page_pool-introduce-ethtool-stats.patch
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
5
6 Introduce page_pool APIs to report stats through ethtool and reduce
7 duplicated code in each driver.
8
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>
13 ---
14 include/net/page_pool.h | 21 ++++++++++++++
15 net/core/page_pool.c | 63 ++++++++++++++++++++++++++++++++++++++++-
16 2 files changed, 83 insertions(+), 1 deletion(-)
17
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;
24 };
25
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);
29 +
30 /*
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 {
34 */
35 bool page_pool_get_stats(struct page_pool *pool,
36 struct page_pool_stats *stats);
37 +#else
38 +
39 +static inline int page_pool_ethtool_stats_get_count(void)
40 +{
41 + return 0;
42 +}
43 +
44 +static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)
45 +{
46 + return data;
47 +}
48 +
49 +static inline u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
50 +{
51 + return data;
52 +}
53 +
54 #endif
55
56 struct page_pool {
57 --- a/net/core/page_pool.c
58 +++ b/net/core/page_pool.c
59 @@ -18,6 +18,7 @@
60 #include <linux/page-flags.h>
61 #include <linux/mm.h> /* for __put_page() */
62 #include <linux/poison.h>
63 +#include <linux/ethtool.h>
64
65 #include <trace/events/page_pool.h>
66
67 @@ -42,6 +43,20 @@
68 this_cpu_add(s->__stat, val); \
69 } while (0)
70
71 +static const char pp_stats[][ETH_GSTRING_LEN] = {
72 + "rx_pp_alloc_fast",
73 + "rx_pp_alloc_slow",
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",
83 +};
84 +
85 bool page_pool_get_stats(struct page_pool *pool,
86 struct page_pool_stats *stats)
87 {
88 @@ -50,7 +65,13 @@ bool page_pool_get_stats(struct page_poo
89 if (!stats)
90 return false;
91
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;
100
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
104 return true;
105 }
106 EXPORT_SYMBOL(page_pool_get_stats);
107 +
108 +u8 *page_pool_ethtool_stats_get_strings(u8 *data)
109 +{
110 + int i;
111 +
112 + for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
113 + memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
114 + data += ETH_GSTRING_LEN;
115 + }
116 +
117 + return data;
118 +}
119 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
120 +
121 +int page_pool_ethtool_stats_get_count(void)
122 +{
123 + return ARRAY_SIZE(pp_stats);
124 +}
125 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
126 +
127 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
128 +{
129 + struct page_pool_stats *pool_stats = stats;
130 +
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;
142 +
143 + return data;
144 +}
145 +EXPORT_SYMBOL(page_pool_ethtool_stats_get);
146 +
147 #else
148 #define alloc_stat_inc(pool, __stat)
149 #define recycle_stat_inc(pool, __stat)