DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal/windows: fix data race when creating threads
@ 2022-03-10  7:35 Tyler Retzlaff
  2022-03-10 16:19 ` Dmitry Kozlyuk
  0 siblings, 1 reply; 3+ messages in thread
From: Tyler Retzlaff @ 2022-03-10  7:35 UTC (permalink / raw)
  To: dev; +Cc: dmitry.kozliuk, Tyler Retzlaff, anand.rawat, stable

create lcore worker threads suspended and then subsequently resume to
allow &lcore_config[i].thread_id be stored before eal_thread_loop
execution.

Fixes: 53ffd9f080fc ("eal/windows: add minimum viable code")
Cc: anand.rawat@intel.com
Cc: stable@dpdk.org

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/windows/eal_thread.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c
index 54fa93f..ff84cb4 100644
--- a/lib/eal/windows/eal_thread.c
+++ b/lib/eal/windows/eal_thread.c
@@ -150,13 +150,18 @@
 
 	th = CreateThread(NULL, 0,
 		(LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
-						NULL, 0, (LPDWORD)thread);
+						NULL, CREATE_SUSPENDED, (LPDWORD)thread);
 	if (!th)
 		return -1;
 
 	SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
 	SetThreadPriority(th, THREAD_PRIORITY_NORMAL);
 
+	if (ResumeThread(th) == (DWORD)-1) {
+		(void)CloseHandle(th);
+		return -1;
+	}
+
 	return 0;
 }
 
-- 
1.8.3.1


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

* Re: [PATCH] eal/windows: fix data race when creating threads
  2022-03-10  7:35 [PATCH] eal/windows: fix data race when creating threads Tyler Retzlaff
@ 2022-03-10 16:19 ` Dmitry Kozlyuk
  2022-03-30 17:04   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Kozlyuk @ 2022-03-10 16:19 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, anand.rawat, stable

Hi Tyler,

2022-03-09 23:35 (UTC-0800), Tyler Retzlaff:
> create lcore worker threads suspended and then subsequently resume to
> allow &lcore_config[i].thread_id be stored before eal_thread_loop
> execution.
> 
> Fixes: 53ffd9f080fc ("eal/windows: add minimum viable code")
> Cc: anand.rawat@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

It takes some effort to correlate &lcore_config[i].thread_id
with the code in the patch and knowledge of CreateThread()
to understand the root cause.
I suggest prepending an explanation to your commit message:

	eal_thread_loop() uses lcore_config[i].thread_id,
	which is stored upon the return from CreateThread().
	Per documentation, eal_thread_loop() can start
	before CreateThread() returns and the ID is stored.

> ---
>  lib/eal/windows/eal_thread.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c
> index 54fa93f..ff84cb4 100644
> --- a/lib/eal/windows/eal_thread.c
> +++ b/lib/eal/windows/eal_thread.c
> @@ -150,13 +150,18 @@
>  
>  	th = CreateThread(NULL, 0,
>  		(LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
> -						NULL, 0, (LPDWORD)thread);
> +						NULL, CREATE_SUSPENDED, (LPDWORD)thread);
>  	if (!th)
>  		return -1;
>  
>  	SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
>  	SetThreadPriority(th, THREAD_PRIORITY_NORMAL);
>  
> +	if (ResumeThread(th) == (DWORD)-1) {
> +		(void)CloseHandle(th);
> +		return -1;
> +	}
> +
>  	return 0;
>  }
>  


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

* Re: [PATCH] eal/windows: fix data race when creating threads
  2022-03-10 16:19 ` Dmitry Kozlyuk
@ 2022-03-30 17:04   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2022-03-30 17:04 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, anand.rawat, stable, Dmitry Kozlyuk

10/03/2022 17:19, Dmitry Kozlyuk:
> Hi Tyler,
> 
> 2022-03-09 23:35 (UTC-0800), Tyler Retzlaff:
> > create lcore worker threads suspended and then subsequently resume to
> > allow &lcore_config[i].thread_id be stored before eal_thread_loop
> > execution.
> > 
> > Fixes: 53ffd9f080fc ("eal/windows: add minimum viable code")
> > Cc: anand.rawat@intel.com
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> 
> It takes some effort to correlate &lcore_config[i].thread_id
> with the code in the patch and knowledge of CreateThread()
> to understand the root cause.
> I suggest prepending an explanation to your commit message:
> 
> 	eal_thread_loop() uses lcore_config[i].thread_id,
> 	which is stored upon the return from CreateThread().
> 	Per documentation, eal_thread_loop() can start
> 	before CreateThread() returns and the ID is stored.

There was now reply to this suggestion after 3 weeks,
so I've decided to include it.

Applied, thanks.






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

end of thread, other threads:[~2022-03-30 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10  7:35 [PATCH] eal/windows: fix data race when creating threads Tyler Retzlaff
2022-03-10 16:19 ` Dmitry Kozlyuk
2022-03-30 17:04   ` Thomas Monjalon

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).