DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v5] raw/ifpga: fix pthread cannot join
       [not found] <20220121012932.9827-1-wei.huang>
@ 2022-01-21  3:32 ` Wei Huang
  2022-01-21 16:19   ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Huang @ 2022-01-21  3:32 UTC (permalink / raw)
  To: dev, rosen.xu, qi.z.zhang
  Cc: stable, tianfei.zhang, ferruh.yigit, stephen, david.marchand

From: Tianfei Zhang <tianfei.zhang@intel.com>

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")
Cc: stable@dpdk.org

Signed-off-by: Tianfei Zhang <tianfei.zhang@intel.com>
---
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
---
 drivers/raw/ifpga/ifpga_rawdev.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 8d9db58..b72c13a 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -68,7 +68,7 @@
 
 static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM];
 
-static int ifpga_monitor_start;
+static rte_atomic32_t ifpga_monitor_start;
 static pthread_t ifpga_monitor_start_thread;
 
 #define IFPGA_MAX_IRQ 12
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
 	int gsd_enable, ret;
 #define MS 1000
 
-	while (1) {
+	while (rte_atomic32_read(&ifpga_monitor_start)) {
 		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 (!rte_atomic32_read(&ifpga_monitor_start)) {
 		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;
+		rte_atomic32_set(&ifpga_monitor_start, 1);
 	}
 
 	return 0;
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
 {
 	int ret;
 
-	if (ifpga_monitor_start == 1) {
+	if (rte_atomic32_read(&ifpga_monitor_start)) {
+		rte_atomic32_set(&ifpga_monitor_start, 0);
+
 		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;
 	}
 
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v5] raw/ifpga: fix pthread cannot join
  2022-01-21  3:32 ` [PATCH v5] raw/ifpga: fix pthread cannot join Wei Huang
@ 2022-01-21 16:19   ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2022-01-21 16:19 UTC (permalink / raw)
  To: Wei Huang
  Cc: dev, rosen.xu, qi.z.zhang, stable, tianfei.zhang, ferruh.yigit,
	david.marchand

On Thu, 20 Jan 2022 22:32:46 -0500
Wei Huang <wei.huang@intel.com> wrote:

> @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
>  	int gsd_enable, ret;
>  #define MS 1000
>  
> -	while (1) {
> +	while (rte_atomic32_read(&ifpga_monitor_start)) {

Better, but rte_atomic is deprecated in favor of using __atomic builtin
instead. This is because there are more options possible with 
__atomic_load_n than rte_atomic32_read.  rte_atomic32_read has to assume
worst case memory ordering, and your example relaxed memory ordering is
what you need.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-21 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220121012932.9827-1-wei.huang>
2022-01-21  3:32 ` [PATCH v5] raw/ifpga: fix pthread cannot join Wei Huang
2022-01-21 16:19   ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).