From 4d6a89044f6e1672d4c6b554c340462a563180de Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 4 Mar 2019 13:16:56 -0700 Subject: [PATCH] event: No longer require event in spdk_subsystem_fini Just use a function pointer and a context. Change-Id: I2d41ed2572d892f3328aadf7f22d8696816bf4d1 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446995 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- include/spdk_internal/event.h | 4 +-- lib/event/app.c | 6 +--- lib/event/reactor.c | 2 +- lib/event/subsystem.c | 28 +++++++++---------- .../unit/lib/event/subsystem.c/subsystem_ut.c | 1 + 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 77570d030..875076426 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -51,7 +51,7 @@ int spdk_reactors_init(void); void spdk_reactors_fini(void); void spdk_reactors_start(void); -void spdk_reactors_stop(void *arg1, void *arg2); +void spdk_reactors_stop(void *arg1); struct spdk_subsystem { const char *name; @@ -88,7 +88,7 @@ void spdk_add_subsystem(struct spdk_subsystem *subsystem); void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend); void spdk_subsystem_init(spdk_msg_fn cb_fn, void *cb_arg); -void spdk_subsystem_fini(struct spdk_event *app_finish_event); +void spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg); void spdk_subsystem_init_next(int rc); void spdk_subsystem_fini_next(void); void spdk_subsystem_config(FILE *fp); diff --git a/lib/event/app.c b/lib/event/app.c index ca1b8d394..a10f266a2 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -703,12 +703,8 @@ spdk_app_fini(void) static void _spdk_app_stop(void *arg1, void *arg2) { - struct spdk_event *app_stop_event; - spdk_rpc_finish(); - - app_stop_event = spdk_event_allocate(spdk_env_get_current_core(), spdk_reactors_stop, NULL, NULL); - spdk_subsystem_fini(app_stop_event); + spdk_subsystem_fini(spdk_reactors_stop, NULL); } void diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 38af3b7b2..815e55527 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -338,7 +338,7 @@ spdk_reactors_start(void) } void -spdk_reactors_stop(void *arg1, void *arg2) +spdk_reactors_stop(void *arg1) { g_reactor_state = SPDK_REACTOR_STATE_EXITING; } diff --git a/lib/event/subsystem.c b/lib/event/subsystem.c index adba5d529..c485e3fee 100644 --- a/lib/event/subsystem.c +++ b/lib/event/subsystem.c @@ -46,8 +46,9 @@ static bool g_subsystems_initialized = false; static bool g_subsystems_init_interrupted = false; static spdk_msg_fn g_app_start_fn = NULL; static void *g_app_start_arg = NULL; -static struct spdk_event *g_app_stop_event; -static uint32_t g_fini_core; +static spdk_msg_fn g_app_stop_fn = NULL; +static void *g_app_stop_arg = NULL; +static struct spdk_thread *g_fini_thread = NULL; void spdk_add_subsystem(struct spdk_subsystem *subsystem) @@ -187,9 +188,9 @@ spdk_subsystem_init(spdk_msg_fn cb_fn, void *cb_arg) } static void -_spdk_subsystem_fini_next(void *arg1, void *arg2) +_spdk_subsystem_fini_next(void *arg1) { - assert(g_fini_core == spdk_env_get_current_core()); + assert(g_fini_thread == spdk_get_thread()); if (!g_next_subsystem) { /* If the initialized flag is false, then we've failed to initialize @@ -214,28 +215,27 @@ _spdk_subsystem_fini_next(void *arg1, void *arg2) g_next_subsystem = TAILQ_PREV(g_next_subsystem, spdk_subsystem_list, tailq); } - spdk_event_call(g_app_stop_event); + g_app_stop_fn(g_app_stop_arg); return; } void spdk_subsystem_fini_next(void) { - if (g_fini_core != spdk_env_get_current_core()) { - struct spdk_event *event; - - event = spdk_event_allocate(g_fini_core, _spdk_subsystem_fini_next, NULL, NULL); - spdk_event_call(event); + if (g_fini_thread != spdk_get_thread()) { + spdk_thread_send_msg(g_fini_thread, _spdk_subsystem_fini_next, NULL); } else { - _spdk_subsystem_fini_next(NULL, NULL); + _spdk_subsystem_fini_next(NULL); } } void -spdk_subsystem_fini(struct spdk_event *app_stop_event) +spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg) { - g_app_stop_event = app_stop_event; - g_fini_core = spdk_env_get_current_core(); + g_app_stop_fn = cb_fn; + g_app_stop_arg = cb_arg; + + g_fini_thread = spdk_get_thread(); spdk_subsystem_fini_next(); } diff --git a/test/unit/lib/event/subsystem.c/subsystem_ut.c b/test/unit/lib/event/subsystem.c/subsystem_ut.c index b7c3c558a..319c01399 100644 --- a/test/unit/lib/event/subsystem.c/subsystem_ut.c +++ b/test/unit/lib/event/subsystem.c/subsystem_ut.c @@ -37,6 +37,7 @@ #include "unit/lib/json_mock.c" #include "event/subsystem.c" +#include "common/lib/test_env.c" static struct spdk_subsystem g_ut_subsystems[8]; static struct spdk_subsystem_depend g_ut_subsystem_deps[8];