Skip to contentSkip to conversation

eth: mpnic: add basic netdev statistics

PATCH Applied Daniel Zahka 6 participants 22 messages Oct 12 – Oct 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover eth: mpnic: add basic netdev statistics

Add basic netdev statistics and report them via ndo_get_stats64 and netdev_stat_ops.

Track per queue netdev statistics such as Tx/Rx: packets, bytes, drops, etc. The driver keeps per-queue state for statistics that is updated mostly from the NAPI poll and ndo_start_xmit paths. The stats are made available through the usual driver APIs.

When the netif is transitioned down, the per-queue stat counters are folded into a global per-device set of counters, and then when the netif is brought back up, the per-queue counters start counting again from 0.

Extra care is needed for implementing ndo_get_stats64 since the instance lock is not taken. When ndo_get_stats64 races against ndo_stop and ndo_open, the reader can attempt to read per-queue stats while the queue count is changing. To deal with this, the writer publishes the aggregated base stats and the active queue counts in a single RCU versioned object.

---
Changes in v2:
- eth: mpnic: count packets, bytes, and drops per ring
- count Rx frames dropped by the driver in rx_packets and rx_bytes
- disable BH instead of preemption around the Tx flush stats update
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Daniel Zahka (4):
eth: mpnic: count packets, bytes, and drops per ring
eth: mpnic: report per-queue stats
eth: mpnic: count Tx queue stops and wakes
eth: mpnic: count Rx allocation failures

 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 182 ++++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.h |  29 ++++
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.c   | 183 ++++++++++++++++++++++---
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.h   |  30 ++++
 4 files changed, 406 insertions(+), 18 deletions(-)

---
base-commit: d8674294aefef02266c4d47ad10131f1bffbe534
change-id: 20261002-mpnic-counters3-d08883b96372

Best regards,

Signature · 1 line
Daniel Zahka <[email protected]>
#1 lore raw

PATCH v2 1/4 eth: mpnic: count packets, bytes, and drops per ring

Keep packet, byte and drop counters on each Tx work, Tx completion, and Rx completion queue. Report them to the core via the rtnl_link_stats64 interface.

Rx completion queues also count errors. Frames the device marked with an uncorrectable error are counted as errors, and frames that fail for any other reason are counted as drops.

All packets cleaned from the TWQ during mpnic_flush() are counted as drops, though completions for some of them may have been DMA'd into the completion ring between the time mpnic_poll() last ran and before mpnic_wait_all_queues_idle() returns. This is done for code simplicity.

An RCU approach is used because ndo_get_stats64 is not called with the instance lock.

---
v2:
- count Rx frames dropped by the driver in rx_packets and rx_bytes
- disable BH instead of preemption around the Tx flush stats update

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c |  76 +++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.h |  26 ++++++
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.c   | 123 +++++++++++++++++++++++--
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.h   |  24 +++++
 4 files changed, 241 insertions(+), 8 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +76 -0
index bd10df4a9d46..5164475a0f94 100644
@@ -28,6 +28,8 @@ static int mpnic_open(struct net_device *netdev)
 	if (err)
 		goto err_free_resources;
 
+	mpnic_stats_attach_rings(mpn);
+
 	mpnic_enable(mpn);
 	mpnic_fill(mpn);
 	mpnic_napi_enable(mpn);
@@ -60,6 +62,8 @@ static int mpnic_stop(struct net_device *netdev)
 	mpnic_wait_all_queues_idle(mpn->mpd);
 	mpnic_flush(mpn);
 
+	mpnic_stats_fold_rings(mpn);
+
 	mpnic_reset_netif_queues(mpn);
 	mpnic_free_resources(mpn);
 	mpnic_free_napi_vectors(mpn);
@@ -67,11 +71,79 @@ static int mpnic_stop(struct net_device *netdev)
 	return 0;
 }
 
+static void
+mpnic_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	u64 bytes, packets, dropped, errors;
+	struct mpnic_queue_stats *stats;
+	struct mpnic_base_stats *base;
+	unsigned int start, i;
+
+	rcu_read_lock();
+
+	base = rcu_dereference(mpn->stats.base);
+
+	stats64->tx_bytes = base->tx.bytes;
+	stats64->tx_packets = base->tx.packets;
+	stats64->tx_dropped = base->tx.dropped;
+
+	stats64->rx_bytes = base->rx.bytes;
+	stats64->rx_packets = base->rx.packets;
+	stats64->rx_dropped = base->rx.dropped;
+	stats64->rx_errors = base->rx.errors;
+
+	for (i = 0; i < base->num_tx_queues; i++) {
+		struct mpnic_ring *txr = base->txr[i];
+		struct mpnic_q_triad *qt;
+
+		qt = container_of(txr, struct mpnic_q_triad, sub0);
+
+		stats = &qt->cmpl.stats;
+		do {
+			start = u64_stats_fetch_begin(&stats->syncp);
+			bytes = u64_stats_read(&stats->tcq.bytes);
+			packets = u64_stats_read(&stats->tcq.packets);
+		} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+		stats = &txr->stats;
+		do {
+			start = u64_stats_fetch_begin(&stats->syncp);
+			dropped = u64_stats_read(&stats->twq.dropped);
+		} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+		stats64->tx_bytes += bytes;
+		stats64->tx_packets += packets;
+		stats64->tx_dropped += dropped;
+	}
+
+	for (i = 0; i < base->num_rx_queues; i++) {
+		struct mpnic_ring *rxr = base->rxr[i];
+
+		stats = &rxr->stats;
+		do {
+			start = u64_stats_fetch_begin(&stats->syncp);
+			bytes = u64_stats_read(&stats->rcq.bytes);
+			packets = u64_stats_read(&stats->rcq.packets);
+			dropped = u64_stats_read(&stats->rcq.dropped);
+			errors = u64_stats_read(&stats->rcq.errors);
+		} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+		stats64->rx_bytes += bytes;
+		stats64->rx_packets += packets;
+		stats64->rx_dropped += dropped;
+		stats64->rx_errors += errors;
+	}
+
+	rcu_read_unlock();
+}
+
 static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_open		= mpnic_open,
 	.ndo_stop		= mpnic_stop,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_start_xmit		= mpnic_xmit_frame,
