DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/5] add lcore set name and get name API
@ 2022-12-07 19:00 Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 1/5] eal: " Tyler Retzlaff
                   ` (13 more replies)
  0 siblings, 14 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, Tyler Retzlaff

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

-- 
1.8.3.1


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

* [PATCH 1/5] eal: add lcore set name and get name API
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
@ 2022-12-07 19:00 ` Tyler Retzlaff
  2022-12-07 21:03   ` Stephen Hemminger
  2022-12-07 19:00 ` [PATCH 2/5] eal: set lcore config thread for lcore main Tyler Retzlaff
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, Tyler Retzlaff

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
index 06c594b..700362a 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -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;
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index c5d8b43..91066e6 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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;
diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..03c1055 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 607684c..e6a76de 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..af85c48 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..251208f 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -13,6 +13,7 @@
  */
 #include <stdio.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_config.h>
 #include <rte_per_lcore.h>
@@ -25,6 +26,7 @@
 #endif
 
 #define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
+#define RTE_LCORE_NAME_MAX_LEN RTE_MAX_THREAD_NAME_LEN
 
 RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);  /**< Per thread "lcore id". */
 
@@ -90,6 +92,48 @@ enum rte_lcore_role_t {
 unsigned int rte_get_main_lcore(void);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Sets the name of an lcore and (if supported) implicitly sets the
+ * debugging name of the lcores thread.
+ *
+ * @param lcore_id
+ *   The targeted lcore.
+ *
+ * @param name
+ *   The name to set for the specified lcore_id. strlen(name) shall be
+ *   no more than RTE_LCORE_NAME_MAX_LEN - 1 long.
+ *
+ * @return
+ *   0 on success or, -errno on failure.
+ */
+__rte_experimental
+int rte_lcore_set_name(unsigned int lcore_id, const char *name);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Gets the name of an lcore thread.
+ *
+ * @param lcore_id
+ *   The targeted lcore.
+ *
+ * @param name
+ *   The buffer used to receive the lcore name.
+ *
+ * @param len
+ *   The length of the buffer name. The buffer len shall be at
+ *   least RTE_LCORE_NAME_MAX_LEN.
+ *
+ * @return
+ *   0 on success or, -errno on failure.
+ */
+__rte_experimental
+int rte_lcore_get_name(unsigned int lcore_id, char *name, size_t len);
+
+/**
  * Return the number of execution units (lcores) on the system.
  *
  * @return
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..713330c 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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.
  *
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 8c118d0..97e2fec 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..2413bc6 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..4110f75 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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;
 };
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..51028ef 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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,45 @@ struct thread_routine_ctx {
 	return thread_id;
 }
 
+void
+rte_thread_set_name(rte_thread_t id, const char *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, id.opaque_id);
+	if (thread_handle == NULL) {
+		ret = thread_log_last_error("OpenThread()");
+		goto cleanup;
+	}
+
+	rv = mbsrtowcs(wname, &name, sizeof(wname) / sizeof(wname[0]), &state);
+	if (rv == (size_t)-1) {
+		ret = EILSEQ;
+		goto cleanup;
+	}
+
+	if (name != NULL) {
+		ret = ERANGE;
+		goto cleanup;
+	}
+
+	if (FAILED(SetThreadDescription(thread_handle, wname))) {
+		ret = EINVAL;
+		goto cleanup;
+	}
+
+cleanup:
+	if (thread_handle != NULL)
+		CloseHandle(thread_handle);
+
+	if (ret != 0)
+		RTE_LOG(DEBUG, EAL, "Cannot set name for lcore\n");
+}
+
 int
 rte_thread_get_priority(rte_thread_t thread_id,
 	enum rte_thread_priority *priority)
-- 
1.8.3.1


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

* [PATCH 2/5] eal: set lcore config thread for lcore main
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 1/5] eal: " Tyler Retzlaff
@ 2022-12-07 19:00 ` Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 3/5] test: add a unit test for set and get lcore name APIs Tyler Retzlaff
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/common/eal_common_thread.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 91066e6..fb1dfc9 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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);
 
-- 
1.8.3.1


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

* [PATCH 3/5] test: add a unit test for set and get lcore name APIs
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 1/5] eal: " Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 2/5] eal: set lcore config thread for lcore main Tyler Retzlaff
@ 2022-12-07 19:00 ` Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 4/5] eal: remove thread getname API Tyler Retzlaff
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, Tyler Retzlaff

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/test_lcores.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
index a6bb412..153b6f4 100644
--- a/app/test/test_lcores.c
+++ b/app/test/test_lcores.c
@@ -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;
 }
 
-- 
1.8.3.1


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

* [PATCH 4/5] eal: remove thread getname API
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (2 preceding siblings ...)
  2022-12-07 19:00 ` [PATCH 3/5] test: add a unit test for set and get lcore name APIs Tyler Retzlaff
@ 2022-12-07 19:00 ` Tyler Retzlaff
  2022-12-07 19:00 ` [PATCH 5/5] eal: deprecate rte thread setname API Tyler Retzlaff
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index af85c48..7d72c18 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 251208f..944d89e 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 2413bc6..5f56650 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 4110f75..6881d19 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH 5/5] eal: deprecate rte thread setname API
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (3 preceding siblings ...)
  2022-12-07 19:00 ` [PATCH 4/5] eal: remove thread getname API Tyler Retzlaff
@ 2022-12-07 19:00 ` Tyler Retzlaff
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 19:00 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 1 +
 2 files changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index b9b02dc..b03c935 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 944d89e..3ca9c52 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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);
 
 /**
-- 
1.8.3.1


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

* Re: [PATCH 1/5] eal: add lcore set name and get name API
  2022-12-07 19:00 ` [PATCH 1/5] eal: " Tyler Retzlaff
@ 2022-12-07 21:03   ` Stephen Hemminger
  2022-12-07 22:33     ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Stephen Hemminger @ 2022-12-07 21:03 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, david.marchand, olivier.matz

On Wed,  7 Dec 2022 11:00:13 -0800
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> +static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];

This copy would redundant on Linux.

> +
> +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?

> +
> +	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;
> +}
> +

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

* Re: [PATCH 1/5] eal: add lcore set name and get name API
  2022-12-07 21:03   ` Stephen Hemminger
@ 2022-12-07 22:33     ` Tyler Retzlaff
  2022-12-08  4:07       ` Stephen Hemminger
  0 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-07 22:33 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, thomas, david.marchand, olivier.matz

On Wed, Dec 07, 2022 at 01:03:41PM -0800, Stephen Hemminger wrote:
> On Wed,  7 Dec 2022 11:00:13 -0800
> Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> 
> > +static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];
> 
> This copy would redundant on Linux.
> 
> > +
> > +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).

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

* Re: [PATCH 1/5] eal: add lcore set name and get name API
  2022-12-07 22:33     ` Tyler Retzlaff
@ 2022-12-08  4:07       ` Stephen Hemminger
  2022-12-08 17:11         ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Stephen Hemminger @ 2022-12-08  4:07 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, david.marchand, olivier.matz

On Wed, 7 Dec 2022 14:33:31 -0800
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> On Wed, Dec 07, 2022 at 01:03:41PM -0800, Stephen Hemminger wrote:
> > On Wed,  7 Dec 2022 11:00:13 -0800
> > Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> >   
> > > +static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];  
> > 
> > This copy would redundant on Linux.
> >   
> > > +
> > > +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).

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

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

* Re: [PATCH 1/5] eal: add lcore set name and get name API
  2022-12-08  4:07       ` Stephen Hemminger
@ 2022-12-08 17:11         ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-08 17:11 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, thomas, david.marchand, olivier.matz

On Wed, Dec 07, 2022 at 08:07:16PM -0800, Stephen Hemminger wrote:
> On Wed, 7 Dec 2022 14:33:31 -0800
> Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> 
> > On Wed, Dec 07, 2022 at 01:03:41PM -0800, Stephen Hemminger wrote:
> > > On Wed,  7 Dec 2022 11:00:13 -0800
> > > Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> > >   
> > > > +static char lcore_names[RTE_MAX_LCORE][RTE_LCORE_NAME_MAX_LEN];  
> > > 
> > > This copy would redundant on Linux.
> > >   
> > > > +
> > > > +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).
> 
> 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.

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

* [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (4 preceding siblings ...)
  2022-12-07 19:00 ` [PATCH 5/5] eal: deprecate rte thread setname API Tyler Retzlaff
@ 2022-12-14 16:47 ` Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (4 more replies)
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
                   ` (7 subsequent siblings)
  13 siblings, 5 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-14 16:47 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb, 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(-)

-- 
1.8.3.1


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

* [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2022-12-14 16:47   ` Tyler Retzlaff
  2023-01-11 16:09     ` David Marchand
  2022-12-14 16:47   ` [PATCH v2 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-14 16:47 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index c5d8b43..a44023c 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..89522dc 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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++;
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 607684c..2a6415e 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 8c118d0..f7a4a10 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..c26659d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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


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

* [PATCH v2 2/4] eal: remove thread getname API
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2022-12-14 16:47   ` Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 3/4] eal: deprecate rte thread setname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-14 16:47 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v2 3/4] eal: deprecate rte thread setname API
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2022-12-14 16:47   ` Tyler Retzlaff
  2022-12-14 16:47   ` [PATCH v2 4/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
  2023-01-10 20:53   ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  4 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-14 16:47 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index b9b02dc..b03c935 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 9c78650..2fb3091 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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);
 
 /**
-- 
1.8.3.1


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

* [PATCH v2 4/4] drivers: mlx5 use rte thread set name
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2022-12-14 16:47   ` [PATCH v2 3/4] eal: deprecate rte thread setname API Tyler Retzlaff
@ 2022-12-14 16:47   ` Tyler Retzlaff
  2022-12-14 16:51     ` Morten Brørup
  2023-01-10 20:53   ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2022-12-14 16:47 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 4 +++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..8103ab9 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* RE: [PATCH v2 4/4] drivers: mlx5 use rte thread set name
  2022-12-14 16:47   ` [PATCH v2 4/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2022-12-14 16:51     ` Morten Brørup
  0 siblings, 0 replies; 91+ messages in thread
From: Morten Brørup @ 2022-12-14 16:51 UTC (permalink / raw)
  To: Tyler Retzlaff, dev; +Cc: thomas, david.marchand, olivier.matz, stephen

> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Wednesday, 14 December 2022 17.47
> 
> Use the new internal rte_thread_set_name API instead of the now
> deprecated rte_thread_setname API.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>


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

* Re: [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (3 preceding siblings ...)
  2022-12-14 16:47   ` [PATCH v2 4/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-10 20:53   ` Tyler Retzlaff
  2023-01-11  7:55     ` Morten Brørup
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-10 20:53 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, olivier.matz, stephen, mb

anymore feedback here folks?

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

thanks!

On Wed, Dec 14, 2022 at 08:47:17AM -0800, Tyler Retzlaff wrote:
> 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(-)
> 
> -- 
> 1.8.3.1

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

* RE: [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t
  2023-01-10 20:53   ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-11  7:55     ` Morten Brørup
  0 siblings, 0 replies; 91+ messages in thread
From: Morten Brørup @ 2023-01-11  7:55 UTC (permalink / raw)
  To: Tyler Retzlaff, dev; +Cc: thomas, david.marchand, olivier.matz, stephen

> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> 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!
> 
> On Wed, Dec 14, 2022 at 08:47:17AM -0800, Tyler Retzlaff wrote:
> > 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>


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

* Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2022-12-14 16:47   ` [PATCH v2 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-11 16:09     ` David Marchand
  2023-01-12 21:32       ` Tyler Retzlaff
  2023-01-13  4:36       ` Jerin Jacob
  0 siblings, 2 replies; 91+ messages in thread
From: David Marchand @ 2023-01-11 16:09 UTC (permalink / raw)
  To: Tyler Retzlaff, Jerin Jacob Kollanukkaran, Sunil Kumar Kori
  Cc: dev, thomas, olivier.matz, stephen, mb

On Wed, Dec 14, 2022 at 5:47 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
> diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> index 5caaac8..89522dc 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -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?


-- 
David Marchand


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

* Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2023-01-11 16:09     ` David Marchand
@ 2023-01-12 21:32       ` Tyler Retzlaff
  2023-01-13  4:36       ` Jerin Jacob
  1 sibling, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:32 UTC (permalink / raw)
  To: David Marchand
  Cc: Jerin Jacob Kollanukkaran, Sunil Kumar Kori, dev, thomas,
	olivier.matz, stephen, mb

On Wed, Jan 11, 2023 at 05:09:25PM +0100, David Marchand wrote:
> On Wed, Dec 14, 2022 at 5:47 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> > diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> > index 5caaac8..89522dc 100644
> > --- a/lib/eal/common/eal_common_trace.c
> > +++ b/lib/eal/common/eal_common_trace.c
> > @@ -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.

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.

> 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?
> 
> 
> -- 
> David Marchand

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

* [PATCH v3 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (5 preceding siblings ...)
  2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-12 21:55 ` Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (3 more replies)
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                   ` (6 subsequent siblings)
  13 siblings, 4 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:55 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, 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(-)

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

* [PATCH v3 1/4] eal: add thread set name API operating on rte thread
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
@ 2023-01-12 21:55   ` Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:55 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index c5d8b43..a44023c 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 607684c..2a6415e 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 8c118d0..f7a4a10 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..c26659d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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


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

* [PATCH v3 2/4] eal: remove thread getname API
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-12 21:55   ` Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:55 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..89522dc 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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++;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v3 3/4] drivers: mlx5 use rte thread set name
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-12 21:55   ` Tyler Retzlaff
  2023-01-12 21:55   ` [PATCH v3 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:55 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* [PATCH v3 4/4] eal: deprecate rte thread setname API
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-12 21:55   ` [PATCH v3 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-12 21:55   ` Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-12 21:55 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..2990bb1 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 9c78650..2fb3091 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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);
 
 /**
-- 
1.8.3.1


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

* Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2023-01-11 16:09     ` David Marchand
  2023-01-12 21:32       ` Tyler Retzlaff
@ 2023-01-13  4:36       ` Jerin Jacob
  2023-01-13 17:09         ` Tyler Retzlaff
  1 sibling, 1 reply; 91+ messages in thread
From: Jerin Jacob @ 2023-01-13  4:36 UTC (permalink / raw)
  To: David Marchand
  Cc: Tyler Retzlaff, Jerin Jacob Kollanukkaran, Sunil Kumar Kori, dev,
	thomas, olivier.matz, stephen, mb

On Wed, Jan 11, 2023 at 9:39 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> On Wed, Dec 14, 2022 at 5:47 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> > diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> > index 5caaac8..89522dc 100644
> > --- a/lib/eal/common/eal_common_trace.c
> > +++ b/lib/eal/common/eal_common_trace.c
> > @@ -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?


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.

>
>
> --
> David Marchand
>

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

* Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2023-01-13  4:36       ` Jerin Jacob
@ 2023-01-13 17:09         ` Tyler Retzlaff
  2023-01-13 18:56           ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 17:09 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: David Marchand, Jerin Jacob Kollanukkaran, Sunil Kumar Kori, dev,
	thomas, olivier.matz, stephen, mb

On Fri, Jan 13, 2023 at 10:06:44AM +0530, Jerin Jacob wrote:
> On Wed, Jan 11, 2023 at 9:39 PM David Marchand
> <david.marchand@redhat.com> wrote:
> >
> > On Wed, Dec 14, 2022 at 5:47 PM Tyler Retzlaff
> > <roretzla@linux.microsoft.com> wrote:
> > > diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> > > index 5caaac8..89522dc 100644
> > > --- a/lib/eal/common/eal_common_trace.c
> > > +++ b/lib/eal/common/eal_common_trace.c
> > > @@ -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?
> 
> 
> 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?

> 
> >
> >
> > --
> > David Marchand
> >

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

* [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (6 preceding siblings ...)
  2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
@ 2023-01-13 18:51 ` Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (3 more replies)
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                   ` (5 subsequent siblings)
  13 siblings, 4 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:51 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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(-)

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

-- 
1.8.3.1


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

* [PATCH v4 1/4] eal: add thread set name API operating on rte thread
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-13 18:52   ` Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:52 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index c5d8b43..a44023c 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 607684c..2a6415e 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 8c118d0..f7a4a10 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..c26659d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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


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

* [PATCH v4 2/4] eal: remove thread getname API
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-13 18:52   ` Tyler Retzlaff
  2023-01-17  7:49     ` Jerin Jacob
  2023-01-13 18:52   ` [PATCH v4 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:52 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..808f9c3 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v4 3/4] drivers: mlx5 use rte thread set name
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-13 18:52   ` Tyler Retzlaff
  2023-01-13 18:52   ` [PATCH v4 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:52 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* [PATCH v4 4/4] eal: deprecate rte thread setname API
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-13 18:52   ` [PATCH v4 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-13 18:52   ` Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:52 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..2990bb1 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 9c78650..2fb3091 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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);
 
 /**
-- 
1.8.3.1


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

* Re: [PATCH v2 1/4] eal: add thread set name API operating on rte thread
  2023-01-13 17:09         ` Tyler Retzlaff
@ 2023-01-13 18:56           ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-13 18:56 UTC (permalink / raw)
  To: Jerin Jacob, david.marchand
  Cc: Jerin Jacob Kollanukkaran, Sunil Kumar Kori, dev, thomas,
	olivier.matz, stephen, mb

On Fri, Jan 13, 2023 at 09:09:21AM -0800, Tyler Retzlaff wrote:
> On Fri, Jan 13, 2023 at 10:06:44AM +0530, Jerin Jacob wrote:
> > On Wed, Jan 11, 2023 at 9:39 PM David Marchand
> > <david.marchand@redhat.com> wrote:
> > >
> > > On Wed, Dec 14, 2022 at 5:47 PM Tyler Retzlaff
> > > <roretzla@linux.microsoft.com> wrote:
> > > > diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> > > > index 5caaac8..89522dc 100644
> > > > --- a/lib/eal/common/eal_common_trace.c
> > > > +++ b/lib/eal/common/eal_common_trace.c
> > > > @@ -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?
> > 
> > 
> > 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?

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!

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

* Re: [PATCH v4 2/4] eal: remove thread getname API
  2023-01-13 18:52   ` [PATCH v4 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-17  7:49     ` Jerin Jacob
  2023-01-17 18:22       ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Jerin Jacob @ 2023-01-17  7:49 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, david.marchand, mb

On Sat, Jan 14, 2023 at 12:22 AM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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)
>  {
> @@ -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?

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

* [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (7 preceding siblings ...)
  2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-17 18:21 ` Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (3 more replies)
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                   ` (4 subsequent siblings)
  13 siblings, 4 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:21 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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(-)

-- 
1.8.3.1


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

* [PATCH v5 1/4] eal: add thread set name API operating on rte thread
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-17 18:21   ` Tyler Retzlaff
  2023-01-18 14:50     ` David Marchand
  2023-01-17 18:21   ` [PATCH v5 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:21 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index c5d8b43..a44023c 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 607684c..2a6415e 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 8c118d0..f7a4a10 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..c26659d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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


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

* [PATCH v5 2/4] eal: remove thread getname API
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-17 18:21   ` Tyler Retzlaff
  2023-01-18  6:28     ` Jerin Jacob
  2023-01-18 14:51     ` David Marchand
  2023-01-17 18:21   ` [PATCH v5 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 2 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:21 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v5 3/4] drivers: mlx5 use rte thread set name
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-17 18:21   ` Tyler Retzlaff
  2023-01-17 18:21   ` [PATCH v5 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:21 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* [PATCH v5 4/4] eal: deprecate rte thread setname API
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-17 18:21   ` [PATCH v5 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-17 18:21   ` Tyler Retzlaff
  2023-01-18 11:49     ` David Marchand
  3 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:21 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, mb, jerinjacobk, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 lib/eal/include/rte_lcore.h          | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..2990bb1 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 9c78650..2fb3091 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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);
 
 /**
-- 
1.8.3.1


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

* Re: [PATCH v4 2/4] eal: remove thread getname API
  2023-01-17  7:49     ` Jerin Jacob
@ 2023-01-17 18:22       ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-17 18:22 UTC (permalink / raw)
  To: Jerin Jacob; +Cc: dev, thomas, david.marchand, mb

On Tue, Jan 17, 2023 at 01:19:25PM +0530, Jerin Jacob wrote:
> On Sat, Jan 14, 2023 at 12:22 AM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> >
> > 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)
> >  {
> > @@ -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

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

* Re: [PATCH v5 2/4] eal: remove thread getname API
  2023-01-17 18:21   ` [PATCH v5 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-18  6:28     ` Jerin Jacob
  2023-01-18 14:51     ` David Marchand
  1 sibling, 0 replies; 91+ messages in thread
From: Jerin Jacob @ 2023-01-18  6:28 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, david.marchand, mb

On Tue, Jan 17, 2023 at 11:51 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Trace changes are looks good to me.
For trace, Acked-by: Jerin Jacob <jerinj@marvell.com>


> ---
>  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(-)
>
> diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> index 5caaac8..75162b7 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -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;
> diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
> index b69f5d3..3227d9b 100644
> --- a/lib/eal/freebsd/eal_thread.c
> +++ b/lib/eal/freebsd/eal_thread.c
> @@ -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;
> -}
> diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
> index 6938c3f..9c78650 100644
> --- a/lib/eal/include/rte_lcore.h
> +++ b/lib/eal/include/rte_lcore.h
> @@ -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:
> diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
> index d5fddab..c07ad9d 100644
> --- a/lib/eal/linux/eal_thread.c
> +++ b/lib/eal/linux/eal_thread.c
> @@ -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;
> -
> -}
> diff --git a/lib/eal/version.map b/lib/eal/version.map
> index c98ba71..6523102 100644
> --- a/lib/eal/version.map
> +++ b/lib/eal/version.map
> @@ -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
>

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

* Re: [PATCH v5 4/4] eal: deprecate rte thread setname API
  2023-01-17 18:21   ` [PATCH v5 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
@ 2023-01-18 11:49     ` David Marchand
  0 siblings, 0 replies; 91+ messages in thread
From: David Marchand @ 2023-01-18 11:49 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, mb, jerinjacobk, techboard

On Tue, Jan 17, 2023 at 7:21 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

I counted one ack from Morten.
With mine (for the notice part, see comment below), that makes two.
Acked-by: David Marchand <david.marchand@redhat.com>

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


> ---
>  doc/guides/rel_notes/deprecation.rst | 4 ++++
>  lib/eal/include/rte_lcore.h          | 2 ++
>  2 files changed, 6 insertions(+)
>
> diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
> index e18ac34..2990bb1 100644
> --- a/doc/guides/rel_notes/deprecation.rst
> +++ b/doc/guides/rel_notes/deprecation.rst
> @@ -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.
> diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
> index 9c78650..2fb3091 100644
> --- a/lib/eal/include/rte_lcore.h
> +++ b/lib/eal/include/rte_lcore.h
> @@ -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);

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.


-- 
David Marchand


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

* Re: [PATCH v5 1/4] eal: add thread set name API operating on rte thread
  2023-01-17 18:21   ` [PATCH v5 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-18 14:50     ` David Marchand
  0 siblings, 0 replies; 91+ messages in thread
From: David Marchand @ 2023-01-18 14:50 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, mb, jerinjacobk

On Tue, Jan 17, 2023 at 7:21 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>
> Series-acked-by: Morten Brørup <mb@smartsharesystems.com>
>
>  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.


> diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
> index 1c1e9d0..c26659d 100644
> --- a/lib/eal/windows/rte_thread.c
> +++ b/lib/eal/windows/rte_thread.c
> @@ -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
>


-- 
David Marchand


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

* Re: [PATCH v5 2/4] eal: remove thread getname API
  2023-01-17 18:21   ` [PATCH v5 2/4] eal: remove thread getname API Tyler Retzlaff
  2023-01-18  6:28     ` Jerin Jacob
@ 2023-01-18 14:51     ` David Marchand
  1 sibling, 0 replies; 91+ messages in thread
From: David Marchand @ 2023-01-18 14:51 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, mb, jerinjacobk

On Tue, Jan 17, 2023 at 7:22 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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.

This comment is not relevant anymore.

>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>


-- 
David Marchand


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

* [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (8 preceding siblings ...)
  2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-18 19:54 ` Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (5 more replies)
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
                   ` (3 subsequent siblings)
  13 siblings, 6 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

-- 
1.8.3.1


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

* [PATCH v6 1/5] eal: add thread set name API operating on rte thread
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-18 19:54   ` Tyler Retzlaff
  2023-01-18 23:13     ` Stephen Hemminger
  2023-01-18 19:54   ` [PATCH v6 2/5] eal: remove thread getname API Tyler Retzlaff
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 38d83a6..3181515 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 8db5007..9303401 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60298c0..d4c3507 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..c26659d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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


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

* [PATCH v6 2/5] eal: remove thread getname API
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-18 19:54   ` Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Jerin Jacob <jerinj@marvell.com>

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

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v6 3/5] eal: set thread name on Windows worker threads
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 2/5] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-18 19:54   ` Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

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

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index b9f95ed..e561f87 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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)
-- 
1.8.3.1


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

* [PATCH v6 4/5] drivers: mlx5 use rte thread set name
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-18 19:54   ` [PATCH v6 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-18 19:54   ` Tyler Retzlaff
  2023-01-18 19:54   ` [PATCH v6 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  2023-01-22 13:55   ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t David Marchand
  5 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* [PATCH v6 5/5] eal: deprecation notice for rte thread setname API
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (3 preceding siblings ...)
  2023-01-18 19:54   ` [PATCH v6 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-18 19:54   ` Tyler Retzlaff
  2023-01-22 13:55   ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t David Marchand
  5 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 19:54 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: David Marchand <david.marchand@redhat.com>
Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..2990bb1 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
-- 
1.8.3.1


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

* Re: [PATCH v6 1/5] eal: add thread set name API operating on rte thread
  2023-01-18 19:54   ` [PATCH v6 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-18 23:13     ` Stephen Hemminger
  2023-01-18 23:44       ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Stephen Hemminger @ 2023-01-18 23:13 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, david.marchand, jerinjacobk, mb

On Wed, 18 Jan 2023 11:54:02 -0800
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> +	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?

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

* Re: [PATCH v6 1/5] eal: add thread set name API operating on rte thread
  2023-01-18 23:13     ` Stephen Hemminger
@ 2023-01-18 23:44       ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-18 23:44 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, thomas, david.marchand, jerinjacobk, mb

On Wed, Jan 18, 2023 at 03:13:12PM -0800, Stephen Hemminger wrote:
> On Wed, 18 Jan 2023 11:54:02 -0800
> Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> 
> > +	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.

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

* Re: [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (4 preceding siblings ...)
  2023-01-18 19:54   ` [PATCH v6 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
@ 2023-01-22 13:55   ` David Marchand
  2023-01-23 18:57     ` Tyler Retzlaff
  5 siblings, 1 reply; 91+ messages in thread
From: David Marchand @ 2023-01-22 13:55 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, jerinjacobk, mb

On Wed, Jan 18, 2023 at 8:54 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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

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.


-- 
David Marchand


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

* Re: [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t
  2023-01-22 13:55   ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t David Marchand
@ 2023-01-23 18:57     ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 18:57 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, thomas, jerinjacobk, mb

On Sun, Jan 22, 2023 at 02:55:18PM +0100, David Marchand wrote:
> On Wed, Jan 18, 2023 at 8:54 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> >
> > 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
> 
> 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?

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.

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

* [PATCH v7 0/5] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (9 preceding siblings ...)
  2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-23 19:39 ` Tyler Retzlaff
  2023-01-23 19:39   ` [PATCH v7 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (4 more replies)
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                   ` (2 subsequent siblings)
  13 siblings, 5 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

-- 
1.8.3.1


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

* [PATCH v7 1/5] eal: add thread set name API operating on rte thread
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
@ 2023-01-23 19:39   ` Tyler Retzlaff
  2023-01-24 15:21     ` Thomas Monjalon
  2023-01-23 19:39   ` [PATCH v7 2/5] eal: remove thread getname API Tyler Retzlaff
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Morten Brørup <mb@smartsharesystems.com>

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

diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 38d83a6..3181515 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 8db5007..9303401 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..8a63a52 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60298c0..d4c3507 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..8556a84 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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,47 @@ 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;
+	}
+
+#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


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

* [PATCH v7 2/5] eal: remove thread getname API
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
  2023-01-23 19:39   ` [PATCH v7 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-23 19:39   ` Tyler Retzlaff
  2023-01-24 15:24     ` Thomas Monjalon
  2023-01-23 19:39   ` [PATCH v7 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>


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

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v7 3/5] eal: set thread name on Windows worker threads
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
  2023-01-23 19:39   ` [PATCH v7 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-23 19:39   ` [PATCH v7 2/5] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-23 19:39   ` Tyler Retzlaff
  2023-01-24 15:25     ` Thomas Monjalon
  2023-01-23 19:39   ` [PATCH v7 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
  2023-01-23 19:39   ` [PATCH v7 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Morten Brørup <mb@smartsharesystems.com>

---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index b9f95ed..e561f87 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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)
-- 
1.8.3.1


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

* [PATCH v7 4/5] drivers: mlx5 use rte thread set name
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-23 19:39   ` [PATCH v7 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-23 19:39   ` Tyler Retzlaff
  2023-01-24 15:50     ` Thomas Monjalon
  2023-01-23 19:39   ` [PATCH v7 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, Tyler Retzlaff

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

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Morten Brørup <mb@smartsharesystems.com>

---
 drivers/net/mlx5/mlx5_hws_cnt.c     | 3 ++-
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
-- 
1.8.3.1


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

* [PATCH v7 5/5] eal: deprecation notice for rte thread setname API
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
                     ` (3 preceding siblings ...)
  2023-01-23 19:39   ` [PATCH v7 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-23 19:39   ` Tyler Retzlaff
  2023-01-24 16:03     ` Thomas Monjalon
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-23 19:39 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: David Marchand <david.marchand@redhat.com>

---
 doc/guides/rel_notes/deprecation.rst | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..2990bb1 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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.
-- 
1.8.3.1


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

* Re: [PATCH v7 1/5] eal: add thread set name API operating on rte thread
  2023-01-23 19:39   ` [PATCH v7 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-24 15:21     ` Thomas Monjalon
  0 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 15:21 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

23/01/2023 20:39, 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.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> 
> ---
>  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(-)
> 
> diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
> index 38d83a6..3181515 100644
> --- a/lib/eal/common/eal_common_thread.c
> +++ b/lib/eal/common/eal_common_thread.c
> @@ -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 =
> diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
> index 8db5007..9303401 100644
> --- a/lib/eal/freebsd/eal.c
> +++ b/lib/eal/freebsd/eal.c
> @@ -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);
> diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
> index ab81b52..b69f5d3 100644
> --- a/lib/eal/freebsd/eal_thread.c
> +++ b/lib/eal/freebsd/eal_thread.c
> @@ -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 */
> diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
> index b9edf70..8a63a52 100644
> --- a/lib/eal/include/rte_thread.h
> +++ b/lib/eal/include/rte_thread.h
> @@ -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.

> + *
> + * @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);

