Skip to contentSkip to conversation

add lcore set name and get name API

PATCH In review Tyler Retzlaff 6 participants 91 messages Dec 7, 2022 – Jan 31, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover add lcore set name and get name API

Set the lcore_config[].thread_id for the main lcore.

Introduce 2 new public APIs rte_lcore_set_name and rte_lcore_get_name that allow set and get of the lcore name and if the underlying platform supports it sets the platform-specific thread name.

Remove rte_thread_getname API

Deprecate rte_thread_setname public API and provide replacement rte_thread_set_name internal API for use by the EAL.

Add basic unit test for new APIs

Tyler Retzlaff (5):
eal: add lcore set name and get name API
eal: set lcore config thread for lcore main
test: add a unit test for set and get lcore name APIs
eal: remove thread getname API
eal: deprecate rte thread setname API

 app/test/test_lcores.c               | 52 ++++++++++++++++++++++++++++++
 doc/guides/rel_notes/deprecation.rst |  4 +++
 lib/eal/common/eal_common_lcore.c    | 32 +++++++++++++++++++
 lib/eal/common/eal_common_thread.c   | 18 ++++++-----
 lib/eal/common/eal_common_trace.c    |  2 +-
 lib/eal/freebsd/eal.c                |  5 ++-
 lib/eal/freebsd/eal_thread.c         | 15 ++++-----
 lib/eal/include/rte_lcore.h          | 62 ++++++++++++++++++++++++++----------
 lib/eal/include/rte_thread.h         |  8 +++++
 lib/eal/linux/eal.c                  |  5 ++-
 lib/eal/linux/eal_thread.c           | 18 +++++++----
 lib/eal/version.map                  |  6 +++-
 lib/eal/windows/rte_thread.c         | 41 ++++++++++++++++++++++++
 13 files changed, 221 insertions(+), 47 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/5 eal: add lcore set name and get name API

Add two new APIs that allow set and get of a name for an lcore that do not explose platform thread details via the public interface.

If the underlying platform thread API does allow set of a name for the lcore thread id it is called as a side-effect of set but lack of support or failure from the platform-specific API does will not cause the call to fail allowing for "debugging" on platforms that happen to support the feature without exposing it as a part of the EAL.

---
 lib/eal/common/eal_common_lcore.c  | 32 +++++++++++++++++++++++++++
 lib/eal/common/eal_common_thread.c | 15 ++++++-------
 lib/eal/common/eal_common_trace.c  |  2 +-
 lib/eal/freebsd/eal.c              |  5 ++++-
 lib/eal/freebsd/eal_thread.c       |  6 ++++++
 lib/eal/include/rte_lcore.h        | 44 ++++++++++++++++++++++++++++++++++++++
 lib/eal/include/rte_thread.h       |  8 +++++++
 lib/eal/linux/eal.c                |  5 ++---
 lib/eal/linux/eal_thread.c         | 19 ++++++++++++++++
 lib/eal/version.map                |  5 +++++
 lib/eal/windows/rte_thread.c       | 41 +++++++++++++++++++++++++++++++++++
 11 files changed, 169 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_lcore.c +32 -0
index 06c594b..700362a 100644
@@ -14,6 +14,38 @@
 #include "eal_private.h"
 #include "eal_thread.h"
 
+static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];
+
+int
+rte_lcore_set_name(unsigned int lcore_id, const char *name)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (strlen(name) >= RTE_LCORE_NAME_MAX_LEN)
+		return -ERANGE;
+
+	(void)strcpy(&lcore_names[lcore_id][0], name);
+
+	rte_thread_set_name((rte_thread_t){lcore_config[lcore_id].thread_id}, name);
+
+	return 0;
+}
+
+int
+rte_lcore_get_name(unsigned int lcore_id, char *name, size_t len)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (len < RTE_LCORE_NAME_MAX_LEN)
+		return -EINVAL;
+
+	(void)strcpy(name, &lcore_names[lcore_id][0]);
+
+	return 0;
+}
+
 unsigned int rte_get_main_lcore(void)
 {
 	return rte_eal_get_configuration()->main_lcore;
lib/eal/common/eal_common_thread.c +7 -8
index c5d8b43..91066e6 100644
@@ -272,6 +272,7 @@ static void *ctrl_thread_init(void *arg)
 		const pthread_attr_t *attr,
 		void *(*start_routine)(void *), void *arg)
 {
+	rte_thread_t id;
 	struct rte_thread_ctrl_params *params;
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 	int ret;
@@ -285,18 +286,16 @@ static void *ctrl_thread_init(void *arg)
 	params->ret = 0;
 	params->ctrl_thread_status = CTRL_THREAD_LAUNCHING;
 
-	ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);
+	ret = pthread_create((pthread_t *)&id.opaque_id, attr, ctrl_thread_init, params);
 	if (ret != 0) {
 		free(params);
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name(id, name);
+
+	*thread = (pthread_t)id.opaque_id;
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
@@ -312,7 +311,7 @@ static void *ctrl_thread_init(void *arg)
 	/* Check if the control thread encountered an error */
 	if (ctrl_thread_status == CTRL_THREAD_ERROR) {
 		/* ctrl thread is exiting */
-		pthread_join(*thread, NULL);
+		(void)rte_thread_join(id, NULL);
 	}
 
 	ret = params->ret;
lib/eal/common/eal_common_trace.c +1 -1
index 5caaac8..03c1055 100644
@@ -356,7 +356,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	(void)rte_lcore_get_name(rte_lcore_id(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal.c +4 -1
index 607684c..e6a76de 100644
@@ -817,7 +817,10 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		ret = rte_lcore_set_name(i, thread_name);
+		if (ret != 0)
+			RTE_LOG(DEBUG, EAL,
+				"Cannot set name for lcore\n");
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +6 -0
index ab81b52..af85c48 100644
@@ -32,6 +32,12 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t id, const char *name)
+{
+	/* this BSD function returns no error */
+	pthread_set_name_np(id.opaque_id, name);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_lcore.h +44 -0

62 lines not on this page · raw message

lib/eal/include/rte_thread.h +8 -0
index b9edf70..713330c 100644
@@ -143,6 +143,14 @@ int rte_thread_create(rte_thread_t *thread_id,
 rte_thread_t rte_thread_self(void);
 
 /**
+ * @internal
+ * Set the name of the thread.
+ */
+__rte_internal
+void
+rte_thread_set_name(rte_thread_t id, const char *name);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
lib/eal/linux/eal.c +2 -3
index 8c118d0..97e2fec 100644
@@ -1255,11 +1255,10 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
+		ret = rte_lcore_set_name(i, thread_name);
 		if (ret != 0)
 			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+				"Cannot set name for lcore\n");
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +19 -0
index 625bde6..2413bc6 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,24 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t id, const char *name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[16];
+
+	strlcpy(truncated, name, sizeof(truncated));
+	ret = pthread_setname_np(id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Cannot set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +5 -0
index 7ad12a7..4110f75 100644
@@ -440,6 +440,10 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_lcore_get_name;
+	rte_lcore_set_name;
 };
 
 INTERNAL {
@@ -483,4 +487,5 @@ INTERNAL {
 	rte_mem_map;
 	rte_mem_page_size;
 	rte_mem_unmap;
+	rte_thread_set_name;
 };
lib/eal/windows/rte_thread.c +41 -0

54 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 1/5] eal: add lcore set name and get name API

Quoted 1 line · On Wed, 7 Dec 2022 11:00:13 -0800 Tyler Retzlaff…

+static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];

This copy would redundant on Linux.

lib/eal/common/eal_common_lcore.c line 28

Quoted 11 lines
lib/eal/common/eal_common_lcore.c +11 -0
+
+int
+rte_lcore_set_name(unsigned int lcore_id, const char *name)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (strlen(name) >= RTE_LCORE_NAME_MAX_LEN)
+		return -ERANGE;
+
+	(void)strcpy(&lcore_names[lcore_id][0], name);

Why the void cast?

Quoted 20 lines
lib/eal/common/eal_common_lcore.c +20 -0
+
+	rte_thread_set_name((rte_thread_t){lcore_config[lcore_id].thread_id}, name);
+
+	return 0;
+}
+
+int
+rte_lcore_get_name(unsigned int lcore_id, char *name, size_t len)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (len < RTE_LCORE_NAME_MAX_LEN)
+		return -EINVAL;
+
+	(void)strcpy(name, &lcore_names[lcore_id][0]);
+
+	return 0;
+}
+
#3 lore raw

Re: [PATCH 1/5] eal: add lcore set name and get name API

Quoted 7 lines · Stephen Hemminger
Quoted 1 line · On Wed, 7 Dec 2022 11:00:13 -0800 Tyler Retzlaff…

+static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];

This copy would redundant on Linux.

Quoted 13 lines

lib/eal/common/eal_common_lcore.c line 28

