From ee8134099afdbcb21aa13433e91837ae15b59afe Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 19 Feb 2020 21:10:04 -0500 Subject: [PATCH] lib/thread: Add spdk_thread_get_by_id() API to get thread whose ID matches Add an new API spdk_thread_get_by_id(). This will be used in the subsequent patches to set the cpumask of the running thread to the specified value. Signed-off-by: Shuhei Matsumoto Change-Id: Ib5d02b9d7b499477c43e6527cf8f603d8323e063 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/966 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris --- include/spdk/thread.h | 8 ++++++++ lib/thread/thread.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 90c96c31b..3f1e73006 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -372,6 +372,14 @@ const char *spdk_thread_get_name(const struct spdk_thread *thread); */ uint64_t spdk_thread_get_id(const struct spdk_thread *thread); +/** + * Get the thread by the ID. + * + * \param id ID of the thread. + * \return Thread whose ID matches or NULL otherwise. + */ +struct spdk_thread *spdk_thread_get_by_id(uint64_t id); + struct spdk_thread_stats { uint64_t busy_tsc; uint64_t idle_tsc; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 5db66b708..600ef75d9 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -735,6 +735,24 @@ spdk_thread_get_id(const struct spdk_thread *thread) return thread->id; } +struct spdk_thread * +spdk_thread_get_by_id(uint64_t id) +{ + struct spdk_thread *thread; + + pthread_mutex_lock(&g_devlist_mutex); + TAILQ_FOREACH(thread, &g_threads, tailq) { + if (thread->id == id) { + pthread_mutex_unlock(&g_devlist_mutex); + + return thread; + } + } + pthread_mutex_unlock(&g_devlist_mutex); + + return NULL; +} + int spdk_thread_get_stats(struct spdk_thread_stats *stats) {