From ad15f44116ec9c50e0dbcd48a3e01b08d387700f Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Wed, 16 Dec 2020 12:59:43 +0100 Subject: [PATCH] scheduler: Don't use main core for new thread if it is too busy We don't want to make main core 100% busy, so don't move thread to it if thread busy time is higher than main core idle time. Signed-off-by: Maciej Szwed Change-Id: Ib521ac0d8959ec8062322ff7b2ad587d85ccada5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5638 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Paul Luse --- lib/event/scheduler_dynamic.c | 5 +++++ test/unit/lib/event/reactor.c/reactor_ut.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/event/scheduler_dynamic.c b/lib/event/scheduler_dynamic.c index ffc9dc963..d9fa634de 100644 --- a/lib/event/scheduler_dynamic.c +++ b/lib/event/scheduler_dynamic.c @@ -161,6 +161,11 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count, target_lcore = g_next_lcore; g_next_lcore = spdk_env_get_next_core(g_next_lcore); + /* Do not use main core if it is too busy for new thread */ + if (target_lcore == g_main_lcore && thread_busy > main_core_idle) { + continue; + } + if (spdk_cpuset_get_cpu(cpumask, target_lcore)) { lw_thread->new_lcore = target_lcore; diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index c1b5c4e8f..56941b331 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -560,6 +560,9 @@ test_scheduler(void) spdk_poller_unregister(&busy); } + reactor->busy_tsc = 0; + reactor->idle_tsc = UINT32_MAX; + /* Run scheduler again, this time all threads are busy */ _reactors_scheduler_gather_metrics(NULL, NULL);