Skip to contentSkip to conversation

net/ixgbe: fix link status inconsistencies

PATCH Applied [email protected] 2 participants 4 messages Feb 26, 2020 – Mar 29, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/ixgbe: fix link status inconsistencies

From: Zhu Tao <[email protected]>

Setting LINK UP or LINK DOWN is divided into two parts, with the main task done in a separate thread, which can take up to 9 seconds. If cancel the thread in execution, may cause state inconsistencies. Therefore, must wait for the previous setting to exit normally before setting the new state.

Note: before using threads, use alarm to handle main tasks. When canceling alarm, the execution of alarm will not be interrupted.

Fixes 819d0d1d57 ("net/ixgbe: fix blocking system events")
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +22 -2
index 23b3f5b0c..2c5797635 100644
@@ -4143,16 +4143,35 @@ ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
 	return ret_val;
 }
 
+/* return 1: setup complete, return 0: setup not complete, and wait timeout*/
+static int
+ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev)
+{
+#define DELAY_INTERVAL 100 /* 100ms */
+#define MAX_TIMEOUT    90 /* 9s (90 * 100ms) in total */
+	struct ixgbe_adapter *ad = dev->data->dev_private;
+	int timeout = MAX_TIMEOUT;
+
+	while (rte_atomic32_read(&ad->link_thread_running) && timeout) {
+		msec_delay(DELAY_INTERVAL);
+		timeout--;
+	}
+
+
+	return !!timeout;
+}
+
 static void
 ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev)
 {
 	struct ixgbe_adapter *ad = dev->data->dev_private;
 	void *retval;
 
-	if (rte_atomic32_read(&ad->link_thread_running)) {
+	if (!ixgbe_dev_wait_setup_link_complete(dev)) {
 		pthread_cancel(ad->link_thread_tid);
 		pthread_join(ad->link_thread_tid, &retval);
 		rte_atomic32_clear(&ad->link_thread_running);
+		PMD_DRV_LOG(ERR, "Link thread not complete, cancel it!");
 	}
 }
 
@@ -4263,7 +4282,8 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev,
 	if (link_up == 0) {
 		if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) {
 			intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
-			if (rte_atomic32_test_and_set(&ad->link_thread_running)) {
+			if (ixgbe_dev_wait_setup_link_complete(dev) &&
+			    rte_atomic32_test_and_set(&ad->link_thread_running)) {
 				if (rte_ctrl_thread_create(&ad->link_thread_tid,
 					"ixgbe-link-handler",
 					NULL,
Signature · 1 line
2.17.1
author
#1 lore raw

+Xiaolong

BR,
Zhu, Tao

Quoted 83 lines

-----Original Message-----
From: Zhu, TaoX
Sent: Wednesday, February 26, 2020 8:07 PM
To: Ananyev, Konstantin <[email protected]>; Lu, Wenzhuo <[email protected]>
Cc: [email protected]; Zhu, TaoX <[email protected]>; [email protected]
Subject: [PATCH] net/ixgbe: fix link status inconsistencies

From: Zhu Tao <[email protected]>

Setting LINK UP or LINK DOWN is divided into two parts, with the main task done in a separate thread, which can take up to 9 seconds. If cancel the thread in execution, may cause state inconsistencies. Therefore, must wait for the previous setting to exit normally before setting the new state.

Note: before using threads, use alarm to handle main tasks. When canceling alarm, the execution of alarm will not be interrupted.

Fixes 819d0d1d57 ("net/ixgbe: fix blocking system events")
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +20 -2
index 23b3f5b0c..2c5797635 100644
@@ -4143,16 +4143,35 @@ ixgbevf_check_link(struct ixgbe_hw *hw,
 ixgbe_link_speed *speed,
 	return ret_val;
 }
 
+/* return 1: setup complete, return 0: setup not complete, and wait
+timeout*/ static int ixgbe_dev_wait_setup_link_complete(struct
+rte_eth_dev *dev) { #define DELAY_INTERVAL 100 /* 100ms */
+#define MAX_TIMEOUT    90 /* 9s (90 * 100ms) in total */
+	struct ixgbe_adapter *ad = dev->data->dev_private;
+	int timeout = MAX_TIMEOUT;
+
+	while (rte_atomic32_read(&ad->link_thread_running) && timeout) {
+		msec_delay(DELAY_INTERVAL);
+		timeout--;
+	}
+
+
+	return !!timeout;
+}
+
 static void
 ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev)  {
 	struct ixgbe_adapter *ad = dev->data->dev_private;
 	void *retval;
 
-	if (rte_atomic32_read(&ad->link_thread_running)) {
+	if (!ixgbe_dev_wait_setup_link_complete(dev)) {
 		pthread_cancel(ad->link_thread_tid);
 		pthread_join(ad->link_thread_tid, &retval);
 		rte_atomic32_clear(&ad->link_thread_running);
+		PMD_DRV_LOG(ERR, "Link thread not complete, cancel it!");
 	}
 }
 
@@ -4263,7 +4282,8 @@ ixgbe_dev_link_update_share(struct rte_eth_dev
 *dev,
 	if (link_up == 0) {
 		if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber)
 {
 			intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
-			if (rte_atomic32_test_and_set(&ad-
 >link_thread_running)) {
+			if (ixgbe_dev_wait_setup_link_complete(dev) &&
+			    rte_atomic32_test_and_set(&ad-
Quoted 1 line

link_thread_running)) {

if (rte_ctrl_thread_create(&ad-

Quoted 1 line

link_thread_tid,

drivers/net/ixgbe/ixgbe_ethdev.c +0 -1
 					"ixgbe-link-handler",
 					NULL,
--

2.17.1

author
#2 lore raw

+Jiang Yu

BR,
Zhu, Tao

Quoted 98 lines

-----Original Message-----
From: Zhu, TaoX
Sent: Tuesday, March 3, 2020 10:00 AM
To: Ananyev, Konstantin <[email protected]>; Lu, Wenzhuo <[email protected]>; Ye, Xiaolong <[email protected]>
Cc: [email protected]; [email protected]
Subject: RE: [PATCH] net/ixgbe: fix link status inconsistencies

+Xiaolong

BR,
Zhu, Tao

Quoted 8 lines

-----Original Message-----
From: Zhu, TaoX
Sent: Wednesday, February 26, 2020 8:07 PM
To: Ananyev, Konstantin <[email protected]>; Lu, Wenzhuo <[email protected]>
Cc: [email protected]; Zhu, TaoX <[email protected]>; [email protected]
Subject: [PATCH] net/ixgbe: fix link status inconsistencies

Quoted 6 lines

From: Zhu Tao <[email protected]>

Setting LINK UP or LINK DOWN is divided into two parts, with the main task done in a separate thread, which can take up to 9 seconds. If cancel the thread in execution, may cause state inconsistencies. Therefore, must wait for the previous setting to exit normally before

setting the new state.

drivers/net/ixgbe/ixgbe_ethdev.c ixgbe_dev_link_update_share(struct

Quoted 53 lines

Note: before using threads, use alarm to handle main tasks. When canceling alarm, the execution of alarm will not be interrupted.

Fixes 819d0d1d57 ("net/ixgbe: fix blocking system events")
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +18 -1
index 23b3f5b0c..2c5797635 100644
@@ -4143,16 +4143,35 @@ ixgbevf_check_link(struct ixgbe_hw *hw,
 ixgbe_link_speed *speed,
 	return ret_val;
 }
 
+/* return 1: setup complete, return 0: setup not complete, and wait
+timeout*/ static int ixgbe_dev_wait_setup_link_complete(struct
+rte_eth_dev *dev) { #define DELAY_INTERVAL 100 /* 100ms */
+#define MAX_TIMEOUT    90 /* 9s (90 * 100ms) in total */
+	struct ixgbe_adapter *ad = dev->data->dev_private;
+	int timeout = MAX_TIMEOUT;
+
+	while (rte_atomic32_read(&ad->link_thread_running) && timeout) {
+		msec_delay(DELAY_INTERVAL);
+		timeout--;
+	}
+
+
+	return !!timeout;
+}
+
 static void
 ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev)  {
 	struct ixgbe_adapter *ad = dev->data->dev_private;
 	void *retval;
 
-	if (rte_atomic32_read(&ad->link_thread_running)) {
+	if (!ixgbe_dev_wait_setup_link_complete(dev)) {
 		pthread_cancel(ad->link_thread_tid);
 		pthread_join(ad->link_thread_tid, &retval);
 		rte_atomic32_clear(&ad->link_thread_running);
+		PMD_DRV_LOG(ERR, "Link thread not complete, cancel it!");
 	}
 }
 
@@ -4263,7 +4282,8 @@ ixgbe_dev_link_update_share(struct

rte_eth_dev

drivers/net/ixgbe/ixgbe_ethdev.c ixgbe_dev_link_update_share(struct · line 4284

Quoted 3 lines
drivers/net/ixgbe/ixgbe_ethdev.c +0 -0
 *dev,
 	if (link_up == 0) {
 		if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber)

{

Quoted 12 lines
drivers/net/ixgbe/ixgbe_ethdev.c +2 -1
 			intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
-			if (rte_atomic32_test_and_set(&ad-
 >link_thread_running)) {
+			if (ixgbe_dev_wait_setup_link_complete(dev) &&
+			    rte_atomic32_test_and_set(&ad-
 >link_thread_running)) {

if (rte_ctrl_thread_create(&ad-

Quoted 1 line

link_thread_tid,

drivers/net/ixgbe/ixgbe_ethdev.c +0 -1
 					"ixgbe-link-handler",
 					NULL,
--

2.17.1

Acked-by on v1 1/1 Applied
#3 lore raw
In reply to [email protected]
Quoted 73 lines · On 02/26, [email protected] wrote:

From: Zhu Tao <[email protected]>

Setting LINK UP or LINK DOWN is divided into two parts, with the main task done in a separate thread, which can take up to 9 seconds. If cancel the thread in execution, may cause state inconsistencies. Therefore, must wait for the previous setting to exit normally before setting the new state.

Note: before using threads, use alarm to handle main tasks. When canceling alarm, the execution of alarm will not be interrupted.

Fixes 819d0d1d57 ("net/ixgbe: fix blocking system events")

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

1 file changed, 22 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethdev.c +18 -0
index 23b3f5b0c..2c5797635 100644
@@ -4143,16 +4143,35 @@ ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
 	return ret_val;
 }
 
+/* return 1: setup complete, return 0: setup not complete, and wait timeout*/
+static int
+ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev)
+{
+#define DELAY_INTERVAL 100 /* 100ms */
+#define MAX_TIMEOUT    90 /* 9s (90 * 100ms) in total */
+	struct ixgbe_adapter *ad = dev->data->dev_private;
+	int timeout = MAX_TIMEOUT;
+
+	while (rte_atomic32_read(&ad->link_thread_running) && timeout) {
+		msec_delay(DELAY_INTERVAL);
+		timeout--;
+	}
+
+
+	return !!timeout;
+}
+

static void ixgbe_dev_cancel_link_thread(struct rte_eth_dev *dev)

{
	struct ixgbe_adapter *ad = dev->data->dev_private;
	void *retval;
drivers/net/ixgbe/ixgbe_ethdev.c +1 -1
-	if (rte_atomic32_read(&ad->link_thread_running)) {
+	if (!ixgbe_dev_wait_setup_link_complete(dev)) {
		pthread_cancel(ad->link_thread_tid);
		pthread_join(ad->link_thread_tid, &retval);
		rte_atomic32_clear(&ad->link_thread_running);
drivers/net/ixgbe/ixgbe_ethdev.c +1 -0
+		PMD_DRV_LOG(ERR, "Link thread not complete, cancel it!");
	}
}
drivers/net/ixgbe/ixgbe_ethdev.c +2 -1
@@ -4263,7 +4282,8 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev,
 	if (link_up == 0) {
 		if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) {
 			intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
-			if (rte_atomic32_test_and_set(&ad->link_thread_running)) {
+			if (ixgbe_dev_wait_setup_link_complete(dev) &&
+			    rte_atomic32_test_and_set(&ad->link_thread_running)) {
 				if (rte_ctrl_thread_create(&ad->link_thread_tid,
 					"ixgbe-link-handler",
 					NULL,
Signature · 1 line
2.17.1

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