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 <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ib5d02b9d7b499477c43e6527cf8f603d8323e063
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/966
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-02-19 21:10:04 -05:00 committed by Tomasz Zawadzki
parent 515733ca4a
commit ee8134099a
2 changed files with 26 additions and 0 deletions

View File

@ -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;

View File

@ -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)
{