[...]
> --- a/lib/eal/linux/eal_thread.c
> +++ b/lib/eal/linux/eal_thread.c
> +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");
> +}

It is very close to rte_thread_setname with few differences. OK


> --- a/lib/eal/windows/rte_thread.c
> +++ b/lib/eal/windows/rte_thread.c
> +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;
> +	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.



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

* Re: [PATCH v7 2/5] eal: remove thread getname API
  2023-01-23 19:39   ` [PATCH v7 2/5] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-24 15:24     ` Thomas Monjalon
  2023-01-24 15:33       ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 15:24 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

23/01/2023 20:39, Tyler Retzlaff:
> 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).

> 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.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: Jerin Jacob <jerinj@marvell.com>

Note: no space before acks.



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

* Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads
  2023-01-23 19:39   ` [PATCH v7 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-24 15:25     ` Thomas Monjalon
  2023-01-24 15:33       ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 15:25 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

23/01/2023 20:39, 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.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> 
> ---
>  lib/eal/windows/eal.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
> index b9f95ed..e561f87 100644
> --- a/lib/eal/windows/eal.c
> +++ b/lib/eal/windows/eal.c
> @@ -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. */

No need of underscore in "thread name".

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



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

* Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads
  2023-01-24 15:25     ` Thomas Monjalon
@ 2023-01-24 15:33       ` Tyler Retzlaff
  2023-01-24 15:47         ` Thomas Monjalon
  0 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 15:33 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand, jerinjacobk, mb

On Tue, Jan 24, 2023 at 04:25:34PM +0100, Thomas Monjalon wrote:
> 23/01/2023 20:39, 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.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > 
> > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > 
> > ---
> >  lib/eal/windows/eal.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
> > index b9f95ed..e561f87 100644
> > --- a/lib/eal/windows/eal.c
> > +++ b/lib/eal/windows/eal.c
> > @@ -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. */
> 
> 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.

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


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

* Re: [PATCH v7 2/5] eal: remove thread getname API
  2023-01-24 15:24     ` Thomas Monjalon