Quoted 11 lines
lib/eal/common/eal_common_lcore.c +11 -0
+
+int
+rte_lcore_set_name(unsigned int lcore_id, const char *name)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (strlen(name) >= RTE_LCORE_NAME_MAX_LEN)
+		return -ERANGE;
+
+	(void)strcpy(&lcore_names[lcore_id][0], name);

Why the void cast?

it's a common convention used in various open source projects indicating the that ignoring the return value is intentional as opposed to being sloppy or accidental.

if it's a violation of dpdk style i'll remove it. but i have come across a lot of dpdk code where i honestly can't tell if it is on purpose or just sloppyness. (sticks out in code reviews too).

#4 lore raw

Re: [PATCH 1/5] eal: add lcore set name and get name API

Quoted 22 lines · On Wed, 7 Dec 2022 14:33:31 -0800 Tyler Retzlaff…
Quoted 7 lines · Stephen Hemminger
Quoted 1 line · On Wed, 7 Dec 2022 11:00:13 -0800 Tyler Retzlaff…

+static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];

This copy would redundant on Linux.

Quoted 13 lines

lib/eal/common/eal_common_lcore.c line 28

Quoted 11 lines
lib/eal/common/eal_common_lcore.c +11 -0
+
+int
+rte_lcore_set_name(unsigned int lcore_id, const char *name)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (strlen(name) >= RTE_LCORE_NAME_MAX_LEN)
+		return -ERANGE;
+
+	(void)strcpy(&lcore_names[lcore_id][0], name);  

Why the void cast?

Quoted 7 lines

it's a common convention used in various open source projects indicating the that ignoring the return value is intentional as opposed to being sloppy or accidental.

if it's a violation of dpdk style i'll remove it. but i have come across a lot of dpdk code where i honestly can't tell if it is on purpose or just sloppyness. (sticks out in code reviews too).

I think it is an old BSD lint ism.
Haven't seen it used in years.

#5 lore raw

Re: [PATCH 1/5] eal: add lcore set name and get name API

Quoted 29 lines · Stephen Hemminger
Quoted 26 lines · On Wed, 7 Dec 2022 14:33:31 -0800 Tyler Retzlaff…
Quoted 7 lines · Stephen Hemminger
Quoted 1 line · On Wed, 7 Dec 2022 11:00:13 -0800 Tyler Retzlaff…

+static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];

This copy would redundant on Linux.

Quoted 13 lines

lib/eal/common/eal_common_lcore.c line 28

Quoted 11 lines
lib/eal/common/eal_common_lcore.c +11 -0
+
+int
+rte_lcore_set_name(unsigned int lcore_id, const char *name)
+{
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return -EINVAL;
+
+	if (strlen(name) >= RTE_LCORE_NAME_MAX_LEN)
+		return -ERANGE;
+
+	(void)strcpy(&lcore_names[lcore_id][0], name);  

Why the void cast?

it's a common convention used in various open source projects indicating the that ignoring the return value is intentional as opposed to being sloppy or accidental.

Quoted 6 lines
Quoted 3 lines

if it's a violation of dpdk style i'll remove it. but i have come across a lot of dpdk code where i honestly can't tell if it is on purpose or just sloppyness. (sticks out in code reviews too).

I think it is an old BSD lint ism.
Haven't seen it used in years.

i guess you're calling me old? and yes it was also used to suppress lint warnings.

i'll remove it in the next rebase.

thanks.

#6 lore raw

PATCH 2/5 eal: set lcore config thread for lcore main

In reply to Tyler Retzlaff

Set the lcore_config[].thread_id for lcore_main during initialization. This allows the new rte_lcore_{set,get}_name() APIs to work with lcore_main consistent with other worker lcores.

---
 lib/eal/common/eal_common_thread.c | 3 +++
 1 file changed, 3 insertions(+)
lib/eal/common/eal_common_thread.c +3 -0
index 91066e6..fb1dfc9 100644
@@ -151,6 +151,9 @@ unsigned rte_socket_id(void)
 
 	/* acquire system unique id */
 	rte_gettid();
+	if (lcore_id == rte_get_main_lcore())
+		lcore_config[lcore_id].thread_id =
+			(pthread_t)(rte_thread_self()).opaque_id;
 
 	thread_update_affinity(cpuset);
 
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 3/5 test: add a unit test for set and get lcore name APIs

In reply to Tyler Retzlaff
---
 app/test/test_lcores.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
app/test/test_lcores.c +52 -0
index a6bb412..153b6f4 100644
@@ -379,6 +379,55 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_lcores_set_get_name(void)
+{
+	char out[RTE_LCORE_NAME_MAX_LEN];
+	char outcmp[RTE_LCORE_NAME_MAX_LEN];
+	const unsigned int lcore_id = rte_get_main_lcore();
+	const size_t outlen = sizeof(out);
+	const char empty[] = "";
+	const char valid[] = "0123456789abcde";
+	const char invalid[] = "0123456789abcdef";
+
+	memset(outcmp, 0xff, outlen);
+
+	memset(out, 0xff, outlen);
+	RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, empty) == 0,
+		"Failed to set empty lcore name.");
+	RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0,
+		"Failed to get empty lcore name.");
+	RTE_TEST_ASSERT(strcmp(empty, out) == 0,
+		"Failed to set and get empty lcore name.");
+
+	memset(out, 0xff, outlen);
+	RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, valid) == 0,
+		"Failed to set valid lcore name.");
+	RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0,
+		"Failed to get valid lcore name.");
+	RTE_TEST_ASSERT(strcmp(valid, out) == 0,
+		"Failed to set and get valid lcore name.");
+
+	memset(out, 0xff, outlen);
+	RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, invalid) == -ERANGE,
+		"Failed to fail set with invalid lcore name.");
+	RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0,
+		"Failed to preserve caller buffer after set failure.");
+
+	RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0,
+		"Failed to get valid lcore name after set failure.");
+	RTE_TEST_ASSERT(strcmp(valid, out) == 0,
+		"Failed to preserve valid lcore name after set failure.");
+
+	memset(out, 0xff, outlen);
+	RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen - 1) == -EINVAL,
+		"Failed to fail get with output buffer too small.");
+	RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0,
+		"Failed to preserve caller buffer after get failure.");
+
+	return TEST_SUCCESS;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +460,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_lcores_set_get_name() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 4/5 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

---
 lib/eal/freebsd/eal_thread.c |  9 ---------
 lib/eal/include/rte_lcore.h  | 17 -----------------
 lib/eal/linux/eal_thread.c   | 15 ---------------
 lib/eal/version.map          |  1 -
 4 files changed, 42 deletions(-)
lib/eal/freebsd/eal_thread.c +0 -9
index af85c48..7d72c18 100644
@@ -44,12 +44,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 251208f..944d89e 100644
@@ -396,23 +396,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index 2413bc6..5f56650 100644
@@ -52,18 +52,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index 4110f75..6881d19 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 5/5 eal: deprecate rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 1 +
 2 files changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..b03c935 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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +1 -0
index 944d89e..3ca9c52 100644
@@ -393,6 +393,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
Signature · 1 line
1.8.3.1
#10 lore raw

v2 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test.
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name.
* adapt mlx5 driver to avoid use of deprecated API.

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: deprecate rte thread setname API
drivers: mlx5 use rte thread set name

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  4 +++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  9 +++----
 lib/eal/common/eal_common_trace.c    |  2 --
 lib/eal/freebsd/eal.c                |  4 +++-
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 19 ++-------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  8 +++----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 13 files changed, 114 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  9 +++-----
 lib/eal/common/eal_common_trace.c  |  2 --
 lib/eal/freebsd/eal.c              |  4 +++-
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  8 +++----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 108 insertions(+), 14 deletions(-)
lib/eal/common/eal_common_thread.c +3 -6
index c5d8b43..a44023c 100644
@@ -291,12 +291,9 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread},
+			name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
-		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
 	trace->nb_trace_mem_list++;
lib/eal/freebsd/eal.c +3 -1
index 607684c..2a6415e 100644
@@ -817,7 +817,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +3 -5
index 8c118d0..f7a4a10 100644
@@ -1255,11 +1255,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +46 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#12 lore raw

Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 361

Quoted 13 lines · Tyler Retzlaff
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
-               __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
        trace->lcore_meta[count].mem = header;
        trace->nb_trace_mem_list++;

Note, this belongs to patch 2.

I understand we can drop the thread name retrieval helper from public API, but at least for the trace framework it added some info in the traces.
Jerin, Sunil, what do you think? Should we keep this helper internally?

Signature · 1 line
David Marchand
#13 lore raw

Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread

Quoted 13 lines · David Marchand
Quoted 11 lines · Tyler Retzlaff
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
-               __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
Quoted 4 lines

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 361

Quoted 2 lines
lib/eal/common/eal_common_trace.c +0 -0
        trace->lcore_meta[count].mem = header;
        trace->nb_trace_mem_list++;

Note, this belongs to patch 2.

agreed, not sure how i fumbled that. since there has been no reply about retaining rte_thread_getname as an internal api i'll just move this change to patch 2.

