From 2d79bf58fb31f5520c30a60439d11ab264ddf2d4 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Wed, 26 May 2021 09:44:28 -0400 Subject: [PATCH] scheduler_dynamic: balance idle threads in separate pass Idle threads are always moved to main core, there are no other considations. Doing it as separate first pass, allows to have the core stats be up to date for second pass for active threads. Core load stats will be used later in the series to determine optimal target core for an active thread. Signed-off-by: Tomasz Zawadzki Change-Id: I6a9bc11b86e954e461f7badebf3a6e4d1718f63c Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8067 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Maciej Szwed Reviewed-by: Paul Luse Reviewed-by: Jim Harris --- lib/event/scheduler_dynamic.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/event/scheduler_dynamic.c b/lib/event/scheduler_dynamic.c index 88922a220e..dfef05f5f7 100644 --- a/lib/event/scheduler_dynamic.c +++ b/lib/event/scheduler_dynamic.c @@ -205,20 +205,27 @@ deinit(struct spdk_governor *governor) } static void -_balance_thread(struct spdk_lw_thread *lw_thread) +_balance_idle(struct spdk_lw_thread *lw_thread) +{ + if (_get_thread_load(lw_thread) >= SCHEDULER_LOAD_LIMIT) { + return; + } + /* This thread is idle, move it to the main core. */ + _move_thread(lw_thread, g_main_lcore); +} + +static void +_balance_active(struct spdk_lw_thread *lw_thread) { uint32_t target_lcore; - uint8_t load; - load = _get_thread_load(lw_thread); - if (load < SCHEDULER_LOAD_LIMIT) { - /* This thread is idle, move it to the main core. */ - _move_thread(lw_thread, g_main_lcore); - } else { - /* This thread is active. */ - target_lcore = _find_optimal_core(lw_thread); - _move_thread(lw_thread, target_lcore); + if (_get_thread_load(lw_thread) < SCHEDULER_LOAD_LIMIT) { + return; } + + /* This thread is active. */ + target_lcore = _find_optimal_core(lw_thread); + _move_thread(lw_thread, target_lcore); } static void @@ -239,8 +246,11 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count, } main_core = &g_cores[g_main_lcore]; - /* Distribute active threads across all cores and move idle threads to main core */ - _foreach_thread(cores_info, _balance_thread); + /* Distribute threads in two passes, to make sure updated core stats are considered on each pass. + * 1) Move all idle threads to main core. */ + _foreach_thread(cores_info, _balance_idle); + /* 2) Distribute active threads across all cores. */ + _foreach_thread(cores_info, _balance_active); /* Switch unused cores to interrupt mode and switch cores to polled mode * if they will be used after rebalancing */