@ 2023-01-24 15:33       ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 15:33 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand, jerinjacobk, mb

On Tue, Jan 24, 2023 at 04:24:04PM +0100, Thomas Monjalon wrote:
> 23/01/2023 20:39, Tyler Retzlaff:
> > 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).
> 
> > 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.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > 
> > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > Acked-by: Jerin Jacob <jerinj@marvell.com>
> 
> Note: no space before acks.
> 

noted, will make the adjustment in the future.

thanks for letting me know.

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

* Re: [PATCH v7 3/5] eal: set thread name on Windows worker threads
  2023-01-24 15:33       ` Tyler Retzlaff
@ 2023-01-24 15:47         ` Thomas Monjalon
  0 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 15:47 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

24/01/2023 16:33, Tyler Retzlaff:
> On Tue, Jan 24, 2023 at 04:25:34PM +0100, Thomas Monjalon wrote:
> > 23/01/2023 20:39, 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.
> > > 
> > > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > > 
> > > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > > 
> > > ---
> > >  lib/eal/windows/eal.c | 7 +++++++
> > >  1 file changed, 7 insertions(+)
> > > 
> > > diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
> > > index b9f95ed..e561f87 100644
> > > --- a/lib/eal/windows/eal.c
> > > +++ b/lib/eal/windows/eal.c
> > > @@ -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. */
> > 
> > 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.

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.



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