Quoted 8 lines

I understand we can drop the thread name retrieval helper from public API, but at least for the trace framework it added some info in the traces.
Jerin, Sunil, what do you think? Should we keep this helper internally?

Signature · 1 line
David Marchand
#14 lore raw

Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread

In reply to David Marchand
Quoted 19 lines · David Marchand

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 361

Quoted 13 lines · Tyler Retzlaff
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
-               __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
        trace->lcore_meta[count].mem = header;
        trace->nb_trace_mem_list++;

Note, this belongs to patch 2.

Quoted 4 lines

I understand we can drop the thread name retrieval helper from public API, but at least for the trace framework it added some info in the traces.
Jerin, Sunil, what do you think? Should we keep this helper internally?

Good catch @David Marchand. Yes, we should be it as internal helper API use it here.
For trace, It will be difficult to make sense without thread name.

Quoted 5 lines

--
David Marchand

#15 lore raw

Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread

Quoted 27 lines · Jerin Jacob
Quoted 19 lines · David Marchand

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 361

Quoted 13 lines · Tyler Retzlaff
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
-               __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
        trace->lcore_meta[count].mem = header;
        trace->nb_trace_mem_list++;

Note, this belongs to patch 2.

Quoted 4 lines

I understand we can drop the thread name retrieval helper from public API, but at least for the trace framework it added some info in the traces.
Jerin, Sunil, what do you think? Should we keep this helper internally?

Quoted 3 lines

Good catch @David Marchand. Yes, we should be it as internal helper API use it here.
For trace, It will be difficult to make sense without thread name.

is the name what is really valuable here because it will only appear in traces for linux with a new enough glibc, i.e. freebsd and windows it will always be empty.

we could just provide the thread id and that is available on all platforms, i'd like to see consistency for all platforms if possible here but i'm not pushing too hard since we don't declare our tracing output to be a compatibility surface.

can we just provide the thread id?

Quoted 6 lines
Quoted 6 lines

--
David Marchand

#16 lore raw

Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread

Quoted 36 lines · Tyler Retzlaff
Quoted 27 lines · Jerin Jacob
Quoted 19 lines · David Marchand

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 361

Quoted 13 lines · Tyler Retzlaff
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
-               __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
        trace->lcore_meta[count].mem = header;
        trace->nb_trace_mem_list++;

Note, this belongs to patch 2.

Quoted 4 lines

I understand we can drop the thread name retrieval helper from public API, but at least for the trace framework it added some info in the traces.
Jerin, Sunil, what do you think? Should we keep this helper internally?

Quoted 3 lines

Good catch @David Marchand. Yes, we should be it as internal helper API use it here.
For trace, It will be difficult to make sense without thread name.

is the name what is really valuable here because it will only appear in traces for linux with a new enough glibc, i.e. freebsd and windows it will always be empty.

Quoted 6 lines

we could just provide the thread id and that is available on all platforms, i'd like to see consistency for all platforms if possible here but i'm not pushing too hard since we don't declare our tracing output to be a compatibility surface.

can we just provide the thread id?

as a compromise i have submitted a new version for the series that curtails the scope of the original rte_thread_getname and allowing it at this single callsite.

going forward however i would suggest we do not allow further internal use.

thanks!

#17 lore raw

PATCH v2 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

