All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Zhichao Zeng <zhichaox.zeng@intel.com>
Cc: dev@dpdk.org, stable@dpdk.org,
	Bruce Richardson <bruce.richardson@intel.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>,
	Ferruh Yigit <ferruh.yigit@amd.com>,
	Wenzhuo Lu <wenzhuo.lu@intel.com>, Jeff Guo <jia.guo@intel.com>
Subject: Re: [PATCH] net/ice: fix statistics read error
Date: Thu, 13 Nov 2025 09:29:10 -0800	[thread overview]
Message-ID: <20251113092910.015df6eb@phoenix> (raw)
In-Reply-To: <20251107074338.957352-1-zhichaox.zeng@intel.com>

On Fri,  7 Nov 2025 15:43:38 +0800
Zhichao Zeng <zhichaox.zeng@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@dpdk.org
> 
> Signed-off-by: Zhichao Zeng <zhichaox.zeng@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;
}

  parent reply	other threads:[~2025-11-13 17:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07  7:43 [PATCH] net/ice: fix statistics read error Zhichao Zeng
2025-11-07  9:26 ` Bruce Richardson
2025-11-10  8:05 ` [PATCH v2] " Zhichao Zeng
2025-11-12 12:04   ` Bruce Richardson
2025-11-13  7:18     ` 回复: " Zeng, ZhichaoX
2025-11-13  7:47   ` [PATCH v3] " Zhichao Zeng
2025-11-13  8:42     ` Bruce Richardson
2025-11-13 10:43       ` Bruce Richardson
2025-11-13 17:29 ` Stephen Hemminger [this message]
2025-11-13 17:33   ` [PATCH] " Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251113092910.015df6eb@phoenix \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=jia.guo@intel.com \
    --cc=stable@dpdk.org \
    --cc=wenzhuo.lu@intel.com \
    --cc=zhichaox.zeng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.