net/ixgbevf: update VF_STAT macros to handle rollover

Message ID 20191211023836.16272-1-dharton@cisco.com (mailing list archive)
State Superseded, archived
Delegated to: xiaolong ye
Headers
Series net/ixgbevf: update VF_STAT macros to handle rollover |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot warning Travis build: failed
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

David Harton Dec. 11, 2019, 2:38 a.m. UTC
  Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.

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. 26, 2020, 9:42 a.m. UTC | #1
On 12/10, David Harton wrote:
>Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
>
>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
>o

Could you provide Fixes: tag and cc stable?

Acked-by: Xiaolong Ye <xiaolong.ye@intel.com>
  
Stephen Hemminger Jan. 26, 2020, 5:13 p.m. UTC | #2
On Tue, 10 Dec 2019 21:38:36 -0500
David Harton <dharton@cisco.com> wrote:

> Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
> 
> 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;                                           \
>  }

The overall approach looks fine.
The code is now long enough the macro should turn into an inline.
Also lots of (extra) parenthesis
  

Patch

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;                                           \
 }