* Re: [PATCH v7 4/5] drivers: mlx5 use rte thread set name
  2023-01-23 19:39   ` [PATCH v7 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
@ 2023-01-24 15:50     ` Thomas Monjalon
  0 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 15:50 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

23/01/2023 20:39, Tyler Retzlaff:
> 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.




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

* Re: [PATCH v7 5/5] eal: deprecation notice for rte thread setname API
  2023-01-23 19:39   ` [PATCH v7 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
@ 2023-01-24 16:03     ` Thomas Monjalon
  0 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 16:03 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

23/01/2023 20:39, 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.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: David Marchand <david.marchand@redhat.com>
> 
> ---
>  doc/guides/rel_notes/deprecation.rst | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
> index e18ac34..2990bb1 100644
> --- a/doc/guides/rel_notes/deprecation.rst
> +++ b/doc/guides/rel_notes/deprecation.rst
> @@ -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.



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

* [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (10 preceding siblings ...)
  2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
@ 2023-01-24 17:42 ` Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (3 more replies)
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  13 siblings, 4 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 17:42 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

-- 
1.8.3.1


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

* [PATCH v8 1/4] eal: add thread set name API operating on rte thread
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-24 17:42   ` Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 17:42 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 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(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 38d83a6..3181515 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 8db5007..9303401 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..d247930 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60298c0..d4c3507 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..8556a84 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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,47 @@ 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;
+	}
+
+#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


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

* [PATCH v8 2/4] eal: remove thread getname API
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-24 17:42   ` Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 17:42 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v8 3/4] eal: set thread name on Windows worker threads
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-24 17:42   ` Tyler Retzlaff
  2023-01-24 17:42   ` [PATCH v8 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 17:42 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index b9f95ed..e7d405b 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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)
-- 
1.8.3.1


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

* [PATCH v8 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-24 17:42   ` [PATCH v8 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-24 17:42   ` Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 17:42 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..112219f 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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
-- 
1.8.3.1


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

* [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (11 preceding siblings ...)
  2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-24 18:02 ` Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (3 more replies)
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  13 siblings, 4 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:02 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

-- 
1.8.3.1


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

* [PATCH v9 1/4] eal: add thread set name API operating on rte thread
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-24 18:02   ` Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:02 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 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(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 38d83a6..3181515 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 8db5007..9303401 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..d247930 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60298c0..d4c3507 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..8556a84 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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,47 @@ 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;
+	}
+
+#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


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

* [PATCH v9 2/4] eal: remove thread getname API
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-24 18:02   ` Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:02 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v9 3/4] eal: set thread name on Windows worker threads
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-24 18:02   ` Tyler Retzlaff
  2023-01-24 18:02   ` [PATCH v9 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  3 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:02 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index b9f95ed..e7d405b 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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)
-- 
1.8.3.1


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

* [PATCH v9 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-24 18:02   ` [PATCH v9 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-24 18:02   ` Tyler Retzlaff
  2023-01-24 18:05     ` Thomas Monjalon
  3 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:02 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..5eb930f 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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
-- 
1.8.3.1


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

* Re: [PATCH v9 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 18:02   ` [PATCH v9 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
@ 2023-01-24 18:05     ` Thomas Monjalon
  2023-01-24 18:21       ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-24 18:05 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

24/01/2023 19:02, Tyler Retzlaff:
> +* 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.



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

* [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t
  2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
                   ` (12 preceding siblings ...)
  2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-24 18:12 ` Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
                     ` (4 more replies)
  13 siblings, 5 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:12 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>

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

-- 
1.8.3.1


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

* [PATCH v10 1/4] eal: add thread set name API operating on rte thread
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
@ 2023-01-24 18:12   ` Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 2/4] eal: remove thread getname API Tyler Retzlaff
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:12 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 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(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 51704ef..05cc954 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -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);
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 4d81976..f3d392c 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -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);
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 38d83a6..3181515 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -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 =
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 8db5007..9303401 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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);
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index ab81b52..b69f5d3 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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 */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index b9edf70..d247930 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -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
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60298c0..d4c3507 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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);
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 625bde6..d5fddab 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 7ad12a7..c98ba71 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -440,6 +440,9 @@ EXPERIMENTAL {
 	rte_thread_detach;
 	rte_thread_equal;
 	rte_thread_join;
+
+	# added in 23.03
+	rte_thread_set_name;
 };
 
 INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 1c1e9d0..8556a84 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -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,47 @@ 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;
+	}
+
+#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


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

* [PATCH v10 2/4] eal: remove thread getname API
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
@ 2023-01-24 18:12   ` Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:12 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 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(-)

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 5caaac8..75162b7 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -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;
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index b69f5d3..3227d9b 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -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;
-}
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 6938c3f..9c78650 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -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:
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index d5fddab..c07ad9d 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -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;
-
-}
diff --git a/lib/eal/version.map b/lib/eal/version.map
index c98ba71..6523102 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -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


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

* [PATCH v10 3/4] eal: set thread name on Windows worker threads
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 2/4] eal: remove thread getname API Tyler Retzlaff
@ 2023-01-24 18:12   ` Tyler Retzlaff
  2023-01-24 18:12   ` [PATCH v10 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
  2023-01-31  9:54   ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t David Marchand
  4 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:12 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/eal/windows/eal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index b9f95ed..e7d405b 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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)
