Skip to contentSkip to conversation

net/e1000: update UPDATE_VF_STAT to handle rollover

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/e1000: update UPDATE_VF_STAT to handle rollover

Modified UPDATE_VF_STAT to properly handle rollover conditions.

---
 drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/e1000/igb_ethdev.c +9 -5
index a3e30dbe5..825663267 100644
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680
Signature · 1 line
2.19.1
Acked-by on v1 1/1
#1 lore raw
Quoted 35 lines · David Harton

Modified UPDATE_VF_STAT to properly handle rollover conditions.

---
drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----

1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/e1000/igb_ethdev.c +9 -5
index a3e30dbe5..825663267 100644
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
 * Define VF Stats MACRO for Non "cleared on read" register
 */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680
Signature · 1 line
2.19.1

Could you provide Fixes: tag and cc stable?

#2 lore raw

PATCH v2 1/1 net/e1000: update UPDATE_VF_STAT to handle rollover

In reply to David Harton

Modified UPDATE_VF_STAT to properly handle rollover conditions.

Fixes d82170d27918 ("igb: add VF support")
Cc intel.com
---
 drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/e1000/igb_ethdev.c +9 -5
index a3e30dbe5..825663267 100644
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680
Signature · 1 line
2.19.1
Acked-by on v2 1/1 Applied
#3 lore raw
Quoted 38 lines · David Harton

Modified UPDATE_VF_STAT to properly handle rollover conditions.

Fixes d82170d27918 ("igb: add VF support")
Cc intel.com

---
drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----

1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/e1000/igb_ethdev.c +9 -5
index a3e30dbe5..825663267 100644
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
 * Define VF Stats MACRO for Non "cleared on read" register
 */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680
Signature · 1 line
2.19.1

Applied to dpdk-next-net-intel, Thanks.

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

Modified UPDATE_VF_STAT to properly handle rollover conditions.

Fixes d82170d27918 ("igb: add VF support")
Cc intel.com
---
 drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/e1000/igb_ethdev.c +0 -0
index a3e30dbe5..825663267 100644

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev *dev); · line 267

Quoted 7 lines
drivers/net/e1000/igb_ethdev.c +0 -4
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \

Why this is wrong? Both 'latest' and 'last' are 'u32', so diff should be correct 'u32' value. And it is added to 'u64' 'cur' value. What I am missing?

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev *dev); · line 271

Quoted 9 lines
drivers/net/e1000/igb_ethdev.c +8 -1
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \

Why & with UINT_MAX, won't this limit the value to 32bits which has 64bit storage?

Quoted 5 lines
drivers/net/e1000/igb_ethdev.c +1 -0
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680
#5 lore raw
Quoted 39 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, January 29, 2020 5:10 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/e1000: update UPDATE_VF_STAT to handle rollover

Quoted 15 lines · David Harton

Modified UPDATE_VF_STAT to properly handle rollover conditions.

Fixes d82170d27918 ("igb: add VF support")
Cc intel.com
---
 drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/net/e1000/igb_ethdev.c index a3e30dbe5..825663267 100644

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev · line 268

Quoted 8 lines
drivers/net/e1000/igb_ethdev.c +0 -4
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev
 *dev);
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \

Why this is wrong? Both 'latest' and 'last' are 'u32', so diff should be correct 'u32' value. And it is added to 'u64' 'cur' value. What I am missing?

Quoted 12 lines

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev *dev); · line 271

Quoted 9 lines
drivers/net/e1000/igb_ethdev.c +8 -1
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \

Why & with UINT_MAX, won't this limit the value to 32bits which has 64bit storage?

I'm embarrassed. I was upstreaming this on behalf of another and honestly didn't even look. :(

You are right about the '&='. In fact, I'm not convinced these diffs are necessary and have asked our local developer to verify why this change and the ixgbevf change are needed. I'm wondering if they were encountering another issue related to sync that cause pkt counts to get out of sync as they were attempting to fix what looked like a rollover issue (huge packet counts after boot).

Sorry,
Dave

Quoted 6 lines
Quoted 6 lines
drivers/net/e1000/igb_ethdev.c +1 -0
+	last = latest;                                          \
 }
 

#define IGB_FC_PAUSE_TIME 0x0680

#6 lore raw
In reply to Ferruh Yigit
Quoted 11 lines · Ferruh Yigit
Quoted 10 lines · David Harton

Modified UPDATE_VF_STAT to properly handle rollover conditions.

Fixes d82170d27918 ("igb: add VF support")
Cc intel.com
---
 drivers/net/e1000/igb_ethdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
Quoted 15 lines

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev *dev); · line 267

Quoted 12 lines
drivers/net/e1000/igb_ethdev.c +0 -4
index a3e30dbe5..825663267 100644
@@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev);
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)            \
-{                                                 \
-	u32 latest = E1000_READ_REG(hw, reg);     \
-	cur += (latest - last) & UINT_MAX;        \

Why this is wrong? Both 'latest' and 'last' are 'u32', so diff should be correct 'u32' value. And it is added to 'u64' 'cur' value. What I am missing?

Per my understanding, stat value read from HW reg would be rolled over after it reaches its maximum, so we need to handle both normal case (latest >= last) and rollover case (latest < last) here. Wait for the original author for more explanation.

Quoted 13 lines

drivers/net/e1000/igb_ethdev.c static int igb_filter_restore(struct rte_eth_dev *dev); · line 271

Quoted 10 lines
drivers/net/e1000/igb_ethdev.c +8 -1
-	last = latest;                            \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
+{                                                               \
+	u32 latest = E1000_READ_REG(hw, reg);                   \
+	if (latest >= last)                                     \
+		cur += (latest - last);                         \
+	else                                                    \
+		cur += ((latest + ((uint64_t)1 << 32)) - last); \
+	cur &= UINT_MAX;                                        \

Why & with UINT_MAX, won't this limit the value to 32bits which has 64bit storage?

Agree & with UINT_MAX should be removed here.

Thanks,
Xiaolong

Quoted 6 lines
Quoted 5 lines
drivers/net/e1000/igb_ethdev.c +1 -0
+	last = latest;                                          \
 }
 
 #define IGB_FC_PAUSE_TIME 0x0680