[PATCH net-next v04 2/4] hinic3: Read the queue counters once per u64_stats retry loop
From: Fan Gong
Date: Tue Nov 17 2026 - 07:09:02 EST
hinic3_get_stats64() accumulates the per-queue counters with += inside the
u64_stats_fetch_begin()/u64_stats_fetch_retry() sequence. A retry repeats
the body, so the values read by an aborted pass would be counted twice.
Read the snapshot of one queue into the locals instead, and add it to the
rtnl_link_stats64 fields after the loop.
This cannot trigger today: the driver depends on 64BIT, where
u64_stats_fetch_retry() always returns false, and the only writers of
these counters are the clean_stats() helpers, which run before the queues
are used. The change is a prerequisite for the per-queue statistics that
will populate them, so it carries no Fixes: tag and reports the same
values as before.
While at it, drop the dead stores into the locals before the loops: every
iteration overwrites them before they are read.
Also drop the nic_dev->txqs and nic_dev->rxqs NULL checks. Both arrays
are allocated by hinic3_sw_init() before register_netdev() and freed by
hinic3_sw_uninit() after unregister_netdev(), and the loops are bounded by
nic_dev->max_qps, the number of entries they were allocated with.
rx_errors keeps reporting csum_errors + other_errors. Neither counter is
populated yet, and the checksum error accounting together with its
"csum_bad" queue statistic belongs to the queue-stats work that adds the
writer.
Co-developed-by: Wu Di <wudi234@xxxxxxxxxx>
Signed-off-by: Wu Di <wudi234@xxxxxxxxxx>
Co-developed-by: Teng Peisen <tengpeisen@xxxxxxxxxx>
Signed-off-by: Teng Peisen <tengpeisen@xxxxxxxxxx>
Signed-off-by: Fan Gong <gongfan1@xxxxxxxxxx>
---
.../huawei/hinic3/hinic3_netdev_ops.c | 43 +++++++------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c b/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
index da73811641a9..6007e0e58478 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
@@ -791,49 +791,36 @@ static void hinic3_get_stats64(struct net_device *netdev,
unsigned int start;
int i;
- bytes = 0;
- packets = 0;
- dropped = 0;
for (i = 0; i < nic_dev->max_qps; i++) {
- if (!nic_dev->txqs)
- break;
-
txq = &nic_dev->txqs[i];
txq_stats = &txq->txq_stats;
do {
start = u64_stats_fetch_begin(&txq_stats->syncp);
- bytes += txq_stats->bytes;
- packets += txq_stats->packets;
- dropped += txq_stats->dropped;
+ bytes = txq_stats->bytes;
+ packets = txq_stats->packets;
+ dropped = txq_stats->dropped;
} while (u64_stats_fetch_retry(&txq_stats->syncp, start));
+ stats->tx_packets += packets;
+ stats->tx_bytes += bytes;
+ stats->tx_dropped += dropped;
}
- stats->tx_packets = packets;
- stats->tx_bytes = bytes;
- stats->tx_dropped = dropped;
- bytes = 0;
- packets = 0;
- errors = 0;
- dropped = 0;
for (i = 0; i < nic_dev->max_qps; i++) {
- if (!nic_dev->rxqs)
- break;
-
rxq = &nic_dev->rxqs[i];
rxq_stats = &rxq->rxq_stats;
do {
start = u64_stats_fetch_begin(&rxq_stats->syncp);
- bytes += rxq_stats->bytes;
- packets += rxq_stats->packets;
- errors += rxq_stats->csum_errors +
- rxq_stats->other_errors;
- dropped += rxq_stats->dropped;
+ bytes = rxq_stats->bytes;
+ packets = rxq_stats->packets;
+ errors = rxq_stats->csum_errors +
+ rxq_stats->other_errors;
+ dropped = rxq_stats->dropped;
} while (u64_stats_fetch_retry(&rxq_stats->syncp, start));
+ stats->rx_packets += packets;
+ stats->rx_bytes += bytes;
+ stats->rx_errors += errors;
+ stats->rx_dropped += dropped;
}
- stats->rx_packets = packets;
- stats->rx_bytes = bytes;
- stats->rx_errors = errors;
- stats->rx_dropped = dropped;
}
static void hinic3_nic_set_rx_mode(struct net_device *netdev)
--
2.43.0