[v2] net/ixgbevf: update VF_STAT macros to handle rollover
diff mbox series

Message ID 20200126173201.19433-1-dharton@cisco.com
State Changes Requested
Delegated to: xiaolong ye
Headers show
Series
  • [v2] net/ixgbevf: update VF_STAT macros to handle rollover
Related show

Checks

Context Check Description
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

David Harton (dharton) Jan. 26, 2020, 5:32 p.m. UTC
Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.

Fixes: af75078fece3 ("first public release")
Cc: intel.com

Signed-off-by: David Harton <dharton@cisco.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Xiaolong Ye Jan. 29, 2020, 7:53 a.m. UTC | #1
On 01/26, David Harton wrote:
>Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
>
>Fixes: af75078fece3 ("first public release")
>Cc: intel.com

Cc: stable@dpdk.org

>
>Signed-off-by: David Harton <dharton@cisco.com>
>---
> drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
>index 49285ce53..bc73ad195 100644
>--- a/drivers/net/ixgbe/ixgbe_ethdev.c
>+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
>@@ -385,7 +385,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
> #define UPDATE_VF_STAT(reg, last, cur)                          \
> {                                                               \
> 	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
>-	cur += (latest - last) & UINT_MAX;                      \
>+	if (latest >= last)                                     \
>+		cur += (latest - last);                         \
>+	else                                                    \
>+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
>+	cur &= UINT_MAX;                                        \
> 	last = latest;                                          \
> }
> 
>@@ -394,7 +398,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
> 	u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
> 	u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
> 	u64 latest = ((new_msb << 32) | new_lsb);                \
>-	cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
>+	if (latest >= last)                                      \
>+		cur += (latest - last);                          \
>+	else                                                     \
>+		cur += ((latest + ((u64)1 << 36)) - last);       \
>+	cur &= 0xFFFFFFFFFLL;                                    \
> 	last = latest;                                           \
> }
> 
>-- 
>2.19.1
>

Acked-by: Xiaolong Ye <xiaolong.ye@intel.com>

Applied to dpdk-next-net-intel, Thanks.
Ferruh Yigit Jan. 29, 2020, 11:22 a.m. UTC | #2
On 1/26/2020 5:32 PM, David Harton wrote:
> Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
> 
> Fixes: af75078fece3 ("first public release")
> Cc: intel.com
> 
> Signed-off-by: David Harton <dharton@cisco.com>
> ---
>  drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
> index 49285ce53..bc73ad195 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> @@ -385,7 +385,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
>  #define UPDATE_VF_STAT(reg, last, cur)                          \
>  {                                                               \
>  	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
> -	cur += (latest - last) & UINT_MAX;                      \

Here since 'last' is 'u64', the 'UINT_MAX' is required, but overall this looks
good, original code should be OK.

> +	if (latest >= last)                                     \
> +		cur += (latest - last);                         \
> +	else                                                    \
> +		cur += ((latest + ((uint64_t)1 << 32)) - last); \
> +	cur &= UINT_MAX;                                        \
>  	last = latest;                                          \
>  }
>  
> @@ -394,7 +398,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
>  	u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
>  	u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
>  	u64 latest = ((new_msb << 32) | new_lsb);                \
> -	cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
> +	if (latest >= last)                                      \
> +		cur += (latest - last);                          \
> +	else                                                     \
> +		cur += ((latest + ((u64)1 << 36)) - last);       \
> +	cur &= 0xFFFFFFFFFLL;                                    \

For this case old and new implementation looks same to me.

>  	last = latest;                                           \
>  }
>  
>
David Harton (dharton) Jan. 29, 2020, 5:57 p.m. UTC | #3
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> Sent: Wednesday, January 29, 2020 6:23 AM
> To: David Harton (dharton) <dharton@cisco.com>; dev@dpdk.org
> Cc: wenzhuo.lu@intel.com; konstantin.ananyev@intel.com;
> xiaolong.ye@intel.com; intel.com@cisco.com
> Subject: Re: [dpdk-dev] [PATCH v2] net/ixgbevf: update VF_STAT macros to
> handle rollover
> 
> On 1/26/2020 5:32 PM, David Harton wrote:
> > Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
> >
> > Fixes: af75078fece3 ("first public release")
> > Cc: intel.com
> >
> > Signed-off-by: David Harton <dharton@cisco.com>
> > ---
> >  drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c
> > b/drivers/net/ixgbe/ixgbe_ethdev.c
> > index 49285ce53..bc73ad195 100644
> > --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> > +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> > @@ -385,7 +385,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev
> *dev);
> >  #define UPDATE_VF_STAT(reg, last, cur)                          \
> >  {                                                               \
> >  	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
> > -	cur += (latest - last) & UINT_MAX;                      \
> 
> Here since 'last' is 'u64', the 'UINT_MAX' is required, but overall this
> looks good, original code should be OK.

Agreed.  As mentioned on the igbvf thread I've gone back to the developer for justification.

Regards,
Dave

> 
> > +	if (latest >= last)                                     \
> > +		cur += (latest - last);                         \
> > +	else                                                    \
> > +		cur += ((latest + ((uint64_t)1 << 32)) - last); \
> > +	cur &= UINT_MAX;                                        \
> >  	last = latest;                                          \
> >  }
> >
> > @@ -394,7 +398,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev
> *dev);
> >  	u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
> >  	u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
> >  	u64 latest = ((new_msb << 32) | new_lsb);                \
> > -	cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
> > +	if (latest >= last)                                      \
> > +		cur += (latest - last);                          \
> > +	else                                                     \
> > +		cur += ((latest + ((u64)1 << 36)) - last);       \
> > +	cur &= 0xFFFFFFFFFLL;                                    \
> 
> For this case old and new implementation looks same to me.
> 
> >  	last = latest;                                           \
> >  }
> >
> >

Patch
diff mbox series

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 49285ce53..bc73ad195 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -385,7 +385,11 @@  static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
 #define UPDATE_VF_STAT(reg, last, cur)                          \
 {                                                               \
 	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
-	cur += (latest - last) & UINT_MAX;                      \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \
 	last = latest;                                          \
 }
 
@@ -394,7 +398,11 @@  static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
 	u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
 	u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
 	u64 latest = ((new_msb << 32) | new_lsb);                \
-	cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
+	if (latest >= last)                                      \
+		cur += (latest - last);                          \
+	else                                                     \
+		cur += ((latest + ((u64)1 << 36)) - last);       \
+	cur &= 0xFFFFFFFFFLL;                                    \
 	last = latest;                                           \
 }