git: 3ba01cb4c61c - main - ena: Batch RX statistics updates
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Jul 2026 18:24:12 UTC
The branch main has been updated by akiyano:
URL: https://cgit.FreeBSD.org/src/commit/?id=3ba01cb4c61cc1e29c4d1d7ea4b73cdffb5ce3c2
commit 3ba01cb4c61cc1e29c4d1d7ea4b73cdffb5ce3c2
Author: David Arinzon <darinzon@amazon.com>
AuthorDate: 2026-04-16 11:22:04 +0000
Commit: Arthur Kiyanovski <akiyano@FreeBSD.org>
CommitDate: 2026-07-16 18:20:41 +0000
ena: Batch RX statistics updates
Move per-packet counter_enter/counter_exit pairs out of the RX
processing loop and batch them into a single update after the
loop completes.
Previously, each received packet triggered two separate
counter_enter/counter_exit blocks -- one for bytes and one for
packet count. This commit accumulates totals in local variables
and updates all four counters (ring and hw stats for both packets
and bytes) in a single counter_enter/counter_exit block after the
loop.
Also move the stats update to after the refill and LRO flush
so that the error path (goto update_stats) and the normal path
converge at the same label, avoiding code duplication.
Submitted by: David Arinzon <darinzon@amazon.com>
MFC after: 2 weeks
Sponsored by: Amazon, Inc.
Reviewed by: cperciva
Differential Revision: https://reviews.freebsd.org/D58240
---
sys/dev/ena/ena_datapath.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index 1e5298c2d984..c11006cbc10f 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -572,6 +572,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
unsigned int qid;
int rc, i;
int budget = (ENA_RX_DESC_BUDGET == -1) ? INT_MAX : ENA_RX_DESC_BUDGET;
+ uint64_t total_pkts = 0;
+ uint64_t total_bytes = 0;
#ifdef DEV_NETMAP
int done;
#endif /* DEV_NETMAP */
@@ -614,7 +616,7 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
}
ena_trigger_reset(adapter, reset_reason);
- return (0);
+ goto update_stats;
}
if (unlikely(ena_rx_ctx.descs == 0))
@@ -646,12 +648,7 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
ena_rx_checksum(rx_ring, &ena_rx_ctx, mbuf);
}
- counter_enter();
- counter_u64_add_protected(rx_ring->rx_stats.bytes,
- mbuf->m_pkthdr.len);
- counter_u64_add_protected(adapter->hw_stats.rx_bytes,
- mbuf->m_pkthdr.len);
- counter_exit();
+ total_bytes += mbuf->m_pkthdr.len;
/*
* LRO is only for IP/TCP packets and TCP checksum of the packet
* should be computed by hardware.
@@ -676,10 +673,7 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
if_input(ifp, mbuf);
}
- counter_enter();
- counter_u64_add_protected(rx_ring->rx_stats.cnt, 1);
- counter_u64_add_protected(adapter->hw_stats.rx_packets, 1);
- counter_exit();
+ total_pkts++;
/*
* Adjust our budget; note that we count descriptors, not
@@ -702,6 +696,13 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
tcp_lro_flush_all(&rx_ring->lro);
+update_stats:
+ counter_enter();
+ counter_u64_add_protected(rx_ring->rx_stats.cnt, total_pkts);
+ counter_u64_add_protected(rx_ring->rx_stats.bytes, total_bytes);
+ counter_u64_add_protected(adapter->hw_stats.rx_packets, total_pkts);
+ counter_u64_add_protected(adapter->hw_stats.rx_bytes, total_bytes);
+ counter_exit();
return (budget <= 0);
}