+	.ndo_get_stats64	= mpnic_get_stats64,
 };
 
 /**
@@ -110,6 +182,10 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
 	mpn->netdev = netdev;
 	mpn->mpd = mpd;
 
+	mpn->stats.buf[0].txr = mpn->tx;
+	mpn->stats.buf[0].rxr = mpn->rx;
+	RCU_INIT_POINTER(mpn->stats.base, &mpn->stats.buf[0]);
+
 	mpn->txq_size = MPNIC_TXQ_SIZE_DEFAULT;
 	mpn->hpq_size = MPNIC_HPQ_SIZE_DEFAULT;
 	mpn->ppq_size = MPNIC_PPQ_SIZE_DEFAULT;
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +26 -0
index ccb0929f9180..a61249d12a04 100644
@@ -4,11 +4,32 @@
 #ifndef _MPNIC_NETDEV_H_
 #define _MPNIC_NETDEV_H_
 
+#include <linux/netdevice.h>
+#include <linux/rcupdate.h>
 #include <linux/types.h>
 
 #include "mpnic.h"
 #include "mpnic_txrx.h"
 
+struct mpnic_base_stats {
+	struct {
+		u64 packets;
+		u64 bytes;
+		u64 dropped;
+	} tx;
+	struct {
+		u64 packets;
+		u64 bytes;
+		u64 dropped;
+		u64 errors;
+	} rx;
+
+	unsigned int num_tx_queues;
+	unsigned int num_rx_queues;
+	struct mpnic_ring **txr;
+	struct mpnic_ring **rxr;
+};
+
 struct mpnic_net {
 	struct mpnic_ring *tx[MPNIC_MAX_TXQS];
 	struct mpnic_ring *rx[MPNIC_MAX_RXQS];
@@ -26,6 +47,11 @@ struct mpnic_net {
 	u16 num_napi;
 	u16 num_tx_queues;
 	u16 num_rx_queues;
+
+	struct {
+		struct mpnic_base_stats __rcu *base;
+		struct mpnic_base_stats buf[2];
+	} stats;
 };
 
 struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd);
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +115 -8

199 lines not on this page · raw message

drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +24 -0
index 767d87a36c35..7b44cf700e5b 100644
@@ -8,6 +8,7 @@
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
 #include <linux/types.h>
+#include <linux/u64_stats_sync.h>
 #include <net/netdev_queues.h>
 #include <net/xdp.h>
 
@@ -84,6 +85,25 @@ struct mpnic_rcq_state {
 	struct mpnic_pg_ctxt payld;
 };
 
+struct mpnic_queue_stats {
+	union {
+		struct {
+			u64_stats_t dropped;
+		} twq;
+		struct {
+			u64_stats_t packets;
+			u64_stats_t bytes;
+		} tcq;
+		struct {
+			u64_stats_t packets;
+			u64_stats_t bytes;
+			u64_stats_t dropped;
+			u64_stats_t errors;
+		} rcq;
+	};
+	struct u64_stats_sync syncp;
+};
+
 struct mpnic_ring {
 	union {
 		struct mpnic_rcq_state *state;	/* RCQ */
@@ -110,6 +130,8 @@ struct mpnic_ring {
 		s32 deferred_meta;
 	};
 
+	struct mpnic_queue_stats stats;
+
 	/* Slow path fields follow */
 	dma_addr_t dma;			/* Phys addr of descriptor memory */
 	size_t size;			/* Size of descriptor ring in memory */
@@ -142,6 +164,8 @@ struct mpnic_napi_vector {
 netdev_tx_t mpnic_xmit_frame(struct sk_buff *skb, struct net_device *dev);
 int mpnic_alloc_napi_vectors(struct mpnic_net *mpn);
 void mpnic_free_napi_vectors(struct mpnic_net *mpn);
+void mpnic_stats_attach_rings(struct mpnic_net *mpn);
+void mpnic_stats_fold_rings(struct mpnic_net *mpn);
 int mpnic_alloc_resources(struct mpnic_net *mpn);
 void mpnic_free_resources(struct mpnic_net *mpn);
 int mpnic_set_netif_queues(struct mpnic_net *mpn);
Signature · 1 line
2.52.0
#15 lore raw

PATCH v2 2/4 eth: mpnic: report per-queue stats

In reply to Daniel Zahka

Expose the per-ring packet and byte counters through the queue stats API. Counters for deactivated rings are reported through the base stats.

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 73 ++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +73 -0
index 5164475a0f94..c2f4a326a8f0 100644
@@ -6,6 +6,7 @@
 #include <linux/netdevice.h>
 #include <linux/pci.h>
 #include <linux/types.h>
+#include <net/netdev_lock.h>
 
 #include "mpnic.h"
 #include "mpnic_netdev.h"
@@ -146,6 +147,77 @@ static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_get_stats64	= mpnic_get_stats64,
 };
 
+static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx,
+				     struct netdev_queue_stats_rx *rx)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	struct mpnic_ring *rxr = mpn->rx[idx];
+	struct mpnic_queue_stats *stats;
+	unsigned int start;
+	u64 bytes, packets;
+
+	if (!rxr)
+		return;
+
+	stats = &rxr->stats;
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		bytes = u64_stats_read(&stats->rcq.bytes);
+		packets = u64_stats_read(&stats->rcq.packets);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	rx->bytes = bytes;
+	rx->packets = packets;
+}
+
+static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
+				     struct netdev_queue_stats_tx *tx)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	struct mpnic_ring *txr = mpn->tx[idx];
+	struct mpnic_queue_stats *stats;
+	struct mpnic_q_triad *qt;
+	unsigned int start;
+	u64 bytes, packets;
+
+	if (!txr)
+		return;
+
+	qt = container_of(txr, struct mpnic_q_triad, sub0);
+
+	stats = &qt->cmpl.stats;
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		bytes = u64_stats_read(&stats->tcq.bytes);
+		packets = u64_stats_read(&stats->tcq.packets);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	tx->bytes = bytes;
+	tx->packets = packets;
+}
+
+static void mpnic_get_base_stats(struct net_device *dev,
+				 struct netdev_queue_stats_rx *rx,
+				 struct netdev_queue_stats_tx *tx)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	struct mpnic_base_stats *base;
+
+	base = netdev_lock_dereference(mpn->stats.base, dev);
+
+	tx->bytes = base->tx.bytes;
+	tx->packets = base->tx.packets;
+
+	rx->bytes = base->rx.bytes;
+	rx->packets = base->rx.packets;
+}
+
+static const struct netdev_stat_ops mpnic_stat_ops = {
+	.get_queue_stats_rx	= mpnic_get_queue_stats_rx,
+	.get_queue_stats_tx	= mpnic_get_queue_stats_tx,
+	.get_base_stats		= mpnic_get_base_stats,
+};
+
 /**
  * mpnic_netdev_free - Free the netdev associated with mpnic
  * @mpd: Driver specific structure to free netdev from
@@ -176,6 +248,7 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
 	mpd->netdev = netdev;
 
 	netdev->netdev_ops = &mpnic_netdev_ops;
+	netdev->stat_ops = &mpnic_stat_ops;
 	netdev->request_ops_lock = true;
 
 	mpn = netdev_priv(netdev);
Signature · 1 line
2.52.0
#19 lore raw

PATCH v2 3/4 eth: mpnic: count Tx queue stops and wakes

In reply to Daniel Zahka

Count how often a Tx queue is stopped for lack of descriptors and woken again by completions, and report the counts through the queue stats API.

Stops are counted on the TWQ from the xmit path and wakes on the TCQ from mpnic_poll(), keeping a single writer context for each.

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 13 ++++++++-
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.h |  2 ++
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.c   | 37 +++++++++++++++++++-------
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.h   |  2 ++
 4 files changed, 44 insertions(+), 10 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +12 -1
index c2f4a326a8f0..9e262f939c79 100644
@@ -176,9 +176,9 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
 	struct mpnic_net *mpn = netdev_priv(dev);
 	struct mpnic_ring *txr = mpn->tx[idx];
 	struct mpnic_queue_stats *stats;
+	u64 bytes, packets, stop, wake;
 	struct mpnic_q_triad *qt;
 	unsigned int start;
-	u64 bytes, packets;
 
 	if (!txr)
 		return;
@@ -190,10 +190,19 @@ static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
 		start = u64_stats_fetch_begin(&stats->syncp);
 		bytes = u64_stats_read(&stats->tcq.bytes);
 		packets = u64_stats_read(&stats->tcq.packets);
+		wake = u64_stats_read(&stats->tcq.wake);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	stats = &txr->stats;
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		stop = u64_stats_read(&stats->twq.stop);
 	} while (u64_stats_fetch_retry(&stats->syncp, start));
 
 	tx->bytes = bytes;
 	tx->packets = packets;
+	tx->stop = stop;
+	tx->wake = wake;
 }
 
 static void mpnic_get_base_stats(struct net_device *dev,
@@ -207,6 +216,8 @@ static void mpnic_get_base_stats(struct net_device *dev,
 
 	tx->bytes = base->tx.bytes;
 	tx->packets = base->tx.packets;
+	tx->stop = base->tx.stop;
+	tx->wake = base->tx.wake;
 
 	rx->bytes = base->rx.bytes;
 	rx->packets = base->rx.packets;
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +2 -0
index a61249d12a04..0d1ee66dd86c 100644
@@ -16,6 +16,8 @@ struct mpnic_base_stats {
 		u64 packets;
 		u64 bytes;
 		u64 dropped;
+		u64 stop;
+		u64 wake;
 	} tx;
 	struct {
 		u64 packets;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +28 -9
index d5185e64f804..931e1031a180 100644
@@ -68,6 +68,23 @@ static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev,
 	return netdev_get_tx_queue(dev, ring->q_idx);
 }
 
+static bool
+mpnic_maybe_stop_tx(const struct net_device *dev, struct mpnic_ring *ring)
+{
+	int res;
+
+	res = netif_txq_maybe_stop(mpnic_txring_txq(dev, ring),
+				   mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC,
+				   MPNIC_TX_DESC_WAKEUP);
+	if (!res) {
+		u64_stats_update_begin(&ring->stats.syncp);
+		u64_stats_inc(&ring->stats.twq.stop);
+		u64_stats_update_end(&ring->stats.syncp);
+	}
+
+	return !res;
+}
+
 static void mpnic_tx_doorbell(struct mpnic_ring *ring, __le64 *meta)
 {
 	*meta |= cpu_to_le64(MPNIC_TWD_FLAG_REQ_COMPLETION);
@@ -164,9 +181,7 @@ mpnic_tx_map(struct mpnic_ring *ring, struct sk_buff *skb, __le64 *meta)
 	ring->tail = tail;
 
 	/* Verify there is room for another packet */
