lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <63efff0da4235bfa2e326848545eb90c211e5db1.1649405981.git.lorenzo@kernel.org>
Date:   Fri,  8 Apr 2022 10:23:59 +0200
From:   Lorenzo Bianconi <lorenzo@...nel.org>
To:     netdev@...r.kernel.org
Cc:     lorenzo.bianconi@...hat.com, davem@...emloft.net, kuba@...nel.org,
        pabeni@...hat.com, thomas.petazzoni@...tlin.com,
        ilias.apalodimas@...aro.org, jbrouer@...hat.com, andrew@...n.ch,
        jdamato@...tly.com
Subject: [PATCH v2 net-next 1/2] net: page_pool: introduce ethtool stats

Introduce page_pool APIs to report stats through ethtool and reduce
duplicated code in each driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@...nel.org>
---
 include/net/page_pool.h | 24 ++++++++++++
 net/core/page_pool.c    | 81 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index ea5fb70e5101..ada528df1843 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -117,6 +117,30 @@ struct page_pool_stats {
 	struct page_pool_recycle_stats recycle_stats;
 };
 
+/* List of page_pool stats exported through ethtool. */
+enum {
+	PP_ETHTOOL_ALLOC_FAST,
+	PP_ETHTOOL_ALLOC_SLOW,
+	PP_ETHTOOL_ALLOC_SLOW_HIGH_ORDER,
+	PP_ETHTOOL_ALLOC_EMPTY,
+	PP_ETHTOOL_ALLOC_REFILL,
+	PP_ETHTOOL_ALLOC_WAIVE,
+	PP_ETHTOOL_RECYCLE_CACHED,
+	PP_ETHTOOL_RECYCLE_CACHE_FULL,
+	PP_ETHTOOL_RECYCLE_RING,
+	PP_ETHTOOL_RECYCLE_RING_FULL,
+	PP_ETHTOOL_RECYCLE_RELEASED_REF,
+	PP_ETHTOOL_STATS_MAX,
+};
+
+static inline int page_pool_ethtool_stats_get_count(void)
+{
+	return PP_ETHTOOL_STATS_MAX;
+}
+
+u8 *page_pool_ethtool_stats_get_strings(u8 *data);
+u64 *page_pool_ethtool_stats_get(u64 *data, struct page_pool_stats *stats);
+
 /*
  * Drivers that wish to harvest page pool stats and report them to users
  * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 4af55d28ffa3..bffc3037d7f6 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -18,6 +18,7 @@
 #include <linux/page-flags.h>
 #include <linux/mm.h> /* for __put_page() */
 #include <linux/poison.h>
+#include <linux/ethtool.h>
 
 #include <trace/events/page_pool.h>
 
@@ -50,7 +51,13 @@ bool page_pool_get_stats(struct page_pool *pool,
 	if (!stats)
 		return false;
 
-	memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
+	/* The caller is responsible to initialize stats. */
+	stats->alloc_stats.fast += pool->alloc_stats.fast;
+	stats->alloc_stats.slow += pool->alloc_stats.slow;
+	stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
+	stats->alloc_stats.empty += pool->alloc_stats.empty;
+	stats->alloc_stats.refill += pool->alloc_stats.refill;
+	stats->alloc_stats.waive += pool->alloc_stats.waive;
 
 	for_each_possible_cpu(cpu) {
 		const struct page_pool_recycle_stats *pcpu =
@@ -66,6 +73,78 @@ bool page_pool_get_stats(struct page_pool *pool,
 	return true;
 }
 EXPORT_SYMBOL(page_pool_get_stats);
+
+u8 *page_pool_ethtool_stats_get_strings(u8 *data)
+{
+	static const char stats[PP_ETHTOOL_STATS_MAX][ETH_GSTRING_LEN] = {
+		"rx_pp_alloc_fast",
+		"rx_pp_alloc_slow",
+		"rx_pp_alloc_slow_ho",
+		"rx_pp_alloc_empty",
+		"rx_pp_alloc_refill",
+		"rx_pp_alloc_waive",
+		"rx_pp_recycle_cached",
+		"rx_pp_recycle_cache_full",
+		"rx_pp_recycle_ring",
+		"rx_pp_recycle_ring_full",
+		"rx_pp_recycle_released_ref",
+	};
+	int i;
+
+	for (i = 0; i < PP_ETHTOOL_STATS_MAX; i++) {
+		memcpy(data, stats[i], ETH_GSTRING_LEN);
+		data += ETH_GSTRING_LEN;
+	}
+
+	return data;
+}
+EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
+
+u64 *page_pool_ethtool_stats_get(u64 *data, struct page_pool_stats *stats)
+{
+	int i;
+
+	for (i = 0; i < PP_ETHTOOL_STATS_MAX; i++) {
+		switch (i) {
+		case PP_ETHTOOL_ALLOC_FAST:
+			*data++ = stats->alloc_stats.fast;
+			break;
+		case PP_ETHTOOL_ALLOC_SLOW:
+			*data++ = stats->alloc_stats.slow;
+			break;
+		case PP_ETHTOOL_ALLOC_SLOW_HIGH_ORDER:
+			*data++ = stats->alloc_stats.slow_high_order;
+			break;
+		case PP_ETHTOOL_ALLOC_EMPTY:
+			*data++ = stats->alloc_stats.empty;
+			break;
+		case PP_ETHTOOL_ALLOC_REFILL:
+			*data++ = stats->alloc_stats.refill;
+			break;
+		case PP_ETHTOOL_ALLOC_WAIVE:
+			*data++ = stats->alloc_stats.waive;
+			break;
+		case PP_ETHTOOL_RECYCLE_CACHED:
+			*data++ = stats->recycle_stats.cached;
+			break;
+		case PP_ETHTOOL_RECYCLE_CACHE_FULL:
+			*data++ = stats->recycle_stats.cache_full;
+			break;
+		case PP_ETHTOOL_RECYCLE_RING:
+			*data++ = stats->recycle_stats.ring;
+			break;
+		case PP_ETHTOOL_RECYCLE_RING_FULL:
+			*data++ = stats->recycle_stats.ring_full;
+			break;
+		case PP_ETHTOOL_RECYCLE_RELEASED_REF:
+			*data++ = stats->recycle_stats.released_refcnt;
+			break;
+		}
+	}
+
+	return data;
+}
+EXPORT_SYMBOL(page_pool_ethtool_stats_get);
 #else
 #define alloc_stat_inc(pool, __stat)
 #define recycle_stat_inc(pool, __stat)
-- 
2.35.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