kernel: bump 5.15 to 5.15.115
[openwrt/staging/hauke.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 --- 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;
22 };
23
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);
27 +
28 /*
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 {
32 */
33 bool page_pool_get_stats(struct page_pool *pool,
34 struct page_pool_stats *stats);
35 +#else
36 +
37 +static inline int page_pool_ethtool_stats_get_count(void)
38 +{
39 + return 0;
40 +}
41 +
42 +static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)
43 +{
44 + return data;
45 +}
46 +
47 +static inline u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
48 +{
49 + return data;
50 +}
51 +
52 #endif
53
54 struct page_pool {
55 --- a/net/core/page_pool.c
56 +++ b/net/core/page_pool.c
57 @@ -18,6 +18,7 @@
58 #include <linux/page-flags.h>
59 #include <linux/mm.h> /* for __put_page() */
60 #include <linux/poison.h>
61 +#include <linux/ethtool.h>
62
63 #include <trace/events/page_pool.h>
64
65 @@ -65,6 +66,20 @@ static void page_pool_producer_unlock(st
66 this_cpu_add(s->__stat, val); \
67 } while (0)
68
69 +static const char pp_stats[][ETH_GSTRING_LEN] = {
70 + "rx_pp_alloc_fast",
71 + "rx_pp_alloc_slow",
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",
81 +};
82 +
83 bool page_pool_get_stats(struct page_pool *pool,
84 struct page_pool_stats *stats)
85 {
86 @@ -73,7 +88,13 @@ bool page_pool_get_stats(struct page_poo
87 if (!stats)
88 return false;
89
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;
98
99 for_each_possible_cpu(cpu) {
100 const struct page_pool_recycle_stats *pcpu =
101 @@ -89,6 +110,46 @@ bool page_pool_get_stats(struct page_poo
102 return true;
103 }
104 EXPORT_SYMBOL(page_pool_get_stats);
105 +
106 +u8 *page_pool_ethtool_stats_get_strings(u8 *data)
107 +{
108 + int i;
109 +
110 + for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
111 + memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
112 + data += ETH_GSTRING_LEN;
113 + }
114 +
115 + return data;
116 +}
117 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
118 +
119 +int page_pool_ethtool_stats_get_count(void)
120 +{
121 + return ARRAY_SIZE(pp_stats);
122 +}
123 +EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
124 +
125 +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
126 +{
127 + struct page_pool_stats *pool_stats = stats;
128 +
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;
140 +
141 + return data;
142 +}
143 +EXPORT_SYMBOL(page_pool_ethtool_stats_get);
144 +
145 #else
146 #define alloc_stat_inc(pool, __stat)
147 #define recycle_stat_inc(pool, __stat)