---
 lib/eal/freebsd/eal_thread.c |  9 ---------
 lib/eal/include/rte_lcore.h  | 17 -----------------
 lib/eal/linux/eal_thread.c   | 15 ---------------
 lib/eal/version.map          |  1 -
 4 files changed, 42 deletions(-)
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v2 3/4 eal: deprecate rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index b9b02dc..b03c935 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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +2 -0
index 9c78650..2fb3091 100644
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>
@@ -349,6 +350,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v2 4/4 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 4 +++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +3 -1
index 51704ef..8103ab9 100644
@@ -465,7 +465,9 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name(
+		(rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#21 lore raw

Re: [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

anymore feedback here folks?

would like to clear this so i can rebase the rte_control_thread_create series.

thanks!

Quoted 35 lines · Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test.
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name.
* adapt mlx5 driver to avoid use of deprecated API.

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: deprecate rte thread setname API
drivers: mlx5 use rte thread set name

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  4 +++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  9 +++----
 lib/eal/common/eal_common_trace.c    |  2 --
 lib/eal/freebsd/eal.c                |  4 +++-
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 19 ++-------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  8 +++----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 13 files changed, 114 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#22 lore raw

RE: [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t

Quoted 28 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 10 January 2023 21.53

anymore feedback here folks?

would like to clear this so i can rebase the rte_control_thread_create series.

thanks!

Quoted 17 lines · Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test.
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name.
* adapt mlx5 driver to avoid use of deprecated API.

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: deprecate rte thread setname API
drivers: mlx5 use rte thread set name

#23 lore raw

v3 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test.
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name.
* adapt mlx5 driver to avoid use of deprecated API.

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
drivers: mlx5 use rte thread set name
eal: deprecate rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  9 +++----
 lib/eal/common/eal_common_trace.c    |  2 --
 lib/eal/freebsd/eal.c                |  4 +++-
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 19 ++-------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  8 +++----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 13 files changed, 113 insertions(+), 55 deletions(-)
#24 lore raw

PATCH v3 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  9 +++-----
 lib/eal/freebsd/eal.c              |  4 +++-
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  8 +++----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 108 insertions(+), 12 deletions(-)
lib/eal/common/eal_common_thread.c +3 -6
index c5d8b43..a44023c 100644
@@ -291,12 +291,9 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread},
+			name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +3 -1
index 607684c..2a6415e 100644
@@ -817,7 +817,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +3 -5
index 8c118d0..f7a4a10 100644
@@ -1255,11 +1255,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +46 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v3 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

---
 lib/eal/common/eal_common_trace.c |  2 --
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 44 deletions(-)
lib/eal/common/eal_common_trace.c +0 -2
index 5caaac8..89522dc 100644
@@ -356,8 +356,6 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
-		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
 	trace->nb_trace_mem_list++;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v3 3/4 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v3 4/4 eal: deprecate rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +2 -0
index 9c78650..2fb3091 100644
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>
@@ -349,6 +350,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
Signature · 1 line
1.8.3.1
#28 lore raw

v4 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
drivers: mlx5 use rte thread set name
eal: deprecate rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  9 +++----
 lib/eal/common/eal_common_trace.c    | 15 +++++++++++-
 lib/eal/freebsd/eal.c                |  4 +++-
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 19 ++-------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  8 +++----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 13 files changed, 127 insertions(+), 54 deletions(-)
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v4 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  9 +++-----
 lib/eal/freebsd/eal.c              |  4 +++-
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  8 +++----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 108 insertions(+), 12 deletions(-)
lib/eal/common/eal_common_thread.c +3 -6
index c5d8b43..a44023c 100644
@@ -291,12 +291,9 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread},
+			name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +3 -1
index 607684c..2a6415e 100644
@@ -817,7 +817,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +3 -5
index 8c118d0..f7a4a10 100644
@@ -1255,11 +1255,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +46 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#30 lore raw

PATCH v4 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.
* limit use of this very platform glibc specific function to the single place it is used.
* change the return type to void since the single use cannot meaningfully check for failure given the platform defined behavior.
* change the thread id type to be rte_thread_t.
* rename the function rte_thread_get_name to be consistent with the exported rte_thread_set_name.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..808f9c3 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+rte_thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	rte_thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#31 lore raw

Re: [PATCH v4 2/4] eal: remove thread getname API

Quoted 12 lines · Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

void
__rte_trace_mem_per_thread_alloc(void)
{

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 372

Quoted 5 lines
lib/eal/common/eal_common_trace.c +1 -1
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
+       rte_thread_get_name(rte_thread_self(), name,

Since it's a local function. Please change thread_get_name or so?

#32 lore raw

Re: [PATCH v4 2/4] eal: remove thread getname API

Quoted 10 lines · Jerin Jacob
Quoted 7 lines · Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Quoted 11 lines

lib/eal/common/eal_common_trace.c rte_trace_mode rte_trace_mode_get(void) · line 372

Quoted 9 lines

void
__rte_trace_mem_per_thread_alloc(void)
{

lib/eal/common/eal_common_trace.c +1 -1
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
+       rte_thread_get_name(rte_thread_self(), name,

Since it's a local function. Please change thread_get_name or so?

done

#33 lore raw

PATCH v4 3/4 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v4 4/4 eal: deprecate rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +2 -0
index 9c78650..2fb3091 100644
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>
@@ -349,6 +350,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
Signature · 1 line
1.8.3.1
#35 lore raw

v5 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
drivers: mlx5 use rte thread set name
eal: deprecate rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  9 +++----
 lib/eal/common/eal_common_trace.c    | 15 +++++++++++-
 lib/eal/freebsd/eal.c                |  4 +++-
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 19 ++-------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  8 +++----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 13 files changed, 127 insertions(+), 54 deletions(-)
Signature · 1 line
1.8.3.1
#36 lore raw

PATCH v5 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---

 lib/eal/common/eal_common_thread.c |  9 +++-----
 lib/eal/freebsd/eal.c              |  4 +++-
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  8 +++----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 108 insertions(+), 12 deletions(-)
lib/eal/common/eal_common_thread.c +3 -6
index c5d8b43..a44023c 100644
@@ -291,12 +291,9 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread},
+			name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +3 -1
index 607684c..2a6415e 100644
@@ -817,7 +817,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +3 -5
index 8c118d0..f7a4a10 100644
@@ -1255,11 +1255,9 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(
+			(rte_thread_t){(uintptr_t)lcore_config[i].thread_id},
+			thread_name);
 
 		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
 			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +46 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#37 lore raw

Re: [PATCH v5 1/4] eal: add thread set name API operating on rte thread

Quoted 10 lines · Tyler Retzlaff

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---

Quoted 10 lines
 lib/eal/common/eal_common_thread.c |  9 +++-----
 lib/eal/freebsd/eal.c              |  4 +++-
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  8 +++----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 108 insertions(+), 12 deletions(-)

[snip]

There is no update in lib/eal/windows/eal.c. Windows worker threads are not renamed like on Linux/FreeBSD.

I'd rather fix this in this series now that Windows EAL offers such facility. Either in this current patch, or a followup patch, as you prefer.

Quoted 68 lines
lib/eal/windows/rte_thread.c +46 -1
index 1c1e9d0..c26659d 100644
@@ -4,7 +4,9 @@
  */
 
 #include <errno.h>
+#include <wchar.h>
 
+#include <rte_eal.h>
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_thread.h>
@@ -305,6 +307,50 @@ struct thread_routine_ctx {
        return thread_id;
 }
 
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+       int ret = 0;
+       wchar_t wname[RTE_MAX_THREAD_NAME_LEN];
+       mbstate_t state = {0};
+       size_t rv;
+       HANDLE thread_handle;
+
+       thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE,
+               thread_id.opaque_id);
+       if (thread_handle == NULL) {
+               ret = thread_log_last_error("OpenThread()");
+               goto cleanup;
+       }
+
+       memset(wname, 0, sizeof(wname));
+       rv = mbsrtowcs(wname, &thread_name, RTE_DIM(wname) - 1, &state);
+       if (rv == (size_t)-1) {
+               ret = EILSEQ;
+               goto cleanup;
+       }
+
+       if (wcslen(wname) < strlen(thread_name))
+               RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+#ifndef RTE_TOOLCHAIN_GCC
+       if (FAILED(SetThreadDescription(thread_handle, wname))) {
+               ret = EINVAL;
+               goto cleanup;
+       }
+#else
+       ret = ENOTSUP;
+       goto cleanup;
+#endif
+
+cleanup:
+       if (thread_handle != NULL)
+               CloseHandle(thread_handle);
+
+       if (ret != 0)
+               RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int
 rte_thread_get_priority(rte_thread_t thread_id,
        enum rte_thread_priority *priority)
--

1.8.3.1

Signature · 1 line
David Marchand
#38 lore raw

PATCH v5 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.
* limit use of this very platform glibc specific function to the single place it is used.
* change the return type to void since the single use cannot meaningfully check for failure given the platform defined behavior.
* change the thread id type to be rte_thread_t.
* rename the function rte_thread_get_name to be consistent with the exported rte_thread_set_name.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#39 lore raw

Re: [PATCH v5 2/4] eal: remove thread getname API

Quoted 16 lines · Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.
* limit use of this very platform glibc specific function to the single place it is used.
* change the return type to void since the single use cannot meaningfully check for failure given the platform defined behavior.
* change the thread id type to be rte_thread_t.
* rename the function rte_thread_get_name to be consistent with the exported rte_thread_set_name.

Quoted 1 line

Trace changes are looks good to me.
For trace, Acked-by: Jerin Jacob <[email protected]>

Quoted 124 lines
---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
                trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+       pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+       RTE_SET_USED(id);
+       RTE_SET_USED(name);
+       RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
        /* Store the thread name */
        char *name = header->stream_header.thread_name;
        memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-       rte_thread_getname(pthread_self(), name,
+       thread_get_name(rte_thread_self(), name,
                __RTE_TRACE_EMIT_STRING_LEN_MAX);
 
        trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
        pthread_set_name_np(id, name);
        return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-       RTE_SET_USED(id);
-       RTE_SET_USED(name);
-       RTE_SET_USED(len);
-
-       return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
        RTE_SET_USED(name);
        return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-       int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-       ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-       RTE_SET_USED(id);
-       RTE_SET_USED(name);
-       RTE_SET_USED(len);
-       return -ret;
-
-}
lib/eal/version.map +0 -2
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
        __rte_trace_point_register;
        per_lcore_trace_mem;
        per_lcore_trace_point_sz;
-       rte_thread_getname; # WINDOWS_NO_EXPORT
        rte_trace_dump; # WINDOWS_NO_EXPORT
        rte_trace_is_enabled; # WINDOWS_NO_EXPORT
        rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
--

1.8.3.1

#40 lore raw

Re: [PATCH v5 2/4] eal: remove thread getname API

In reply to Tyler Retzlaff
Quoted 15 lines · Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.
* limit use of this very platform glibc specific function to the single place it is used.
* change the return type to void since the single use cannot meaningfully check for failure given the platform defined behavior.
* change the thread id type to be rte_thread_t.

Quoted 2 lines

* rename the function rte_thread_get_name to be consistent with the exported rte_thread_set_name.

This comment is not relevant anymore.

Quoted 2 lines
Signature · 1 line
David Marchand
#41 lore raw

PATCH v5 3/4 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#42 lore raw

PATCH v5 4/4 eal: deprecate rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +2 -0
index 9c78650..2fb3091 100644
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>
@@ -349,6 +350,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
Signature · 1 line
1.8.3.1
Acked-by on v5 4/4
#43 lore raw

Re: [PATCH v5 4/4] eal: deprecate rte thread setname API

Quoted 7 lines · Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it is being removed as it exposes platform-specific thread details. The functionality it provided is now implicitly provided via the rte_lcore_set_name API if the underlying platform supports it.

I counted one ack from Morten.
With mine (for the notice part, see comment below), that makes two.

We need one more ack (Cc: techboard, hoping that some kind member will ack).

Quoted 30 lines
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
lib/eal/include/rte_lcore.h +1 -0
index 9c78650..2fb3091 100644
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>

lib/eal/include/rte_lcore.h enum rte_lcore_role_t { · line 354

Quoted 5 lines
lib/eal/include/rte_lcore.h +1 -0
@@ -349,6 +350,7 @@ enum rte_lcore_role_t {
  * @return
  *   On success, return 0; otherwise return a negative value.
  */
+__rte_deprecated
 int rte_thread_setname(pthread_t id, const char *name);

However, this part should be removed and postponed to when rte_thread_set_name is marked stable.
As long as the set_name new symbol is experimental, we can't mark as deprecated as users would be left with no stable API.

Signature · 1 line
David Marchand
#44 lore raw

v6 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (5):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: set thread name on Windows worker threads
drivers: mlx5 use rte thread set name
eal: deprecation notice for rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  8 ++-----
 lib/eal/common/eal_common_trace.c    | 15 +++++++++++-
 lib/eal/freebsd/eal.c                |  3 +--
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++-------
 lib/eal/include/rte_lcore.h          | 17 -------------
 lib/eal/include/rte_thread.h         | 17 +++++++++++++
 lib/eal/linux/eal.c                  |  6 +----
 lib/eal/linux/eal_thread.c           | 29 ++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/eal.c                |  7 ++++++
 lib/eal/windows/rte_thread.c         | 46 ++++++++++++++++++++++++++++++++++++
 14 files changed, 127 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#45 lore raw

PATCH v6 1/5 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  8 ++-----
 lib/eal/freebsd/eal.c              |  3 +--
 lib/eal/freebsd/eal_thread.c       | 11 +++++++++
 lib/eal/include/rte_thread.h       | 17 ++++++++++++++
 lib/eal/linux/eal.c                |  6 +----
 lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 103 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +1 -5
index 60298c0..d4c3507 100644
@@ -1261,11 +1261,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +46 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#46 lore raw

Re: [PATCH v6 1/5] eal: add thread set name API operating on rte thread

Review

Quoted 2 lines · On Wed, 18 Jan 2023 11:54:02 -0800 Tyler Retzlaff…
(quoted diff) +2 -0
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name)

Do we really need so many casts here? Looks like the wrong type was passed in the first place?

#47 lore raw

Re: [PATCH v6 1/5] eal: add thread set name API operating on rte thread

Quoted 8 lines · Stephen Hemminger

Review

Quoted 2 lines · On Wed, 18 Jan 2023 11:54:02 -0800 Tyler Retzlaff…
(quoted diff) +2 -0
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name)

Do we really need so many casts here? Looks like the wrong type was passed in the first place?

we do until this code is converted to use rte_thread_create. the pthread_t needs to be casted to the uintptr_t (implementation detail of rte_thread_t) and rte_thread_t is required by rte_thread_set_name.

#48 lore raw

PATCH v6 2/5 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#49 lore raw

PATCH v6 3/5 eal: set thread name on Windows worker threads

In reply to Tyler Retzlaff

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +7 -0
index b9f95ed..e561f87 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread_name for aid in debugging. */
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
 		if (ret != 0)
Signature · 1 line
1.8.3.1
#50 lore raw

PATCH v6 4/5 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#51 lore raw

PATCH v6 5/5 eal: deprecation notice for rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
Signature · 1 line
1.8.3.1
#52 lore raw

Re: [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff
Quoted 4 lines · Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

Quoted 8 lines

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

The unit tests are failing in the UNH Windows env though it was fine with v5.
https://lab.dpdk.org/results/dashboard/patchsets/25031/

1/91 DPDK:fast-tests / acl_autotest FAIL
1.05s (exit status 3221225477 or signal 3221225349 SIGinvalid)
06:02:25 MALLOC_PERTURB_=92 DPDK_TEST=acl_autotest C:\Users\builder\jenkins\workspace\Generic-VM-Unit-Test-DPDK\dpdk\build\app\test\dpdk-test.exe ----------------------------------- output ----------------------------------- stderr:
EAL: Detected CPU lcores: 4

EAL: Detected NUMA nodes: 1

EAL: Multi-process support is requested, but not available.

------------------------------------------------------------------------------

Could you have a look?
Thanks.

Signature · 1 line
David Marchand
#53 lore raw

Re: [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t

Quoted 26 lines · David Marchand
Quoted 4 lines · Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

Quoted 8 lines

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

The unit tests are failing in the UNH Windows env though it was fine with v5.
https://lab.dpdk.org/results/dashboard/patchsets/25031/

1/91 DPDK:fast-tests / acl_autotest FAIL
1.05s (exit status 3221225477 or signal 3221225349 SIGinvalid)
06:02:25 MALLOC_PERTURB_=92 DPDK_TEST=acl_autotest C:\Users\builder\jenkins\workspace\Generic-VM-Unit-Test-DPDK\dpdk\build\app\test\dpdk-test.exe ----------------------------------- output ----------------------------------- stderr:
EAL: Detected CPU lcores: 4

Quoted 7 lines

EAL: Detected NUMA nodes: 1

EAL: Multi-process support is requested, but not available.

------------------------------------------------------------------------------

Could you have a look?

it's a bug in the windows implementation, v7 will be submitted to fix it.

thankfully you asked for the eal worker thread initialization to be made consistent with freebsd/linux. it was that change that caused the failure to be exposed in this revision of the series.

thank you.

#54 lore raw

v7 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

Replace the rte_thread_setname API which operates on pthread_t with rte_thread_set_name that operates on rte_thread_t.

We should try to align tracing output from the EAL for all platforms but in this case we are retaining an exception for linux as requested from the community.

v7:
* don't dereference thread_name after successful completion of mbsrtowcs. (fixes NULL dereference on Windows).

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (5):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: set thread name on Windows worker threads
drivers: mlx5 use rte thread set name
eal: deprecation notice for rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  4 ++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  8 ++-----
 lib/eal/common/eal_common_trace.c    | 15 ++++++++++++-
 lib/eal/freebsd/eal.c                |  3 +--
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++--------
 lib/eal/include/rte_lcore.h          | 17 --------------
 lib/eal/include/rte_thread.h         | 17 ++++++++++++++
 lib/eal/linux/eal.c                  |  6 +----
 lib/eal/linux/eal_thread.c           | 29 +++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/eal.c                |  7 ++++++
 lib/eal/windows/rte_thread.c         | 43 ++++++++++++++++++++++++++++++++++++
 14 files changed, 124 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#55 lore raw

PATCH v7 1/5 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  8 ++-----
 lib/eal/freebsd/eal.c              |  3 +--
 lib/eal/freebsd/eal_thread.c       | 11 ++++++++++
 lib/eal/include/rte_thread.h       | 17 +++++++++++++++
 lib/eal/linux/eal.c                |  6 +-----
 lib/eal/linux/eal_thread.c         | 22 +++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 43 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 100 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +17 -0
index b9edf70..8a63a52 100644
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +1 -5
index 60298c0..d4c3507 100644
@@ -1261,11 +1261,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +43 -0

56 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#56 lore raw

Re: [PATCH v7 1/5] eal: add thread set name API operating on rte thread

23/01/2023 20:39, Tyler Retzlaff:

Quoted 79 lines

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

---
 lib/eal/common/eal_common_thread.c |  8 ++-----
 lib/eal/freebsd/eal.c              |  3 +--
 lib/eal/freebsd/eal_thread.c       | 11 ++++++++++
 lib/eal/include/rte_thread.h       | 17 +++++++++++++++
 lib/eal/linux/eal.c                |  6 +-----
 lib/eal/linux/eal_thread.c         | 22 +++++++++++++++++++
 lib/eal/version.map                |  3 +++
 lib/eal/windows/rte_thread.c       | 43 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 100 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +0 -0
index b9edf70..8a63a52 100644

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

Quoted 4 lines
lib/eal/include/rte_thread.h +1 -0
@@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.

We need to explain that it can fail.

Quoted 11 lines
lib/eal/include/rte_thread.h +11 -0
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);

[...]

Quoted 12 lines
lib/eal/linux/eal_thread.c +10 -0
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");

lib/eal/linux/eal_thread.c int rte_sys_gettid(void) · line 41

Quoted 10 lines
lib/eal/linux/eal_thread.c +10 -0
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}

It is very close to rte_thread_setname with few differences. OK

Quoted 32 lines
lib/eal/windows/rte_thread.c +30 -0
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = 0;
+	wchar_t wname[RTE_MAX_THREAD_NAME_LEN];
+	mbstate_t state = {0};
+	size_t rv;
+	HANDLE thread_handle;
+
+	thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE,
+		thread_id.opaque_id);
+	if (thread_handle == NULL) {
+		ret = thread_log_last_error("OpenThread()");
+		goto cleanup;
+	}
+
+	memset(wname, 0, sizeof(wname));
+	rv = mbsrtowcs(wname, &thread_name, RTE_DIM(wname) - 1, &state);
+	if (rv == (size_t)-1) {
+		ret = EILSEQ;
+		goto cleanup;
+	}
+
+#ifndef RTE_TOOLCHAIN_GCC
+	if (FAILED(SetThreadDescription(thread_handle, wname))) {
+		ret = EINVAL;
+		goto cleanup;
+	}
+#else
+	ret = ENOTSUP;

lib/eal/windows/rte_thread.c struct thread_routine_ctx { · line 349

Quoted 10 lines
lib/eal/windows/rte_thread.c +10 -0
+	goto cleanup;
+#endif
+
+cleanup:
+	if (thread_handle != NULL)
+		CloseHandle(thread_handle);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}

This is a new function for Windows, right?
It should be noted in the commit log.

#57 lore raw

PATCH v7 2/5 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#58 lore raw

Re: [PATCH v7 2/5] eal: remove thread getname API

23/01/2023 20:39, Tyler Retzlaff:

Quoted 2 lines

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

You should give a justification in this commit log, and note the removal in the release notes (removed items).

Quoted 10 lines

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

Quoted 4 lines

Note: no space before acks.

#59 lore raw

Re: [PATCH v7 2/5] eal: remove thread getname API

Quoted 17 lines · Thomas Monjalon

23/01/2023 20:39, Tyler Retzlaff:

Quoted 2 lines

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

You should give a justification in this commit log, and note the removal in the release notes (removed items).

Quoted 10 lines

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

Quoted 7 lines
Quoted 4 lines

Note: no space before acks.

noted, will make the adjustment in the future.

thanks for letting me know.

#60 lore raw

PATCH v7 3/5 eal: set thread name on Windows worker threads

In reply to Tyler Retzlaff

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +7 -0
index b9f95ed..e561f87 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread_name for aid in debugging. */
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
 		if (ret != 0)
Signature · 1 line
1.8.3.1
#61 lore raw

Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads

23/01/2023 20:39, Tyler Retzlaff:

Quoted 25 lines

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +1 -0
index b9f95ed..e561f87 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 

lib/eal/windows/eal.c enum rte_proc_type_t · line 442

Quoted 5 lines
lib/eal/windows/eal.c +2 -0
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread_name for aid in debugging. */

No need of underscore in "thread name".

lib/eal/windows/eal.c enum rte_proc_type_t · line 445

Quoted 3 lines
lib/eal/windows/eal.c +3 -0
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);

Thanks for making implementations more uniform.

#62 lore raw

Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads

Quoted 25 lines · Thomas Monjalon

23/01/2023 20:39, Tyler Retzlaff:

Quoted 24 lines

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +1 -0
index b9f95ed..e561f87 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
Quoted 8 lines

lib/eal/windows/eal.c enum rte_proc_type_t · line 442

Quoted 6 lines
lib/eal/windows/eal.c +2 -0
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread_name for aid in debugging. */

No need of underscore in "thread name".

The variable name was copied from linux/eal.c and matches freebsd/eal.c do you still want me to remove the underscore? It will require another revision of the series.

Quoted 6 lines

lib/eal/windows/eal.c enum rte_proc_type_t · line 445

Quoted 4 lines
lib/eal/windows/eal.c +3 -0
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);

Thanks for making implementations more uniform.

my pleasure.

#63 lore raw

Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads

24/01/2023 16:33, Tyler Retzlaff:

Quoted 35 lines · Thomas Monjalon
Quoted 25 lines

23/01/2023 20:39, Tyler Retzlaff:

Quoted 24 lines

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +1 -0
index b9f95ed..e561f87 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
Quoted 8 lines

lib/eal/windows/eal.c enum rte_proc_type_t · line 442

Quoted 6 lines
lib/eal/windows/eal.c +2 -0
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread_name for aid in debugging. */

No need of underscore in "thread name".

Quoted 3 lines

The variable name was copied from linux/eal.c and matches freebsd/eal.c do you still want me to remove the underscore? It will require another revision of the series.

I mean in the comment, you want to use natural language, not the variable name.

Before making a new revision, let me check all patches.

#64 lore raw

PATCH v7 4/5 drivers: mlx5 use rte thread set name

In reply to Tyler Retzlaff

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
Signature · 1 line
1.8.3.1
#65 lore raw

Re: [PATCH v7 4/5] drivers: mlx5 use rte thread set name

23/01/2023 20:39, Tyler Retzlaff:

Quoted 2 lines

Use the new internal rte_thread_set_name API instead of the now deprecated rte_thread_setname API.

I think it should be squashed with the first patch, while introducing the new function.

#66 lore raw

PATCH v7 5/5 eal: deprecation notice for rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +4 -0
index e18ac34..2990bb1 100644
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.
Signature · 1 line
1.8.3.1
#67 lore raw

Re: [PATCH v7 5/5] eal: deprecation notice for rte thread setname API

23/01/2023 20:39, Tyler Retzlaff:

Quoted 18 lines

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)
doc/guides/rel_notes/deprecation.rst +0 -0
index e18ac34..2990bb1 100644

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

