Skip to contentSkip to conversation

eal: rte_ctrl_thread_create API replacement

PATCH Superseded Tyler Retzlaff 8 participants 56 messages Dec 5, 2022 – Feb 24, 2023

lore
Share & tools
lore
#0 lore raw

cover eal: rte_ctrl_thread_create API replacement

Remove rte_ctrl_thread_create API which exposes pthread_t and provide new rte_control_thread_create API based on EALs rte_thread_t.

To limit compatibility regression risk and ease of removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation. The duplication will be removed when rte_ctrl_thread_create is finally duplicated/removed.

The unit test for rte_ctrl_thread_create has been duplicated to exercise both the old and the new API during transition, as with the API the duplicate test will be removed when the rte_ctrl_thread_create API is removed.

Tyler Retzlaff (3):
eal: add rte control thread create API
test: add rte control thread create API test
eal: deprecate pthread control thread create API

 app/test/test_lcores.c               | 44 +++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 ++
 lib/eal/common/eal_common_thread.c   | 93 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 29 +++++++++++
 lib/eal/version.map                  |  3 ++
 5 files changed, 165 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/3 eal: add rte control thread create API

---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +85 -8
index c5d8b43..ca85c51 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void * (*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (0 != ctrl_thread_init(arg))
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.thread_func;
+
+	if (0 != ctrl_thread_init(arg))
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 
 int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (!params)
+		return -ENOMEM;
+
+	params->u.thread_func = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname(thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h +29 -0
index b9edf70..ffc6207 100644
@@ -95,6 +95,35 @@ int rte_thread_create(rte_thread_t *thread_id,
 		rte_thread_func thread_func, void *arg);
 
 /**
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the dataplane and service
+ * lcores are then excluded. If setting the name of the thread fails,
+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').
+ * @param attr
+ *   Attributes for the new thread.
+ * @param start_routine
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
 };
 
 INTERNAL {
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 1/3] eal: add rte control thread create API

Quoted 12 lines · On Mon, 5 Dec 2022 12:24:26 -0800 Tyler Retzlaff…
---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +0 -0
index c5d8b43..ca85c51 100644

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 240

Quoted 8 lines
lib/eal/common/eal_common_thread.c +4 -1
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void * (*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;

Why not just use rte_thread_func, this in internal.

Quoted 31 lines
lib/eal/common/eal_common_thread.c +2 -5
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 277

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (0 != ctrl_thread_init(arg))
+		return NULL;

DPDK uses the Linux not Windows coding style.
Windows uses the constant on left side of comparison because of the common programming error of putting assignment where conditional was intended. Linux uses a compiler that puts out a warning, so the more natural style is action != result

#3 lore raw

Re: [PATCH 1/3] eal: add rte control thread create API

Quoted 65 lines · Stephen Hemminger
Quoted 12 lines · On Mon, 5 Dec 2022 12:24:26 -0800 Tyler Retzlaff…
---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +0 -0
index c5d8b43..ca85c51 100644

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 240

Quoted 8 lines
lib/eal/common/eal_common_thread.c +4 -1
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void * (*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;

Why not just use rte_thread_func, this in internal.

Quoted 39 lines
lib/eal/common/eal_common_thread.c +10 -5
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
Quoted 8 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 277

Quoted 2 lines
lib/eal/common/eal_common_thread.c +2 -0
+	if (0 != ctrl_thread_init(arg))
+		return NULL;

DPDK uses the Linux not Windows coding style.
Windows uses the constant on left side of comparison because of the common programming error of putting assignment where conditional was intended. Linux uses a compiler that puts out a warning, so the more natural style is action != result

yes, of course.

i will fix this along with another minor style problem picked up by the CI.

thanks.

#4 lore raw

Re: [PATCH 1/3] eal: add rte control thread create API

In reply to Stephen Hemminger
Quoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Mon, 5 Dec 2022 12:24:26 -0800 Tyler Retzlaff…
---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +0 -0
index c5d8b43..ca85c51 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
Quoted 8 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 240

Quoted 6 lines
lib/eal/common/eal_common_thread.c +4 -1
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void * (*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;

Why not just use rte_thread_func, this in internal.

I'm not sure i completely understand your comment here. The main reason for using a union is to avoid dealing with casting. Later when the rte_ctrl_thread_create is deprecated the union will be discarded.

No change was made in v2 but if you still think this should be addressed let me know.

#5 lore raw

Re: [PATCH 1/3] eal: add rte control thread create API

Quoted 27 lines · On Tue, 6 Dec 2022 09:35:14 -0800 Tyler Retzlaff…
Quoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Mon, 5 Dec 2022 12:24:26 -0800 Tyler Retzlaff…
---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +0 -0
index c5d8b43..ca85c51 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
Quoted 8 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 240

Quoted 6 lines
lib/eal/common/eal_common_thread.c +4 -1
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void * (*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;  

Why not just use rte_thread_func, this in internal.

Quoted 6 lines

I'm not sure i completely understand your comment here. The main reason for using a union is to avoid dealing with casting. Later when the rte_ctrl_thread_create is deprecated the union will be discarded.

No change was made in v2 but if you still think this should be addressed let me know.

Is it possible to do it without union or casting.
Aliasing function pointers is something that leads to long term issues. The Linux kernel developers are actively fixing up all the casting there; would like DPDK to adopt the same hygiene.

#6 lore raw

PATCH 2/3 test: add rte control thread create API test

In reply to Tyler Retzlaff

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both apis under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
app/test/test_lcores.c +44 -0
index a6bb412..517dc3c 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
@@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -379,6 +392,34 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	rte_thread_t jid;
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	jid.opaque_id = t->id;
+	rte_thread_join(jid, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +452,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 3/3 eal: deprecate pthread control thread create API

In reply to Tyler Retzlaff
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..cb74e08 100644
@@ -119,3 +119,7 @@ Deprecation Notices
   Its removal has been postponed to let potential users report interest
   in maintaining it.
   In the absence of such interest, this library will be removed in DPDK 23.11.
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create``api, continuing the
+  effort to decouple eal from platform-specific thread implementations.
Signature · 1 line
1.8.3.1
#8 lore raw

Re: [PATCH 3/3] eal: deprecate pthread control thread create API

doc/guides/rel_notes/deprecation.rst Deprecation Notices · line 125

Quoted 4 lines · On Mon, 5 Dec 2022 12:24:28 -0800 Tyler Retzlaff…
doc/guides/rel_notes/deprecation.rst +4 -0
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create``api, continuing the
+  effort to decouple eal from platform-specific thread implementations.

If you want to change this (which is a good idea)
then mark the function with __rte_deprecated now, and cleanup all the examples and test programs please.

#9 lore raw

Re: [PATCH 3/3] eal: deprecate pthread control thread create API

Quoted 11 lines · Stephen Hemminger

doc/guides/rel_notes/deprecation.rst Deprecation Notices · line 125

Quoted 4 lines · On Mon, 5 Dec 2022 12:24:28 -0800 Tyler Retzlaff…
doc/guides/rel_notes/deprecation.rst +4 -0
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create``api, continuing the
+  effort to decouple eal from platform-specific thread implementations.

If you want to change this (which is a good idea)
then mark the function with __rte_deprecated now, and cleanup all the examples and test programs please.

i would like to mark it deprecated now but it seems the policy governing abi replacement prevent me from doing so.

```
3.3.3. New API replacing previous one
If a new API proposed functionally replaces an existing one, when the
new API becomes non-experimental then the old one is marked with
__rte_deprecated. Deprecated APIs are removed completely just after the
next LTS.
```

as i interpreted this i am not permitted to mark the old api __rte_deprecated until the new api is no longer marked __rte_experimental.

of course i'm happy to skip marking the new api __rte_experimental if people find that a satisfactory solution?

let me know.

#10 lore raw
In reply to Tyler Retzlaff
Quoted 30 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Monday, 5 December 2022 21.24

Remove rte_ctrl_thread_create API which exposes pthread_t and provide new rte_control_thread_create API based on EALs rte_thread_t.

To limit compatibility regression risk and ease of removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation. The duplication will be removed when rte_ctrl_thread_create is finally duplicated/removed.

The unit test for rte_ctrl_thread_create has been duplicated to exercise
both the old and the new API during transition, as with the API the duplicate test will be removed when the rte_ctrl_thread_create API is removed.

Tyler Retzlaff (3):
eal: add rte control thread create API
test: add rte control thread create API test
eal: deprecate pthread control thread create API

 app/test/test_lcores.c               | 44 +++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 ++
 lib/eal/common/eal_common_thread.c   | 93
++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 29 +++++++++++
 lib/eal/version.map                  |  3 ++
 5 files changed, 165 insertions(+), 8 deletions(-)
Quoted 3 lines

--
1.8.3.1

#11 lore raw

v2 cover eal: rte_ctrl_thread_create API replacement

In reply to Tyler Retzlaff

Remove rte_ctrl_thread_create API which exposes pthread_t and provide new rte_control_thread_create API based on EALs rte_thread_t.

To limit compatibility regression risk and ease of removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation. The duplication will be removed when rte_ctrl_thread_create is finally duplicated/removed.

The unit test for rte_ctrl_thread_create has been duplicated to exercise both the old and the new API during transition, as with the API the duplicate test will be removed when the rte_ctrl_thread_create API is removed.

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
test: add rte control thread create API test
eal: deprecate pthread control thread create API

 app/test/test_lcores.c               | 44 +++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 ++
 lib/eal/common/eal_common_thread.c   | 93 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 29 +++++++++++
 lib/eal/version.map                  |  3 ++
 5 files changed, 165 insertions(+), 8 deletions(-)
Signature · 3 lines
1.8.3.1

Series-Acked-by: Morten Brørup <[email protected]>
#12 lore raw

PATCH v2 1/3 eal: add rte control thread create API

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +85 -8
index c5d8b43..7950b50 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*start_routine)(void *);
+		rte_thread_func thread_func;
+	} u;
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.thread_func;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 
 int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (!params)
+		return -ENOMEM;
+
+	params->u.thread_func = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h +29 -0
index b9edf70..ae7afbe 100644
@@ -95,6 +95,35 @@ int rte_thread_create(rte_thread_t *thread_id,
 		rte_thread_func thread_func, void *arg);
 
 /**
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the dataplane and service
+ * lcores are then excluded. If setting the name of the thread fails,
+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
 };
 
 INTERNAL {
Signature · 1 line
1.8.3.1
#13 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

Quoted 16 lines · Tyler Retzlaff

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
  lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
  lib/eal/include/rte_thread.h       | 29 ++++++++++++
  lib/eal/version.map                |  3 ++
  3 files changed, 117 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +0 -0
index c5d8b43..7950b50 100644

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 239

Quoted 7 lines
lib/eal/common/eal_common_thread.c +3 -1
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
  };
 
  struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*start_routine)(void *);
+		rte_thread_func thread_func;

To be consistent with function naming scheme, where "ctrl" is the old API, and "control" the new, you could call the start functions something with "ctrl" and "control" as well.

Maybe it's worth mentioning that fact somewhere in the beginning of the file, as a comment (i.e., that "ctrl" denotes the old API).

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 242

Quoted 3 lines
lib/eal/common/eal_common_thread.c +1 -0
+	} u;
  	void *arg;
  	int ret;

Why is 'ret' needed? (This question is unrelated to your patch.)

Quoted 74 lines
lib/eal/common/eal_common_thread.c +27 -7
  	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
  	enum __rte_ctrl_thread_status ctrl_thread_status;
  };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
  {
  	struct internal_config *internal_conf =
  		eal_get_internal_configuration();
  	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
  	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
  	__rte_thread_init(rte_lcore_id(), cpuset);
  	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
  	if (params->ret != 0) {
  		__atomic_store_n(&params->ctrl_thread_status,
  			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
  	}
 
  	__atomic_store_n(&params->ctrl_thread_status,
  		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.thread_func;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
  }
 
  int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
  	if (!params)
  		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.start_routine = start_routine;
  	params->arg = arg;
  	params->ret = 0;
  	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
  	if (ret != 0) {
  		free(params);
  		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
  }
 
  int

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 357

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (!params)

params == NULL

Quoted 18 lines
lib/eal/common/eal_common_thread.c +18 -0
+		return -ENOMEM;
+
+	params->u.thread_func = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 385

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */

sched_yield() also doesn't necessarily yield the CPU.

Quoted 24 lines
lib/eal/common/eal_common_thread.c +16 -0
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
  rte_thread_register(void)
  {
  	unsigned int lcore_id;
lib/eal/include/rte_thread.h +0 -0
index b9edf70..ae7afbe 100644

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 103

Quoted 9 lines
lib/eal/include/rte_thread.h +6 -0
@@ -95,6 +95,35 @@ int rte_thread_create(rte_thread_t *thread_id,
  		rte_thread_func thread_func, void *arg);
 
  /**
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the dataplane and service
+ * lcores are then excluded. If setting the name of the thread fails,

"the EAL threads are then excluded"

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 109

Quoted 6 lines
lib/eal/include/rte_thread.h +6 -0
+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').

Is there a constant for this limit?

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 118

Quoted 9 lines
lib/eal/include/rte_thread.h +9 -0
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.

List the possible error codes.

Quoted 25 lines
lib/eal/include/rte_thread.h +8 -0
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
   * @warning
   * @b EXPERIMENTAL: this API may change without prior notice.
   *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
  	rte_thread_detach;
  	rte_thread_equal;
  	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
  };
 
  INTERNAL {
#14 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

Quoted 12 lines · Mattias Rönnblom
Quoted 11 lines · Tyler Retzlaff

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 29 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 117 insertions(+), 8 deletions(-)
Quoted 15 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 238

Quoted 11 lines
lib/eal/common/eal_common_thread.c +3 -1
index c5d8b43..7950b50 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*start_routine)(void *);
+		rte_thread_func thread_func;

To be consistent with function naming scheme, where "ctrl" is the old API, and "control" the new, you could call the start functions something with "ctrl" and "control" as well.

i'll make this change in v3.

Quoted 3 lines

Maybe it's worth mentioning that fact somewhere in the beginning of the file, as a comment (i.e., that "ctrl" denotes the old API).

i'll make this change in v3.

Quoted 6 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 242

Quoted 4 lines
lib/eal/common/eal_common_thread.c +1 -0
+	} u;
 	void *arg;
 	int ret;

Why is 'ret' needed? (This question is unrelated to your patch.)

i'm not the original author so difficult to answer authoritatively. but if i have to speculate i'd say it might be to work around the windows pthread_join stub being implemented as a noop. specifically it didn't communicate the return value from the start_routine.

the recently added rte_thread_join addresses this (which rte_control_thread_create uses) and could remove ret parameter and to avoid touching the new function implementation in the future it can not use ret now.

i'll make this change in v3.

for the original function i will leave the code as is to minimize the diff. when rte_ctrl_thread_create is removed i'll make a note to eliminate the ret parameter as well.

Quoted 71 lines
Quoted 71 lines
lib/eal/common/eal_common_thread.c +31 -7
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.thread_func;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
-	params->start_routine = start_routine;
+	params->u.start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
 }
 int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
Quoted 8 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 357

Quoted 6 lines
lib/eal/common/eal_common_thread.c +6 -0
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (!params)

params == NULL

copied from original code, i'll fix the style in the new function to comply with the dpdk coding standard.

i'll fix in v3.

Quoted 23 lines
Quoted 23 lines
lib/eal/common/eal_common_thread.c +22 -0
+		return -ENOMEM;
+
+	params->u.thread_func = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
Quoted 8 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 385

Quoted 6 lines
lib/eal/common/eal_common_thread.c +6 -0
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */

sched_yield() also doesn't necessarily yield the CPU.

copied from original code and understood, but are you requesting a change here or just a comment correction? can you offer wording you would find suitable?

Quoted 27 lines
Quoted 27 lines
lib/eal/common/eal_common_thread.c +16 -0
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h +0 -0
index b9edf70..ae7afbe 100644
@@ -95,6 +95,35 @@ int rte_thread_create(rte_thread_t *thread_id,
 		rte_thread_func thread_func, void *arg);
 /**
Quoted 8 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 103

Quoted 6 lines
lib/eal/include/rte_thread.h +6 -0
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the dataplane and service
+ * lcores are then excluded. If setting the name of the thread fails,

"the EAL threads are then excluded"

i'll modify in v3.

Quoted 9 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 109

Quoted 7 lines
lib/eal/include/rte_thread.h +6 -0
+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').

Is there a constant for this limit?

i have a series introducing rte_lcore_{set,get}_name api that introduces a constant (probably i'll post it today). as of this series there is no constant.

Quoted 11 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 118

Quoted 10 lines
lib/eal/include/rte_thread.h +9 -0
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
Quoted 1 line

List the possible error codes.

i would like to see the range of codes be part of the api & abi i've received resistance to the idea. for now i'll nack this comment which leaves it consistent with other apis documentation.

Quoted 25 lines
Quoted 25 lines
lib/eal/include/rte_thread.h +8 -0
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
 };
 INTERNAL {
#15 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

just following up.

Quoted 6 lines · Tyler Retzlaff
Quoted 4 lines · Mattias Rönnblom

To be consistent with function naming scheme, where "ctrl" is the old API, and "control" the new, you could call the start functions something with "ctrl" and "control" as well.

Quoted 7 lines

i'll make this change in v3.

Quoted 3 lines

Maybe it's worth mentioning that fact somewhere in the beginning of the file, as a comment (i.e., that "ctrl" denotes the old API).

i'll make this change in v3.

didn't end up doing this, didn't think it was necessary once i looked at it the commit history and the rename you suggested above should be satisfactory.

Quoted 13 lines
Quoted 7 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 242

Quoted 5 lines
lib/eal/common/eal_common_thread.c +1 -0
+	} u;
 	void *arg;
 	int ret;

Why is 'ret' needed? (This question is unrelated to your patch.)

i'm not the original author so difficult to answer authoritatively. but if i have to speculate i'd say it might be to work around the windows pthread_join stub being implemented as a noop. specifically it didn't communicate the return value from the start_routine.

Quoted 6 lines

the recently added rte_thread_join addresses this (which rte_control_thread_create uses) and could remove ret parameter and to avoid touching the new function implementation in the future it can not use ret now.

i'll make this change in v3.

also did not do this, once looked at i was concerned about inter-mixing too much semantic change in the implementation of a couple of the functions to accomplish it. it is best revisited when the old api is removed.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ * Filled with the thread id of the new created thread.
+ * @param name
+ * The name of the control thread (max 16 characters including '\0').

Quoted 5 lines
Quoted 1 line

Is there a constant for this limit?

i have a series introducing rte_lcore_{set,get}_name api that introduces a constant (probably i'll post it today). as of this series there is no constant.

change in v3, i forgot we were talking about the thread length limit and not the lcore name length limit and there was already a preprocessor definition for the limit. api documentation comment was updated in v3.

thanks!

#16 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

In reply to Tyler Retzlaff
Quoted 54 lines · Tyler Retzlaff
Quoted 12 lines · Mattias Rönnblom
Quoted 11 lines · Tyler Retzlaff

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
  lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
  lib/eal/include/rte_thread.h       | 29 ++++++++++++
  lib/eal/version.map                |  3 ++
  3 files changed, 117 insertions(+), 8 deletions(-)
Quoted 15 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 238

Quoted 11 lines
lib/eal/common/eal_common_thread.c +3 -1
index c5d8b43..7950b50 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
  };
  struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*start_routine)(void *);
+		rte_thread_func thread_func;

To be consistent with function naming scheme, where "ctrl" is the old API, and "control" the new, you could call the start functions something with "ctrl" and "control" as well.

i'll make this change in v3.

Quoted 3 lines

Maybe it's worth mentioning that fact somewhere in the beginning of the file, as a comment (i.e., that "ctrl" denotes the old API).

i'll make this change in v3.

Quoted 6 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 242

Quoted 4 lines
lib/eal/common/eal_common_thread.c +1 -0
+	} u;
  	void *arg;
  	int ret;

Why is 'ret' needed? (This question is unrelated to your patch.)

i'm not the original author so difficult to answer authoritatively. but if i have to speculate i'd say it might be to work around the windows pthread_join stub being implemented as a noop. specifically it didn't communicate the return value from the start_routine.

the recently added rte_thread_join addresses this (which rte_control_thread_create uses) and could remove ret parameter and to avoid touching the new function implementation in the future it can not use ret now.

Quoted 6 lines

i'll make this change in v3.

for the original function i will leave the code as is to minimize the diff. when rte_ctrl_thread_create is removed i'll make a note to eliminate the ret parameter as well.

I would focus on minimizing the complexity of the end result, rather than the size of the patch.

Quoted 117 lines
Quoted 71 lines
Quoted 71 lines
lib/eal/common/eal_common_thread.c +31 -7
  	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
  	enum __rte_ctrl_thread_status ctrl_thread_status;
  };
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
  {
  	struct internal_config *internal_conf =
  		eal_get_internal_configuration();
  	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
  	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
  	__rte_thread_init(rte_lcore_id(), cpuset);
  	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
  	if (params->ret != 0) {
  		__atomic_store_n(&params->ctrl_thread_status,
  			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
  	}
  	__atomic_store_n(&params->ctrl_thread_status,
  		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.thread_func;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
  }
  int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
  	if (!params)
  		return -ENOMEM;
-	params->start_routine = start_routine;
+	params->u.start_routine = start_routine;
  	params->arg = arg;
  	params->ret = 0;
  	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
  	if (ret != 0) {
  		free(params);
  		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
  }
  int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
Quoted 8 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 357

Quoted 6 lines
lib/eal/common/eal_common_thread.c +6 -0
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (!params)

params == NULL

copied from original code, i'll fix the style in the new function to comply with the dpdk coding standard.

i'll fix in v3.

Quoted 23 lines
Quoted 23 lines
lib/eal/common/eal_common_thread.c +22 -0
+		return -ENOMEM;
+
+	params->u.thread_func = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
Quoted 8 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 385

Quoted 6 lines
lib/eal/common/eal_common_thread.c +6 -0
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */

sched_yield() also doesn't necessarily yield the CPU.

Quoted 4 lines

copied from original code and understood, but are you requesting a change here or just a comment correction? can you offer wording you would find suitable?

I would just remove the comment.

"Yield the CPU. sched_yield() may seem like a natural choice here, but does not guarantee that a context switch will actually occur, and also does not exist on Windows."

Quoted 93 lines
Quoted 27 lines
Quoted 27 lines
lib/eal/common/eal_common_thread.c +16 -0
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
  rte_thread_register(void)
  {
  	unsigned int lcore_id;
lib/eal/include/rte_thread.h +0 -0
index b9edf70..ae7afbe 100644
@@ -95,6 +95,35 @@ int rte_thread_create(rte_thread_t *thread_id,
  		rte_thread_func thread_func, void *arg);
  /**
Quoted 8 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 103

Quoted 6 lines
lib/eal/include/rte_thread.h +6 -0
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the dataplane and service
+ * lcores are then excluded. If setting the name of the thread fails,

"the EAL threads are then excluded"

i'll modify in v3.

Quoted 9 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 109

Quoted 7 lines
lib/eal/include/rte_thread.h +6 -0
+ * the error is ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').

Is there a constant for this limit?

i have a series introducing rte_lcore_{set,get}_name api that introduces a constant (probably i'll post it today). as of this series there is no constant.

Quoted 11 lines

lib/eal/include/rte_thread.h int rte_thread_create(rte_thread_t *thread_id, · line 118

Quoted 10 lines
lib/eal/include/rte_thread.h +9 -0
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
Quoted 1 line

List the possible error codes.

i would like to see the range of codes be part of the api & abi i've received resistance to the idea. for now i'll nack this comment which leaves it consistent with other apis documentation.

Quoted 25 lines
Quoted 25 lines
lib/eal/include/rte_thread.h +8 -0
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
   * @warning
   * @b EXPERIMENTAL: this API may change without prior notice.
   *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
  	rte_thread_detach;
  	rte_thread_equal;
  	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
  };
  INTERNAL {
#17 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

Quoted 21 lines · Mattias Rönnblom
Quoted 20 lines · Tyler Retzlaff
Quoted 7 lines

lib/eal/common/eal_common_thread.c enum __rte_ctrl_thread_status { · line 242

Quoted 5 lines
lib/eal/common/eal_common_thread.c +1 -0
+	} u;
 	void *arg;
 	int ret;

Why is 'ret' needed? (This question is unrelated to your patch.)

i'm not the original author so difficult to answer authoritatively. but if i have to speculate i'd say it might be to work around the windows pthread_join stub being implemented as a noop. specifically it didn't communicate the return value from the start_routine.

the recently added rte_thread_join addresses this (which rte_control_thread_create uses) and could remove ret parameter and to avoid touching the new function implementation in the future it can not use ret now.

i'll make this change in v3.

Quoted 7 lines
Quoted 4 lines

for the original function i will leave the code as is to minimize the diff. when rte_ctrl_thread_create is removed i'll make a note to eliminate the ret parameter as well.

I would focus on minimizing the complexity of the end result, rather than the size of the patch.

agreed, that's why i decided to leave it as is. more change than is needed right now and simpler to make after the old api is removed.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 385

Quoted 8 lines
lib/eal/common/eal_common_thread.c +8 -0
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */

sched_yield() also doesn't necessarily yield the CPU.

Quoted 6 lines
Quoted 4 lines

copied from original code and understood, but are you requesting a change here or just a comment correction? can you offer wording you would find suitable?

I would just remove the comment.

sounds good, i'll remove it in the next rev.

thanks!

#18 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

In reply to Tyler Retzlaff

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 387

Quoted 10 lines · On Tue, 6 Dec 2022 09:28:24 -0800 Tyler Retzlaff…
lib/eal/common/eal_common_thread.c +10 -0
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */
+		rte_delay_us_sleep(1);
+	}

Would it be worth introducing and using rte_thread_yield(). Rather than waiting 1us which seems like a long time for this.

#19 lore raw

Re: [PATCH v2 1/3] eal: add rte control thread create API

Quoted 16 lines · Stephen Hemminger

lib/eal/common/eal_common_thread.c static void *ctrl_thread_init(void *arg) · line 387

Quoted 10 lines · On Tue, 6 Dec 2022 09:28:24 -0800 Tyler Retzlaff…
lib/eal/common/eal_common_thread.c +10 -0
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */
+		rte_delay_us_sleep(1);
+	}

Would it be worth introducing and using rte_thread_yield(). Rather than waiting 1us which seems like a long time for this.

i'd have to figure out if it can be provided for all platforms, if so then it seems reasonable. though i would not introduce it in this patch series since it isn't the central purpose of this change. more than happy to do it in a new series.

of course if someone else wants to put up a patch to add it i'm more than happy to review that too. (i have a lot of patches in the pipe already i'd like to avoid getting too distracted).

i'll put it in my backlog to take a look.

thanks

#20 lore raw

PATCH v2 2/3 test: add rte control thread create API test

In reply to Tyler Retzlaff

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread_create to keep both apis under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
app/test/test_lcores.c +44 -0
index a6bb412..517dc3c 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
@@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -379,6 +392,34 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	rte_thread_t jid;
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	jid.opaque_id = t->id;
+	rte_thread_join(jid, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +452,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH v2 3/3 eal: deprecate pthread control thread create API

In reply to Tyler Retzlaff

Give notice of rte_ctrl_thread_create deprecation.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..cb74e08 100644
@@ -119,3 +119,7 @@ Deprecation Notices
   Its removal has been postponed to let potential users report interest
   in maintaining it.
   In the absence of such interest, this library will be removed in DPDK 23.11.
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create``api, continuing the
+  effort to decouple eal from platform-specific thread implementations.
Signature · 1 line
1.8.3.1
#22 lore raw

v3 cover eal: rte_ctrl_thread_create API replacement

In reply to Tyler Retzlaff

Remove rte_ctrl_thread_create API which exposes pthread_t and provide new rte_control_thread_create API based on EALs rte_thread_t.

To limit compatibility regression risk and ease of removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation. The duplication will be removed when rte_ctrl_thread_create is finally duplicated/removed.

The unit test for rte_ctrl_thread_create has been duplicated to exercise both the old and the new API during transition, as with the API the duplicate test will be removed when the rte_ctrl_thread_create API is removed.

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
test: add rte control thread create API test
eal: deprecate pthread control thread create API

 app/test/test_lcores.c               | 42 ++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 ++
 lib/eal/common/eal_common_thread.c   | 93 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 30 ++++++++++++
 lib/eal/version.map                  |  3 ++
 5 files changed, 164 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH v3 1/3 eal: add rte control thread create API

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
 lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 30 ++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 118 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +85 -8
index c5d8b43..7c2552d 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*ctrl_start_routine)(void *);
+		rte_thread_func control_start_routine;
+	} u;
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.control_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 
 int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.ctrl_start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (params == NULL)
