From af1c51505d5b57ff623bb8b2b95ebabbd687c64d Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Mon, 25 Jan 2021 14:13:04 +0100 Subject: [PATCH] scheduler: Move busy thread if its mask do not match current lcore When using interrupt mode we can have a situation when we create thread (which is always busy) with a particular core mask, but this thread will be scheduled for different core, because core pointed by thread mask is in interrupt mode. This thread will never be moved by scheduler to correct core because currently scheduler do not move busy threads. This change makes scheduler to move busy threads if their mask do not match core on which they are executed currently. Signed-off-by: Maciej Szwed Change-Id: I35abdc91b197f1b9d40e491f964d31debad72fa5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6073 Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/event/scheduler_dynamic.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/event/scheduler_dynamic.c b/lib/event/scheduler_dynamic.c index b1428bfd7..ab685b410 100644 --- a/lib/event/scheduler_dynamic.c +++ b/lib/event/scheduler_dynamic.c @@ -205,8 +205,26 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count, main_core_busy += spdk_min(UINT64_MAX - main_core_busy, thread_busy); main_core_idle -= spdk_min(main_core_idle, thread_busy); } else { - /* This thread should remain on the same core */ + /* Move busy thread only if cpumask does not match current core (except main core) */ if (i != g_main_lcore) { + if (!spdk_cpuset_get_cpu(cpumask, i)) { + for (k = 0; k < spdk_env_get_core_count(); k++) { + target_lcore = _get_next_target_core(); + + if (spdk_cpuset_get_cpu(cpumask, target_lcore)) { + lw_thread->new_lcore = target_lcore; + cores_info[target_lcore].pending_threads_count++; + core->pending_threads_count--; + + if (target_lcore == g_main_lcore) { + main_core_busy += spdk_min(UINT64_MAX - main_core_busy, thread_busy); + main_core_idle -= spdk_min(main_core_idle, thread_busy); + } + break; + } + } + } + busy_threads_present = true; } }