Re: [PATCH 1/2] tg3: Move the [rt]x_dropped counters to tg3_napi

From: Michael Chan
Date: Wed Nov 08 2023 - 04:11:51 EST


On Tue, Nov 7, 2023 at 5:01 PM <alexey.pakhunov@xxxxxxxxxx> wrote:
>
> From: Alex Pakhunov <alexey.pakhunov@xxxxxxxxxx>
>
> This change moves [rt]x_dropped counters to tg3_napi so that they can be
> updated by a single writer, race-free.
>
> Signed-off-by: Alex Pakhunov <alexey.pakhunov@xxxxxxxxxx>
> Signed-off-by: Vincent Wong <vincent.wong2@xxxxxxxxxx>
> ---
...
> @@ -11895,6 +11898,9 @@ static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats)
> {
> struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev;
> struct tg3_hw_stats *hw_stats = tp->hw_stats;
> + unsigned long rx_dropped = 0;
> + unsigned long tx_dropped = 0;
> + int i;
>
> stats->rx_packets = old_stats->rx_packets +
> get_stat64(&hw_stats->rx_ucast_packets) +
> @@ -11941,8 +11947,23 @@ static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats)
> stats->rx_missed_errors = old_stats->rx_missed_errors +
> get_stat64(&hw_stats->rx_discards);
>
> - stats->rx_dropped = tp->rx_dropped;
> - stats->tx_dropped = tp->tx_dropped;
> + /* Aggregate per-queue counters. The per-queue counters are updated
> + * by a single writer, race-free. The result computed by this loop
> + * might not be 100% accurate (counters can be updated in the middle of
> + * the loop) but the next tg3_get_nstats() will recompute the current
> + * value so it is acceptable.
> + */
> + for (i = 0; i < tp->irq_cnt; i++) {
> + struct tg3_napi *tnapi = &tp->napi[i];
> +
> + rx_dropped += tnapi->rx_dropped;
> + tx_dropped += tnapi->tx_dropped;
> + }
> +
> + /* The counters wrap around at 4G on 32bit machines. */
> + stats->rx_dropped = rx_dropped;
> + stats->tx_dropped = tx_dropped;

I think here we need to keep these counters accumulate across a reset:

stats->rx_dropped = old_stats->rx_dropped + rx_dropped;
stats->tx_dropped = old_stats->tx_dropped + tx_dropped;

> +
> }
>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature