DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/ice: fix statistics read error
@ 2025-11-07  7:43 Zhichao Zeng
  2025-11-07  9:26 ` Bruce Richardson
  0 siblings, 1 reply; 2+ messages in thread
From: Zhichao Zeng @ 2025-11-07  7:43 UTC (permalink / raw)
  To: dev
  Cc: stable, Zhichao Zeng, Bruce Richardson, Anatoly Burakov,
	Ferruh Yigit, Wenzhuo Lu, Jeff Guo

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>
---
 drivers/net/intel/ice/ice_ethdev.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/intel/ice/ice_ethdev.c b/drivers/net/intel/ice/ice_ethdev.c
index 513777e372..be08be0826 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -6036,10 +6036,19 @@ ice_stat_update_40(struct ice_hw *hw,
 		   uint64_t *stat)
 {
 	uint64_t new_data;
+	uint32_t lo, hi, lo2;
 
-	new_data = (uint64_t)ICE_READ_REG(hw, loreg);
-	new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
-		    ICE_32_BIT_WIDTH;
+	lo = ICE_READ_REG(hw, loreg);
+	hi = ICE_READ_REG(hw, hireg);
+	lo2 = ICE_READ_REG(hw, loreg);
+
+	if (lo2 < lo) {
+		lo = ICE_READ_REG(hw, loreg);
+		hi = ICE_READ_REG(hw, hireg);
+	}
+
+	new_data = (uint64_t)lo;
+	new_data |= (uint64_t)(hi & ICE_8_BIT_MASK) << ICE_32_BIT_WIDTH;
 
 	if (!offset_loaded)
 		*offset = new_data;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/ice: fix statistics read error
  2025-11-07  7:43 [PATCH] net/ice: fix statistics read error Zhichao Zeng
@ 2025-11-07  9:26 ` Bruce Richardson
  0 siblings, 0 replies; 2+ messages in thread
From: Bruce Richardson @ 2025-11-07  9:26 UTC (permalink / raw)
  To: Zhichao Zeng; +Cc: dev

On Fri, Nov 07, 2025 at 03:43:38PM +0800, Zhichao Zeng 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>
> ---

See comments inline below.

/Bruce

>  drivers/net/intel/ice/ice_ethdev.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/intel/ice/ice_ethdev.c b/drivers/net/intel/ice/ice_ethdev.c
> index 513777e372..be08be0826 100644
> --- a/drivers/net/intel/ice/ice_ethdev.c
> +++ b/drivers/net/intel/ice/ice_ethdev.c
> @@ -6036,10 +6036,19 @@ ice_stat_update_40(struct ice_hw *hw,
>  		   uint64_t *stat)
>  {
>  	uint64_t new_data;
> +	uint32_t lo, hi, lo2;
>  
> -	new_data = (uint64_t)ICE_READ_REG(hw, loreg);
> -	new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
> -		    ICE_32_BIT_WIDTH;
> +	lo = ICE_READ_REG(hw, loreg);
> +	hi = ICE_READ_REG(hw, hireg);
> +	lo2 = ICE_READ_REG(hw, loreg);
> +
> +	if (lo2 < lo) {
> +		lo = ICE_READ_REG(hw, loreg);
> +		hi = ICE_READ_REG(hw, hireg);
> +	}
> +

While I can't see multiple wrap-arounds occuring, it is theoretically
possible e.g. if a process gets context switched out. Therefore, I think
using a "while" construction would be better. For example:

	uint32_t lo_old, hi, lo;
	do {
		lo_old = ...
		hi = ...
		lo = ...
	} while (lo_old > lo);

> +	new_data = (uint64_t)lo;
> +	new_data |= (uint64_t)(hi & ICE_8_BIT_MASK) << ICE_32_BIT_WIDTH;
>  

Using "lo" rather than "lo2" here means we are returning data we know is
old. We should be returning the second value read. Suggest using something
like what I suggest above, where we make "lo" the second read rather than
the first.

>  	if (!offset_loaded)
>  		*offset = new_data;
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-07  9:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-07  7:43 [PATCH] net/ice: fix statistics read error Zhichao Zeng
2025-11-07  9:26 ` Bruce Richardson

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).