-	netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring),
-			     mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC,
-			     MPNIC_TX_DESC_WAKEUP);
+	mpnic_maybe_stop_tx(skb->dev, ring);
 
 	if (__netdev_tx_sent_queue(mpnic_txring_txq(skb->dev, ring),
 				   MPNIC_XMIT_CB(skb)->bytecount,
@@ -204,9 +219,7 @@ static netdev_tx_t mpnic_xmit_frame_ring(struct sk_buff *skb,
 	if (skb_put_padto(skb, MPNIC_MIN_FRAME_LEN))
 		goto err_drop;
 
-	if (!netif_txq_maybe_stop(mpnic_txring_txq(skb->dev, ring),
-				  mpnic_desc_unused(ring), MPNIC_MAX_SKB_DESC,
-				  MPNIC_TX_DESC_WAKEUP)) {
+	if (mpnic_maybe_stop_tx(skb->dev, ring)) {
 		mpnic_tx_flush_doorbell(ring);
 		return NETDEV_TX_BUSY;
 	}
@@ -310,9 +323,13 @@ static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget,
 	u64_stats_update_end(&cmpl->stats.syncp);
 
 	txq = mpnic_txring_txq(nv->napi.dev, ring);
-	netif_txq_completed_wake(txq, total_packets, total_bytes,
-				 mpnic_desc_unused(ring),
-				 MPNIC_TX_DESC_WAKEUP);
+	if (!netif_txq_completed_wake(txq, total_packets, total_bytes,
+				      mpnic_desc_unused(ring),
+				      MPNIC_TX_DESC_WAKEUP)) {
+		u64_stats_update_begin(&cmpl->stats.syncp);
+		u64_stats_inc(&cmpl->stats.tcq.wake);
+		u64_stats_update_end(&cmpl->stats.syncp);
+	}
 }
 
 static void mpnic_commit_cq_head(struct mpnic_ring *cmpl)
@@ -697,6 +714,7 @@ static void mpnic_aggregate_ring_twq_counters(struct mpnic_base_stats *base,
 					      struct mpnic_ring *twq)
 {
 	base->tx.dropped += u64_stats_read(&twq->stats.twq.dropped);
+	base->tx.stop += u64_stats_read(&twq->stats.twq.stop);
 }
 
 static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base,
@@ -704,6 +722,7 @@ static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base,
 {
 	base->tx.packets += u64_stats_read(&tcq->stats.tcq.packets);
 	base->tx.bytes += u64_stats_read(&tcq->stats.tcq.bytes);
+	base->tx.wake += u64_stats_read(&tcq->stats.tcq.wake);
 }
 
 static void mpnic_aggregate_ring_rcq_counters(struct mpnic_base_stats *base,
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +2 -0
index 7b44cf700e5b..764e78918b8f 100644
@@ -89,10 +89,12 @@ struct mpnic_queue_stats {
 	union {
 		struct {
 			u64_stats_t dropped;
+			u64_stats_t stop;
 		} twq;
 		struct {
 			u64_stats_t packets;
 			u64_stats_t bytes;
+			u64_stats_t wake;
 		} tcq;
 		struct {
 			u64_stats_t packets;
Signature · 1 line
2.52.0
#20 lore raw

PATCH v2 4/4 eth: mpnic: count Rx allocation failures

In reply to Daniel Zahka

Count both skb allocation failures and page pool allocation failures per queue, and report them through the queue stats API. The bdq allocation failures are added to the skb allocation failures when reporting to core and folded into base stats during aggregation, because the qstats API doesn't support reporting them separately.

Page pool allocation failures are also counted when the BDQs are first filled in ndo_open, which runs in process context. mpnic_fill() disables BH around the fill, so the u64_stats update happens with preemption disabled.

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 24 ++++++++++++++++++++++-
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.h |  1 +
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.c   | 27 +++++++++++++++++++++++---
 drivers/net/ethernet/meta/mpnic/mpnic_txrx.h   |  4 ++++
 4 files changed, 52 insertions(+), 4 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +23 -1
index 9e262f939c79..7fdf57f70151 100644
@@ -147,14 +147,29 @@ static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_get_stats64	= mpnic_get_stats64,
 };
 
+static u64 mpnic_bdq_alloc_failed(struct mpnic_ring *bdq)
+{
+	struct mpnic_queue_stats *stats = &bdq->stats;
+	unsigned int start;
+	u64 alloc_failed;
+
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		alloc_failed = u64_stats_read(&stats->bdq.alloc_failed);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	return alloc_failed;
+}
+
 static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx,
 				     struct netdev_queue_stats_rx *rx)
 {
 	struct mpnic_net *mpn = netdev_priv(dev);
 	struct mpnic_ring *rxr = mpn->rx[idx];
+	u64 bytes, packets, alloc_failed;
 	struct mpnic_queue_stats *stats;
+	struct mpnic_q_triad *qt;
 	unsigned int start;
-	u64 bytes, packets;
 
 	if (!rxr)
 		return;
@@ -164,10 +179,16 @@ static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx,
 		start = u64_stats_fetch_begin(&stats->syncp);
 		bytes = u64_stats_read(&stats->rcq.bytes);
 		packets = u64_stats_read(&stats->rcq.packets);
+		alloc_failed = u64_stats_read(&stats->rcq.alloc_failed);
 	} while (u64_stats_fetch_retry(&stats->syncp, start));
 
+	qt = container_of(rxr, struct mpnic_q_triad, cmpl);
+	alloc_failed += mpnic_bdq_alloc_failed(&qt->sub0);
+	alloc_failed += mpnic_bdq_alloc_failed(&qt->sub1);
+
 	rx->bytes = bytes;
 	rx->packets = packets;
+	rx->alloc_fail = alloc_failed;
 }
 
 static void mpnic_get_queue_stats_tx(struct net_device *dev, int idx,
@@ -221,6 +242,7 @@ static void mpnic_get_base_stats(struct net_device *dev,
 
 	rx->bytes = base->rx.bytes;
 	rx->packets = base->rx.packets;
+	rx->alloc_fail = base->rx.alloc_failed;
 }
 
 static const struct netdev_stat_ops mpnic_stat_ops = {
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +1 -0
index 0d1ee66dd86c..6711766ebc3c 100644
@@ -23,6 +23,7 @@ struct mpnic_base_stats {
 		u64 packets;
 		u64 bytes;
 		u64 dropped;
+		u64 alloc_failed;
 		u64 errors;
 	} rx;
 
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +24 -3
index 931e1031a180..93abdec44642 100644
@@ -409,8 +409,12 @@ static unsigned int __mpnic_fill_bdq(struct mpnic_ring *bdq)
 		struct page *page;
 
 		page = page_pool_dev_alloc_pages(bdq->page_pool);
-		if (!page)
+		if (!page) {
+			u64_stats_update_begin(&bdq->stats.syncp);
+			u64_stats_inc(&bdq->stats.bdq.alloc_failed);
+			u64_stats_update_end(&bdq->stats.syncp);
 			break;
+		}
 
 		bdq->rx_buf[i] = page;
 		mpnic_bd_prep(bdq, i, page);
@@ -598,6 +602,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 	unsigned int packets = 0, bytes = 0, dropped = 0, errors = 0;
 	struct mpnic_ring *rcq = &qt->cmpl;
 	struct mpnic_rcq_state *state;
+	unsigned int alloc_failed = 0;
 	__le64 *raw_rcd, done;
 	u32 head = rcq->head;
 
@@ -632,6 +637,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 				   !state->pkt.add_frag_failed)) {
 				bytes += xdp_get_buff_len(&state->pkt.buff);
 				skb = xdp_build_skb_from_buff(&state->pkt.buff);
+				alloc_failed += !skb;
 			}
 
 			if (likely(skb)) {
@@ -665,6 +671,7 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 	u64_stats_add(&rcq->stats.rcq.packets, packets - errors);
 	u64_stats_add(&rcq->stats.rcq.bytes, bytes);
 	u64_stats_add(&rcq->stats.rcq.dropped, dropped);
+	u64_stats_add(&rcq->stats.rcq.alloc_failed, alloc_failed);
 	u64_stats_add(&rcq->stats.rcq.errors, errors);
 	u64_stats_update_end(&rcq->stats.syncp);
 
@@ -725,12 +732,19 @@ static void mpnic_aggregate_ring_tcq_counters(struct mpnic_base_stats *base,
 	base->tx.wake += u64_stats_read(&tcq->stats.tcq.wake);
 }
 
+static void mpnic_aggregate_ring_bdq_counters(struct mpnic_base_stats *base,
+					      struct mpnic_ring *bdq)
+{
+	base->rx.alloc_failed += u64_stats_read(&bdq->stats.bdq.alloc_failed);
+}
+
 static void mpnic_aggregate_ring_rcq_counters(struct mpnic_base_stats *base,
 					      struct mpnic_ring *rcq)
 {
 	base->rx.packets += u64_stats_read(&rcq->stats.rcq.packets);
 	base->rx.bytes += u64_stats_read(&rcq->stats.rcq.bytes);
 	base->rx.dropped += u64_stats_read(&rcq->stats.rcq.dropped);
+	base->rx.alloc_failed += u64_stats_read(&rcq->stats.rcq.alloc_failed);
 	base->rx.errors += u64_stats_read(&rcq->stats.rcq.errors);
 }
 
@@ -767,8 +781,13 @@ void mpnic_stats_fold_rings(struct mpnic_net *mpn)
 			mpnic_aggregate_ring_tcq_counters(new, &qt->cmpl);
 		}
 
-		for (j = 0; j < nv->rxt_count; j++, t++)
-			mpnic_aggregate_ring_rcq_counters(new, &nv->qt[t].cmpl);
+		for (j = 0; j < nv->rxt_count; j++, t++) {
+			struct mpnic_q_triad *qt = &nv->qt[t];
+
+			mpnic_aggregate_ring_bdq_counters(new, &qt->sub0);
+			mpnic_aggregate_ring_bdq_counters(new, &qt->sub1);
+			mpnic_aggregate_ring_rcq_counters(new, &qt->cmpl);
+		}
 	}
 
 	rcu_assign_pointer(mpn->stats.base, new);
@@ -1494,7 +1513,9 @@ void mpnic_fill(struct mpnic_net *mpn)
 			state->hdr.idx = UINT_MAX;
 			state->payld.idx = UINT_MAX;
 
+			local_bh_disable();
 			mpnic_fill_qt_bdqs(qt);
+			local_bh_enable();
 		}
 	}
 }
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +4 -0
index 764e78918b8f..52492e3f484f 100644
@@ -100,8 +100,12 @@ struct mpnic_queue_stats {
 			u64_stats_t packets;
 			u64_stats_t bytes;
 			u64_stats_t dropped;
+			u64_stats_t alloc_failed;
 			u64_stats_t errors;
 		} rcq;
