From 16ea979d71a3e1f33fecb5e8b1a6b0f9b736b743 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 17 Dec 2019 00:19:47 -0500 Subject: [PATCH] lib/event: Check if reactor scheduled thread to the correct core Add check if reactor scheduled the thread to one of the allowed cores correctly to _schedule_thread(). This check will be useful in the next patch and may be helpful when we schedule SPDK thread dynamically. Signed-off-by: Shuhei Matsumoto Change-Id: Ibea8e8315187ae8a3a421007d8865bbee2d7e037 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478156 Tested-by: SPDK CI Jenkins Community-CI: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/event/reactor.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 2e6161820..7820e9f67 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -473,9 +473,21 @@ static void _schedule_thread(void *arg1, void *arg2) { struct spdk_lw_thread *lw_thread = arg1; + struct spdk_thread *thread; + struct spdk_cpuset *cpumask; struct spdk_reactor *reactor; + uint32_t current_core; - reactor = spdk_reactor_get(spdk_env_get_current_core()); + current_core = spdk_env_get_current_core(); + + thread = spdk_thread_get_from_ctx(lw_thread); + cpumask = spdk_thread_get_cpumask(thread); + if (!spdk_cpuset_get_cpu(cpumask, current_core)) { + SPDK_ERRLOG("Thread was scheduled to the wrong core %d\n", current_core); + assert(false); + } + + reactor = spdk_reactor_get(current_core); assert(reactor != NULL); TAILQ_INSERT_TAIL(&reactor->threads, lw_thread, link);