+		return -ENOMEM;
+
+	params->u.control_start_routine = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		/* Yield the CPU. Using sched_yield call requires maintaining
+		 * another implementation for Windows as sched_yield is not
+		 * supported on Windows.
+		 */
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h +30 -0
index b9edf70..97c27a9 100644
@@ -95,6 +95,36 @@ int rte_thread_create(rte_thread_t *thread_id,
 		rte_thread_func thread_func, void *arg);
 
 /**
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
 };
 
 INTERNAL {
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH v3 2/3 test: add rte control thread create API test

In reply to Tyler Retzlaff

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both apis under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
app/test/test_lcores.c +42 -0
index a6bb412..375ecdb 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
@@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -379,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	rte_thread_join((rte_thread_t){(uintptr_t)t->id}, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +450,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v3 3/3 eal: deprecate pthread control thread create API

In reply to Tyler Retzlaff

Give notice of rte_ctrl_thread_create deprecation.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..cb74e08 100644
@@ -119,3 +119,7 @@ Deprecation Notices
   Its removal has been postponed to let potential users report interest
   in maintaining it.
   In the absence of such interest, this library will be removed in DPDK 23.11.
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create``api, continuing the
+  effort to decouple eal from platform-specific thread implementations.
Signature · 1 line
1.8.3.1
#26 lore raw

v4 cover eal: rte_ctrl_thread_create API replacement

In reply to Tyler Retzlaff

Remove rte_ctrl_thread_create API which exposes pthread_t and provide new rte_control_thread_create API based on EALs rte_thread_t.

To limit compatibility regression risk and ease of removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation. The duplication will be removed when rte_ctrl_thread_create is finally duplicated/removed.

The unit test for rte_ctrl_thread_create has been duplicated to exercise both the old and the new API during transition, as with the API the duplicate test will be removed when the rte_ctrl_thread_create API is removed.

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
test: add rte control thread create API test
eal: deprecate pthread control thread create API

 app/test/test_lcores.c               | 42 +++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 ++
 lib/eal/common/eal_common_thread.c   | 89 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 30 ++++++++++++
 lib/eal/version.map                  |  3 ++
 5 files changed, 160 insertions(+), 8 deletions(-)
Signature · 3 lines
1.8.3.1

Series-Acked-by: Morten Brørup <[email protected]>
#27 lore raw

PATCH v4 1/3 eal: add rte control thread create API

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

---
 lib/eal/common/eal_common_thread.c | 89 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 30 +++++++++++++
 lib/eal/version.map                |  3 ++
 3 files changed, 114 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_thread.c +81 -8
index c5d8b43..872ad20 100644
@@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*ctrl_start_routine)(void *arg);
+		rte_thread_func control_start_routine;
+	} u;
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -243,14 +246,12 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset),
@@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg)
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.control_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 
 int
@@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.ctrl_start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -322,6 +345,56 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg)
+{
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (params == NULL)
+		return -ENOMEM;
+
+	params->u.control_start_routine = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL) {
+		ret = rte_thread_setname((pthread_t)thread->opaque_id, name);
+		if (ret < 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for ctrl thread\n");
+	}
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h +30 -0
index b9edf70..97c27a9 100644
@@ -95,6 +95,36 @@ int rte_thread_create(rte_thread_t *thread_id,
 		rte_thread_func thread_func, void *arg);
 
 /**
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/version.map +3 -0
index 7ad12a7..8f9eeb9 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_control_thread_create;
 };
 
 INTERNAL {
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v4 2/3 test: add rte control thread create API test

In reply to Tyler Retzlaff

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both apis under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
app/test/test_lcores.c +42 -0
index a6bb412..375ecdb 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
@@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -379,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	rte_thread_join((rte_thread_t){(uintptr_t)t->id}, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +450,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v4 3/3 eal: deprecate pthread control thread create API

In reply to Tyler Retzlaff

Give notice of rte_ctrl_thread_create deprecation.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..ce3b4b7 100644
@@ -119,3 +119,7 @@ Deprecation Notices
   Its removal has been postponed to let potential users report interest
   in maintaining it.
   In the absence of such interest, this library will be removed in DPDK 23.11.
+
+* eal: The function ``rte_ctrl_thread_create`` will be removed and
+  replaced by the new ``rte_control_thread_create`` api, continuing the
+  effort to decouple eal from platform-specific thread implementations.
Signature · 1 line
1.8.3.1
#31 lore raw

v5 cover eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_control_thread_create that uses the new rte_thread_t type.

Provide a unit test for the new rte_control_thread_create API.

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

v5:
* rebase series now that rte_thread_set_name has been merged, remove now unnecessary casts.
* combine patch adding rte_control_thread_create and patch adding unit test into patch 1.
* reword deprecation notice to indicate which release we intend to mark rte_ctrl_thread_create deprecated and which release we intend to remove the same.
* adjust deprecation notice commit subject based on previous deprecation notice series feedback.
* add (mostly unrelated) patch to series to add thread / rte_thread.h to doxygen index (an oversight missed from previous series).

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
doc: add missing index entry for thread
doc: announce deprecation of thread ctrl create function

 app/test/test_lcores.c               | 41 +++++++++++++++++
 doc/api/doxy-api-index.md            |  1 +
 doc/guides/rel_notes/deprecation.rst |  5 +++
 lib/eal/common/eal_common_thread.c   | 85 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 33 ++++++++++++++
 lib/eal/version.map                  |  1 +
 6 files changed, 158 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH v5 1/3 eal: add rte control thread create API

From: Tyler Retzlaff <[email protected]>

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both APIs under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c             | 41 ++++++++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 152 insertions(+), 8 deletions(-)
app/test/test_lcores.c +41 -0
index 5b43aa5..9766f78 100644
@@ -353,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -380,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create(&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	rte_thread_join(t->id, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -409,6 +447,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
lib/eal/common/eal_common_thread.c +77 -8

129 lines not on this page · raw message

lib/eal/include/rte_thread.h +33 -0
index d247930..792d8b0 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -0
index 6523102..a9d0a03 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
 	rte_thread_join;
 
 	# added in 23.03
+	rte_control_thread_create;
 	rte_thread_set_name;
 };
 
Signature · 1 line
1.8.3.1
#33 lore raw

PATCH v5 2/3 doc: add missing index entry for thread

In reply to Tyler Retzlaff

From: Tyler Retzlaff <[email protected]>

Add missing thread index referencing rte_thread.h under the basic topic.

---
 doc/api/doxy-api-index.md | 1 +
 1 file changed, 1 insertion(+)
doc/api/doxy-api-index.md +1 -0
index de488c7..e8ed51a 100644
@@ -211,6 +211,7 @@ The public API headers are grouped by topics:
   [config file](@ref rte_cfgfile.h),
   [key/value args](@ref rte_kvargs.h),
   [string](@ref rte_string_fns.h)
+  [thread](@ref rte_thread.h)
 
 - **debug**:
   [jobstats](@ref rte_jobstats.h),
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v5 3/3 doc: announce deprecation of thread ctrl create function

In reply to Tyler Retzlaff

From: Tyler Retzlaff <[email protected]>

Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details.

---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
index eea99b4..c6e7d04 100644
@@ -23,6 +23,11 @@ Deprecation Notices
   rte_thread_set_name being marked as stable, and planned to be removed
   by the 23.11 release.
 
+* eal: The function ``rte_ctrl_thread_create`` is planned to be deprecated
+  starting with the 23.07 release, subject to the replacement API
+  rte_control_thread_create being marked as stable, and planned to be removed
+  by the 23.11 release.
+
 * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does
   not allow for writing optimized code for all the CPU architectures supported
   in DPDK. DPDK has adopted the atomic operations from
Signature · 1 line
1.8.3.1
#35 lore raw

v5 cover eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_control_thread_create that uses the new rte_thread_t type.

Provide a unit test for the new rte_control_thread_create API.

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

v5:
* rebase series now that rte_thread_set_name has been merged, remove now unnecessary casts.
* combine patch adding rte_control_thread_create and patch adding unit test into patch 1.
* reword deprecation notice to indicate which release we intend to mark rte_ctrl_thread_create deprecated and which release we intend to remove the same.
* adjust deprecation notice commit subject based on previous deprecation notice series feedback.
* add (mostly unrelated) patch to series to add thread / rte_thread.h to doxygen index (an oversight missed from previous series).

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
doc: add missing index entry for thread
doc: announce deprecation of thread ctrl create function

 app/test/test_lcores.c               | 41 +++++++++++++++++
 doc/api/doxy-api-index.md            |  1 +
 doc/guides/rel_notes/deprecation.rst |  5 +++
 lib/eal/common/eal_common_thread.c   | 85 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 33 ++++++++++++++
 lib/eal/version.map                  |  1 +
 6 files changed, 158 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
#36 lore raw

PATCH v5 1/3 eal: add rte control thread create API

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both APIs under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c             | 41 ++++++++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 152 insertions(+), 8 deletions(-)
app/test/test_lcores.c +41 -0
index 5b43aa5..9766f78 100644
@@ -353,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -380,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create(&t->id, "test_control_threads",
+					NULL, control_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	rte_thread_join(t->id, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -409,6 +447,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
lib/eal/common/eal_common_thread.c +77 -8

129 lines not on this page · raw message

lib/eal/include/rte_thread.h +33 -0
index d247930..792d8b0 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_control_thread_create(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -0
index 6523102..a9d0a03 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
 	rte_thread_join;
 
 	# added in 23.03
+	rte_control_thread_create;
 	rte_thread_set_name;
 };
 
Signature · 1 line
1.8.3.1
#37 lore raw

Re: [PATCH v5 1/3] eal: add rte control thread create API

Quoted 76 lines · Tyler Retzlaff

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both APIs under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c             | 41 ++++++++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 152 insertions(+), 8 deletions(-)
app/test/test_lcores.c +38 -0
index 5b43aa5..9766f78 100644
@@ -353,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
        return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+       struct thread_context *t = arg;
+
+       printf("Control thread running successfully\n");
+
+       /* Set the thread state to DONE */
+       t->state = Thread_DONE;
+
+       return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -380,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+       struct thread_context ctrl_thread_context;
+       struct thread_context *t;
+
+       /* Create one control thread */
+       t = &ctrl_thread_context;
+       t->state = Thread_INIT;
+       if (rte_control_thread_create(&t->id, "test_control_threads",
+                                       NULL, control_thread_loop, t) != 0)
+               return -1;
+
+       /* Wait till the control thread exits.
+        * This also acts as the barrier such that the memory operations
+        * in control thread are visible to this thread.
+        */
+       rte_thread_join(t->id, NULL);
+
+       /* Check if the control thread set the correct state */
+       if (t->state != Thread_DONE)
+               return -1;
+
+       return 0;
+}
+
+static int
 test_lcores(void)
 {
        unsigned int eal_threads_count = 0;

app/test/test_lcores.c static void *ctrl_thread_loop(void *arg) · line 455

Quoted 9 lines
app/test/test_lcores.c +3 -0
@@ -409,6 +447,9 @@ static void *ctrl_thread_loop(void *arg)
        if (test_ctrl_thread() < 0)
                return TEST_FAILED;
 
+       if (test_control_thread() < 0)
+               return TEST_FAILED;
+
        return TEST_SUCCESS;
 }
 

