From 20362e5bc8afd50f02d3cbe96fe2e38f84e1da54 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Mon, 25 Jan 2021 16:56:31 +0100 Subject: [PATCH] schedulers: Add _get_next_target_lcore function This function will be useful in upcoming patch. Signed-off-by: Maciej Szwed Change-Id: I2a79305b8cb155a94c83b4baa3f5d7014cb602c9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6079 Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/event/scheduler_dynamic.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/event/scheduler_dynamic.c b/lib/event/scheduler_dynamic.c index 22e91eede..b1428bfd7 100644 --- a/lib/event/scheduler_dynamic.c +++ b/lib/event/scheduler_dynamic.c @@ -48,6 +48,21 @@ uint64_t g_last_main_core_busy, g_last_main_core_idle; #define SCHEDULER_THREAD_BUSY 100 #define SCHEDULER_LOAD_LIMIT 50 +static uint32_t +_get_next_target_core(void) +{ + uint32_t target_lcore; + + if (g_next_lcore == SPDK_ENV_LCORE_ID_ANY) { + g_next_lcore = spdk_env_get_first_core(); + } + + target_lcore = g_next_lcore; + g_next_lcore = spdk_env_get_next_core(g_next_lcore); + + return target_lcore; +} + static uint8_t _get_thread_load(struct spdk_lw_thread *lw_thread) { @@ -160,12 +175,7 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count, if (i == g_main_lcore && load >= SCHEDULER_LOAD_LIMIT) { /* This thread is active and on the main core, we need to pick a core to move it to */ for (k = 0; k < spdk_env_get_core_count(); k++) { - if (g_next_lcore == SPDK_ENV_LCORE_ID_ANY) { - g_next_lcore = spdk_env_get_first_core(); - } - - target_lcore = g_next_lcore; - g_next_lcore = spdk_env_get_next_core(g_next_lcore); + target_lcore = _get_next_target_core(); /* Do not use main core if it is too busy for new thread */ if (target_lcore == g_main_lcore && thread_busy > main_core_idle) {