Skip to contentSkip to conversation

raw/ifpga: fix pthread cannot join

PATCH Superseded Wei Huang 3 participants 5 messages Jan 22, 2022 – Jan 25, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20220121033246.10339-1-wei.huang

Wei Huang

author
#1 lore raw

PATCH v6 1/1 raw/ifpga: fix pthread cannot join

From: Tianfei Zhang <[email protected]>

When we want to close a thread, we should set a flag to notify thread handler function.

Fixes 9c006c45 ("raw/ifpga: scan PCIe BDF device tree")

---
v2: update commit log
---
v3: set thread id to 0 after pthread_join
---
v4: do not evaluate and set pthread_t variable
---
v5: use builtin atomic function to access ifpga_monitor_start flag
---
v6: use __atomic_xxx_n to replace rte_atomicNN_xxx

---
 drivers/raw/ifpga/ifpga_rawdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +6 -6
index 8d9db58..19c2357 100644
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		gsd_enable = 0;
 		for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
 			ifpga_rdev = &ifpga_rawdevices[i];
@@ -525,7 +525,7 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 0) {
+	if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
 					     "ifpga-monitor", NULL,
 					     ifpga_rawdev_gsd_handle, NULL);
@@ -534,7 +534,7 @@ static int set_surprise_link_check_aer(
 				"Fail to create ifpga nonitor thread");
 			return -1;
 		}
-		ifpga_monitor_start = 1;
+		__atomic_store_n(&ifpga_monitor_start, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+		__atomic_store_n(&ifpga_monitor_start, 0, __ATOMIC_RELAXED);
+
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
@@ -553,8 +555,6 @@ static int set_surprise_link_check_aer(
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-		ifpga_monitor_start = 0;
-
 		return ret;
 	}
 
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v7 1/1 raw/ifpga: fix pthread cannot join

From: Tianfei Zhang <[email protected]>

When we want to close a thread, we should set a flag to notify thread handler function.

Fixes 9c006c45 ("raw/ifpga: scan PCIe BDF device tree")

---
v2: update commit log
---
v3: set thread id to 0 after pthread_join
---
v4: do not evaluate and set pthread_t variable
---
v5: use builtin atomic function to access ifpga_monitor_start flag
---
v6: use __atomic_xxx_n to replace rte_atomicNN_xxx
---
v7: fix patch applying issue

---
 drivers/raw/ifpga/ifpga_rawdev.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +7 -7
index 8d9db58..719f3b0 100644
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		gsd_enable = 0;
 		for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
 			ifpga_rdev = &ifpga_rawdevices[i];
@@ -525,16 +525,16 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 0) {
+	if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
 					     "ifpga-monitor", NULL,
 					     ifpga_rawdev_gsd_handle, NULL);
 		if (ret != 0) {
 			IFPGA_RAWDEV_PMD_ERR(
-				"Fail to create ifpga nonitor thread");
+				"Fail to create ifpga monitor thread");
 			return -1;
 		}
-		ifpga_monitor_start = 1;
+		__atomic_store_n(&ifpga_monitor_start, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+		__atomic_store_n(&ifpga_monitor_start, 0, __ATOMIC_RELAXED);
+
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
@@ -553,8 +555,6 @@ static int set_surprise_link_check_aer(
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-		ifpga_monitor_start = 0;
-
 		return ret;
 	}
 
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v8 1/1 raw/ifpga: fix pthread cannot join

From: Tianfei Zhang <[email protected]>

When we want to close a thread, we should set a flag to notify thread handler function.

Fixes 9c006c45 ("raw/ifpga: scan PCIe BDF device tree")

---
v2: update commit log
---
v3: set thread id to 0 after pthread_join
---
v4: do not evaluate and set pthread_t variable
---
v5: use builtin atomic function to access ifpga_monitor_start flag
---
v6: use __atomic_xxx_n to replace rte_atomicNN_xxx
---
v7: fix typo
---
v8: solve patch applying issue

---
 drivers/raw/ifpga/ifpga_rawdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +6 -6
index 8d9db58..19c2357 100644
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		gsd_enable = 0;
 		for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
 			ifpga_rdev = &ifpga_rawdevices[i];
@@ -525,7 +525,7 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 0) {
+	if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
 					     "ifpga-monitor", NULL,
 					     ifpga_rawdev_gsd_handle, NULL);
@@ -534,7 +534,7 @@ static int set_surprise_link_check_aer(
 				"Fail to create ifpga monitor thread");
 			return -1;
 		}
-		ifpga_monitor_start = 1;
+		__atomic_store_n(&ifpga_monitor_start, 1, __ATOMIC_RELAXED);
 	}
 
 	return 0;
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+		__atomic_store_n(&ifpga_monitor_start, 0, __ATOMIC_RELAXED);
+
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
@@ -553,8 +555,6 @@ static int set_surprise_link_check_aer(
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-		ifpga_monitor_start = 0;
-
 		return ret;
 	}
 
Signature · 1 line
1.8.3.1
Acked-by on v8 1/1
#4 lore raw

Hi,

Quoted 91 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Monday, January 24, 2022 11:50
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Zhang, Tianfei <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v8] raw/ifpga: fix pthread cannot join

From: Tianfei Zhang <[email protected]>

When we want to close a thread, we should set a flag to notify thread handler function.

