On Thu, Jun 25, 2026 at 09:36:19AM +0000, Ciara Loftus wrote:
> The number of Rx packets is computed as the sum of the unicast,
> multicast and broadcast packet counters, minus the discarded packet
> count:
> 
>     ipackets = rx_unicast + rx_multicast + rx_broadcast - rx_discards
> 
> The unicast, multicast and broadcast counters already include the
> packets that were subsequently dropped, so subtracting rx_discards
> yields only the packets delivered to the application. These values are
> provided by the PF in a virtchnl_eth_stats message; the PF samples them
> from separate sources and the VF cannot guarantee the order in which
> they are read. Under load, rx_discards can therefore momentarily exceed
> the sum of the unicast, multicast and broadcast counters. As ipackets is
> unsigned, the subtraction then wraps to a huge bogus value, reported to
> the application as an enormous Rx packet count and packet rate.
> 
> The read order cannot be guaranteed from the VF, so use a saturating
> subtraction: when rx_discards exceeds the sum of the unicast, multicast
> and broadcast counters essentially nothing was delivered, so report zero
> instead of underflowing.
> 
> Fixes: e71ffcc1008e ("net/iavf: fix Rx total stats")
> Cc: [email protected]
> 
> Signed-off-by: Ciara Loftus <[email protected]>
> ---
Acked-by: Bruce Richardson <[email protected]>

Reply via email to