[PATCH] net/ice: fix statistics read error

Bruce Richardson bruce.richardson at intel.com
Thu Nov 13 18:33:54 CET 2025


On Thu, Nov 13, 2025 at 09:29:10AM -0800, Stephen Hemminger wrote:
> On Fri,  7 Nov 2025 15:43:38 +0800
> Zhichao Zeng <zhichaox.zeng at intel.com> wrote:
> 
> > The statistics contain 40 bits. The lower 32 bits are read first, followed
> > by the upper 8 bits.
> > 
> > In some cases, after reading the lower 32 bits, a carry occurs from the
> > lower bits, which causes the final statistics to be incorrect.
> > 
> > This commit fixes this issue.
> > 
> > Fixes: a37bde56314d ("net/ice: support statistics")
> > Cc: stable at dpdk.org
> > 
> > Signed-off-by: Zhichao Zeng <zhichaox.zeng at intel.com>
> 
> This works but may still have issues under really high load.
> I have seen code like this (from ChatGPT)
>

How is checking high for equality better? I considered when reviewing
having the high be double-read, but I though we'd get better accuracy by
reading the more frequency-changing counter (lo) last.

/Bruce
 
> 
> /*
>  * Safely read a 64-bit counter split across two 32-bit registers.
>  * Handles rollover and avoids inconsistency if low overflows
>  * between high and low reads.
>  */
> static inline uint64_t read_hw_counter_64(void)
> {
>     uint32_t hi1, lo, hi2;
> 
>     /*
>      * Read high-low-high and check for wraparound:
>      * if high changed, low overflowed during read — reread.
>      */
>     do {
>         hi1 = read_reg32_high();
>         lo  = read_reg32_low();
>         hi2 = read_reg32_high();
>     } while (hi1 != hi2);
> 
>     return ((uint64_t)hi1 << 32) | lo;
> }


More information about the dev mailing list