Fixes 9c006c45 ("raw/ifpga: scan PCIe BDF device tree")

---
v2: update commit log
---
v3: set thread id to 0 after pthread_join
---
v4: do not evaluate and set pthread_t variable
---
v5: use builtin atomic function to access ifpga_monitor_start flag
---
v6: use __atomic_xxx_n to replace rte_atomicNN_xxx
---
v7: fix typo
---
v8: solve patch applying issue

---
 drivers/raw/ifpga/ifpga_rawdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +1 -1
index 8d9db58..19c2357 100644
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (__atomic_load_n(&ifpga_monitor_start,
 __ATOMIC_RELAXED)) {
 		gsd_enable = 0;
 		for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
drivers/raw/ifpga/ifpga_rawdev.c +2 -2
 			ifpga_rdev = &ifpga_rawdevices[i];
@@ -525,7 +525,7 @@ static int set_surprise_link_check_aer(  {
 	int ret;
 
-	if (ifpga_monitor_start == 0) {
+	if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
 					     "ifpga-monitor", NULL,
 					     ifpga_rawdev_gsd_handle, NULL);
@@ -534,7 +534,7 @@ static int set_surprise_link_check_aer(
 				"Fail to create ifpga monitor thread");
 			return -1;
 		}
-		ifpga_monitor_start = 1;
+		__atomic_store_n(&ifpga_monitor_start, 1,
 __ATOMIC_RELAXED);
 	}
 
drivers/raw/ifpga/ifpga_rawdev.c +3 -1
 	return 0;
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(  {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+		__atomic_store_n(&ifpga_monitor_start, 0,
 __ATOMIC_RELAXED);
+
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't cancel the

thread"); @@ -553,8 +555,6 @@ static int set_surprise_link_check_aer(

drivers/raw/ifpga/ifpga_rawdev.c +0 -3
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-		ifpga_monitor_start = 0;
-
 		return ret;
 	}
 
--
Quoted 1 line

1.8.3.1

Applied
#5 lore raw
Quoted 107 lines

-----Original Message-----
From: Xu, Rosen <[email protected]>
Sent: Tuesday, January 25, 2022 9:43 AM
To: Huang, Wei <[email protected]>; [email protected]; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Zhang, Tianfei <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH v8] raw/ifpga: fix pthread cannot join

Hi,

Quoted 51 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Monday, January 24, 2022 11:50
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Zhang, Tianfei <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v8] raw/ifpga: fix pthread cannot join

From: Tianfei Zhang <[email protected]>

When we want to close a thread, we should set a flag to notify thread handler function.

Fixes 9c006c45 ("raw/ifpga: scan PCIe BDF device tree")

---
v2: update commit log
---
v3: set thread id to 0 after pthread_join
---
v4: do not evaluate and set pthread_t variable
---
v5: use builtin atomic function to access ifpga_monitor_start flag
---
v6: use __atomic_xxx_n to replace rte_atomicNN_xxx
---
v7: fix typo
---
v8: solve patch applying issue

---
 drivers/raw/ifpga/ifpga_rawdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +1 -1
index 8d9db58..19c2357 100644
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (__atomic_load_n(&ifpga_monitor_start,
 __ATOMIC_RELAXED)) {
 		gsd_enable = 0;
 		for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
Quoted 1 line

ifpga_rdev = &ifpga_rawdevices[i]; @@ -525,7 +525,7

@@ static int

Quoted 8 lines

set_surprise_link_check_aer( {

drivers/raw/ifpga/ifpga_rawdev.c +1 -1
 	int ret;
 
-	if (ifpga_monitor_start == 0) {
+	if (!__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
 		ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread,
 					     "ifpga-monitor", NULL,
 					     ifpga_rawdev_gsd_handle, NULL);
(quoted diff) +0 -0
@@ -534,7 +534,7 @@ static
Quoted 11 lines

int set_surprise_link_check_aer(

drivers/raw/ifpga/ifpga_rawdev.c +1 -1
 				"Fail to create ifpga monitor thread");
 			return -1;
 		}
-		ifpga_monitor_start = 1;
+		__atomic_store_n(&ifpga_monitor_start, 1,

__ATOMIC_RELAXED);

drivers/raw/ifpga/ifpga_rawdev.c +0 -0
 	}
 
 	return 0;

drivers/raw/ifpga/ifpga_rawdev.c static int set_surprise_link_check_aer( { · line 552

Quoted 10 lines
drivers/raw/ifpga/ifpga_rawdev.c +3 -1
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(  {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (__atomic_load_n(&ifpga_monitor_start, __ATOMIC_RELAXED)) {
+		__atomic_store_n(&ifpga_monitor_start, 0,
 __ATOMIC_RELAXED);
+
 		ret = pthread_cancel(ifpga_monitor_start_thread);
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't cancel the

thread"); @@ -553,8 +555,6

Quoted 9 lines

@@ static int set_surprise_link_check_aer(

drivers/raw/ifpga/ifpga_rawdev.c +0 -2
 		if (ret)
 			IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
 
-		ifpga_monitor_start = 0;
-
 		return ret;
 	}
Quoted 4 lines
Quoted 2 lines

--
1.8.3.1

Applied to dpdk-next-net-intel.

Thanks
Qi

Quoted 1 line