Quoted 7 lines
doc/guides/rel_notes/deprecation.rst +4 -0
@@ -126,3 +126,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_thread_setname`` will be removed, continuing
+  the effort to decouple EAL from platform-specific thread
+  implementations.

You need to specify when it will be marked as deprecated
and when it will be removed.
You can mark it as deprecated when the replacement is not experimental.

minor note: insert it near other EAL deprecations.

#68 lore raw

v8 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

v8:
* document that no implementation or internal implementation is a noop for rte_thread_set_name
* update commit message to indicate windows now provides an implementation for rte_thread_set_name
* remove '_' from thread_name in comment
* squish drivers/mlx5 patch into patch 1 as requested.
* clarify rte_thread_setname anticipated deprecation and removal releases in deprecation notice
* group deprecation notice with other eal deprecation notices

v7:
* don't dereference thread_name after successful completion of mbsrtowcs. (fixes NULL dereference on Windows).

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: set thread name on Windows worker threads
eal: deprecation notice for rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  5 +++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  8 ++-----
 lib/eal/common/eal_common_trace.c    | 15 ++++++++++++-
 lib/eal/freebsd/eal.c                |  3 +--
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++--------
 lib/eal/include/rte_lcore.h          | 17 --------------
 lib/eal/include/rte_thread.h         | 20 +++++++++++++++++
 lib/eal/linux/eal.c                  |  6 +----
 lib/eal/linux/eal_thread.c           | 29 +++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/eal.c                |  7 ++++++
 lib/eal/windows/rte_thread.c         | 43 ++++++++++++++++++++++++++++++++++++
 14 files changed, 128 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#69 lore raw