+		struct {
+			u64_stats_t alloc_failed;
+		} bdq;
 	};
 	struct u64_stats_sync syncp;
 };
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Daniel Zahka
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In mpnic_clean_rcq() (drivers/net/ethernet/meta/mpnic/mpnic_txrx.c), an Rx frame the driver…

--

eth: mpnic: count packets, bytes, and drops per ring

This commit adds packet, byte, drop and error counters to each Tx work, Tx completion and Rx completion ring in the mpnic driver. The counters are reported through ndo_get_stats64. An RCU-protected base snapshot holds the totals folded in from rings that have been torn down.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0 -0
index 5495e9a9aa651..d5185e64f804c 100644

[ ... ]

Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4 -3
@@ -594,13 +612,20 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 
 			if (likely(!(rcd &
 				     MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) &&
-				   !state->pkt.add_frag_failed))
+				   !state->pkt.add_frag_failed)) {
+				bytes += xdp_get_buff_len(&state->pkt.buff);
 				skb = xdp_build_skb_from_buff(&state->pkt.buff);
+			}
 
-			if (likely(skb))
+			if (likely(skb)) {
 				napi_gro_receive(&nv->napi, skb);
-			else

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, · line 631

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6 -0
+			} else {
 				mpnic_put_pkt_buff(&state->pkt, true);
+				if (rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK)
+					errors++;
+				else
+					dropped++;
+			}
 
 			state->pkt.buff.data_hard_start = NULL;
 			packets++;

[Severity: Medium]
Is rx_bytes undercounted for frames that are dropped because state->pkt.add_frag_failed is set?

mpnic_add_rx_frag() sets add_frag_failed when xdp_buff_add_frag() fails. That happens once nr_frags reaches MAX_SKB_FRAGS and the fragment cannot be coalesced:

mpnic_add_rx_frag() {
    ...
	if (!xdp_buff_add_frag(buff, page_to_netmem(page), pg_off, len,
			       truesz)) {
		state->payld.pagecnt_bias++;
		state->pkt.add_frag_failed = true;
	}
}

For such a frame the guarded branch above is skipped, so nothing is added to bytes. skb stays NULL and the uncorrectable error bit is clear, so dropped++ runs. packets++ runs unconditionally.

The frame is then counted in rcq.packets through packets - errors, but it adds nothing to rcq.bytes:

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, · line 652

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6 -0
@@ -619,6 +644,13 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 
 	rcq->head = head;
 
