net/ixgbevf: update VF_STAT macros to handle rollover
PATCH 1/1 net/ixgbevf: update VF_STAT macros to handle rollover
Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +10 -2
@@ -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; \ }
Signature · 1 line
2.19.1
Quoted 40 lines · David Harton
Added rollover logic to
UPDATE_VF_STATandUPDATE_VF_STAT_36BITmacros.Signed-off-by David Harton <[email protected]>---
drivers/net/ixgbe/ixgbe_ethdev.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ixgbe/ixgbe_ethdev.c +10
-2@@ -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; \ }Signature · 2 lines
2.19.1 o
Could you provide Fixes: tag and cc stable?
Quoted 26 lines · On Tue, 10 Dec 2019 21:38:36 -0500 David Harton <[email protected]> wrote:
Added rollover logic to
UPDATE_VF_STATandUPDATE_VF_STAT_36BITmacros.Signed-off-by David Harton <[email protected]>--- drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ixgbe/ixgbe_ethdev.c +5
-1@@ -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); \
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev); · line 407
Quoted 10 lines
drivers/net/ixgbe/ixgbe_ethdev.c +5
-1u64 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 v2 1/1 net/ixgbevf: update VF_STAT macros to handle rollover
In reply to David HartonAdded rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +10 -2
@@ -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; \ }
Signature · 1 line
2.19.1
Quoted 4 lines · David Harton
Added rollover logic to
UPDATE_VF_STATandUPDATE_VF_STAT_36BITmacros.Fixes af75078fece3 ("first public release")Cc intel.com
Quoted 39 lines
Signed-off-by David Harton <[email protected]>---
drivers/net/ixgbe/ixgbe_ethdev.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ixgbe/ixgbe_ethdev.c +10
-2@@ -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; \ }Signature · 1 line
2.19.1
Applied to dpdk-next-net-intel, Thanks.
Quoted 15 lines · David Harton
Added rollover logic to
UPDATE_VF_STATandUPDATE_VF_STAT_36BITmacros.Fixes af75078fece3 ("first public release")Cc intel.comSigned-off-by David Harton <[email protected]>--- drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ixgbe/ixgbe_ethdev.c +0
-0
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev); · line 388
Quoted 4 lines
drivers/net/ixgbe/ixgbe_ethdev.c +0
-1@@ -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.
Quoted 9 lines
drivers/net/ixgbe/ixgbe_ethdev.c +5
-0+if (latest >= last) \ + cur += (latest - last); \ +else \ + cur += ((latest + ((uint64_t )1 <<32 )) - last); \ + cur &=UINT_MAX ; \ last = latest; \ }
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev); · line 405
Quoted 9 lines
drivers/net/ixgbe/ixgbe_ethdev.c +5
-1@@ -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.
Quoted 4 lines
drivers/net/ixgbe/ixgbe_ethdev.c +0
-0last = latest; \ }
Quoted 29 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, January 29, 2020 6:23 AM
To: David Harton (dharton) <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2] net/ixgbevf: updateVF_STATmacros to handle rolloverdrivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev
Quoted 16 lines · David Harton
Added rollover logic to
UPDATE_VF_STATandUPDATE_VF_STAT_36BITmacros.Fixes af75078fece3 ("first public release")Cc intel.comSigned-off-by David Harton <[email protected]>--- drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ixgbe/ixgbe_ethdev.c +0
-0@@ -385,7 +385,11 @@ static void ixgbe_l2_tunnel_conf(struct rte_eth_dev*dev);
Quoted 7 lines
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev); · line 388
Quoted 4 lines
drivers/net/ixgbe/ixgbe_ethdev.c +0
-1#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
Quoted 27 lines
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev
Quoted 10 lines
drivers/net/ixgbe/ixgbe_ethdev.c +5
-0+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);
drivers/net/ixgbe/ixgbe_ethdev.c static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev); · line 405
Quoted 9 lines
drivers/net/ixgbe/ixgbe_ethdev.c +5
-1u64 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.
Quoted 4 lines
drivers/net/ixgbe/ixgbe_ethdev.c +0
-0last = latest; \ }