Skip to contentSkip to conversation

net: fec: add xdp and page pool statistics

PATCH In review Shenwei Wang 3 participants 8 messages Nov 15, 2022 – Nov 17, 2022

Subsystems (4)
lore
Share & tools
lore

Shenwei Wang

author reviewer
#0 lore raw

v5 cover net: fec: add xdp and page pool statistics

Changes in V5:
- split the patch into two: one for xdp statistics and one for page pool
- fix the bug to zero xdp_stats array
- use empty 'page_pool_stats' when CONFIG_PAGE_POOL_STATS is disabled.

Changes in V4:
- Using u64 to record the XDP statistics
- Changing strncpy to strscpy
- Remove the "PAGE_POOL_STATS" select per Alexander's feedback
- Export the page_pool_stats definition in the page_pool.h

Changes in v3:
- change memcpy to strncpy to fix the warning reported by Paolo Abeni
- fix the compile errors on powerpc

Changes in v2:
- clean up and restructure the codes per Andrew Lunn's review comments
- clear the statistics when the adaptor is down

Shenwei Wang (3):
net: page_pool: export page_pool_stats definition
net: fec: add xdp statistics
net: fec: add page pool statistics

 drivers/net/ethernet/freescale/fec.h      | 15 ++++
 drivers/net/ethernet/freescale/fec_main.c | 96 +++++++++++++++++++++--
 include/net/page_pool.h                   |  2 +
 3 files changed, 107 insertions(+), 6 deletions(-)

--
2.34.1

author reviewer
#1 lore raw

PATCH v5 1/3 net: page_pool: export page_pool_stats definition

The definition of the 'struct page_pool_stats' is required even when the CONFIG_PAGE_POOL_STATS is not defined. Add an empty page_pool_stats stub, Otherwise it would require the drivers to handle the case of CONFIG_PAGE_POOL_STATS undefined.

---
 include/net/page_pool.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/page_pool.h +2 -0
index 813c93499f20..516d943bc1eb 100644
@@ -129,6 +129,8 @@ u64 *page_pool_ethtool_stats_get(u64 *data, void *stats);
 bool page_pool_get_stats(struct page_pool *pool,
 			 struct page_pool_stats *stats);
 #else
