Skip to contentSkip to conversation

net/ixgbevf: update VF_STAT macros to handle rollover

PATCH Superseded David Harton 4 participants 7 messages Dec 11, 2019 – Jan 29, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

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
index 49285ce53..bc73ad195 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
Quoted 40 lines · David Harton

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
index 49285ce53..bc73ad195 100644
@@ -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?

#2 lore raw
In reply to David Harton
Quoted 26 lines · On Tue, 10 Dec 2019 21:38:36 -0500 David Harton <[email protected]> wrote:

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 +5 -1
index 49285ce53..bc73ad195 100644
@@ -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 -1
 	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

#3 lore raw

PATCH v2 1/1 net/ixgbevf: update VF_STAT macros to handle rollover

In reply to David Harton

Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.

Fixes af75078fece3 ("first public release")
Cc intel.com
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +10 -2
index 49285ce53..bc73ad195 100644
@@ -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
Acked-by on v2 1/1 Applied
#4 lore raw
Quoted 4 lines · David Harton

Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.

Fixes af75078fece3 ("first public release")
Cc intel.com
Quoted 39 lines

---
drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--

1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +10 -2
index 49285ce53..bc73ad195 100644
@@ -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.

#5 lore raw
In reply to David Harton
Quoted 15 lines · David Harton

Added rollover logic to UPDATE_VF_STAT and UPDATE_VF_STAT_36BIT macros.

Fixes af75078fece3 ("first public release")
Cc intel.com
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +0 -0
index 49285ce53..bc73ad195 100644

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 -0
 	last = latest;                                           \
 }
 
#6 lore raw
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: update VF_STAT macros to handle rollover

drivers/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_STAT and UPDATE_VF_STAT_36BIT macros.

Fixes af75078fece3 ("first public release")
Cc intel.com
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +0 -0
index 49285ce53..bc73ad195 100644
@@ -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 -1
 	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 -0
 	last = latest;                                           \
 }