From: Bruce Richardson <bruce.richardson@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Zhichao Zeng <zhichaox.zeng@intel.com>, <dev@dpdk.org>,
<stable@dpdk.org>, 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 17:33:54 +0000 [thread overview]
Message-ID: <aRYWgnRDIN0PL05X@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20251113092910.015df6eb@phoenix>
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@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)
>
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;
> }
prev parent reply other threads:[~2025-11-13 17:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-07 7:43 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 ` [PATCH] " Stephen Hemminger
2025-11-13 17:33 ` Bruce Richardson [this message]
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=aRYWgnRDIN0PL05X@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=jia.guo@intel.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).