kernel: pick patches for MediaTek Ethernet from linux-next
[openwrt/staging/dedeckeh.git] / target / linux / generic / backport-5.15 / 602-v5.18-page_pool-Add-function-to-batch-and-return-stats.patch
1 commit 6b95e3388b1ea0ca63500c5a6e39162dbf828433
2 Author: Joe Damato <jdamato@fastly.com>
3 Date: Tue Mar 1 23:55:49 2022 -0800
4
5 page_pool: Add function to batch and return stats
6
7 Adds a function page_pool_get_stats which can be used by drivers to obtain
8 stats for a specified page_pool.
9
10 Signed-off-by: Joe Damato <jdamato@fastly.com>
11 Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
12 Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14
15 --- a/include/net/page_pool.h
16 +++ b/include/net/page_pool.h
17 @@ -105,6 +105,23 @@ struct page_pool_recycle_stats {
18 * refcnt
19 */
20 };
21 +
22 +/* This struct wraps the above stats structs so users of the
23 + * page_pool_get_stats API can pass a single argument when requesting the
24 + * stats for the page pool.
25 + */
26 +struct page_pool_stats {
27 + struct page_pool_alloc_stats alloc_stats;
28 + struct page_pool_recycle_stats recycle_stats;
29 +};
30 +
31 +/*
32 + * Drivers that wish to harvest page pool stats and report them to users
33 + * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
34 + * struct page_pool_stats call page_pool_get_stats to get stats for the specified pool.
35 + */
36 +bool page_pool_get_stats(struct page_pool *pool,
37 + struct page_pool_stats *stats);
38 #endif
39
40 struct page_pool {
41 --- a/net/core/page_pool.c
42 +++ b/net/core/page_pool.c
43 @@ -35,6 +35,31 @@
44 struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \
45 this_cpu_inc(s->__stat); \
46 } while (0)
47 +
48 +bool page_pool_get_stats(struct page_pool *pool,
49 + struct page_pool_stats *stats)
50 +{
51 + int cpu = 0;
52 +
53 + if (!stats)
54 + return false;
55 +
56 + memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
57 +
58 + for_each_possible_cpu(cpu) {
59 + const struct page_pool_recycle_stats *pcpu =
60 + per_cpu_ptr(pool->recycle_stats, cpu);
61 +
62 + stats->recycle_stats.cached += pcpu->cached;
63 + stats->recycle_stats.cache_full += pcpu->cache_full;
64 + stats->recycle_stats.ring += pcpu->ring;
65 + stats->recycle_stats.ring_full += pcpu->ring_full;
66 + stats->recycle_stats.released_refcnt += pcpu->released_refcnt;
67 + }
68 +
69 + return true;
70 +}
71 +EXPORT_SYMBOL(page_pool_get_stats);
72 #else
73 #define alloc_stat_inc(pool, __stat)
74 #define recycle_stat_inc(pool, __stat)