Afair, the "legacy" API test being in test_lcores.c is mainly a side effect of the API being defined in rte_lcore.h.

The new API is genuinely located in rte_thread.h and there is no consideration over lcores: control thread are just "specialised" rte_thread objects.
I'd rather see this test in app/test/test_threads.c with other rte_thread API tests.

I think something like below would be enough, wdyt?
If you are fine with it and there is no other comment on this patch, I plan to do this change before applying.

app/test/test_threads.c +8 -0
index e0f18e4329..cc0bb69190 100644
@@ -232,6 +232,31 @@ test_thread_attributes_priority(void)
        return 0;
 }
 
+static int
+test_control_thread_create_join(void)
+{
+       rte_thread_t thread_id;
+       rte_thread_t thread_main_id;
+
+       thread_id_ready = 0;
+       RTE_TEST_ASSERT(rte_control_thread_create(&thread_id,

"test_control_threads", NULL,
+ thread_main, &thread_main_id) == 0,
+ "Failed to create thread.");
+
+ while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+ ;
+
+ RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+ "Unexpected thread id.");
+
+ __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+ RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+ "Failed to join thread.");
+
+ return 0;
+}
+
static struct unit_test_suite threads_test_suite = {
.suite_name = "threads autotest",
.setup = NULL,
@@ -243,6 +268,7 @@ static struct unit_test_suite threads_test_suite = {
TEST_CASE(test_thread_priority), TEST_CASE(test_thread_attributes_affinity), TEST_CASE(test_thread_attributes_priority),
+ TEST_CASE(test_control_thread_create_join),

                TEST_CASES_END()
        }

};