+	u64_stats_update_begin(&rcq->stats.syncp);
+	u64_stats_add(&rcq->stats.rcq.packets, packets - errors);
+	u64_stats_add(&rcq->stats.rcq.bytes, bytes);
+	u64_stats_add(&rcq->stats.rcq.dropped, dropped);
+	u64_stats_add(&rcq->stats.rcq.errors, errors);
+	u64_stats_update_end(&rcq->stats.syncp);

mpnic_get_stats64() and mpnic_stats_fold_rings() report these values as rx_packets and rx_bytes. The rtnl_link_stats64 kernel-doc says rx_packets includes packets dropped by the driver, and that rx_bytes corresponds to rx_packets.

The v2 changelog says:

- count Rx frames dropped by the driver in rx_packets and rx_bytes

That seems true only for the xdp_build_skb_from_buff() failure path.

The same counters are used by mpnic_get_queue_stats_rx(), which is added later in this series in "eth: mpnic: report per-queue stats". The code looks the same at the end of the series, apart from the new alloc_failed counter.

Moving the bytes += line out of the guarded branch might not be enough by itself. __xdp_buff_add_frag() returns before it adds the rejected fragment to xdp_frags_size:

	} else if (unlikely(nr_frags == MAX_SKB_FRAGS)) {
		return false;
	} else {
	...
	sinfo->xdp_frags_size += size;

Would it work to track the lengths reported by the descriptors separately here? If not, should the changelog be reworded?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012-mpnic-counters3-v2-0-8afba81c2d5a%40gmail.com
#16 lore raw

Re: [PATCH net-next v2 2/4] eth: mpnic: report per-queue stats

In reply to Daniel Zahka
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] This patch reports the RCQ rcq.packets and rcq.bytes counters as the netdev qstats rx-packets and rx-bytes attributes.

--

eth: mpnic: report per-queue stats

This commit exposes the per-ring packet and byte counters through the netdev queue stats API. Counters for deactivated rings are reported through the base stats.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 5164475a0f943..c2f4a326a8f0f 100644

[ ... ]

Quoted 16 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +12 -0
@@ -146,6 +147,77 @@ static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_get_stats64	= mpnic_get_stats64,
 };
 
+static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx,
+				     struct netdev_queue_stats_rx *rx)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	struct mpnic_ring *rxr = mpn->rx[idx];
+	struct mpnic_queue_stats *stats;
+	unsigned int start;
+	u64 bytes, packets;
+
+	if (!rxr)
+		return;
+

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static const struct net_device_ops mpnic_netdev_ops = { · line 171

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +10 -0
+	stats = &rxr->stats;
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		bytes = u64_stats_read(&stats->rcq.bytes);
+		packets = u64_stats_read(&stats->rcq.packets);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	rx->bytes = bytes;
+	rx->packets = packets;
+}

[Severity: Medium]
Do rcq.packets and rcq.bytes match the qstats meaning of rx-packets and rx-bytes?

The netdev.yaml spec defines rx-packets as "Number of wire packets successfully received and passed to the stack". It defines rx-bytes as "Successfully received bytes, see rx-packets".

In mpnic_clean_rcq() in mpnic_txrx.c, packets++ runs for every META completion, including completions where the driver drops the packet:

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:mpnic_clean_rcq() {
    ...
			if (likely(!(rcd &
				     MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) &&
				   !state->pkt.add_frag_failed)) {
				bytes += xdp_get_buff_len(&state->pkt.buff);
				skb = xdp_build_skb_from_buff(&state->pkt.buff);
			}

			if (likely(skb)) {
				napi_gro_receive(&nv->napi, skb);
			} else {
				mpnic_put_pkt_buff(&state->pkt, true);
				if (rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK)
					errors++;
				else
					dropped++;
			}

			state->pkt.buff.data_hard_start = NULL;
			packets++;
    ...
	u64_stats_add(&rcq->stats.rcq.packets, packets - errors);
	u64_stats_add(&rcq->stats.rcq.bytes, bytes);
	u64_stats_add(&rcq->stats.rcq.dropped, dropped);
    ...
}

Only errors are subtracted from packets. If add_frag_failed is set, or if xdp_build_skb_from_buff() returns NULL, the packet is counted in dropped and also in rx-packets.

The buffer length is also added to bytes before xdp_build_skb_from_buff() runs. A failed skb build therefore still counts toward rx-bytes. An add_frag_failed drop adds to packets but not to bytes, so the two counters also disagree with each other.

mpnic_get_base_stats() reports the same values once mpnic_aggregate_ring_rcq_counters() folds them into base->rx. The miscount carries over after a ring is deactivated.

fbnic_clean_rcq() handles this by jumping to next_dont_count for dropped packets, so they are counted in neither packets nor bytes. Could mpnic do the same?

The counter semantics come from "eth: mpnic: count packets, bytes, and drops per ring" earlier in this series. This patch is the one that exposes them as qstats rx-packets and rx-bytes.

The later patch "eth: mpnic: count Rx allocation failures" also counts skb build failures in alloc_failed. Those packets still stay in packets and bytes.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012-mpnic-counters3-v2-0-8afba81c2d5a%40gmail.com
#3 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to [email protected]
Quoted 110 lines · netdev-bot+sashiko

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In mpnic_clean_rcq() (drivers/net/ethernet/meta/mpnic/mpnic_txrx.c), an Rx frame the driver…

--

eth: mpnic: count packets, bytes, and drops per ring

This commit adds packet, byte, drop and error counters to each Tx work, Tx completion and Rx completion ring in the mpnic driver. The counters are reported through ndo_get_stats64. An RCU-protected base snapshot holds the totals folded in from rings that have been torn down.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0 -0
index 5495e9a9aa651..d5185e64f804c 100644

[ ... ]

Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4 -3
@@ -594,13 +612,20 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 
 			if (likely(!(rcd &
 				     MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) &&
-				   !state->pkt.add_frag_failed))
+				   !state->pkt.add_frag_failed)) {
+				bytes += xdp_get_buff_len(&state->pkt.buff);
 				skb = xdp_build_skb_from_buff(&state->pkt.buff);
+			}
 
-			if (likely(skb))
+			if (likely(skb)) {
 				napi_gro_receive(&nv->napi, skb);
-			else

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, · line 631

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6 -0
+			} else {
 				mpnic_put_pkt_buff(&state->pkt, true);
+				if (rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK)
+					errors++;
+				else
+					dropped++;
+			}
 
 			state->pkt.buff.data_hard_start = NULL;
 			packets++;

[Severity: Medium]
Is rx_bytes undercounted for frames that are dropped because state->pkt.add_frag_failed is set?

mpnic_add_rx_frag() sets add_frag_failed when xdp_buff_add_frag() fails. That happens once nr_frags reaches MAX_SKB_FRAGS and the fragment cannot be coalesced:

mpnic_add_rx_frag() {
    ...
	if (!xdp_buff_add_frag(buff, page_to_netmem(page), pg_off, len,
			       truesz)) {
		state->payld.pagecnt_bias++;
		state->pkt.add_frag_failed = true;
	}
}

For such a frame the guarded branch above is skipped, so nothing is added to bytes. skb stays NULL and the uncorrectable error bit is clear, so dropped++ runs. packets++ runs unconditionally.

