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