Signature · 1 line
David Marchand
#38 lore raw

Re: [PATCH v5 1/3] eal: add rte control thread create API

Quoted 91 lines · David Marchand
Quoted 76 lines · Tyler Retzlaff

Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both APIs under test until rte_ctrl_thread_create is removed.

---
 app/test/test_lcores.c             | 41 ++++++++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 152 insertions(+), 8 deletions(-)
app/test/test_lcores.c +38 -0
index 5b43aa5..9766f78 100644
@@ -353,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
        return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+       struct thread_context *t = arg;
+
+       printf("Control thread running successfully\n");
+
+       /* Set the thread state to DONE */
+       t->state = Thread_DONE;
+
+       return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -380,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+       struct thread_context ctrl_thread_context;
+       struct thread_context *t;
+
+       /* Create one control thread */
+       t = &ctrl_thread_context;
+       t->state = Thread_INIT;
+       if (rte_control_thread_create(&t->id, "test_control_threads",
+                                       NULL, control_thread_loop, t) != 0)
+               return -1;
+
+       /* Wait till the control thread exits.
+        * This also acts as the barrier such that the memory operations
+        * in control thread are visible to this thread.
+        */
+       rte_thread_join(t->id, NULL);
+
+       /* Check if the control thread set the correct state */
+       if (t->state != Thread_DONE)
+               return -1;
+
+       return 0;
+}
+
+static int
 test_lcores(void)
 {
        unsigned int eal_threads_count = 0;

app/test/test_lcores.c static void *ctrl_thread_loop(void *arg) · line 455

Quoted 9 lines
app/test/test_lcores.c +3 -0
@@ -409,6 +447,9 @@ static void *ctrl_thread_loop(void *arg)
        if (test_ctrl_thread() < 0)
                return TEST_FAILED;
 
+       if (test_control_thread() < 0)
+               return TEST_FAILED;
+
        return TEST_SUCCESS;
 }
 

