Thread (15 messages) 15 messages, 2 authors, 11d ago
COOLING11d

[PATCH 06/10] net: emac: batch stats, eliminate modulo, tighten barrier in RX poll

From: Rosen Penev <hidden>
Date: 2026-06-30 04:16:45
Also in: lkml
Subsystem: networking drivers, the rest · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

Three small hot-path changes in emac_poll_rx():

- Batch per-packet 64-bit stat updates into local accumulators and
  write dev->stats once after the poll loop, avoiding expensive
  load-linked/store-conditional sequences on 32-bit PPC for every
  received packet.

- Replace slot = (slot + 1) % NUM_RX_BUFF with a simple
  if (++slot == NUM_RX_BUFF) branch, avoiding a div/mul by a
  non-power-of-2 constant.

- Use dma_rmb() instead of mb() when ordering the ctrl vs. data_len
  read of the coherent RX descriptor.  The device writes the
  descriptor fields in-order and clears MAL_RX_CTRL_EMPTY last;
  a read barrier is sufficient.

Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <redacted>
---
 drivers/net/ethernet/ibm/emac/core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 5e7b85d28bde..ced9690cddc3 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -1741,6 +1741,7 @@ static int emac_poll_rx(void *param, int budget)
 {
 	struct emac_instance *dev = param;
 	int slot = dev->rx_slot, received = 0;
+	u64 packets = 0, bytes = 0;
 
 	DBG2(dev, "poll_rx(%d)" NL, budget);
 
@@ -1797,10 +1798,11 @@ static int emac_poll_rx(void *param, int budget)
 
 		napi_gro_receive(&dev->mal->napi, skb);
 	next:
-		++dev->stats.rx_packets;
+		++packets;
 	skip:
-		dev->stats.rx_bytes += len;
-		slot = (slot + 1) % NUM_RX_BUFF;
+		bytes += len;
+		if (++slot == NUM_RX_BUFF)
+			slot = 0;
 		--budget;
 		++received;
 		continue;
@@ -1864,6 +1866,9 @@ static int emac_poll_rx(void *param, int budget)
 		emac_rx_enable(dev);
 		dev->rx_slot = 0;
 	}
+
+	dev->stats.rx_packets += packets;
+	dev->stats.rx_bytes += bytes;
 	return received;
 }
 
-- 
2.54.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help