The frame is then counted in rcq.packets through packets - errors, but it adds nothing to rcq.bytes:

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static int mpnic_clean_rcq(struct mpnic_napi_vector *nv, · line 652

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6 -0
@@ -619,6 +644,13 @@ static int mpnic_clean_rcq(struct mpnic_napi_vector *nv,
 
 	rcq->head = head;
 
+	u64_stats_update_begin(&rcq->stats.syncp);
+	u64_stats_add(&rcq->stats.rcq.packets, packets - errors);
+	u64_stats_add(&rcq->stats.rcq.bytes, bytes);
+	u64_stats_add(&rcq->stats.rcq.dropped, dropped);
+	u64_stats_add(&rcq->stats.rcq.errors, errors);
+	u64_stats_update_end(&rcq->stats.syncp);

mpnic_get_stats64() and mpnic_stats_fold_rings() report these values as rx_packets and rx_bytes. The rtnl_link_stats64 kernel-doc says rx_packets includes packets dropped by the driver, and that rx_bytes corresponds to rx_packets.

The v2 changelog says:

- count Rx frames dropped by the driver in rx_packets and rx_bytes

That seems true only for the xdp_build_skb_from_buff() failure path.

The same counters are used by mpnic_get_queue_stats_rx(), which is added later in this series in "eth: mpnic: report per-queue stats". The code looks the same at the end of the series, apart from the new alloc_failed counter.

Moving the bytes += line out of the guarded branch might not be enough by itself. __xdp_buff_add_frag() returns before it adds the rejected fragment to xdp_frags_size:

Quoted 8 lines
	} else if (unlikely(nr_frags == MAX_SKB_FRAGS)) {
		return false;
	} else {
	...
	sinfo->xdp_frags_size += size;

Would it work to track the lengths reported by the descriptors separately here? If not, should the changelog be reworded?

This is intentional. Summing the bytes of dropped parts of the payload and using that to adjust the rx byte count is a large change that I don't think is worth it, given that with our supported MTU size each skb should have a max of 4 frags.

#17 lore raw

Re: [PATCH net-next v2 2/4] eth: mpnic: report per-queue stats

In reply to [email protected]
Quoted 104 lines · netdev-bot+sashiko

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] This patch reports the RCQ rcq.packets and rcq.bytes counters as the netdev qstats rx-packets and rx-bytes attributes.

--

eth: mpnic: report per-queue stats

This commit exposes the per-ring packet and byte counters through the netdev queue stats API. Counters for deactivated rings are reported through the base stats.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 5164475a0f943..c2f4a326a8f0f 100644

[ ... ]

Quoted 16 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +12 -0
@@ -146,6 +147,77 @@ static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_get_stats64	= mpnic_get_stats64,
 };
 
