From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, david.marchand@redhat.com,
olivier.matz@6wind.com, stephen@networkplumber.org,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH 1/5] eal: add lcore set name and get name API
Date: Wed, 7 Dec 2022 11:00:13 -0800 [thread overview]
Message-ID: <1670439617-9054-2-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1670439617-9054-1-git-send-email-roretzla@linux.microsoft.com>
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
next prev parent reply other threads:[~2022-12-07 19:00 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 19:00 [PATCH 0/5] " Tyler Retzlaff
2022-12-07 19:00 ` Tyler Retzlaff [this message]
2022-12-07 21:03 ` [PATCH 1/5] eal: " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1670439617-9054-2-git-send-email-roretzla@linux.microsoft.com \
--to=roretzla@linux.microsoft.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=olivier.matz@6wind.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).