PATCH v8 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

Introduces Windows implementation for rte_thread_set_name not previously available on Windows.

Adapt drivers/mlx5 to use the new internal rte_thread_set_name API instead of the soon to be deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c |  3 +--
 lib/eal/common/eal_common_thread.c  |  8 ++-----
 lib/eal/freebsd/eal.c               |  3 +--
 lib/eal/freebsd/eal_thread.c        | 11 ++++++++++
 lib/eal/include/rte_thread.h        | 20 +++++++++++++++++
 lib/eal/linux/eal.c                 |  6 +-----
 lib/eal/linux/eal_thread.c          | 22 +++++++++++++++++++
 lib/eal/version.map                 |  3 +++
 lib/eal/windows/rte_thread.c        | 43 +++++++++++++++++++++++++++++++++++++
 10 files changed, 106 insertions(+), 16 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +20 -0
index b9edf70..d247930 100644
@@ -146,6 +146,26 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ * This API is a noop if the underlying platform does not
+ * support setting the thread name or the platform-specific
+ * API used to set the thread name fails.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +1 -5
index 60298c0..d4c3507 100644
@@ -1261,11 +1261,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +43 -0

56 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#70 lore raw

PATCH v8 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#71 lore raw

PATCH v8 3/4 eal: set thread name on Windows worker threads

In reply to Tyler Retzlaff

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +7 -0
index b9f95ed..e7d405b 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread name for aid in debugging. */
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
 		if (ret != 0)
Signature · 1 line
1.8.3.1
#72 lore raw

PATCH v8 4/4 eal: deprecation notice for rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
index e18ac34..112219f 100644
@@ -18,6 +18,11 @@ 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 deprectated
+  starting with the 23.03 release subject to the replacement API
+  rte_thread_set_name 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
#73 lore raw

v9 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

v9:
* fix typo in v8 deprecation notice picked up by ci

v8:
* document that no implementation or internal implementation failure is a noop for rte_thread_set_name
* update commit message to indicate windows now provides an implementation for rte_thread_set_name
* remove '_' from thread_name in comment
* squish drivers/mlx5 patch into patch 1 as requested
* clarify rte_thread_setname anticipated deprecation and removal releases in deprecation notice
* group deprecation notice with other eal deprecation notices

v7:
* don't dereference thread_name after successful completion of mbsrtowcs. (fixes NULL dereference on Windows).

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: set thread name on Windows worker threads
eal: deprecation notice for rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  5 +++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  8 ++-----
 lib/eal/common/eal_common_trace.c    | 15 ++++++++++++-
 lib/eal/freebsd/eal.c                |  3 +--
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++--------
 lib/eal/include/rte_lcore.h          | 17 --------------
 lib/eal/include/rte_thread.h         | 20 +++++++++++++++++
 lib/eal/linux/eal.c                  |  6 +----
 lib/eal/linux/eal_thread.c           | 29 +++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/eal.c                |  7 ++++++
 lib/eal/windows/rte_thread.c         | 43 ++++++++++++++++++++++++++++++++++++
 14 files changed, 128 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#74 lore raw

PATCH v9 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

Introduces Windows implementation for rte_thread_set_name not previously available on Windows.

Adapt drivers/mlx5 to use the new internal rte_thread_set_name API instead of the soon to be deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c |  3 +--
 lib/eal/common/eal_common_thread.c  |  8 ++-----
 lib/eal/freebsd/eal.c               |  3 +--
 lib/eal/freebsd/eal_thread.c        | 11 ++++++++++
 lib/eal/include/rte_thread.h        | 20 +++++++++++++++++
 lib/eal/linux/eal.c                 |  6 +-----
 lib/eal/linux/eal_thread.c          | 22 +++++++++++++++++++
 lib/eal/version.map                 |  3 +++
 lib/eal/windows/rte_thread.c        | 43 +++++++++++++++++++++++++++++++++++++
 10 files changed, 106 insertions(+), 16 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +20 -0
index b9edf70..d247930 100644
@@ -146,6 +146,26 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ * This API is a noop if the underlying platform does not
+ * support setting the thread name or the platform-specific
+ * API used to set the thread name fails.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +1 -5
index 60298c0..d4c3507 100644
@@ -1261,11 +1261,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +43 -0

56 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#75 lore raw

PATCH v9 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#76 lore raw

PATCH v9 3/4 eal: set thread name on Windows worker threads

In reply to Tyler Retzlaff

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +7 -0
index b9f95ed..e7d405b 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread name for aid in debugging. */
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
 		if (ret != 0)
Signature · 1 line
1.8.3.1
#77 lore raw

PATCH v9 4/4 eal: deprecation notice for rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
index e18ac34..5eb930f 100644
@@ -18,6 +18,11 @@ 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.03 release subject to the replacement API
+  rte_thread_set_name 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
#78 lore raw

