1 commit 6b95e3388b1ea0ca63500c5a6e39162dbf828433
2 Author: Joe Damato <jdamato@fastly.com>
3 Date: Tue Mar 1 23:55:49 2022 -0800
5 page_pool: Add function to batch and return stats
7 Adds a function page_pool_get_stats which can be used by drivers to obtain
8 stats for a specified page_pool.
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>
15 --- a/include/net/page_pool.h
16 +++ b/include/net/page_pool.h
17 @@ -105,6 +105,23 @@ struct page_pool_recycle_stats {
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.
26 +struct page_pool_stats {
27 + struct page_pool_alloc_stats alloc_stats;
28 + struct page_pool_recycle_stats recycle_stats;
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.
36 +bool page_pool_get_stats(struct page_pool *pool,
37 + struct page_pool_stats *stats);
41 --- a/net/core/page_pool.c
42 +++ b/net/core/page_pool.c
44 struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \
45 this_cpu_inc(s->__stat); \
48 +bool page_pool_get_stats(struct page_pool *pool,
49 + struct page_pool_stats *stats)
56 + memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
58 + for_each_possible_cpu(cpu) {
59 + const struct page_pool_recycle_stats *pcpu =
60 + per_cpu_ptr(pool->recycle_stats, cpu);
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;
71 +EXPORT_SYMBOL(page_pool_get_stats);
73 #define alloc_stat_inc(pool, __stat)
74 #define recycle_stat_inc(pool, __stat)