diff --git a/lib/event/reactor.c b/lib/event/reactor.c index d2e51adf9..de4dff47a 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -43,6 +43,14 @@ #include "spdk/env.h" #include "spdk/util.h" +#ifdef __linux__ +#include +#endif + +#ifdef __FreeBSD__ +#include +#endif + #define SPDK_EVENT_BATCH_SIZE 8 enum spdk_reactor_state { @@ -219,6 +227,18 @@ spdk_reactor_context_switch_monitor_enabled(void) return g_context_switch_monitor_enabled; } +static void +_set_thread_name(const char *thread_name) +{ +#if defined(__linux__) + prctl(PR_SET_NAME, thread_name, 0, 0, 0); +#elif defined(__FreeBSD__) + pthread_set_name_np(pthread_self(), thread_name); +#else +#error missing platform support for thread name +#endif +} + static int _spdk_reactor_run(void *arg) { @@ -226,9 +246,16 @@ _spdk_reactor_run(void *arg) struct spdk_thread *thread; uint64_t last_rusage = 0; struct spdk_lw_thread *lw_thread, *tmp; + char thread_name[32]; SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore); + /* Rename the POSIX thread because the reactor is tied to the POSIX + * thread in the SPDK event library. + */ + snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore); + _set_thread_name(thread_name); + while (1) { uint64_t now; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 92bc086be..09d9cd88e 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -42,14 +42,6 @@ #include "spdk_internal/log.h" #include "spdk_internal/thread.h" -#ifdef __linux__ -#include -#endif - -#ifdef __FreeBSD__ -#include -#endif - #define SPDK_MSG_BATCH_SIZE 8 static pthread_mutex_t g_devlist_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -151,18 +143,6 @@ _get_thread(void) return tls_thread; } -static void -_set_thread_name(const char *thread_name) -{ -#if defined(__linux__) - prctl(PR_SET_NAME, thread_name, 0, 0, 0); -#elif defined(__FreeBSD__) - pthread_set_name_np(pthread_self(), thread_name); -#else -#error missing platform support for thread name -#endif -} - int spdk_thread_lib_init(spdk_new_thread_fn new_thread_fn, size_t ctx_sz) { @@ -254,7 +234,6 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask) } if (name) { - _set_thread_name(name); thread->name = strdup(name); } else { thread->name = spdk_sprintf_alloc("%p", thread);