Commit ee813409 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ib5d02b9d7b499477c43e6527cf8f603d8323e063
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/966


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 515733ca
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;
+18 −0
Original line number Diff line number Diff line
@@ -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)
{