+struct page_pool_stats {
+};
 
 static inline int page_pool_ethtool_stats_get_count(void)
 {
Signature · 1 line
2.34.1
author reviewer
#2 lore raw

PATCH v5 2/3 net: fec: add xdp statistics

In reply to Shenwei Wang

Add xdp statistics for ethtool stats and using u64 to record the xdp counters.

---
 drivers/net/ethernet/freescale/fec.h      | 15 +++++
 drivers/net/ethernet/freescale/fec_main.c | 74 +++++++++++++++++++++--
 2 files changed, 83 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.h +15 -0
index 61e847b18343..adbe661552be 100644
@@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info {
 	struct  sk_buff *skb;
 };
 
+enum {
+	RX_XDP_REDIRECT = 0,
+	RX_XDP_PASS,
+	RX_XDP_DROP,
+	RX_XDP_TX,
+	RX_XDP_TX_ERRORS,
+	TX_XDP_XMIT,
+	TX_XDP_XMIT_ERRORS,
+
+	/* The following must be the last one */
+	XDP_STATS_TOTAL,
+};
+
 struct fec_enet_priv_tx_q {
 	struct bufdesc_prop bd;
 	unsigned char *tx_bounce[TX_RING_SIZE];
@@ -546,6 +559,8 @@ struct fec_enet_priv_rx_q {
 	/* page_pool */
 	struct page_pool *page_pool;
 	struct xdp_rxq_info xdp_rxq;
+	struct u64_stats_sync syncp;
+	u64 stats[XDP_STATS_TOTAL];
 
 	/* rx queue number, in the range 0-7 */
 	u8 id;
drivers/net/ethernet/freescale/fec_main.c +68 -6

162 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v5 2/3] net: fec: add xdp statistics

From: Shenwei Wang <[email protected]>
Date: Tue, 15 Nov 2022 14:49:50 -0600

Quoted 4 lines

Add xdp statistics for ethtool stats and using u64 to record the xdp counters.

Nit: would be nice if you Cc me for the next submissions as I was commenting on the previous ones. Just to make sure reviewers won't miss anything.

Quoted 30 lines
---
 drivers/net/ethernet/freescale/fec.h      | 15 +++++
 drivers/net/ethernet/freescale/fec_main.c | 74 +++++++++++++++++++++--
 2 files changed, 83 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.h +13 -0
index 61e847b18343..adbe661552be 100644
@@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info {
 	struct  sk_buff *skb;
 };
 
+enum {
+	RX_XDP_REDIRECT = 0,
+	RX_XDP_PASS,
+	RX_XDP_DROP,
+	RX_XDP_TX,
+	RX_XDP_TX_ERRORS,
+	TX_XDP_XMIT,
+	TX_XDP_XMIT_ERRORS,
+
+	/* The following must be the last one */
+	XDP_STATS_TOTAL,
+};
+
 struct fec_enet_priv_tx_q {
 	struct bufdesc_prop bd;
 	unsigned char *tx_bounce[TX_RING_SIZE];

drivers/net/ethernet/freescale/fec.h struct fec_enet_priv_rx_q { · line 563

Quoted 5 lines
drivers/net/ethernet/freescale/fec.h +2 -0
@@ -546,6 +559,8 @@ struct fec_enet_priv_rx_q {
 	/* page_pool */
 	struct page_pool *page_pool;
 	struct xdp_rxq_info xdp_rxq;
+	struct u64_stats_sync syncp;
+	u64 stats[XDP_STATS_TOTAL];

Why u64? u64_stats infra declares u64_stat_t type and a bunch of helpers like u64_stats_add(), u64_stats_read() and so on, they will be solved then by the compiler to the most appropriate ops for the architecture. So they're more "generic" if you prefer. Sure, if you show some numbers where u64_stat_t is slower than u64 on your machine, then okay, but otherwise...

Quoted 3 lines
drivers/net/ethernet/freescale/fec.h +0 -0
 	/* rx queue number, in the range 0-7 */
 	u8 id;

[...]

Quoted 2 lines
Signature · 1 line
2.34.1

Thanks,
Olek

author reviewer
#4 lore raw

RE: [EXT] Re: [PATCH v5 2/3] net: fec: add xdp statistics

Quoted 21 lines

-----Original Message-----
From: Alexander Lobakin <[email protected]>
Sent: Wednesday, November 16, 2022 10:02 AM
To: Shenwei Wang <[email protected]>
Cc: Alexander Lobakin <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Ilias Apalodimas <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; John Fastabend <[email protected]>; [email protected]; linux- [email protected]; [email protected]; kernel test robot <[email protected]>
Subject: [EXT] Re: [PATCH v5 2/3] net: fec: add xdp statistics

Caution: EXT Email

From: Shenwei Wang <[email protected]>
Date: Tue, 15 Nov 2022 14:49:50 -0600

Quoted 7 lines
Quoted 4 lines

Add xdp statistics for ethtool stats and using u64 to record the xdp counters.

Nit: would be nice if you Cc me for the next submissions as I was commenting on the previous ones. Just to make sure reviewers won't miss anything.

Sure of course.

Quoted 37 lines
Quoted 37 lines
---
 drivers/net/ethernet/freescale/fec.h      | 15 +++++
 drivers/net/ethernet/freescale/fec_main.c | 74
+++++++++++++++++++++--
 2 files changed, 83 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.h +13 -0
index 61e847b18343..adbe661552be 100644
@@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info {
      struct  sk_buff *skb;
 };
 
+enum {
+     RX_XDP_REDIRECT = 0,
+     RX_XDP_PASS,
+     RX_XDP_DROP,
+     RX_XDP_TX,
+     RX_XDP_TX_ERRORS,
+     TX_XDP_XMIT,
+     TX_XDP_XMIT_ERRORS,
+
+     /* The following must be the last one */
+     XDP_STATS_TOTAL,
+};
+
 struct fec_enet_priv_tx_q {
      struct bufdesc_prop bd;
      unsigned char *tx_bounce[TX_RING_SIZE]; @@ -546,6 +559,8 @@
struct fec_enet_priv_rx_q {
      /* page_pool */
      struct page_pool *page_pool;
      struct xdp_rxq_info xdp_rxq;

+ struct u64_stats_sync syncp;

Quoted 8 lines
Quoted 1 line

+ u64 stats[XDP_STATS_TOTAL];

Why u64? u64_stats infra declares u64_stat_t type and a bunch of helpers like u64_stats_add(), u64_stats_read() and so on, they will be solved then by the compiler to the most appropriate ops for the architecture. So they're more "generic" if you prefer.
Sure, if you show some numbers where u64_stat_t is slower than u64 on your machine, then okay, but otherwise...

I will take a leave next week. Will do a compare testing when I come back. Then we can decide which way to go.

Thanks,
Shenwei

Quoted 12 lines
Quoted 4 lines

      /* rx queue number, in the range 0-7 */
      u8 id;

[...]

Quoted 2 lines

--
2.34.1

Thanks,
Olek

author reviewer
#5 lore raw

PATCH v5 3/3 net: fec: add page pool statistics

In reply to Shenwei Wang

add page pool statistics to ethtool stats.

---
 drivers/net/ethernet/freescale/fec_main.c | 24 ++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/fec_main.c +23 -1
index bb2157022022..ae905ea1ab7d 100644
@@ -2755,6 +2755,24 @@ static void fec_enet_get_xdp_stats(struct fec_enet_private *fep, u64 *data)
 	memcpy(data, xdp_stats, sizeof(xdp_stats));
 }
 
+static void fec_enet_page_pool_stats(struct fec_enet_private *fep, u64 *data)
+{
+	struct page_pool_stats stats = {};
+	struct fec_enet_priv_rx_q *rxq;
+	int i;
+
+	for (i = fep->num_rx_queues - 1; i >= 0; i--) {
+		rxq = fep->rx_queue[i];
+
+		if (!rxq->page_pool)
+			continue;
+
+		page_pool_get_stats(rxq->page_pool, &stats);
+	}
+
+	page_pool_ethtool_stats_get(data, &stats);
+}
+
 static void fec_enet_get_ethtool_stats(struct net_device *dev,
 				       struct ethtool_stats *stats, u64 *data)
 {
@@ -2768,6 +2786,8 @@ static void fec_enet_get_ethtool_stats(struct net_device *dev,
 
 	fec_enet_get_xdp_stats(fep, data);
 	data += XDP_STATS_TOTAL;
+
+	fec_enet_page_pool_stats(fep, data);
 }
 
 static void fec_enet_get_strings(struct net_device *netdev,
@@ -2784,6 +2804,7 @@ static void fec_enet_get_strings(struct net_device *netdev,
 			strscpy(data, fec_xdp_stat_strs[i], ETH_GSTRING_LEN);
 			data += ETH_GSTRING_LEN;
 		}
+		page_pool_ethtool_stats_get_strings(data);
 		break;
 	case ETH_SS_TEST:
 		net_selftest_get_strings(data);
@@ -2795,7 +2816,8 @@ static int fec_enet_get_sset_count(struct net_device *dev, int sset)
 {
 	switch (sset) {
 	case ETH_SS_STATS:
-		return (ARRAY_SIZE(fec_stats) + XDP_STATS_TOTAL);
+		return (ARRAY_SIZE(fec_stats) + XDP_STATS_TOTAL
+				+ page_pool_ethtool_stats_get_count());
 	case ETH_SS_TEST:
 		return net_selftest_get_count();
 	default:
Signature · 1 line
2.34.1
maintainer
#6 lore raw
In reply to Shenwei Wang
Quoted 5 lines · On Tue, 15 Nov 2022 14:49:48 -0600 Shenwei Wang wrote:

Changes in V5:
- split the patch into two: one for xdp statistics and one for page pool
- fix the bug to zero xdp_stats array
- use empty 'page_pool_stats' when CONFIG_PAGE_POOL_STATS is disabled.

Hi, IIUC there was a previous revision of this set which got applied too hastily. Unfortunately that means you need to rebase on top of what's already applied, or add a revert to your series. Otherwise the patches won't apply cleanly.

author reviewer
#7 lore raw
Quoted 24 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Wednesday, November 16, 2022 10:47 AM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Ilias Apalodimas <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; John Fastabend <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [EXT] Re: [PATCH v5 0/3] net: fec: add xdp and page pool statistics

Caution: EXT Email

Quoted 5 lines · On Tue, 15 Nov 2022 14:49:48 -0600 Shenwei Wang wrote:

Changes in V5:
- split the patch into two: one for xdp statistics and one for page pool
- fix the bug to zero xdp_stats array
- use empty 'page_pool_stats' when CONFIG_PAGE_POOL_STATS is disabled.

Quoted 3 lines

Hi, IIUC there was a previous revision of this set which got applied too hastily. Unfortunately that means you need to rebase on top of what's already applied, or add a revert to your series. Otherwise the patches won't apply cleanly.

I will do a rebase.

Thanks,
Shenwei