Re: [PATCH v9 4/4] eal: deprecation notice for rte thread setname API

24/01/2023 19:02, Tyler Retzlaff:

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

Quoted 4 lines
doc/guides/rel_notes/deprecation.rst +4 -0
+* eal: The function ``rte_thread_setname`` is planned to be deprecated
+  starting with the 23.03 release subject to the replacement API
+  rte_thread_set_name being marked as stable and planned to be removed
+  by the 23.11 release.

You are introducing rte_thread_set_name as experimental in 23.03. So we are supposed to wait at least a release to make it stable. Let's deprecate it in 23.07 and remove in 23.11.

#79 lore raw

Re: [PATCH v9 4/4] eal: deprecation notice for rte thread setname API

Quoted 10 lines · Thomas Monjalon

24/01/2023 19:02, Tyler Retzlaff:

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

Quoted 4 lines
doc/guides/rel_notes/deprecation.rst +4 -0
+* eal: The function ``rte_thread_setname`` is planned to be deprecated
+  starting with the 23.03 release subject to the replacement API
+  rte_thread_set_name being marked as stable and planned to be removed
+  by the 23.11 release.

You are introducing rte_thread_set_name as experimental in 23.03. So we are supposed to wait at least a release to make it stable. Let's deprecate it in 23.07 and remove in 23.11.

updated with recommended date.

thanks

#80 lore raw

v10 cover add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff

v10:
* change intended deprecation of rte_thread_setname

    from 23.03 to 23.07

v9:
* fix typo in v8 deprecation notice picked up by ci

v8:
* document that no implementation or internal implementation failure is a noop for rte_thread_set_name
* update commit message to indicate windows now provides an implementation for rte_thread_set_name
* remove '_' from thread_name in comment
* squish drivers/mlx5 patch into patch 1 as requested
* clarify rte_thread_setname anticipated deprecation and removal releases in deprecation notice
* group deprecation notice with other eal deprecation notices

v7:
* don't dereference thread_name after successful completion of mbsrtowcs. (fixes NULL dereference on Windows).

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Tyler Retzlaff (4):
eal: add thread set name API operating on rte thread
eal: remove thread getname API
eal: set thread name on Windows worker threads
eal: deprecation notice for rte thread setname API

 doc/guides/rel_notes/deprecation.rst |  5 +++++
 drivers/net/mlx5/mlx5_hws_cnt.c      |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c  |  3 +--
 lib/eal/common/eal_common_thread.c   |  8 ++-----
 lib/eal/common/eal_common_trace.c    | 15 ++++++++++++-
 lib/eal/freebsd/eal.c                |  3 +--
 lib/eal/freebsd/eal_thread.c         | 20 +++++++++--------
 lib/eal/include/rte_lcore.h          | 17 --------------
 lib/eal/include/rte_thread.h         | 20 +++++++++++++++++
 lib/eal/linux/eal.c                  |  6 +----
 lib/eal/linux/eal_thread.c           | 29 +++++++++++++++---------
 lib/eal/version.map                  |  4 +++-
 lib/eal/windows/eal.c                |  7 ++++++
 lib/eal/windows/rte_thread.c         | 43 ++++++++++++++++++++++++++++++++++++
 14 files changed, 128 insertions(+), 55 deletions(-)
Signature · 1 line
1.8.3.1
#81 lore raw

PATCH v10 1/4 eal: add thread set name API operating on rte thread

Add a rte_thread_set_name that sets the name of an rte_thread_t thread. This is a replacement for the rte_thread_setname(pthread_t, ...) which exposes platform-specific details.

Introduces Windows implementation for rte_thread_set_name not previously available on Windows.

Adapt drivers/mlx5 to use the new internal rte_thread_set_name API instead of the soon to be deprecated rte_thread_setname API.

---
 drivers/net/mlx5/mlx5_hws_cnt.c     |  3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c |  3 +--
 lib/eal/common/eal_common_thread.c  |  8 ++-----
 lib/eal/freebsd/eal.c               |  3 +--
 lib/eal/freebsd/eal_thread.c        | 11 ++++++++++
 lib/eal/include/rte_thread.h        | 20 +++++++++++++++++
 lib/eal/linux/eal.c                 |  6 +-----
 lib/eal/linux/eal_thread.c          | 22 +++++++++++++++++++
 lib/eal/version.map                 |  3 +++
 lib/eal/windows/rte_thread.c        | 43 +++++++++++++++++++++++++++++++++++++
 10 files changed, 106 insertions(+), 16 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +2 -1
index 51704ef..05cc954 100644
@@ -465,7 +465,8 @@ struct mlx5_hws_cnt_pool *
 	}
 	snprintf(name, CNT_THREAD_NAME_MAX - 1, "%s/svc@%d",
 		 sh->ibdev_name, service_core);
-	rte_thread_setname(sh->cnt_svc->service_thread, name);
+	rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread},
+		name);
 	CPU_SET(service_core, &cpuset);
 	pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset),
 				&cpuset);
drivers/vdpa/mlx5/mlx5_vdpa_event.c +1 -2
index 4d81976..f3d392c 100644
@@ -547,8 +547,7 @@
 		goto out;
 	}
 	snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
-	if (rte_thread_setname(priv->timer_tid, name) != 0)
-		DRV_LOG(DEBUG, "Cannot set timer thread name.");
+	rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name);
 out:
 	if (attrp != NULL)
 		pthread_attr_destroy(attrp);
lib/eal/common/eal_common_thread.c +2 -6
index 38d83a6..3181515 100644
@@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg)
 		return -ret;
 	}
 
-	if (name != NULL) {
-		ret = rte_thread_setname(*thread, name);
-		if (ret < 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for ctrl thread\n");
-	}
+	if (name != NULL)
+		rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name);
 
 	/* Wait for the control thread to initialize successfully */
 	while ((ctrl_thread_status =
lib/eal/freebsd/eal.c +1 -2
index 8db5007..9303401 100644
@@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"rte-worker-%d", i);
-		rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/freebsd/eal_thread.c +11 -0
index ab81b52..b69f5d3 100644
@@ -32,6 +32,17 @@ int rte_sys_gettid(void)
 	return (int)lwpid;
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated);
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	/* this BSD function returns no error */
lib/eal/include/rte_thread.h +20 -0
index b9edf70..d247930 100644
@@ -146,6 +146,26 @@ int rte_thread_create(rte_thread_t *thread_id,
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
+ * Set the name of the thread.
+ * This API is a noop if the underlying platform does not
+ * support setting the thread name or the platform-specific
+ * API used to set the thread name fails.
+ *
+ * @param thread_id
+ *    The id of the thread to set name.
+ *
+ * @param thread_name
+ *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    including terminating NUL if necessary.
+ */
+__rte_experimental
+void
+rte_thread_set_name(rte_thread_t thread_id, const char *thread_name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
  * Check if 2 thread ids are equal.
  *
  * @param t1
lib/eal/linux/eal.c +1 -5
index 60298c0..d4c3507 100644
@@ -1261,11 +1261,7 @@ static void rte_eal_init_alert(const char *msg)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"rte-worker-%d", i);
-		ret = rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id,
-			thread_name);
-		if (ret != 0)
-			RTE_LOG(DEBUG, EAL,
-				"Cannot set name for lcore thread\n");
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
 
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
lib/eal/linux/eal_thread.c +22 -0
index 625bde6..d5fddab 100644
@@ -10,6 +10,7 @@
 
 #include <rte_eal.h>
 #include <rte_lcore.h>
+#include <rte_log.h>
 #include <rte_string_fns.h>
 
 /* require calling thread tid by gettid() */
@@ -18,6 +19,27 @@ int rte_sys_gettid(void)
 	return (int)syscall(SYS_gettid);
 }
 
+void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
+{
+	int ret = ENOSYS;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	const size_t truncatedsz = sizeof(truncated);
+
+	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
+		RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
+
+	ret = pthread_setname_np((pthread_t)thread_id.opaque_id, truncated);
+#endif
+#endif
+	RTE_SET_USED(thread_id);
+	RTE_SET_USED(thread_name);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
+}
+
 int rte_thread_setname(pthread_t id, const char *name)
 {
 	int ret = ENOSYS;
lib/eal/version.map +3 -0
index 7ad12a7..c98ba71 100644
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
lib/eal/windows/rte_thread.c +43 -0

56 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#82 lore raw

PATCH v10 2/4 eal: remove thread getname API

In reply to Tyler Retzlaff

Remove the rte_thread_getname API. The API is __rte_experimental and requires no deprecation notice.

Fold the platform specific variants into the one place it is used as a special case to retain the functionality for linux only.

Adjust the function as follows.

* reduce scope where thread_get_name can be used to eal_common_trace.c
* change the return type to void since the return value is not consistent reportable depending on glibc version.
* change the thread id type to be rte_thread_t.

---
 lib/eal/common/eal_common_trace.c | 15 ++++++++++++++-
 lib/eal/freebsd/eal_thread.c      |  9 ---------
 lib/eal/include/rte_lcore.h       | 17 -----------------
 lib/eal/linux/eal_thread.c        | 15 ---------------
 lib/eal/version.map               |  1 -
 5 files changed, 14 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_trace.c +14 -1
index 5caaac8..75162b7 100644
@@ -298,6 +298,19 @@ rte_trace_mode rte_trace_mode_get(void)
 		trace_point_dump(f, tp);
 }
 
