[PATCH] net/ice: fix statistics read error

Stephen Hemminger stephen at networkplumber.org
Thu Nov 13 18:29:10 CET 2025


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)


/*
 * 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