Afair, the "legacy" API test being in test_lcores.c is mainly a side effect of the API being defined in rte_lcore.h.

Quoted 5 lines

The new API is genuinely located in rte_thread.h and there is no consideration over lcores: control thread are just "specialised" rte_thread objects.
I'd rather see this test in app/test/test_threads.c with other rte_thread API tests.

no problem, i wondered if i should retain the original location or not. i'll move it to test_threads.c

i kind of wonder if the function should be named rte_thread_create_ctrl or something now so that all the functions from rte_thread have a consistent naming prefix?

let me know if this is desired. if it is i'll submit a new version otherwise you can apply the series as is with your suggested test moved to test_threads.c below.

Quoted 4 lines

I think something like below would be enough, wdyt?
If you are fine with it and there is no other comment on this patch, I plan to do this change before applying.

no problem with this, sounds good.

Quoted 51 lines
app/test/test_threads.c +25 -0
index e0f18e4329..cc0bb69190 100644
@@ -232,6 +232,31 @@ test_thread_attributes_priority(void)
        return 0;
 }
 
+static int
+test_control_thread_create_join(void)
+{
+       rte_thread_t thread_id;
+       rte_thread_t thread_main_id;
+
+       thread_id_ready = 0;
+       RTE_TEST_ASSERT(rte_control_thread_create(&thread_id,
 "test_control_threads", NULL,
+               thread_main, &thread_main_id) == 0,
+               "Failed to create thread.");
+
+       while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+               ;
+
+       RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+               "Unexpected thread id.");
+
+       __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+       RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+               "Failed to join thread.");
+
+       return 0;
+}
+
 static struct unit_test_suite threads_test_suite = {
        .suite_name = "threads autotest",

.setup = NULL,

app/test/test_threads.c +1 -0
@@ -243,6 +268,7 @@ static struct unit_test_suite threads_test_suite = {
                TEST_CASE(test_thread_priority),
                TEST_CASE(test_thread_attributes_affinity),
                TEST_CASE(test_thread_attributes_priority),
+               TEST_CASE(test_control_thread_create_join),
                TEST_CASES_END()
        }
 };
Signature · 2 lines
-- 
David Marchand
#39 lore raw

PATCH v5 2/3 doc: add missing index entry for thread

In reply to Tyler Retzlaff

Add missing thread index referencing rte_thread.h under the basic topic.

---
 doc/api/doxy-api-index.md | 1 +
 1 file changed, 1 insertion(+)
doc/api/doxy-api-index.md +1 -0
index de488c7..e8ed51a 100644
@@ -211,6 +211,7 @@ The public API headers are grouped by topics:
   [config file](@ref rte_cfgfile.h),
   [key/value args](@ref rte_kvargs.h),
   [string](@ref rte_string_fns.h)
+  [thread](@ref rte_thread.h)
 
 - **debug**:
   [jobstats](@ref rte_jobstats.h),
Signature · 1 line
1.8.3.1
Reviewed-by on v5 2/3
#40 lore raw

Re: [PATCH v5 2/3] doc: add missing index entry for thread

Quoted 14 lines · Tyler Retzlaff

Add missing thread index referencing rte_thread.h under the basic topic.

---
 doc/api/doxy-api-index.md | 1 +
 1 file changed, 1 insertion(+)
doc/api/doxy-api-index.md +0 -0
index de488c7..e8ed51a 100644

doc/api/doxy-api-index.md The public API headers are grouped by topics: · line 214

Quoted 4 lines
doc/api/doxy-api-index.md +1 -0
@@ -211,6 +211,7 @@ The public API headers are grouped by topics:
   [config file](@ref rte_cfgfile.h),
   [key/value args](@ref rte_kvargs.h),
   [string](@ref rte_string_fns.h)
+  [thread](@ref rte_thread.h)

A , is missing on the line before.
This can be seen in the rendered html:
"basic: bitops, approx fraction, random, config file, key/value args, string thread"

I'll fix when applying.

Signature · 1 line
David Marchand
#41 lore raw

Re: [PATCH v5 2/3] doc: add missing index entry for thread

Quoted 11 lines · David Marchand
Quoted 9 lines · Tyler Retzlaff

Add missing thread index referencing rte_thread.h under the basic topic.

---
 doc/api/doxy-api-index.md | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines

doc/api/doxy-api-index.md The public API headers are grouped by topics: · line 214

Quoted 9 lines
doc/api/doxy-api-index.md +1 -0
index de488c7..e8ed51a 100644
@@ -211,6 +211,7 @@ The public API headers are grouped by topics:
   [config file](@ref rte_cfgfile.h),
   [key/value args](@ref rte_kvargs.h),
   [string](@ref rte_string_fns.h)
+  [thread](@ref rte_thread.h)

A , is missing on the line before.
This can be seen in the rendered html:
"basic: bitops, approx fraction, random, config file, key/value args, string thread"

sorry, just me being a derp. i will fix it in the next version since need a new rev for moving the test to test_threads.c

Quoted 8 lines

I'll fix when applying.

Signature · 1 line
David Marchand
#42 lore raw

PATCH v5 3/3 doc: announce deprecation of thread ctrl create function

In reply to Tyler Retzlaff

Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details.

---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
index eea99b4..c6e7d04 100644
@@ -23,6 +23,11 @@ Deprecation Notices
   rte_thread_set_name being marked as stable, and planned to be removed
   by the 23.11 release.
 
+* eal: The function ``rte_ctrl_thread_create`` is planned to be deprecated
+  starting with the 23.07 release, subject to the replacement API
+  rte_control_thread_create being marked as stable, and planned to be removed
+  by the 23.11 release.
+
 * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does
   not allow for writing optimized code for all the CPU architectures supported
   in DPDK. DPDK has adopted the atomic operations from
Signature · 1 line
1.8.3.1
Acked-by on v5 3/3
#43 lore raw

Re: [PATCH v5 3/3] doc: announce deprecation of thread ctrl create function

Quoted 7 lines · Tyler Retzlaff

Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details.

We could merge together the two notices about thread API, but the proposed form is ok for me.

Signature · 1 line
David Marchand
#44 lore raw

Re: [PATCH v5 0/3] eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff

top-post

this is a re-submission of v5 of the series due to a mistake i made in the first submission that caused it not to be correctly submitted to patchwork.

apologies for the noise.

Quoted 78 lines · Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_control_thread_create that uses the new rte_thread_t type.

Provide a unit test for the new rte_control_thread_create API.

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

v5:
* rebase series now that rte_thread_set_name has been merged, remove now unnecessary casts.
* combine patch adding rte_control_thread_create and patch adding unit test into patch 1.
* reword deprecation notice to indicate which release we intend to mark rte_ctrl_thread_create deprecated and which release we intend to remove the same.
* adjust deprecation notice commit subject based on previous deprecation notice series feedback.
* add (mostly unrelated) patch to series to add thread / rte_thread.h to doxygen index (an oversight missed from previous series).

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte control thread create API
doc: add missing index entry for thread
doc: announce deprecation of thread ctrl create function

 app/test/test_lcores.c               | 41 +++++++++++++++++
 doc/api/doxy-api-index.md            |  1 +
 doc/guides/rel_notes/deprecation.rst |  5 +++
 lib/eal/common/eal_common_thread.c   | 85 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 33 ++++++++++++++
 lib/eal/version.map                  |  1 +
 6 files changed, 158 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.3.1
#45 lore raw

v6 cover eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_thread_create_control that uses the new rte_thread_t type.

Provide a unit test for the new rte_thread_create_control API (test code provided by David Marchand.)

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

v6:
* fix missing comma in doxygen index
* combine deprecation notice for rte_ctrl_thread_create into notice of removal of rte_thread_setname.
* remove test_lcore.c test and add test provided by David Marchand to test_threads.c.
* rename the function to start with rte_thread to be consistent with the rest of functions in the rte_thread.h APIs.

v5:
* rebase series now that rte_thread_set_name has been merged, remove now unnecessary casts.
* combine patch adding rte_control_thread_create and patch adding unit test into patch 1.
* reword deprecation notice to indicate which release we intend to mark rte_ctrl_thread_create deprecated and which release we intend to remove the same.
* adjust deprecation notice commit subject based on previous deprecation notice series feedback.
* add (mostly unrelated) patch to series to add thread / rte_thread.h to doxygen index (an oversight missed from previous series).

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte thread create control API
doc: add missing index entry for thread
doc: announce deprecation of thread ctrl create function

 app/test/test_threads.c              | 26 +++++++++++
 doc/api/doxy-api-index.md            |  3 +-
 doc/guides/rel_notes/deprecation.rst |  8 ++--
 lib/eal/common/eal_common_thread.c   | 85 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 33 ++++++++++++++
 lib/eal/version.map                  |  1 +
 6 files changed, 143 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
#46 lore raw

PATCH v6 1/3 eal: add rte thread create control API

