* [PATCH v1] raw/ifpga: fix pthread cannot join
@ 2022-01-19 5:54 Wei Huang
2022-01-19 10:45 ` Xu, Rosen
2022-01-20 2:35 ` [PATCH v2] " Wei Huang
0 siblings, 2 replies; 8+ messages in thread
From: Wei Huang @ 2022-01-19 5:54 UTC (permalink / raw)
To: dev, rosen.xu, qi.z.zhang; +Cc: stable, tianfei.zhang, ferruh.yigit
From: Tianfei Zhang <tianfei.zhang@intel.com>
When we want to close a thread, we should set a flag to
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>
---
drivers/raw/ifpga/ifpga_rawdev.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 8d9db58..9663b67 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
int gsd_enable, ret;
#define MS 1000
- while (1) {
+ while (ifpga_monitor_start) {
gsd_enable = 0;
for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
ifpga_rdev = &ifpga_rawdevices[i];
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
{
int ret;
- if (ifpga_monitor_start == 1) {
+ if (ifpga_monitor_start == 1 && ifpga_monitor_start_thread) {
+ 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] 8+ messages in thread
* RE: [PATCH v1] raw/ifpga: fix pthread cannot join
2022-01-19 5:54 [PATCH v1] raw/ifpga: fix pthread cannot join Wei Huang
@ 2022-01-19 10:45 ` Xu, Rosen
2022-01-20 2:35 ` [PATCH v2] " Wei Huang
1 sibling, 0 replies; 8+ messages in thread
From: Xu, Rosen @ 2022-01-19 10:45 UTC (permalink / raw)
To: Huang, Wei, dev, Zhang, Qi Z; +Cc: stable, Zhang, Tianfei, Yigit, Ferruh
Hi Wei,
Some ci/iol-intel-Functional issues, pls check. Thanks a lot.
> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Wednesday, January 19, 2022 13:54
> To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Yigit, Ferruh
> <ferruh.yigit@intel.com>
> Subject: [PATCH v1] raw/ifpga: fix pthread cannot join
>
> From: Tianfei Zhang <tianfei.zhang@intel.com>
>
> When we want to close a thread, we should set a flag to 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>
> ---
> drivers/raw/ifpga/ifpga_rawdev.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> b/drivers/raw/ifpga/ifpga_rawdev.c
> index 8d9db58..9663b67 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
> int gsd_enable, ret;
> #define MS 1000
>
> - while (1) {
> + while (ifpga_monitor_start) {
> gsd_enable = 0;
> for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
> ifpga_rdev = &ifpga_rawdevices[i];
> @@ -544,7 +544,9 @@ static int set_surprise_link_check_aer( {
> int ret;
>
> - if (ifpga_monitor_start == 1) {
> + if (ifpga_monitor_start == 1 && ifpga_monitor_start_thread) {
> + 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] 8+ messages in thread
* [PATCH v2] raw/ifpga: fix pthread cannot join
2022-01-19 5:54 [PATCH v1] raw/ifpga: fix pthread cannot join Wei Huang
2022-01-19 10:45 ` Xu, Rosen
@ 2022-01-20 2:35 ` Wei Huang
2022-01-20 5:58 ` [PATCH v3] " Wei Huang
1 sibling, 1 reply; 8+ messages in thread
From: Wei Huang @ 2022-01-20 2:35 UTC (permalink / raw)
To: dev, rosen.xu, qi.z.zhang; +Cc: stable, tianfei.zhang, ferruh.yigit
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
---
drivers/raw/ifpga/ifpga_rawdev.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 8d9db58..26752c4 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
int gsd_enable, ret;
#define MS 1000
- while (1) {
+ while (ifpga_monitor_start) {
gsd_enable = 0;
for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
ifpga_rdev = &ifpga_rawdevices[i];
@@ -544,7 +544,9 @@ static int set_surprise_link_check_aer(
{
int ret;
- if (ifpga_monitor_start == 1) {
+ if ((ifpga_monitor_start == 1) && ifpga_monitor_start_thread) {
+ 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] 8+ messages in thread
* [PATCH v3] raw/ifpga: fix pthread cannot join
2022-01-20 2:35 ` [PATCH v2] " Wei Huang
@ 2022-01-20 5:58 ` Wei Huang
2022-01-20 8:08 ` David Marchand
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Wei Huang @ 2022-01-20 5:58 UTC (permalink / raw)
To: dev, rosen.xu, qi.z.zhang; +Cc: stable, tianfei.zhang, ferruh.yigit
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
---
drivers/raw/ifpga/ifpga_rawdev.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 8d9db58..2bc569b 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
int gsd_enable, ret;
#define MS 1000
- while (1) {
+ while (ifpga_monitor_start) {
gsd_enable = 0;
for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
ifpga_rdev = &ifpga_rawdevices[i];
@@ -542,18 +542,21 @@ static int set_surprise_link_check_aer(
static int
ifpga_monitor_stop_func(void)
{
+ void *status;
int ret;
- if (ifpga_monitor_start == 1) {
+ if ((ifpga_monitor_start == 1) && ifpga_monitor_start_thread) {
+ ifpga_monitor_start = 0;
+
ret = pthread_cancel(ifpga_monitor_start_thread);
if (ret)
IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
- ret = pthread_join(ifpga_monitor_start_thread, NULL);
+ ret = pthread_join(ifpga_monitor_start_thread, &status);
if (ret)
IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
- ifpga_monitor_start = 0;
+ ifpga_monitor_start_thread = 0;
return ret;
}
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] raw/ifpga: fix pthread cannot join
2022-01-20 5:58 ` [PATCH v3] " Wei Huang
@ 2022-01-20 8:08 ` David Marchand
2022-01-20 15:46 ` Stephen Hemminger
2022-01-21 1:29 ` [PATCH v4] " Wei Huang
2 siblings, 0 replies; 8+ messages in thread
From: David Marchand @ 2022-01-20 8:08 UTC (permalink / raw)
To: Wei Huang
Cc: dev, Rosen Xu, Qi Zhang, dpdk stable, Zhang, Tianfei, Yigit, Ferruh
On Thu, Jan 20, 2022 at 7:01 AM Wei Huang <wei.huang@intel.com> wrote:
>
> 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
Evaluating/setting a pthread_t variable is a bad idea: this type
should be considered opaque.
Plus here, the ifpga_monitor_start variable already indicates whether
ifpga_monitor_start_thread is valid.
Only checking for ifpga_monitor_start in ifpga_rawdev_gsd_handle loop
should be enough.
> ---
> drivers/raw/ifpga/ifpga_rawdev.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
> index 8d9db58..2bc569b 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
> int gsd_enable, ret;
> #define MS 1000
>
> - while (1) {
> + while (ifpga_monitor_start) {
> gsd_enable = 0;
> for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
> ifpga_rdev = &ifpga_rawdevices[i];
> @@ -542,18 +542,21 @@ static int set_surprise_link_check_aer(
> static int
> ifpga_monitor_stop_func(void)
> {
> + void *status;
This status variable is unused, no need for it.
> int ret;
>
> - if (ifpga_monitor_start == 1) {
> + if ((ifpga_monitor_start == 1) && ifpga_monitor_start_thread) {
> + ifpga_monitor_start = 0;
> +
> ret = pthread_cancel(ifpga_monitor_start_thread);
> if (ret)
> IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
>
> - ret = pthread_join(ifpga_monitor_start_thread, NULL);
> + ret = pthread_join(ifpga_monitor_start_thread, &status);
> if (ret)
> IFPGA_RAWDEV_PMD_ERR("Can't join the thread");
>
> - ifpga_monitor_start = 0;
> + ifpga_monitor_start_thread = 0;
>
> return ret;
> }
> --
> 1.8.3.1
>
--
David Marchand
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] raw/ifpga: fix pthread cannot join
2022-01-20 5:58 ` [PATCH v3] " Wei Huang
2022-01-20 8:08 ` David Marchand
@ 2022-01-20 15:46 ` Stephen Hemminger
2022-01-21 8:02 ` Zhang, Tianfei
2022-01-21 1:29 ` [PATCH v4] " Wei Huang
2 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2022-01-20 15:46 UTC (permalink / raw)
To: Wei Huang; +Cc: dev, rosen.xu, qi.z.zhang, stable, tianfei.zhang, ferruh.yigit
On Thu, 20 Jan 2022 00:58:14 -0500
Wei Huang <wei.huang@intel.com> wrote:
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
> index 8d9db58..2bc569b 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
> int gsd_enable, ret;
> #define MS 1000
>
> - while (1) {
> + while (ifpga_monitor_start) {
This will work on x86 CPU but not on CPU's with weak memory
ordering like ARM.
You need to use atomic_builtin when accessing a flag shared between
threads that is not being protected by a lock.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH v3] raw/ifpga: fix pthread cannot join
2022-01-20 15:46 ` Stephen Hemminger
@ 2022-01-21 8:02 ` Zhang, Tianfei
0 siblings, 0 replies; 8+ messages in thread
From: Zhang, Tianfei @ 2022-01-21 8:02 UTC (permalink / raw)
To: Stephen Hemminger, Huang, Wei
Cc: dev, Xu, Rosen, Zhang, Qi Z, stable, Yigit, Ferruh
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, January 20, 2022 11:47 PM
> To: Huang, Wei <wei.huang@intel.com>
> Cc: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; stable@dpdk.org; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
> Subject: Re: [PATCH v3] raw/ifpga: fix pthread cannot join
>
> On Thu, 20 Jan 2022 00:58:14 -0500
> Wei Huang <wei.huang@intel.com> wrote:
>
> > diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> > b/drivers/raw/ifpga/ifpga_rawdev.c
> > index 8d9db58..2bc569b 100644
> > --- a/drivers/raw/ifpga/ifpga_rawdev.c
> > +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> > @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
> > int gsd_enable, ret;
> > #define MS 1000
> >
> > - while (1) {
> > + while (ifpga_monitor_start) {
>
> This will work on x86 CPU but not on CPU's with weak memory ordering like
> ARM.
>
> You need to use atomic_builtin when accessing a flag shared between threads
> that is not being protected by a lock.
We submitted a v5 patch for your suggestion, but got a " coding style issues" which said that:
Warning in drivers/raw/ifpga/ifpga_rawdev.c:
Using rte_atomicNN_xxx
We look at the devtools/checkpatches.sh script, it mentioned that rte_atomic APIs are forbidden.
ifpga_monitor_start just a flags to enable and disable the threads not share with threads. When the driver init it will start the thread,
when the driver remove it want to stop the thread. I don't think it will has a concurrency issue on this scenario.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4] raw/ifpga: fix pthread cannot join
2022-01-20 5:58 ` [PATCH v3] " Wei Huang
2022-01-20 8:08 ` David Marchand
2022-01-20 15:46 ` Stephen Hemminger
@ 2022-01-21 1:29 ` Wei Huang
2 siblings, 0 replies; 8+ messages in thread
From: Wei Huang @ 2022-01-21 1:29 UTC (permalink / raw)
To: dev, rosen.xu, qi.z.zhang; +Cc: stable, tianfei.zhang, ferruh.yigit
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
---
drivers/raw/ifpga/ifpga_rawdev.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 8d9db58..cb5166e 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -497,7 +497,7 @@ static int set_surprise_link_check_aer(
int gsd_enable, ret;
#define MS 1000
- while (1) {
+ while (ifpga_monitor_start) {
gsd_enable = 0;
for (i = 0; i < IFPGA_RAWDEV_NUM; i++) {
ifpga_rdev = &ifpga_rawdevices[i];
@@ -542,19 +542,20 @@ static int set_surprise_link_check_aer(
static int
ifpga_monitor_stop_func(void)
{
+ void *status;
int ret;
if (ifpga_monitor_start == 1) {
+ ifpga_monitor_start = 0;
+
ret = pthread_cancel(ifpga_monitor_start_thread);
if (ret)
IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread");
- ret = pthread_join(ifpga_monitor_start_thread, NULL);
+ ret = pthread_join(ifpga_monitor_start_thread, &status);
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] 8+ messages in thread
end of thread, other threads:[~2022-01-21 8:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 5:54 [PATCH v1] raw/ifpga: fix pthread cannot join Wei Huang
2022-01-19 10:45 ` Xu, Rosen
2022-01-20 2:35 ` [PATCH v2] " Wei Huang
2022-01-20 5:58 ` [PATCH v3] " Wei Huang
2022-01-20 8:08 ` David Marchand
2022-01-20 15:46 ` Stephen Hemminger
2022-01-21 8:02 ` Zhang, Tianfei
2022-01-21 1:29 ` [PATCH v4] " Wei Huang
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).