+static void
+thread_get_name(rte_thread_t id, char *name, size_t len)
+{
+#if defined(RTE_EXEC_ENV_LINUX) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 12)
+	pthread_getname_np((pthread_t)id.opaque_id, name, len);
+#endif
+#endif
+	RTE_SET_USED(id);
+	RTE_SET_USED(name);
+	RTE_SET_USED(len);
+}
+
 void
 __rte_trace_mem_per_thread_alloc(void)
 {
@@ -356,7 +369,7 @@ rte_trace_mode rte_trace_mode_get(void)
 	/* Store the thread name */
 	char *name = header->stream_header.thread_name;
 	memset(name, 0, __RTE_TRACE_EMIT_STRING_LEN_MAX);
-	rte_thread_getname(pthread_self(), name,
+	thread_get_name(rte_thread_self(), name,
 		__RTE_TRACE_EMIT_STRING_LEN_MAX);
 
 	trace->lcore_meta[count].mem = header;
lib/eal/freebsd/eal_thread.c +0 -9
index b69f5d3..3227d9b 100644
@@ -49,12 +49,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	pthread_set_name_np(id, name);
 	return 0;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-
-	return -ENOTSUP;
-}
lib/eal/include/rte_lcore.h +0 -17
index 6938c3f..9c78650 100644
@@ -352,23 +352,6 @@ enum rte_lcore_role_t {
 int rte_thread_setname(pthread_t id, const char *name);
 
 /**
- * Get thread name.
- *
- * @note It fails with glibc < 2.12.
- *
- * @param id
- *   Thread id.
- * @param name
- *   Thread name to set.
- * @param len
- *   Thread name buffer length.
- * @return
- *   On success, return 0; otherwise return a negative value.
- */
-__rte_experimental
-int rte_thread_getname(pthread_t id, char *name, size_t len);
-
-/**
  * Register current non-EAL thread as a lcore.
  *
  * @note This API is not compatible with the multi-process feature:
lib/eal/linux/eal_thread.c +0 -15
index d5fddab..c07ad9d 100644
@@ -55,18 +55,3 @@ int rte_thread_setname(pthread_t id, const char *name)
 	RTE_SET_USED(name);
 	return -ret;
 }
-
-int rte_thread_getname(pthread_t id, char *name, size_t len)
-{
-	int ret = ENOSYS;
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
-#if __GLIBC_PREREQ(2, 12)
-	ret = pthread_getname_np(id, name, len);
-#endif
-#endif
-	RTE_SET_USED(id);
-	RTE_SET_USED(name);
-	RTE_SET_USED(len);
-	return -ret;
-
-}
lib/eal/version.map +0 -1
index c98ba71..6523102 100644
@@ -369,7 +369,6 @@ EXPERIMENTAL {
 	__rte_trace_point_register;
 	per_lcore_trace_mem;
 	per_lcore_trace_point_sz;
-	rte_thread_getname; # WINDOWS_NO_EXPORT
 	rte_trace_dump; # WINDOWS_NO_EXPORT
 	rte_trace_is_enabled; # WINDOWS_NO_EXPORT
 	rte_trace_metadata_dump; # WINDOWS_NO_EXPORT
Signature · 1 line
1.8.3.1
#83 lore raw

PATCH v10 3/4 eal: set thread name on Windows worker threads

In reply to Tyler Retzlaff

Bring Windows EAL worker thread initialization in line with linux & freebsd by setting the worker thread name using the new platform agnostic rte_thread_set_name API.

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/eal/windows/eal.c +7 -0
index b9f95ed..e7d405b 100644
@@ -282,6 +282,7 @@ enum rte_proc_type_t
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
 	eal_log_init(NULL, 0);
 
@@ -437,6 +438,12 @@ enum rte_proc_type_t
 		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
+
+		/* Set thread name for aid in debugging. */
+		snprintf(thread_name, sizeof(thread_name),
+			"rte-worker-%d", i);
+		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+
 		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
 			&lcore_config[i].cpuset);
 		if (ret != 0)
Signature · 1 line
1.8.3.1
#84 lore raw

PATCH v10 4/4 eal: deprecation notice for rte thread setname API

In reply to Tyler Retzlaff

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)
doc/guides/rel_notes/deprecation.rst +5 -0
index e18ac34..bae7441 100644
@@ -18,6 +18,11 @@ 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.
+
 * 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 v10 4/4
#85 lore raw

Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API

Hi,

The title should start with a verb.
I suppose it can be fixed while merging with a title like:
doc: announce deprecation of thread naming function

24/01/2023 19:12, Tyler Retzlaff:

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

Quoted 12 lines

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---

doc/guides/rel_notes/deprecation.rst +4 -0
+* 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.

Minor: it would be clearer if adding some commas after "release" and "stable".

For the series,

#86 lore raw

Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API

Quoted 6 lines · Thomas Monjalon

Hi,

The title should start with a verb.
I suppose it can be fixed while merging with a title like:
doc: announce deprecation of thread naming function

Yes, I will handle it.

Quoted 14 lines

24/01/2023 19:12, Tyler Retzlaff:

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

Quoted 12 lines

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---

doc/guides/rel_notes/deprecation.rst +4 -0
+* 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.
Quoted 1 line

Minor: it would be clearer if adding some commas after "release" and "stable".

And this too.

Quoted 4 lines

For the series,

Thanks.

Signature · 1 line
David Marchand
#87 lore raw

Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API

Quoted 26 lines · David Marchand
Quoted 6 lines · Thomas Monjalon

Hi,

The title should start with a verb.
I suppose it can be fixed while merging with a title like:
doc: announce deprecation of thread naming function

Yes, I will handle it.

Quoted 14 lines

24/01/2023 19:12, Tyler Retzlaff:

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

Quoted 12 lines

Notify deprecation of rte_thread_setname API, it will be removed as it exposes platform-specific thread details. The functionality it provided is now available via the new rte_lcore_set_name API.

---

doc/guides/rel_notes/deprecation.rst +4 -0
+* 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.
Quoted 1 line

Minor: it would be clearer if adding some commas after "release" and "stable".

Quoted 8 lines

And this too.

Quoted 4 lines

For the series,

Thanks.

thank you both, i'll rebase the rte_ctrl_thread_create patch series once this is merged to get it moving forward again.

#88 lore raw

Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API

Quoted 3 lines · Tyler Retzlaff

thank you both, i'll rebase the rte_ctrl_thread_create patch series once this is merged to get it moving forward again.

We are missing a reference to rte_thread.h in doc/api/doxy-api-index.md. Please, can you send a patch for this too?

Thanks.

Signature · 1 line
David Marchand
#89 lore raw

Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API

Quoted 8 lines · David Marchand
Quoted 3 lines · Tyler Retzlaff

thank you both, i'll rebase the rte_ctrl_thread_create patch series once this is merged to get it moving forward again.

We are missing a reference to rte_thread.h in doc/api/doxy-api-index.md. Please, can you send a patch for this too?

no problem.

Quoted 6 lines

Thanks.

Signature · 1 line
David Marchand
#90 lore raw

Re: [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t

In reply to Tyler Retzlaff
Quoted 39 lines · Tyler Retzlaff

v10:
* change intended deprecation of rte_thread_setname

    from 23.03 to 23.07

v9:
* fix typo in v8 deprecation notice picked up by ci

v8:
* document that no implementation or internal implementation failure is a noop for rte_thread_set_name
* update commit message to indicate windows now provides an implementation for rte_thread_set_name
* remove '_' from thread_name in comment
* squish drivers/mlx5 patch into patch 1 as requested
* clarify rte_thread_setname anticipated deprecation and removal releases in deprecation notice
* group deprecation notice with other eal deprecation notices

v7:
* don't dereference thread_name after successful completion of mbsrtowcs. (fixes NULL dereference on Windows).

v6:
* clean up commit descriptions
* add patch to set worker thread name on windows
* remove __rte_deprecated from rte_thread_setname

v5:
* rename rte_thread_getname -> thread_get_name

v4:
* retain and move rte_thread_getname function to the single site of use

v3:
* fix coding style error
* move remove of rte_thread_getname to patch #2

Quoted 8 lines

v2:
* initial series provided get/set for lcore thread id, those additions have been removed as per discussion. including unit test
* add a single api rte_thread_set_name does not fail but emits debug logging if the internal implementation is aware of in-exact use of the name or failure to set the name
* adapt mlx5 driver to avoid use of deprecated API

Series applied, thanks Tyler.

Signature · 1 line
David Marchand