Add rte_thread_create_control API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Add test from David Marchand to exercise the new API.

---
 app/test/test_threads.c            | 26 ++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 137 insertions(+), 8 deletions(-)
app/test/test_threads.c +26 -0
index e0f18e4..657ecad 100644
@@ -232,6 +232,31 @@
 	return 0;
 }
 
+static int
+test_thread_create_control_join(void)
+{
+	rte_thread_t thread_id;
+	rte_thread_t thread_main_id;
+
+	thread_id_ready = 0;
+	RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "test_control_threads",
+		NULL, thread_main, &thread_main_id) == 0,
+		"Failed to create thread.");
+
+	while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+		;
+
+	RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+		"Unexpected thread id.");
+
+	__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+	RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+		"Failed to join thread.");
+
+	return 0;
+}
+
 static struct unit_test_suite threads_test_suite = {
 	.suite_name = "threads autotest",
 	.setup = NULL,
@@ -243,6 +268,7 @@
 		TEST_CASE(test_thread_priority),
 		TEST_CASE(test_thread_attributes_affinity),
 		TEST_CASE(test_thread_attributes_priority),
+		TEST_CASE(test_thread_create_control_join),
 		TEST_CASES_END()
 	}
 };
lib/eal/common/eal_common_thread.c +77 -8

129 lines not on this page · raw message

lib/eal/include/rte_thread.h +33 -0
index d247930..fae26a7 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -0
index 6523102..285a0bd 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
 	rte_thread_join;
 
 	# added in 23.03
+	rte_thread_create_control;
 	rte_thread_set_name;
 };
 
Signature · 1 line
1.8.3.1
#47 lore raw

RE: [PATCH v6 1/3] eal: add rte thread create control API

Hi, Tyler Retzlaff

We found an error when ASAN test, AddressSanitizer: stack-buffer-overflow error when quit testpmd. Could you please have a look at it , also submitted a Bugzilla ticket: https://bugs.dpdk.org/show_bug.cgi?id=1166
Thanks.

Regards,
Li, Weiyuan

Quoted 266 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Thursday, February 9, 2023 5:27 AM
To: [email protected]
Cc: [email protected]; [email protected]; Matz, Olivier <[email protected]>; [email protected]; [email protected]; [email protected]; Tyler Retzlaff <[email protected]>
Subject: [PATCH v6 1/3] eal: add rte thread create control API

Add rte_thread_create_control API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Add test from David Marchand to exercise the new API.

---
 app/test/test_threads.c            | 26 ++++++++++++
 lib/eal/common/eal_common_thread.c | 85
++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 137 insertions(+), 8 deletions(-)
app/test/test_threads.c index renamed from app/test/test_threads.c +0 -0

e0f18e4..657ecad 100644

app/test/test_threads.c +25 -0
@@ -232,6 +232,31 @@
 	return 0;
 }
 
+static int
+test_thread_create_control_join(void)
+{
+	rte_thread_t thread_id;
+	rte_thread_t thread_main_id;
+
+	thread_id_ready = 0;
+	RTE_TEST_ASSERT(rte_thread_create_control(&thread_id,
 "test_control_threads",
+		NULL, thread_main, &thread_main_id) == 0,
+		"Failed to create thread.");
+
+	while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE)
 == 0)
+		;
+
+	RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) !=
 0,
+		"Unexpected thread id.");
+
+	__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+	RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+		"Failed to join thread.");
+
+	return 0;
+}
+

static struct unit_test_suite threads_test_suite = {

app/test/test_threads.c +1 -0
 	.suite_name = "threads autotest",
 	.setup = NULL,
@@ -243,6 +268,7 @@
 		TEST_CASE(test_thread_priority),
 		TEST_CASE(test_thread_attributes_affinity),
 		TEST_CASE(test_thread_attributes_priority),
+		TEST_CASE(test_thread_create_control_join),
 		TEST_CASES_END()
 	}
 };
lib/eal/common/eal_common_thread.c +74 -8
index 3181515..4f83c97 100644
@@ -232,7 +232,10 @@ enum __rte_ctrl_thread_status {  };
 
 struct rte_thread_ctrl_params {
-	void *(*start_routine)(void *);
+	union {
+		void *(*ctrl_start_routine)(void *arg);
+		rte_thread_func control_start_routine;
+	} u;
 	void *arg;
 	int ret;
 	/* Control thread status.
@@ -241,27 +244,47 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;  };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
 	struct rte_thread_ctrl_params *params = arg;
-	void *(*start_routine)(void *) = params->start_routine;
-	void *routine_arg = params->arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
 	params->ret = rte_thread_set_affinity_by_id(rte_thread_self(),
 cpuset);
 	if (params->ret != 0) {
 		__atomic_store_n(&params->ctrl_thread_status,
 			CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-		return NULL;
+		return params->ret;
 	}
 
 	__atomic_store_n(&params->ctrl_thread_status,
 		CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-	return start_routine(routine_arg);
+	return 0;
+}
+
+static void *ctrl_thread_start(void *arg) {
+	struct rte_thread_ctrl_params *params = arg;
+	void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return NULL;
+
+	return start_routine(params->arg);
+}
+
+static uint32_t control_thread_start(void *arg) {
+	struct rte_thread_ctrl_params *params = arg;
+	rte_thread_func start_routine = params->u.control_start_routine;
+
+	if (ctrl_thread_init(arg) != 0)
+		return params->ret;
+
+	return start_routine(params->arg);
 }
 
 int
@@ -277,12 +300,12 @@ static void *ctrl_thread_init(void *arg)
 	if (!params)
 		return -ENOMEM;
 
-	params->start_routine = start_routine;
+	params->u.ctrl_start_routine = start_routine;
 	params->arg = arg;
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
@@ -315,6 +338,52 @@ static void *ctrl_thread_init(void *arg)  }
 
 int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+	const rte_thread_attr_t *attr,
+	rte_thread_func start_routine, void *arg) {
+	struct rte_thread_ctrl_params *params;
+	enum __rte_ctrl_thread_status ctrl_thread_status;
+	int ret;
+
+	params = malloc(sizeof(*params));
+	if (params == NULL)
+		return -ENOMEM;
+
+	params->u.control_start_routine = start_routine;
+	params->arg = arg;
+	params->ret = 0;
+	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+	ret = rte_thread_create(thread, attr, control_thread_start, params);
+	if (ret != 0) {
+		free(params);
+		return -ret;
+	}
+
+	if (name != NULL)
+		rte_thread_set_name(*thread, name);
+
+	/* Wait for the control thread to initialize successfully */
+	while ((ctrl_thread_status =
+			__atomic_load_n(&params->ctrl_thread_status,
+			__ATOMIC_ACQUIRE)) ==
 CTRL_THREAD_LAUNCHING) {
+		rte_delay_us_sleep(1);
+	}
+
+	/* Check if the control thread encountered an error */
+	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+		/* ctrl thread is exiting */
+		rte_thread_join(*thread, NULL);
+	}
+
+	ret = params->ret;
+	free(params);
+
+	return ret;
+}
+
+int
 rte_thread_register(void)
 {
 	unsigned int lcore_id;
lib/eal/include/rte_thread.h index renamed from lib/eal/include/rte_thread.h +0 -0

d247930..fae26a7 100644

lib/eal/include/rte_thread.h +33 -0
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+		const rte_thread_attr_t *thread_attr,
+		rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map index 6523102..285a0bd renamed from lib/eal/version.map +0 -0

100644

lib/eal/version.map +1 -1
@@ -441,6 +441,7 @@ EXPERIMENTAL {
 	rte_thread_join;
 
 	# added in 23.03
+	rte_thread_create_control;
 	rte_thread_set_name;
 };
 
--

1.8.3.1

#48 lore raw

Re: [PATCH v6 1/3] eal: add rte thread create control API

In reply to Tyler Retzlaff
Quoted 106 lines · Tyler Retzlaff

Add rte_thread_create_control API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Add test from David Marchand to exercise the new API.

---
 app/test/test_threads.c            | 26 ++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 137 insertions(+), 8 deletions(-)
app/test/test_threads.c +26 -0
index e0f18e4..657ecad 100644
@@ -232,6 +232,31 @@
        return 0;
 }
 
+static int
+test_thread_create_control_join(void)
+{
+       rte_thread_t thread_id;
+       rte_thread_t thread_main_id;
+
+       thread_id_ready = 0;
+       RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "test_control_threads",
+               NULL, thread_main, &thread_main_id) == 0,
+               "Failed to create thread.");
+
+       while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+               ;
+
+       RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+               "Unexpected thread id.");
+
+       __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+       RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+               "Failed to join thread.");
+
+       return 0;
+}
+
 static struct unit_test_suite threads_test_suite = {
        .suite_name = "threads autotest",
        .setup = NULL,
@@ -243,6 +268,7 @@
                TEST_CASE(test_thread_priority),
                TEST_CASE(test_thread_attributes_affinity),
                TEST_CASE(test_thread_attributes_priority),
+               TEST_CASE(test_thread_create_control_join),
                TEST_CASES_END()
        }
 };