-- 
1.8.3.1


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

* [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (2 preceding siblings ...)
  2023-01-24 18:12   ` [PATCH v10 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
@ 2023-01-24 18:12   ` Tyler Retzlaff
  2023-01-30 15:46     ` Thomas Monjalon
  2023-01-31  9:54   ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t David Marchand
  4 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:12 UTC (permalink / raw)
  To: dev; +Cc: thomas, david.marchand, jerinjacobk, mb, 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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/rel_notes/deprecation.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index e18ac34..bae7441 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -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
-- 
1.8.3.1


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

* Re: [PATCH v9 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 18:05     ` Thomas Monjalon
@ 2023-01-24 18:21       ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-24 18:21 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand, jerinjacobk, mb

On Tue, Jan 24, 2023 at 07:05:18PM +0100, Thomas Monjalon wrote:
> 24/01/2023 19:02, Tyler Retzlaff:
> > +* 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

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

* Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-24 18:12   ` [PATCH v10 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
@ 2023-01-30 15:46     ` Thomas Monjalon
  2023-01-30 16:19       ` David Marchand
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2023-01-30 15:46 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, david.marchand, jerinjacobk, mb

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:
> 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.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: David Marchand <david.marchand@redhat.com>
> ---
> +* 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,
Acked-by: Thomas Monjalon <thomas@monjalon.net>



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

* Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-30 15:46     ` Thomas Monjalon
@ 2023-01-30 16:19       ` David Marchand
  2023-01-30 20:34         ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: David Marchand @ 2023-01-30 16:19 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: Tyler Retzlaff, dev, jerinjacobk, mb

On Mon, Jan 30, 2023 at 4:47 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 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.

> 24/01/2023 19:12, 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.
> >
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > Acked-by: David Marchand <david.marchand@redhat.com>
> > ---
> > +* 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".

And this too.

>
>
> For the series,
> Acked-by: Thomas Monjalon <thomas@monjalon.net>

Thanks.


-- 
David Marchand


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

* Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-30 16:19       ` David Marchand
@ 2023-01-30 20:34         ` Tyler Retzlaff
  2023-01-31  9:53           ` David Marchand
  0 siblings, 1 reply; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-30 20:34 UTC (permalink / raw)
  To: David Marchand; +Cc: Thomas Monjalon, dev, jerinjacobk, mb

On Mon, Jan 30, 2023 at 05:19:20PM +0100, David Marchand wrote:
> On Mon, Jan 30, 2023 at 4:47 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > 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.
> 
> > 24/01/2023 19:12, 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.
> > >
> > > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > > Acked-by: David Marchand <david.marchand@redhat.com>
> > > ---
> > > +* 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".
> 
> And this too.
> 
> >
> >
> > For the series,
> > Acked-by: Thomas Monjalon <thomas@monjalon.net>
> 
> Thanks.

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

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

* Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-30 20:34         ` Tyler Retzlaff
@ 2023-01-31  9:53           ` David Marchand
  2023-01-31 17:09             ` Tyler Retzlaff
  0 siblings, 1 reply; 91+ messages in thread
From: David Marchand @ 2023-01-31  9:53 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: Thomas Monjalon, dev, jerinjacobk, mb

On Mon, Jan 30, 2023 at 9:35 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
> 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.


-- 
David Marchand


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

* Re: [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t
  2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
                     ` (3 preceding siblings ...)
  2023-01-24 18:12   ` [PATCH v10 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
@ 2023-01-31  9:54   ` David Marchand
  4 siblings, 0 replies; 91+ messages in thread
From: David Marchand @ 2023-01-31  9:54 UTC (permalink / raw)
  To: Tyler Retzlaff; +Cc: dev, thomas, jerinjacobk, mb

On Tue, Jan 24, 2023 at 7:12 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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

Series applied, thanks Tyler.


-- 
David Marchand


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

* Re: [PATCH v10 4/4] eal: deprecation notice for rte thread setname API
  2023-01-31  9:53           ` David Marchand
@ 2023-01-31 17:09             ` Tyler Retzlaff
  0 siblings, 0 replies; 91+ messages in thread
From: Tyler Retzlaff @ 2023-01-31 17:09 UTC (permalink / raw)
  To: David Marchand; +Cc: Thomas Monjalon, dev, jerinjacobk, mb

On Tue, Jan 31, 2023 at 10:53:17AM +0100, David Marchand wrote:
> On Mon, Jan 30, 2023 at 9:35 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> > 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.

> 
> Thanks.
> 
> 
> -- 
> David Marchand

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

end of thread, other threads:[~2023-01-31 17:09 UTC | newest]

Thread overview: 91+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 19:00 [PATCH 0/5] add lcore set name and get name API Tyler Retzlaff
2022-12-07 19:00 ` [PATCH 1/5] eal: " Tyler Retzlaff
2022-12-07 21:03   ` Stephen Hemminger
2022-12-07 22:33     ` Tyler Retzlaff
2022-12-08  4:07       ` Stephen Hemminger
2022-12-08 17:11         ` Tyler Retzlaff
2022-12-07 19:00 ` [PATCH 2/5] eal: set lcore config thread for lcore main Tyler Retzlaff
2022-12-07 19:00 ` [PATCH 3/5] test: add a unit test for set and get lcore name APIs Tyler Retzlaff
2022-12-07 19:00 ` [PATCH 4/5] eal: remove thread getname API Tyler Retzlaff
2022-12-07 19:00 ` [PATCH 5/5] eal: deprecate rte thread setname API Tyler Retzlaff
2022-12-14 16:47 ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2022-12-14 16:47   ` [PATCH v2 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-11 16:09     ` David Marchand
2023-01-12 21:32       ` Tyler Retzlaff
2023-01-13  4:36       ` Jerin Jacob
2023-01-13 17:09         ` Tyler Retzlaff
2023-01-13 18:56           ` Tyler Retzlaff
2022-12-14 16:47   ` [PATCH v2 2/4] eal: remove thread getname API Tyler Retzlaff
2022-12-14 16:47   ` [PATCH v2 3/4] eal: deprecate rte thread setname API Tyler Retzlaff
2022-12-14 16:47   ` [PATCH v2 4/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
2022-12-14 16:51     ` Morten Brørup
2023-01-10 20:53   ` [PATCH v2 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-11  7:55     ` Morten Brørup
2023-01-12 21:55 ` [PATCH v3 " Tyler Retzlaff
2023-01-12 21:55   ` [PATCH v3 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-12 21:55   ` [PATCH v3 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-12 21:55   ` [PATCH v3 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
2023-01-12 21:55   ` [PATCH v3 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
2023-01-13 18:51 ` [PATCH v4 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-13 18:52   ` [PATCH v4 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-13 18:52   ` [PATCH v4 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-17  7:49     ` Jerin Jacob
2023-01-17 18:22       ` Tyler Retzlaff
2023-01-13 18:52   ` [PATCH v4 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
2023-01-13 18:52   ` [PATCH v4 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
2023-01-17 18:21 ` [PATCH v5 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-17 18:21   ` [PATCH v5 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-18 14:50     ` David Marchand
2023-01-17 18:21   ` [PATCH v5 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-18  6:28     ` Jerin Jacob
2023-01-18 14:51     ` David Marchand
2023-01-17 18:21   ` [PATCH v5 3/4] drivers: mlx5 use rte thread set name Tyler Retzlaff
2023-01-17 18:21   ` [PATCH v5 4/4] eal: deprecate rte thread setname API Tyler Retzlaff
2023-01-18 11:49     ` David Marchand
2023-01-18 19:54 ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-18 19:54   ` [PATCH v6 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-18 23:13     ` Stephen Hemminger
2023-01-18 23:44       ` Tyler Retzlaff
2023-01-18 19:54   ` [PATCH v6 2/5] eal: remove thread getname API Tyler Retzlaff
2023-01-18 19:54   ` [PATCH v6 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
2023-01-18 19:54   ` [PATCH v6 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
2023-01-18 19:54   ` [PATCH v6 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
2023-01-22 13:55   ` [PATCH v6 0/5] add rte_thread_set_name API for rte_thread_t David Marchand
2023-01-23 18:57     ` Tyler Retzlaff
2023-01-23 19:39 ` [PATCH v7 " Tyler Retzlaff
2023-01-23 19:39   ` [PATCH v7 1/5] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-24 15:21     ` Thomas Monjalon
2023-01-23 19:39   ` [PATCH v7 2/5] eal: remove thread getname API Tyler Retzlaff
2023-01-24 15:24     ` Thomas Monjalon
2023-01-24 15:33       ` Tyler Retzlaff
2023-01-23 19:39   ` [PATCH v7 3/5] eal: set thread name on Windows worker threads Tyler Retzlaff
2023-01-24 15:25     ` Thomas Monjalon
2023-01-24 15:33       ` Tyler Retzlaff
2023-01-24 15:47         ` Thomas Monjalon
2023-01-23 19:39   ` [PATCH v7 4/5] drivers: mlx5 use rte thread set name Tyler Retzlaff
2023-01-24 15:50     ` Thomas Monjalon
2023-01-23 19:39   ` [PATCH v7 5/5] eal: deprecation notice for rte thread setname API Tyler Retzlaff
2023-01-24 16:03     ` Thomas Monjalon
2023-01-24 17:42 ` [PATCH v8 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-24 17:42   ` [PATCH v8 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-24 17:42   ` [PATCH v8 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-24 17:42   ` [PATCH v8 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
2023-01-24 17:42   ` [PATCH v8 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
2023-01-24 18:02 ` [PATCH v9 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-24 18:02   ` [PATCH v9 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-24 18:02   ` [PATCH v9 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-24 18:02   ` [PATCH v9 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
2023-01-24 18:02   ` [PATCH v9 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
2023-01-24 18:05     ` Thomas Monjalon
2023-01-24 18:21       ` Tyler Retzlaff
2023-01-24 18:12 ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t Tyler Retzlaff
2023-01-24 18:12   ` [PATCH v10 1/4] eal: add thread set name API operating on rte thread Tyler Retzlaff
2023-01-24 18:12   ` [PATCH v10 2/4] eal: remove thread getname API Tyler Retzlaff
2023-01-24 18:12   ` [PATCH v10 3/4] eal: set thread name on Windows worker threads Tyler Retzlaff
2023-01-24 18:12   ` [PATCH v10 4/4] eal: deprecation notice for rte thread setname API Tyler Retzlaff
2023-01-30 15:46     ` Thomas Monjalon
2023-01-30 16:19       ` David Marchand
2023-01-30 20:34         ` Tyler Retzlaff
2023-01-31  9:53           ` David Marchand
2023-01-31 17:09             ` Tyler Retzlaff
2023-01-31  9:54   ` [PATCH v10 0/4] add rte_thread_set_name API for rte_thread_t David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).