From b518cbe2d4991bdc98f1fcf8f7cd9056b3961e44 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 27 Aug 2021 04:53:20 -0400 Subject: [PATCH] lib/event: handle error before balance() Make sure to cancel the scheduling during: 1) gather_metrics error (already present) 2) setting the scheduler to NULL (new) 3) shutdown of the application (new) In all of the above scheduler cannot proceed to the balance() function. Prior to this patch lack of setting g_scheduling_in_progress to false would block _start_subsystem_fini() from proceeding. Resuling in application never shutting down. thread_infos are allocated during gather_metrics, and freed on threads_reschedule. The added cleanup is used during 1) and 2). Signed-off-by: Tomasz Zawadzki Change-Id: I5ab77c85aaa9f94bd4e1a1660b55ab2f2c47bbdc Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9326 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- lib/event/reactor.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 7b726996d..cdf6aa1d1 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -748,23 +748,36 @@ _reactors_scheduler_update_core_mode(void *ctx) _reactors_scheduler_fini(); } +static void +_reactors_scheduler_cancel(void *arg1, void *arg2) +{ + struct spdk_scheduler_core_info *core; + uint32_t i; + + SPDK_ENV_FOREACH_CORE(i) { + core = &g_core_infos[i]; + core->threads_count = 0; + free(core->thread_infos); + core->thread_infos = NULL; + } + + g_scheduling_in_progress = false; +} + static void _reactors_scheduler_balance(void *arg1, void *arg2) { struct spdk_scheduler *scheduler = _spdk_scheduler_get(); - if (g_reactor_state == SPDK_REACTOR_STATE_RUNNING && scheduler != NULL) { - scheduler->balance(g_core_infos, g_reactor_count); - - g_scheduler_core_number = spdk_env_get_first_core(); - _reactors_scheduler_update_core_mode(NULL); + if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING || scheduler == NULL) { + _reactors_scheduler_cancel(NULL, NULL); + return; } -} -static void -_reactors_scheduler_cancel(void *arg1, void *arg2) -{ - g_scheduling_in_progress = false; + scheduler->balance(g_core_infos, g_reactor_count); + + g_scheduler_core_number = spdk_env_get_first_core(); + _reactors_scheduler_update_core_mode(NULL); } /* Phase 1 of thread scheduling is to gather metrics on the existing threads */