lib/eal/common/eal_common_thread.c +8 -6
index 3181515..4f83c97 100644
@@ -232,7 +232,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-       void *(*start_routine)(void *);
+       union {
+               void *(*ctrl_start_routine)(void *arg);
+               rte_thread_func control_start_routine;
+       } u;
        void *arg;
        int ret;
        /* Control thread status.
@@ -241,27 +244,47 @@ struct rte_thread_ctrl_params {
        enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
        struct internal_config *internal_conf =
                eal_get_internal_configuration();
        rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
        struct rte_thread_ctrl_params *params = arg;
-       void *(*start_routine)(void *) = params->start_routine;
-       void *routine_arg = params->arg;
 
        __rte_thread_init(rte_lcore_id(), cpuset);
        params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset);
        if (params->ret != 0) {
                __atomic_store_n(&params->ctrl_thread_status,
                        CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-               return NULL;
+               return params->ret;
        }
 
        __atomic_store_n(&params->ctrl_thread_status,
                CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-       return start_routine(routine_arg);
+       return 0;
+}

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 276

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+
+static void *ctrl_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return NULL;
+
+       return start_routine(params->arg);

Does this patch open a race on params->arg between the newly created thread, and the one that asked for creation?
Reading params->arg is not under the ctrl_thread_status syncrhonisation point anymore (which was protecting against free(params)).

WDYT?

(Note that I doubt this patch has anything to do with the recent bz opened by Intel QE)

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 285

Quoted 9 lines
lib/eal/common/eal_common_thread.c +9 -0
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       rte_thread_func start_routine = params->u.control_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return params->ret;

Idem here for params->ret.

Quoted 132 lines
lib/eal/common/eal_common_thread.c +50 -2
+
+       return start_routine(params->arg);
 }
 
 int
@@ -277,12 +300,12 @@ static void *ctrl_thread_init(void *arg)
        if (!params)
                return -ENOMEM;
 
-       params->start_routine = start_routine;
+       params->u.ctrl_start_routine = start_routine;
        params->arg = arg;
        params->ret = 0;
        params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-       ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+       ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
        if (ret != 0) {
                free(params);
                return -ret;
@@ -315,6 +338,52 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+       const rte_thread_attr_t *attr,
+       rte_thread_func start_routine, void *arg)
+{
+       struct rte_thread_ctrl_params *params;
+       enum __rte_ctrl_thread_status ctrl_thread_status;
+       int ret;
+
+       params = malloc(sizeof(*params));
+       if (params == NULL)
+               return -ENOMEM;
+
+       params->u.control_start_routine = start_routine;
+       params->arg = arg;
+       params->ret = 0;
+       params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+       ret = rte_thread_create(thread, attr, control_thread_start, params);
+       if (ret != 0) {
+               free(params);
+               return -ret;
+       }
+
+       if (name != NULL)
+               rte_thread_set_name(*thread, name);
+
+       /* Wait for the control thread to initialize successfully */
+       while ((ctrl_thread_status =
+                       __atomic_load_n(&params->ctrl_thread_status,
+                       __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+               rte_delay_us_sleep(1);
+       }
+
+       /* Check if the control thread encountered an error */
+       if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+               /* ctrl thread is exiting */
+               rte_thread_join(*thread, NULL);
+       }
+
+       ret = params->ret;
+       free(params);
+
+       return ret;
+}
+
+int
 rte_thread_register(void)
 {
        unsigned int lcore_id;
lib/eal/include/rte_thread.h +33 -0
index d247930..fae26a7 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+               const rte_thread_attr_t *thread_attr,
+               rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -1
index 6523102..285a0bd 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
        rte_thread_join;
 
        # added in 23.03
+       rte_thread_create_control;
        rte_thread_set_name;
 };
 
--

1.8.3.1

Signature · 1 line
David Marchand
#49 lore raw

Re: [PATCH v6 1/3] eal: add rte thread create control API

Quoted 125 lines · David Marchand
Quoted 106 lines · Tyler Retzlaff

Add rte_thread_create_control API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Add test from David Marchand to exercise the new API.

---
 app/test/test_threads.c            | 26 ++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 137 insertions(+), 8 deletions(-)
app/test/test_threads.c +26 -0
index e0f18e4..657ecad 100644
@@ -232,6 +232,31 @@
        return 0;
 }
 
+static int
+test_thread_create_control_join(void)
+{
+       rte_thread_t thread_id;
+       rte_thread_t thread_main_id;
+
+       thread_id_ready = 0;
+       RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "test_control_threads",
+               NULL, thread_main, &thread_main_id) == 0,
+               "Failed to create thread.");
+
+       while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+               ;
+
+       RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+               "Unexpected thread id.");
+
+       __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+       RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+               "Failed to join thread.");
+
+       return 0;
+}
+
 static struct unit_test_suite threads_test_suite = {
        .suite_name = "threads autotest",
        .setup = NULL,
@@ -243,6 +268,7 @@
                TEST_CASE(test_thread_priority),
                TEST_CASE(test_thread_attributes_affinity),
                TEST_CASE(test_thread_attributes_priority),
+               TEST_CASE(test_thread_create_control_join),
                TEST_CASES_END()
        }
 };
lib/eal/common/eal_common_thread.c +8 -6
index 3181515..4f83c97 100644
@@ -232,7 +232,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-       void *(*start_routine)(void *);
+       union {
+               void *(*ctrl_start_routine)(void *arg);
+               rte_thread_func control_start_routine;
+       } u;
        void *arg;
        int ret;
        /* Control thread status.
@@ -241,27 +244,47 @@ struct rte_thread_ctrl_params {
        enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
        struct internal_config *internal_conf =
                eal_get_internal_configuration();
        rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
        struct rte_thread_ctrl_params *params = arg;
-       void *(*start_routine)(void *) = params->start_routine;
-       void *routine_arg = params->arg;
 
        __rte_thread_init(rte_lcore_id(), cpuset);
        params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset);
        if (params->ret != 0) {
                __atomic_store_n(&params->ctrl_thread_status,
                        CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-               return NULL;
+               return params->ret;
        }
 
        __atomic_store_n(&params->ctrl_thread_status,
                CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-       return start_routine(routine_arg);
+       return 0;
+}

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 276

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+
+static void *ctrl_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return NULL;
+
+       return start_routine(params->arg);

Does this patch open a race on params->arg between the newly created thread, and the one that asked for creation?
Reading params->arg is not under the ctrl_thread_status syncrhonisation point anymore (which was protecting against free(params)).

Quoted 1 line

WDYT?

i will take a look, thanks for letting me know.

Quoted 154 lines

(Note that I doubt this patch has anything to do with the recent bz opened by Intel QE)

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 285

Quoted 9 lines
lib/eal/common/eal_common_thread.c +9 -0
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       rte_thread_func start_routine = params->u.control_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return params->ret;

Idem here for params->ret.

Quoted 132 lines
lib/eal/common/eal_common_thread.c +50 -2
+
+       return start_routine(params->arg);
 }
 
 int
@@ -277,12 +300,12 @@ static void *ctrl_thread_init(void *arg)
        if (!params)
                return -ENOMEM;
 
-       params->start_routine = start_routine;
+       params->u.ctrl_start_routine = start_routine;
        params->arg = arg;
        params->ret = 0;
        params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-       ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+       ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
        if (ret != 0) {
                free(params);
                return -ret;
@@ -315,6 +338,52 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+       const rte_thread_attr_t *attr,
+       rte_thread_func start_routine, void *arg)
+{
+       struct rte_thread_ctrl_params *params;
+       enum __rte_ctrl_thread_status ctrl_thread_status;
+       int ret;
+
+       params = malloc(sizeof(*params));
+       if (params == NULL)
+               return -ENOMEM;
+
+       params->u.control_start_routine = start_routine;
+       params->arg = arg;
+       params->ret = 0;
+       params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+       ret = rte_thread_create(thread, attr, control_thread_start, params);
+       if (ret != 0) {
+               free(params);
+               return -ret;
+       }
+
+       if (name != NULL)
+               rte_thread_set_name(*thread, name);
+
+       /* Wait for the control thread to initialize successfully */
+       while ((ctrl_thread_status =
+                       __atomic_load_n(&params->ctrl_thread_status,
+                       __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+               rte_delay_us_sleep(1);
+       }
+
+       /* Check if the control thread encountered an error */
+       if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+               /* ctrl thread is exiting */
+               rte_thread_join(*thread, NULL);
+       }
+
+       ret = params->ret;
+       free(params);
+
+       return ret;
+}
+
+int
 rte_thread_register(void)
 {
        unsigned int lcore_id;
lib/eal/include/rte_thread.h +33 -0
index d247930..fae26a7 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+               const rte_thread_attr_t *thread_attr,
+               rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -1
index 6523102..285a0bd 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
        rte_thread_join;
 
        # added in 23.03
+       rte_thread_create_control;
        rte_thread_set_name;
 };
 
--

1.8.3.1

Signature · 1 line
David Marchand
#50 lore raw

Re: [PATCH v6 1/3] eal: add rte thread create control API

In reply to David Marchand
Quoted 93 lines · David Marchand
Quoted 91 lines · Tyler Retzlaff

Add rte_thread_create_control API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API.

Add test from David Marchand to exercise the new API.

---
 app/test/test_threads.c            | 26 ++++++++++++
 lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h       | 33 +++++++++++++++
 lib/eal/version.map                |  1 +
 4 files changed, 137 insertions(+), 8 deletions(-)
app/test/test_threads.c +26 -0
index e0f18e4..657ecad 100644
@@ -232,6 +232,31 @@
        return 0;
 }
 
+static int
+test_thread_create_control_join(void)
+{
+       rte_thread_t thread_id;
+       rte_thread_t thread_main_id;
+
+       thread_id_ready = 0;
+       RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "test_control_threads",
+               NULL, thread_main, &thread_main_id) == 0,
+               "Failed to create thread.");
+
+       while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+               ;
+
+       RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+               "Unexpected thread id.");
+
+       __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+       RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+               "Failed to join thread.");
+
+       return 0;
+}
+
 static struct unit_test_suite threads_test_suite = {
        .suite_name = "threads autotest",
        .setup = NULL,
@@ -243,6 +268,7 @@
                TEST_CASE(test_thread_priority),
                TEST_CASE(test_thread_attributes_affinity),
                TEST_CASE(test_thread_attributes_priority),
+               TEST_CASE(test_thread_create_control_join),
                TEST_CASES_END()
        }
 };