+static void mpnic_get_queue_stats_rx(struct net_device *dev, int idx,
+				     struct netdev_queue_stats_rx *rx)
+{
+	struct mpnic_net *mpn = netdev_priv(dev);
+	struct mpnic_ring *rxr = mpn->rx[idx];
+	struct mpnic_queue_stats *stats;
+	unsigned int start;
+	u64 bytes, packets;
+
+	if (!rxr)
+		return;
+

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static const struct net_device_ops mpnic_netdev_ops = { · line 171

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +10 -0
+	stats = &rxr->stats;
+	do {
+		start = u64_stats_fetch_begin(&stats->syncp);
+		bytes = u64_stats_read(&stats->rcq.bytes);
+		packets = u64_stats_read(&stats->rcq.packets);
+	} while (u64_stats_fetch_retry(&stats->syncp, start));
+
+	rx->bytes = bytes;
+	rx->packets = packets;
+}

[Severity: Medium]
Do rcq.packets and rcq.bytes match the qstats meaning of rx-packets and rx-bytes?

The netdev.yaml spec defines rx-packets as "Number of wire packets successfully received and passed to the stack". It defines rx-bytes as "Successfully received bytes, see rx-packets".

In mpnic_clean_rcq() in mpnic_txrx.c, packets++ runs for every META completion, including completions where the driver drops the packet:

drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:mpnic_clean_rcq() {
    ...
			if (likely(!(rcd &
				     MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) &&
				   !state->pkt.add_frag_failed)) {
				bytes += xdp_get_buff_len(&state->pkt.buff);
				skb = xdp_build_skb_from_buff(&state->pkt.buff);
			}

			if (likely(skb)) {
				napi_gro_receive(&nv->napi, skb);
			} else {
				mpnic_put_pkt_buff(&state->pkt, true);
				if (rcd & MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK)
					errors++;
				else
					dropped++;
			}

			state->pkt.buff.data_hard_start = NULL;
			packets++;
    ...
	u64_stats_add(&rcq->stats.rcq.packets, packets - errors);
	u64_stats_add(&rcq->stats.rcq.bytes, bytes);
	u64_stats_add(&rcq->stats.rcq.dropped, dropped);
    ...
}

Only errors are subtracted from packets. If add_frag_failed is set, or if xdp_build_skb_from_buff() returns NULL, the packet is counted in dropped and also in rx-packets.

The buffer length is also added to bytes before xdp_build_skb_from_buff() runs. A failed skb build therefore still counts toward rx-bytes. An add_frag_failed drop adds to packets but not to bytes, so the two counters also disagree with each other.

Quoted 8 lines

mpnic_get_base_stats() reports the same values once mpnic_aggregate_ring_rcq_counters() folds them into base->rx. The miscount carries over after a ring is deactivated.

fbnic_clean_rcq() handles this by jumping to next_dont_count for dropped packets, so they are counted in neither packets nor bytes. Could mpnic do the same?

v1 of this series matched fbnic in this regard, but the bot pointed out correctly that rtnl stats docs say that packets received ok at the host, but dropped in the driver (mainly skb allocation failure here), should be counted in rx-packets.

Quoted 9 lines

The counter semantics come from "eth: mpnic: count packets, bytes, and drops per ring" earlier in this series. This patch is the one that exposes them as qstats rx-packets and rx-bytes.

The later patch "eth: mpnic: count Rx allocation failures" also counts skb build failures in alloc_failed. Those packets still stay in packets and bytes.

[ ... ]

So, the question is whether or not rx-packets, reported both to rtnl stats and qstats, should count drops in the driver. Here, drops are either running out of shinfo frags, but really just skb allocation failure.

The docs for rtnl stats strongly suggest an skb allocation failure should still be counted for rx-packets.

The docs for qstats imply the opposite. Especially when xdp is not present, which is the case as of this point. Once xdp is introduced, though, counting an skb allocation failure in rx-packets becomes reasonable by the qstats docs, because xdp runs before the point of skb allocation.

Another option would be reporting rx-packets differently for the two APIs. I think this is not desirable, and seems to violate what is in the stats.py selftest.

So, I could either submit a v3, which would just be reverting to v1, or take the approach here as is.

I'm going to hold off on sending a v3, unless there is some human feedback.

#4 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Daniel Zahka
Quoted 8 lines · Daniel Zahka

Keep packet, byte and drop counters on each Tx work, Tx completion, and Rx completion queue. Report them to the core via the rtnl_link_stats64 interface.

Rx completion queues also count errors. Frames the device marked with an uncorrectable error are counted as errors, and frames that fail for any other reason are counted as drops.

Quoted 7 lines

All packets cleaned from the TWQ during mpnic_flush() are counted as drops, though completions for some of them may have been DMA'd into the completion ring between the time mpnic_poll() last ran and before mpnic_wait_all_queues_idle() returns. This is done for code simplicity.

An RCU approach is used because ndo_get_stats64 is not called with the instance lock.

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Quoted 1 line

Sebastian

#5 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

Quoted 14 lines · Sebastian Andrzej Siewior
Quoted 13 lines · Daniel Zahka

Keep packet, byte and drop counters on each Tx work, Tx completion, and Rx completion queue. Report them to the core via the rtnl_link_stats64 interface.

Rx completion queues also count errors. Frames the device marked with an uncorrectable error are counted as errors, and frames that fail for any other reason are counted as drops.

All packets cleaned from the TWQ during mpnic_flush() are counted as drops, though completions for some of them may have been DMA'd into the completion ring between the time mpnic_poll() last ran and before mpnic_wait_all_queues_idle() returns. This is done for code simplicity.

Quoted 7 lines
Quoted 2 lines

An RCU approach is used because ndo_get_stats64 is not called with the instance lock.

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Quoted 3 lines
Quoted 1 line

Sebastian

#6 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

Quoted 8 lines · Daniel Zahka
Quoted 7 lines
Quoted 2 lines

An RCU approach is used because ndo_get_stats64 is not called with the instance lock.

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Quoted 7 lines

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

Right. But looking at hinic3_get_stats64() for instance (I just grabbed a random one) it simply does query the stats for each queue, add up, return. It probably does not drop the queues on down, just reallocates them while changing the number of queues (and maybe MTU).

Quoted 8 lines

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats. If the interface goes down and frees all its queues, then the stats are gone, true. But preserving them at the price of two (down+up) forced RCU grace period, I don't know. It looks like a bit too much.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Sebastian

maintainer Acked-by
#18 lore raw

Re: [PATCH net-next v2 2/4] eth: mpnic: report per-queue stats

In reply to Daniel Zahka
Quoted 22 lines · On Tue, 13 Oct 2026 09:30:02 -0400 Daniel Zahka wrote:
Quoted 7 lines

The counter semantics come from "eth: mpnic: count packets, bytes, and drops per ring" earlier in this series. This patch is the one that exposes them as qstats rx-packets and rx-bytes.

The later patch "eth: mpnic: count Rx allocation failures" also counts skb build failures in alloc_failed. Those packets still stay in packets and bytes.

So, the question is whether or not rx-packets, reported both to rtnl stats and qstats, should count drops in the driver. Here, drops are either running out of shinfo frags, but really just skb allocation failure.

The docs for rtnl stats strongly suggest an skb allocation failure should still be counted for rx-packets.

The docs for qstats imply the opposite. Especially when xdp is not present, which is the case as of this point. Once xdp is introduced, though, counting an skb allocation failure in rx-packets becomes reasonable by the qstats docs, because xdp runs before the point of skb allocation.

Quoted 6 lines

Another option would be reporting rx-packets differently for the two APIs. I think this is not desirable, and seems to violate what is in the stats.py selftest.

So, I could either submit a v3, which would just be reverting to v1, or take the approach here as is.

The rtnl stats and qstats are supposed to behave the same if maintained by SW. I should have been clearer in the doc but "XDP is considered the first layer" was supposed to mean - if you reach the point in the driver where you'd call an XDP prog - its a successful Rx, whether the XDP prog is actually attached & called, or is NULL & skipped.

I believe the series is good as is.

maintainer Acked-by
#7 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Sebastian Andrzej Siewior
Quoted 10 lines · On Mon, 19 Oct 2026 23:54:05 +0200 Sebastian Andrzej Siewior wrote:
Quoted 9 lines · Daniel Zahka
Quoted 4 lines

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

Quoted 8 lines
Quoted 3 lines

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

Right. But looking at hinic3_get_stats64() for instance (I just grabbed a random one) it simply does query the stats for each queue, add up, return. It probably does not drop the queues on down, just reallocates them while changing the number of queues (and maybe MTU).

I don't think pre-allocating stats for chips which supports thousands of queues is reasonable.

Quoted 11 lines
Quoted 8 lines

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

Quoted 3 lines

If the interface goes down and frees all its queues, then the stats are gone, true. But preserving them at the price of two (down+up) forced RCU grace period, I don't know. It looks like a bit too much.

This is a modern driver, the down / up path is not taken when interface is reconfigured. It's only taken when the interface is actually taken down or bought up. Which virtually never happens for a datacenter NIC.

I don't mean to dismiss your concerns, we agonized over this off-list for a week, and don't love the resulting flow, either. But I strongly prefer the RCU grace period that never really runs, but is easy to reason about, to more advanced fixes which use memory barriers etc.

Anyway, I'll punt to Paolo for the final call but I think this is fine.

#8 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Mon, 19 Oct 2026 23:54:05 +0200 Sebastian Andrzej Siewior wrote:
Quoted 12 lines · Daniel Zahka
Quoted 4 lines

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

Quoted 7 lines
Quoted 4 lines

Right. But looking at hinic3_get_stats64() for instance (I just grabbed a random one) it simply does query the stats for each queue, add up, return. It probably does not drop the queues on down, just reallocates them while changing the number of queues (and maybe MTU).

I don't think pre-allocating stats for chips which supports thousands of queues is reasonable.

I don't mean to pre-allocate stats. If device-down removes queues then the stats gone, so what. The queues could remain.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Quoted 5 lines
Quoted 2 lines

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

Quoted 7 lines
Quoted 3 lines

If the interface goes down and frees all its queues, then the stats are gone, true. But preserving them at the price of two (down+up) forced RCU grace period, I don't know. It looks like a bit too much.

This is a modern driver, the down / up path is not taken when interface is reconfigured. It's only taken when the interface is actually taken down or bought up. Which virtually never happens for a datacenter NIC.

So if this never happens, it might not be needed to preserve this. That force-RCU might not be needed. This does happen on down and I would assume that the device is no longer processing packets.

Quoted 4 lines

I don't mean to dismiss your concerns, we agonized over this off-list for a week, and don't love the resulting flow, either. But I strongly prefer the RCU grace period that never really runs, but is easy to reason about, to more advanced fixes which use memory barriers etc.

Right. If you think is all makes sense and is needed then why not. It just looks odd.

Quoted 3 lines

Anyway, I'll punt to Paolo for the final call but I think this is fine.

Sebastian

#9 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

Quoted 21 lines · Sebastian Andrzej Siewior
Quoted 20 lines · Jakub Kicinski
Quoted 18 lines · On Mon, 19 Oct 2026 23:54:05 +0200 Sebastian Andrzej Siewior wrote:
Quoted 5 lines · Daniel Zahka
Quoted 4 lines

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Quoted 7 lines

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

Right. But looking at hinic3_get_stats64() for instance (I just grabbed a random one) it simply does query the stats for each queue, add up, return. It probably does not drop the queues on down, just reallocates them while changing the number of queues (and maybe MTU).

Quoted 6 lines
Quoted 2 lines

I don't think pre-allocating stats for chips which supports thousands of queues is reasonable.

I don't mean to pre-allocate stats. If device-down removes queues then the stats gone, so what. The queues could remain.

hinic3 preallocates stats state for the max supported queues at registration time. That's why it doesn't keep aggregated base stats. It also doesn't implement the netdev_stat_ops API, and if it did, it would need a bit of a redesign to be able to report historical device level counters separately from live per-queue counters.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

Quoted 8 lines
Quoted 2 lines

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

The per queue stats are kept in per-napi state that is freed after folding in the down path and then zero allocated on the subsequent up.

maintainer
#10 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Sebastian Andrzej Siewior
Quoted 10 lines · On Tue, 20 Oct 2026 23:21:55 +0200 Sebastian Andrzej Siewior wrote:
Quoted 5 lines
Quoted 2 lines

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

Yes, that's intentional and recommended by the docs for queue stats.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

If the interface goes down and frees all its queues, then the stats are gone, true. But preserving them at the price of two (down+up) forced RCU grace period, I don't know. It looks like a bit too much.

This is a modern driver, the down / up path is not taken when interface is reconfigured. It's only taken when the interface is actually taken down or bought up. Which virtually never happens for a datacenter NIC.

So if this never happens, it might not be needed to preserve this. That force-RCU might not be needed. This does happen on down and I would assume that the device is no longer processing packets.

The (old) ndo for stats reading runs under RCU, only. AI will immediately point that out if we remove the sync.

May I ask why you care? Is there another driver you're trying to implement stats in? I'm not sure where you're coming from and therefore what to explain to you.

maintainer
#13 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Sebastian Andrzej Siewior
Quoted 59 lines · Sebastian Andrzej Siewior
Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Mon, 19 Oct 2026 23:54:05 +0200 Sebastian Andrzej Siewior wrote:
Quoted 12 lines · Daniel Zahka
Quoted 4 lines

Why do you have the two mpnic_base_stats and fold the stats into into it? My guess would be that on stop the counters are reset and you want to preserve the stats.

Not sure I understand. I think you are asking about two things:

1. Why have two mpnic_base_stats?

To avoid a separate heap allocation that can fail. Handling an allocation failure in the ndo_stop path when doing the aggregation into the base stats is tricky.

Quoted 7 lines
Quoted 4 lines

Right. But looking at hinic3_get_stats64() for instance (I just grabbed a random one) it simply does query the stats for each queue, add up, return. It probably does not drop the queues on down, just reallocates them while changing the number of queues (and maybe MTU).

I don't think pre-allocating stats for chips which supports thousands of queues is reasonable.

I don't mean to pre-allocate stats. If device-down removes queues then the stats gone, so what. The queues could remain.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

2. Why split stats into base stats and per queue stats, and why reset the per queue counts when the device transitions down?

This is the way the stats in netdev.yaml are exposed depending on the 'scope' request attribute. My reading of the relevant kernel docs is that the per queue counters are counting events for the current live queue, so it makes sense to reset them and fold those counts into the base stats when the interface is transitioned down.

Quoted 5 lines
Quoted 2 lines

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

Quoted 7 lines
Quoted 3 lines

If the interface goes down and frees all its queues, then the stats are gone, true. But preserving them at the price of two (down+up) forced RCU grace period, I don't know. It looks like a bit too much.

This is a modern driver, the down / up path is not taken when interface is reconfigured. It's only taken when the interface is actually taken down or bought up. Which virtually never happens for a datacenter NIC.

So if this never happens, it might not be needed to preserve this. That force-RCU might not be needed. This does happen on down and I would assume that the device is no longer processing packets.

Quoted 7 lines
Quoted 4 lines

I don't mean to dismiss your concerns, we agonized over this off-list for a week, and don't love the resulting flow, either. But I strongly prefer the RCU grace period that never really runs, but is easy to reason about, to more advanced fixes which use memory barriers etc.

Right. If you think is all makes sense and is needed then why not. It just looks odd.

Sebastian, my understanding is that your doubts are mostly because you are unfamiliar with the current reference NIC stats scheme. That has evolved significantly in recent time.

I think the approach here is actually quite nice, I don't see blockers.

/P

#21 lore raw
In reply to Daniel Zahka
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 12 Oct 2026 05:04:33 -0700 you wrote:

Add basic netdev statistics and report them via ndo_get_stats64 and netdev_stat_ops.

Track per queue netdev statistics such as Tx/Rx: packets, bytes, drops, etc. The driver keeps per-queue state for statistics that is updated mostly from the NAPI poll and ndo_start_xmit paths. The stats are made available through the usual driver APIs.

[...]

Here is the summary with links:
- [net-next,v2,1/4] eth: mpnic: count packets, bytes, and drops per ring

    https://git.kernel.org/netdev/net-next/c/554c7af9367a
  - [net-next,v2,2/4] eth: mpnic: report per-queue stats
    https://git.kernel.org/netdev/net-next/c/5cc79ff41b07
  - [net-next,v2,3/4] eth: mpnic: count Tx queue stops and wakes
    https://git.kernel.org/netdev/net-next/c/3b28e126619f
  - [net-next,v2,4/4] eth: mpnic: count Rx allocation failures
    https://git.kernel.org/netdev/net-next/c/ce0d47658920

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#11 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Jakub Kicinski
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 20 Oct 2026 23:21:55 +0200 Sebastian Andrzej Siewior wrote:
Quoted 5 lines
Quoted 2 lines

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

Quoted 6 lines
Quoted 4 lines

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

Yes, that's intentional and recommended by the docs for queue stats.

I guess this is Documentation/networking/statistics.rst that I need to study.

Quoted 10 lines
Quoted 3 lines

So if this never happens, it might not be needed to preserve this. That force-RCU might not be needed. This does happen on down and I would assume that the device is no longer processing packets.

The (old) ndo for stats reading runs under RCU, only. AI will immediately point that out if we remove the sync.

May I ask why you care? Is there another driver you're trying to implement stats in? I'm not sure where you're coming from and therefore what to explain to you.

I tried to be useful and do so some reviews and this stats part is what I did not expect to be "expected". I would expect per-queue stats which are folded into device stats on query time. Anyway. Let me study what is recommended before making noise here again.
One last thing: If you replace RCU with SRCU then the logic should remain the same. On the plus side you would have some domain separation and the "synchronize" part will not force/ wait for the global grace period but be limited to the local one.

Sebastian

#14 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Paolo Abeni
Quoted 7 lines · Paolo Abeni
Quoted 2 lines

Right. If you think is all makes sense and is needed then why not. It just looks odd.

Sebastian, my understanding is that your doubts are mostly because you are unfamiliar with the current reference NIC stats scheme. That has evolved significantly in recent time.

I think the approach here is actually quite nice, I don't see blockers.

That might be it. As I just wrote in my recent reply, if you have a driver recommendation what is currently recommended I would take a look.

Quoted 1 line

/P

Sebastian

#12 lore raw

Re: [PATCH net-next v2 1/4] eth: mpnic: count packets, bytes, and drops per ring

In reply to Sebastian Andrzej Siewior
Quoted 38 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 20 Oct 2026 23:21:55 +0200 Sebastian Andrzej Siewior wrote:
Quoted 5 lines
Quoted 2 lines

Is there any other driver doing this?
There is ::get_sset_count() and so on for the per-queue stats.

You may be mixing up queue stats (netlink) with the old ethtool -S kitchen sink / garbage dump.

Quoted 6 lines
Quoted 4 lines

The statistics is folded on device-down into a global counter. So on device-up the statistics is still available. At least that is my understanding. This means the per-queue stats are lost and global stats don't match the per queue stats anymore.

Yes, that's intentional and recommended by the docs for queue stats.

I guess this is Documentation/networking/statistics.rst that I need to study.

Quoted 10 lines
Quoted 3 lines

So if this never happens, it might not be needed to preserve this. That force-RCU might not be needed. This does happen on down and I would assume that the device is no longer processing packets.

The (old) ndo for stats reading runs under RCU, only. AI will immediately point that out if we remove the sync.

May I ask why you care? Is there another driver you're trying to implement stats in? I'm not sure where you're coming from and therefore what to explain to you.

I tried to be useful and do so some reviews and this stats part is what I did not expect to be "expected". I would expect per-queue stats which are folded into device stats on query time. Anyway. Let me study what is recommended before making noise here again.
One last thing: If you replace RCU with SRCU then the logic should remain the same. On the plus side you would have some domain separation and the "synchronize" part will not force/ wait for the global grace period but be limited to the local one.

Quoted 1 line

Sebastian

I do appreciate the review. Thanks for the SRCU suggestion. I hadn't considered that. Optimizing the writer side performance will become more important when we implement ethtool ringparam/channel reconfiguration. Another idea we had was to heap allocate the base stats and use call_rcu() to free instead. I decided against that for now, because I thought it was more complicated, and the writer side is limted to just ndo_open/ndo_stop for now.