patch 'eal/windows: fix thread creation' has been queued to stable release 22.11.2

Xueming Li xuemingl at nvidia.com
Sun Apr 9 17:24:01 CEST 2023


Hi,

FYI, your patch has been queued to stable release 22.11.2

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 04/11/23. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging/commit/bf878ca704dedd6242d194522065dd97a9da5140

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From bf878ca704dedd6242d194522065dd97a9da5140 Mon Sep 17 00:00:00 2001
From: Tyler Retzlaff <roretzla at linux.microsoft.com>
Date: Thu, 2 Mar 2023 10:44:42 -0800
Subject: [PATCH] eal/windows: fix thread creation
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit 4ca43a8898181e52ea5789ea36d8681dc05931d5 ]

In rte_thread_create setting affinity after CreateThread may fail. Such
a failure is reported but strands the newly created thread in a
suspended state.

Resolve the above issue by notifying the newly created thread that
it should terminate as soon as it is resumed, while still continuing to
free the ctx.

Fixes: ce6e911d20f6 ("eal: add thread lifetime API")

Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
Reviewed-by: David Marchand <david.marchand at redhat.com>
---
 lib/eal/windows/rte_thread.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d01e3..3538633816 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -17,6 +17,7 @@ struct eal_tls_key {
 
 struct thread_routine_ctx {
 	rte_thread_func thread_func;
+	bool thread_init_failed;
 	void *routine_args;
 };
 
@@ -165,9 +166,13 @@ static DWORD
 thread_func_wrapper(void *arg)
 {
 	struct thread_routine_ctx ctx = *(struct thread_routine_ctx *)arg;
+	const bool thread_exit = __atomic_load_n(&ctx.thread_init_failed, __ATOMIC_ACQUIRE);
 
 	free(arg);
 
+	if (thread_exit)
+		return 0;
+
 	return (DWORD)ctx.thread_func(ctx.routine_args);
 }
 
@@ -181,6 +186,7 @@ rte_thread_create(rte_thread_t *thread_id,
 	HANDLE thread_handle = NULL;
 	GROUP_AFFINITY thread_affinity;
 	struct thread_routine_ctx *ctx;
+	bool thread_exit = false;
 
 	ctx = calloc(1, sizeof(*ctx));
 	if (ctx == NULL) {
@@ -190,6 +196,7 @@ rte_thread_create(rte_thread_t *thread_id,
 	}
 	ctx->routine_args = args;
 	ctx->thread_func = thread_func;
+	ctx->thread_init_failed = false;
 
 	thread_handle = CreateThread(NULL, 0, thread_func_wrapper, ctx,
 		CREATE_SUSPENDED, &tid);
@@ -207,23 +214,29 @@ rte_thread_create(rte_thread_t *thread_id,
 							);
 			if (ret != 0) {
 				RTE_LOG(DEBUG, EAL, "Unable to convert cpuset to thread affinity\n");
-				goto cleanup;
+				thread_exit = true;
+				goto resume_thread;
 			}
 
 			if (!SetThreadGroupAffinity(thread_handle,
 						    &thread_affinity, NULL)) {
 				ret = thread_log_last_error("SetThreadGroupAffinity()");
-				goto cleanup;
+				thread_exit = true;
+				goto resume_thread;
 			}
 		}
 		ret = rte_thread_set_priority(*thread_id,
 				thread_attr->priority);
 		if (ret != 0) {
 			RTE_LOG(DEBUG, EAL, "Unable to set thread priority\n");
-			goto cleanup;
+			thread_exit = true;
+			goto resume_thread;
 		}
 	}
 
+resume_thread:
+	__atomic_store_n(&ctx->thread_init_failed, thread_exit, __ATOMIC_RELEASE);
+
 	if (ResumeThread(thread_handle) == (DWORD)-1) {
 		ret = thread_log_last_error("ResumeThread()");
 		goto cleanup;
-- 
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-04-09 21:45:40.153091800 +0800
+++ 0053-eal-windows-fix-thread-creation.patch	2023-04-09 21:45:38.659042200 +0800
@@ -1 +1 @@
-From 4ca43a8898181e52ea5789ea36d8681dc05931d5 Mon Sep 17 00:00:00 2001
+From bf878ca704dedd6242d194522065dd97a9da5140 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 4ca43a8898181e52ea5789ea36d8681dc05931d5 ]
@@ -15 +17,0 @@
-Cc: stable at dpdk.org
@@ -24 +26 @@
-index 8556a84f13..e528ac9991 100644
+index 1c1e9d01e3..3538633816 100644
@@ -27 +29 @@
-@@ -19,6 +19,7 @@ struct eal_tls_key {
+@@ -17,6 +17,7 @@ struct eal_tls_key {
@@ -35 +37 @@
-@@ -167,9 +168,13 @@ static DWORD
+@@ -165,9 +166,13 @@ static DWORD
@@ -49 +51 @@
-@@ -183,6 +188,7 @@ rte_thread_create(rte_thread_t *thread_id,
+@@ -181,6 +186,7 @@ rte_thread_create(rte_thread_t *thread_id,
@@ -57 +59 @@
-@@ -192,6 +198,7 @@ rte_thread_create(rte_thread_t *thread_id,
+@@ -190,6 +196,7 @@ rte_thread_create(rte_thread_t *thread_id,
@@ -65 +67 @@
-@@ -209,23 +216,29 @@ rte_thread_create(rte_thread_t *thread_id,
+@@ -207,23 +214,29 @@ rte_thread_create(rte_thread_t *thread_id,


More information about the stable mailing list