lib/eal/common/eal_common_thread.c +5 -4
index 3181515..4f83c97 100644
@@ -232,7 +232,10 @@ enum __rte_ctrl_thread_status {
 };
 
 struct rte_thread_ctrl_params {
-       void *(*start_routine)(void *);
+       union {
+               void *(*ctrl_start_routine)(void *arg);
+               rte_thread_func control_start_routine;
+       } u;
        void *arg;
        int ret;
        /* Control thread status.
@@ -241,27 +244,47 @@ struct rte_thread_ctrl_params {
        enum __rte_ctrl_thread_status ctrl_thread_status;
 };
 
-static void *ctrl_thread_init(void *arg)
+static int ctrl_thread_init(void *arg)
 {
        struct internal_config *internal_conf =
                eal_get_internal_configuration();
        rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
        struct rte_thread_ctrl_params *params = arg;
-       void *(*start_routine)(void *) = params->start_routine;
-       void *routine_arg = params->arg;
 
Quoted 7 lines

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 259

Quoted 7 lines
lib/eal/common/eal_common_thread.c +1 -1
        __rte_thread_init(rte_lcore_id(), cpuset);
        params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset);
        if (params->ret != 0) {
                __atomic_store_n(&params->ctrl_thread_status,
                        CTRL_THREAD_ERROR, __ATOMIC_RELEASE);
-               return NULL;
+               return params->ret;

here too, though a narrow window.

Quoted 25 lines
Quoted 8 lines
lib/eal/common/eal_common_thread.c +2 -1
        }
 
        __atomic_store_n(&params->ctrl_thread_status,
                CTRL_THREAD_RUNNING, __ATOMIC_RELEASE);
 
-       return start_routine(routine_arg);
+       return 0;
+}

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 276

Quoted 10 lines
lib/eal/common/eal_common_thread.c +10 -0
+
+static void *ctrl_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       void *(*start_routine)(void *) = params->u.ctrl_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return NULL;
+
+       return start_routine(params->arg);

Does this patch open a race on params->arg between the newly created thread, and the one that asked for creation?
Reading params->arg is not under the ctrl_thread_status syncrhonisation point anymore (which was protecting against free(params)).

Quoted 1 line

WDYT?

yeah, this is definitely wrong. i'm preparing a patch now. both params->ret and params->arg are loaded unsynchronized in multiple places.

sorry about the mistake. fix coming soon.

Quoted 155 lines

(Note that I doubt this patch has anything to do with the recent bz opened by Intel QE)

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 285

Quoted 9 lines
lib/eal/common/eal_common_thread.c +9 -0
+}
+
+static uint32_t control_thread_start(void *arg)
+{
+       struct rte_thread_ctrl_params *params = arg;
+       rte_thread_func start_routine = params->u.control_start_routine;
+
+       if (ctrl_thread_init(arg) != 0)
+               return params->ret;

Idem here for params->ret.

Quoted 132 lines
lib/eal/common/eal_common_thread.c +50 -2
+
+       return start_routine(params->arg);
 }
 
 int
@@ -277,12 +300,12 @@ static void *ctrl_thread_init(void *arg)
        if (!params)
                return -ENOMEM;
 
-       params->start_routine = start_routine;
+       params->u.ctrl_start_routine = start_routine;
        params->arg = arg;
        params->ret = 0;
        params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-       ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+       ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params);
        if (ret != 0) {
                free(params);
                return -ret;
@@ -315,6 +338,52 @@ static void *ctrl_thread_init(void *arg)
 }
 
 int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+       const rte_thread_attr_t *attr,
+       rte_thread_func start_routine, void *arg)
+{
+       struct rte_thread_ctrl_params *params;
+       enum __rte_ctrl_thread_status ctrl_thread_status;
+       int ret;
+
+       params = malloc(sizeof(*params));
+       if (params == NULL)
+               return -ENOMEM;
+
+       params->u.control_start_routine = start_routine;
+       params->arg = arg;
+       params->ret = 0;
+       params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
+
+       ret = rte_thread_create(thread, attr, control_thread_start, params);
+       if (ret != 0) {
+               free(params);
+               return -ret;
+       }
+
+       if (name != NULL)
+               rte_thread_set_name(*thread, name);
+
+       /* Wait for the control thread to initialize successfully */
+       while ((ctrl_thread_status =
+                       __atomic_load_n(&params->ctrl_thread_status,
+                       __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) {
+               rte_delay_us_sleep(1);
+       }
+
+       /* Check if the control thread encountered an error */
+       if (ctrl_thread_status == CTRL_THREAD_ERROR) {
+               /* ctrl thread is exiting */
+               rte_thread_join(*thread, NULL);
+       }
+
+       ret = params->ret;
+       free(params);
+
+       return ret;
+}
+
+int
 rte_thread_register(void)
 {
        unsigned int lcore_id;
lib/eal/include/rte_thread.h +33 -0
index d247930..fae26a7 100644
@@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Create a control thread.
+ *
+ * Creates a control thread with the given name and attributes. The
+ * affinity of the new thread is based on the CPU affinity retrieved
+ * at the time rte_eal_init() was called, the EAL threads are then
+ * excluded. If setting the name of the thread fails, the error is
+ * ignored and a debug message is logged.
+ *
+ * @param thread
+ *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread
+ *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * @param thread_attr
+ *   Attributes for the new thread.
+ * @param thread_func
+ *   Function to be executed by the new thread.
+ * @param arg
+ *   Argument passed to start_routine.
+ * @return
+ *   On success, returns 0; on error, it returns a negative value
+ *   corresponding to the error number.
+ */
+__rte_experimental
+int
+rte_thread_create_control(rte_thread_t *thread, const char *name,
+               const rte_thread_attr_t *thread_attr,
+               rte_thread_func thread_func, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Waits for the thread identified by 'thread_id' to terminate
  *
  * @param thread_id
lib/eal/version.map +1 -1
index 6523102..285a0bd 100644
@@ -441,6 +441,7 @@ EXPERIMENTAL {
        rte_thread_join;
 
        # added in 23.03
+       rte_thread_create_control;
        rte_thread_set_name;
 };
 
--

1.8.3.1

Signature · 1 line
David Marchand
#51 lore raw

PATCH v6 2/3 doc: add missing index entry for thread

In reply to Tyler Retzlaff

Add missing thread index referencing rte_thread.h under the basic topic.

---
 doc/api/doxy-api-index.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
doc/api/doxy-api-index.md +2 -1
index de488c7..2deec7e 100644
@@ -210,7 +210,8 @@ The public API headers are grouped by topics:
   [random](@ref rte_random.h),
   [config file](@ref rte_cfgfile.h),
   [key/value args](@ref rte_kvargs.h),
-  [string](@ref rte_string_fns.h)
+  [string](@ref rte_string_fns.h),
+  [thread](@ref rte_thread.h)
 
 - **debug**:
   [jobstats](@ref rte_jobstats.h),
Signature · 1 line
1.8.3.1
#52 lore raw

PATCH v6 3/3 doc: announce deprecation of thread ctrl create function

In reply to Tyler Retzlaff

Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details.

---
 doc/guides/rel_notes/deprecation.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
doc/guides/rel_notes/deprecation.rst +4 -4
index ac9aa76..6eb9721 100644
@@ -23,10 +23,10 @@ Deprecation Notices
   in the future. Applications can use ``devtools/cocci/func_or_ret.cocci``
   to update their code.
 
-* eal: The function ``rte_thread_setname`` is planned to be deprecated
-  starting with the 23.07 release, subject to the replacement API
-  rte_thread_set_name being marked as stable, and planned to be removed
-  by the 23.11 release.
+* eal: The function ``rte_thread_setname`` and ``rte_ctrl_thread_create``
+  are planned to be deprecated starting with the 23.07 release, subject to
+  the replacement API rte_thread_set_name and rte_thread_create_control being
+  marked as stable, and planned to be removed by the 23.11 release.
 
 * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does
   not allow for writing optimized code for all the CPU architectures supported
Signature · 1 line
1.8.3.1
Acked-by on v6 3/3
#53 lore raw

Re: [PATCH v6 3/3] doc: announce deprecation of thread ctrl create function

Quoted 8 lines · Tyler Retzlaff

Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details.

---

#54 lore raw

Re: [PATCH v6 0/3] eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff
Quoted 30 lines · Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_thread_create_control that uses the new rte_thread_t type.

Provide a unit test for the new rte_thread_create_control API (test code provided by David Marchand.)

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

Quoted 8 lines

v6:
* fix missing comma in doxygen index
* combine deprecation notice for rte_ctrl_thread_create into notice of removal of rte_thread_setname.
* remove test_lcore.c test and add test provided by David Marchand to test_threads.c.
* rename the function to start with rte_thread to be consistent with the rest of functions in the rte_thread.h APIs.

Thank you Tyler.

The series lgtm.
The deprecation notice is missing one ack, I'll still wait a bit. If we don't get it soon, I'll apply the first two patches for rc1.

Signature · 1 line
David Marchand
#55 lore raw

Re: [PATCH v6 0/3] eal: deprecate last use of pthread_t in public API

In reply to Tyler Retzlaff
Quoted 79 lines · Tyler Retzlaff

Announce deprecation of rte_ctrl_thread_create API which is the final remaining stable API exposing pthread_t.

Provide an equivalent replacement API rte_thread_create_control that uses the new rte_thread_t type.

Provide a unit test for the new rte_thread_create_control API (test code provided by David Marchand.)

Add missing doxygen index for thread / rte_thread.h.

Notice!

To limit compatibility regression risk and ease removal of the existing rte_ctrl_thread_create in the future duplicate most of the existing implementation rather than try to have it accommodate both public API contracts.

The duplication, the union introduced to support it along with remaining internal pthread_xxx calls will be removed when rte_ctrl_thread_create is finally removed.

The old unit test for rte_ctrl_thread_create is kept in place to guarantee correct behavior while deprecated and will be removed when rte_ctrl_thread_create is finally removed.

v6:
* fix missing comma in doxygen index
* combine deprecation notice for rte_ctrl_thread_create into notice of removal of rte_thread_setname.
* remove test_lcore.c test and add test provided by David Marchand to test_threads.c.
* rename the function to start with rte_thread to be consistent with the rest of functions in the rte_thread.h APIs.

v5:
* rebase series now that rte_thread_set_name has been merged, remove now unnecessary casts.
* combine patch adding rte_control_thread_create and patch adding unit test into patch 1.
* reword deprecation notice to indicate which release we intend to mark rte_ctrl_thread_create deprecated and which release we intend to remove the same.
* adjust deprecation notice commit subject based on previous deprecation notice series feedback.
* add (mostly unrelated) patch to series to add thread / rte_thread.h to doxygen index (an oversight missed from previous series).

v4:
* fix missing whitespace in deprecation notice text
* remove comment in rte_control_thread_create implementation referring to sched_yield as requested by community feedback
* add missing parameter name to function pointer declaration

v3:
* use {ctrl,control}_start_routine for start_routine field names
* fix conditional evaluation style p == NULL instead of !p
* tweak documentation comment for rte_control_thread_create
- "the EAL threads are then excluded"
- note RTE_MAX_THREAD_NAME_LEN preprocessor definition is the name size (including terminating NUL) limit
* add missing cast to uintptr_t

v2:
* correct style error void * (*foo) -> void *(*foo)
* place retval on lhs of comparison 0 != foo() -> foo() != 0
* add missing commit description on patch 3/3
* add cast uintptr_t to pthread_t where appropriate
* fix doxygen @param names to match parameter names

Tyler Retzlaff (3):
eal: add rte thread create control API
doc: add missing index entry for thread
doc: announce deprecation of thread ctrl create function

Quoted 7 lines
 app/test/test_threads.c              | 26 +++++++++++
 doc/api/doxy-api-index.md            |  3 +-
 doc/guides/rel_notes/deprecation.rst |  8 ++--
 lib/eal/common/eal_common_thread.c   | 85 ++++++++++++++++++++++++++++++++----
 lib/eal/include/rte_thread.h         | 33 ++++++++++++++
 lib/eal/version.map                  |  1 +
 6 files changed, 143 insertions(+), 13 deletions(-)

Series applied.
Thanks Tyler.

Signature · 1 line
David Marchand