git: cfa09932b9aa - main - dwc: Do not report a negative number of output errors with the QoS core
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 20 Nov 2026 13:55:52 UTC
The branch main has been updated by manu:
URL: https://cgit.FreeBSD.org/src/commit/?id=cfa09932b9aa1d88bb75cedc0fecd912a44295af
commit cfa09932b9aa1d88bb75cedc0fecd912a44295af
Author: Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-20 15:01:29 +0000
Commit: Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-20 13:55:28 +0000
dwc: Do not report a negative number of output errors with the QoS core
The good and the total transmitted packet counters are not read atomically,
so the difference can be negative when a packet completes between the two
reads. It was added to the error counter as a huge unsigned value. Only
add it when the total is larger.
Differential Revision: https://reviews.freebsd.org/D60919
---
sys/dev/dwc/dwc4_core.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sys/dev/dwc/dwc4_core.c b/sys/dev/dwc/dwc4_core.c
index 57cbb541edda..f3edc5cc2b2b 100644
--- a/sys/dev/dwc/dwc4_core.c
+++ b/sys/dev/dwc/dwc4_core.c
@@ -387,6 +387,7 @@ void
dwc4_harvest_stats(struct dwc_softc *sc)
{
if_t ifp __unused;
+ uint32_t good_bad, good;
int val;
/* We don't need to harvest too often. */
@@ -399,9 +400,14 @@ dwc4_harvest_stats(struct dwc_softc *sc)
val = READ4(sc, ETH_RX_RECEIVE_ERROR);
if_inc_counter(ifp, IFCOUNTER_IERRORS, val);
- val = READ4(sc, ETH_TX_PACKET_COUNT_GOOD_BAD);
- val -= READ4(sc, ETH_TX_PACKET_COUNT_GOOD);
- if_inc_counter(ifp, IFCOUNTER_OERRORS, val);
+ /*
+ * The two counters are not read atomically, a packet can complete
+ * between the reads.
+ */
+ good_bad = READ4(sc, ETH_TX_PACKET_COUNT_GOOD_BAD);
+ good = READ4(sc, ETH_TX_PACKET_COUNT_GOOD);
+ if (good_bad > good)
+ if_inc_counter(ifp, IFCOUNTER_OERRORS, good_bad - good);
val = READ4(sc, ETH_TX_SINGLE_COLLISION_GOOD_PACKETS);
val += READ4(sc, ETH_TX_MULTIPLE_COLLISION_GOOD_PACKETS);