diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 542e26620..1f32db439 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -245,7 +245,7 @@ void _spdk_scheduler_period_set(uint32_t period); #define SPDK_SCHEDULER_REGISTER(scheduler) \ static void __attribute__((constructor)) _spdk_scheduler_register_##name(void) \ { \ - spdk_scheduler_list_add(scheduler); \ + _spdk_scheduler_list_add(scheduler); \ } \ /** diff --git a/lib/event/Makefile b/lib/event/Makefile index 3cdf6e149..2011ea238 100644 --- a/lib/event/Makefile +++ b/lib/event/Makefile @@ -39,7 +39,7 @@ SO_MINOR := 0 LIBNAME = event C_SRCS = app.c reactor.c rpc.c subsystem.c json_config.c log_rpc.c \ - app_rpc.c subsystem_rpc.c + app_rpc.c subsystem_rpc.c scheduler_static.c SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_event.map) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 73a001931..b8acbefd6 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -92,9 +92,14 @@ _spdk_scheduler_set(char *name) scheduler = _scheduler_find(name); if (scheduler == NULL) { + SPDK_ERRLOG("Requested scheduler is missing\n"); return -ENOENT; } + if (scheduler->init != NULL) { + scheduler->init(); + } + g_scheduler = scheduler; return 0; } @@ -163,6 +168,12 @@ spdk_reactors_init(void) uint32_t i, last_core; char mempool_name[32]; + rc = _spdk_scheduler_set("static"); + if (rc != 0) { + SPDK_ERRLOG("Failed setting up scheduler\n"); + return rc; + } + snprintf(mempool_name, sizeof(mempool_name), "evtpool_%d", getpid()); g_spdk_event_mempool = spdk_mempool_create(mempool_name, 262144 - 1, /* Power of 2 minus 1 is optimal for memory consumption */ @@ -210,6 +221,10 @@ spdk_reactors_fini(void) return; } + if (g_scheduler->deinit != NULL) { + g_scheduler->deinit(); + } + spdk_thread_lib_fini(); SPDK_ENV_FOREACH_CORE(i) { diff --git a/lib/event/scheduler_static.c b/lib/event/scheduler_static.c new file mode 100644 index 000000000..493808bcc --- /dev/null +++ b/lib/event/scheduler_static.c @@ -0,0 +1,48 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "spdk/stdinc.h" +#include "spdk/likely.h" +#include "spdk/event.h" +#include "spdk/log.h" +#include "spdk/env.h" + +#include "spdk_internal/event.h" + +static struct spdk_scheduler scheduler = { + .name = "static", + .init = NULL, + .deinit = NULL, + .balance = NULL, +}; +SPDK_SCHEDULER_REGISTER(&scheduler); diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index edf96e544..c05540352 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -37,6 +37,7 @@ #include "common/lib/test_env.c" #include "event/reactor.c" #include "spdk_internal/thread.h" +#include "event/scheduler_static.c" static void test_create_reactor(void)