From 1368aec8700a5e8af407fa9aba1f89e1e71fb2b2 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Sun, 23 Feb 2020 17:43:09 -0500 Subject: [PATCH] lib/event: Use spdk_thread_lib_init_ext() to initialize thread library Remove the prefix "spdk" from spdk_reactor_schedule_thread(), add spdk_reactor_thread_op() and spdk_reactor_thread_op_supported(). For SPDK_THREAD_OP_NEW, spdk_reactor_thread_op() calls _reactor_schedule_thread() and spdk_reactor_thread_op_supported() returns true. Then replace spdk_thread_lib_init() by spdk_thread_lib_init_ext() with spdk_reactor_thread_op() and spdk_reactor_thread_op_supported(). Signed-off-by: Shuhei Matsumoto Change-Id: I232a3b2c6bcaf4d86b0dd3cefacd3e47eadda6d8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/968 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/event/reactor.c | 30 +++++++++++++++++++--- test/unit/lib/event/reactor.c/reactor_ut.c | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 94cb37143..a6112ebdd 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -92,7 +92,8 @@ spdk_reactor_get(uint32_t lcore) return reactor; } -static int spdk_reactor_schedule_thread(struct spdk_thread *thread); +static int spdk_reactor_thread_op(struct spdk_thread *thread, enum spdk_thread_op op); +static bool spdk_reactor_thread_op_supported(enum spdk_thread_op op); int spdk_reactors_init(void) @@ -126,7 +127,8 @@ spdk_reactors_init(void) memset(g_reactors, 0, (last_core + 1) * sizeof(struct spdk_reactor)); - spdk_thread_lib_init(spdk_reactor_schedule_thread, sizeof(struct spdk_lw_thread)); + spdk_thread_lib_init_ext(spdk_reactor_thread_op, spdk_reactor_thread_op_supported, + sizeof(struct spdk_lw_thread)); SPDK_ENV_FOREACH_CORE(i) { spdk_reactor_construct(&g_reactors[i], i); @@ -474,7 +476,7 @@ _schedule_thread(void *arg1, void *arg2) } static int -spdk_reactor_schedule_thread(struct spdk_thread *thread) +_reactor_schedule_thread(struct spdk_thread *thread) { uint32_t core; struct spdk_lw_thread *lw_thread; @@ -514,6 +516,28 @@ spdk_reactor_schedule_thread(struct spdk_thread *thread) return 0; } +static int +spdk_reactor_thread_op(struct spdk_thread *thread, enum spdk_thread_op op) +{ + switch (op) { + case SPDK_THREAD_OP_NEW: + return _reactor_schedule_thread(thread); + default: + return -ENOTSUP; + } +} + +static bool +spdk_reactor_thread_op_supported(enum spdk_thread_op op) +{ + switch (op) { + case SPDK_THREAD_OP_NEW: + return true; + default: + return false; + } +} + struct call_reactor { uint32_t cur_core; spdk_event_fn fn; diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index 68a4f85d9..9fe448e6a 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -124,7 +124,7 @@ test_schedule_thread(void) spdk_cpuset_set_cpu(&cpuset, 3, true); g_next_core = 4; - /* spdk_reactor_schedule_thread() will be called in spdk_thread_create() + /* _reactor_schedule_thread() will be called in spdk_thread_create() * at its end because it is passed to SPDK thread library by * spdk_thread_lib_init(). */