From a86e40f320b884f2fadb4e025f5396d85ef2df36 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 6 Aug 2021 05:17:16 -0400 Subject: [PATCH] scheduler: create public API and subsystem for scheduler/governor This patch moves schedueler and governor related API from the internal event.h to public scheduler.h. With this it is possible to create subsystem responsible for handling the schedulers. Three schedulers and a governor were moved to scheduler modules from event framework. This will allow next patch to add JSON RPC configuration to the whole subsystem. Along with easier addition of other schedulers. Removed debug logs from gscheduler, as they serve little purpose. Signed-off-by: Krzysztof Karas Signed-off-by: Tomasz Zawadzki Change-Id: I98ca1ea4fb281beb71941656444267842a8875b7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6995 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- include/spdk/scheduler.h | 286 ++++++++++++++++++ include/spdk_internal/event.h | 234 -------------- lib/event/Makefile | 11 +- lib/event/app.c | 2 +- lib/event/app_rpc.c | 14 +- lib/event/reactor.c | 29 +- lib/event/scheduler_static.c | 1 + lib/event/spdk_event.map | 10 + mk/spdk.lib.mk | 1 + mk/spdk.lib_deps.mk | 17 +- mk/spdk.modules.mk | 9 +- module/Makefile | 8 +- module/event/subsystems/Makefile | 2 +- module/event/subsystems/scheduler/Makefile | 45 +++ module/event/subsystems/scheduler/scheduler.c | 72 +++++ module/scheduler/Makefile | 53 ++++ module/scheduler/dpdk_governor/Makefile | 47 +++ .../scheduler/dpdk_governor}/dpdk_governor.c | 1 + module/scheduler/gscheduler/Makefile | 45 +++ .../scheduler/gscheduler}/gscheduler.c | 15 +- module/scheduler/scheduler_dynamic/Makefile | 45 +++ .../scheduler_dynamic}/scheduler_dynamic.c | 8 +- test/event/scheduler/Makefile | 2 +- test/unit/lib/event/reactor.c/reactor_ut.c | 10 +- 24 files changed, 672 insertions(+), 295 deletions(-) create mode 100644 include/spdk/scheduler.h create mode 100644 module/event/subsystems/scheduler/Makefile create mode 100644 module/event/subsystems/scheduler/scheduler.c create mode 100644 module/scheduler/Makefile create mode 100644 module/scheduler/dpdk_governor/Makefile rename {lib/event => module/scheduler/dpdk_governor}/dpdk_governor.c (99%) create mode 100644 module/scheduler/gscheduler/Makefile rename {lib/event => module/scheduler/gscheduler}/gscheduler.c (88%) create mode 100644 module/scheduler/scheduler_dynamic/Makefile rename {lib/event => module/scheduler/scheduler_dynamic}/scheduler_dynamic.c (98%) diff --git a/include/spdk/scheduler.h b/include/spdk/scheduler.h new file mode 100644 index 000000000..521625ef7 --- /dev/null +++ b/include/spdk/scheduler.h @@ -0,0 +1,286 @@ +/*- + * 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. + */ + +#ifndef SPDK_SCHEDULER_H +#define SPDK_SCHEDULER_H + +#include "spdk/stdinc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "spdk/event.h" +#include "spdk/json.h" +#include "spdk/thread.h" +#include "spdk/util.h" + +struct spdk_governor_capabilities { + bool priority; /* Core with higher base frequency */ +}; + +/** + * Cores governor + * Implements core frequency control for schedulers. Functions from this structure + * are invoked from scheduling reactor. + */ +struct spdk_governor { + const char *name; + + /** + * Get current frequency of a given core. + * + * \param lcore_id Core number. + * + * \return Currently set core frequency. + */ + uint32_t (*get_core_curr_freq)(uint32_t lcore_id); + + /** + * Increase core frequency to next available one. + * + * \param lcore_id Core number. + * + * \return 1 on success, 0 already at max frequency, negative on error. + */ + int (*core_freq_up)(uint32_t lcore_id); + + /** + * Decrease core frequency to next available one. + * + * \param lcore_id Core number. + * + * \return 1 on success, 0 already at min frequency, negative on error. + */ + int (*core_freq_down)(uint32_t lcore_id); + + /** + * Set core frequency to maximum available. + * + * \param lcore_id Core number. + * + * \return 1 on success, 0 already at max frequency, negative on error. + */ + int (*set_core_freq_max)(uint32_t lcore_id); + + /** + * Set core frequency to minimum available. + * + * \param lcore_id Core number. + * + * \return 1 on success, 0 already at min frequency, negative on error. + */ + int (*set_core_freq_min)(uint32_t lcore_id); + + /** + * Get capabilities of a given core. + * + * \param lcore_id Core number. + * \param capabilities Structure to fill with capabilities data. + * + * \return 0 on success, negative on error. + */ + int (*get_core_capabilities)(uint32_t lcore_id, struct spdk_governor_capabilities *capabilities); + + /** + * Initialize a governor. + * + * \return 0 on success, non-zero on error. + */ + int (*init)(void); + + /** + * Deinitialize a governor. + */ + void (*deinit)(void); + + TAILQ_ENTRY(spdk_governor) link; +}; + +/** + * Set the current governor. + * + * Always deinitalizes previously set governor. + * No governor will be set if name parameter is NULL. + * This function should be invoked on scheduling reactor. + * + * \param name Name of the governor to be used. + * + * \return 0 on success or non-zero on failure. + */ +int spdk_governor_set(const char *name); + +/** + * Get currently set governor. + * + * \return a pointer to spdk governor or NULL if none is set. + */ +struct spdk_governor *spdk_governor_get(void); + +/** + * Add the given governor to the list of registered governors. + * This function should be invoked by referencing the macro + * SPDK_GOVERNOR_REGISTER in the governor c file. + * + * \param governor Governor to be added. + * + * \return 0 on success or non-zero on failure. + */ +void spdk_governor_register(struct spdk_governor *governor); + +/** + * Macro used to register new governors. + */ +#define SPDK_GOVERNOR_REGISTER(governor) \ + static void __attribute__((constructor)) _spdk_governor_register_ ## governor(void) \ + { \ + spdk_governor_register(&governor); \ + } \ + +/** + * Structure representing thread used for scheduling. + */ +struct spdk_scheduler_thread_info { + uint32_t lcore; + uint64_t thread_id; + /* stats over a lifetime of a thread */ + struct spdk_thread_stats total_stats; + /* stats during the last scheduling period */ + struct spdk_thread_stats current_stats; +}; + +/** + * A list of cores and threads which is used for scheduling. + */ +struct spdk_scheduler_core_info { + /* stats over a lifetime of a core */ + uint64_t total_idle_tsc; + uint64_t total_busy_tsc; + /* stats during the last scheduling period */ + uint64_t current_idle_tsc; + uint64_t current_busy_tsc; + + uint32_t lcore; + uint32_t threads_count; + bool interrupt_mode; + struct spdk_scheduler_thread_info *thread_infos; +}; + +/** + * Thread scheduler. + * Functions from this structure are invoked from scheduling reactor. + */ +struct spdk_scheduler { + const char *name; + + /** + * This function is called to initialize a scheduler. + * + * \return 0 on success or non-zero on failure. + */ + int (*init)(void); + + /** + * This function is called to deinitialize a scheduler. + */ + void (*deinit)(void); + + /** + * Function to balance threads across cores by modifying + * the value of their lcore field. + * + * \param core_info Structure describing cores and threads on them. + * \param count Size of the core_info array. + */ + void (*balance)(struct spdk_scheduler_core_info *core_info, uint32_t count); + + TAILQ_ENTRY(spdk_scheduler) link; +}; + +/** + * Change current scheduler. If another scheduler was used prior, + * it will be deinitalized. No scheduler will be set if name parameter + * is NULL. + * This function should be invoked from scheduling reactor. + * + * \param name Name of the scheduler to be used. + * + * \return 0 on success or non-zero on failure. + */ +int spdk_scheduler_set(const char *name); + +/** + * Get currently set scheduler. + * + * \return a pointer to spdk scheduler or NULL if none is set. + */ +struct spdk_scheduler *spdk_scheduler_get(void); + +/** + * Change current scheduling period. + * Setting period to 0 disables scheduling. + * + * \param period Period to set in microseconds. + */ +void spdk_scheduler_set_period(uint64_t period); + +/** + * Get scheduling period of currently set scheduler. + * + * \return Scheduling period in microseconds. + */ +uint64_t spdk_scheduler_get_period(void); + +/** + * Add the given scheduler to the list of registered schedulers. + * This function should be invoked by referencing the macro + * SPDK_SCHEDULER_REGISTER in the scheduler c file. + * + * \param scheduler Scheduler to be added. + */ +void spdk_scheduler_register(struct spdk_scheduler *scheduler); + +/* + * Macro used to register new scheduler. + */ +#define SPDK_SCHEDULER_REGISTER(scheduler) \ +static void __attribute__((constructor)) _spdk_scheduler_register_ ## scheduler (void) \ +{ \ + spdk_scheduler_register(&scheduler); \ +} \ + +#ifdef __cplusplus +} +#endif + +#endif /* SPDK_SCHEDULER_H */ diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index fdc3c4d20..32ea645f3 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -163,240 +163,6 @@ int spdk_reactor_set_interrupt_mode(uint32_t lcore, bool new_in_interrupt, */ struct spdk_thread *_spdk_get_app_thread(void); -struct spdk_governor_capabilities { - bool priority; /* Core with higher base frequency */ -}; - -/** - * Cores governor - * Implements core frequency control for schedulers. Functions from this structure - * are invoked from scheduling reactor. - */ -struct spdk_governor { - const char *name; - - /** - * Get current frequency of a given core. - * - * \param lcore_id Core number. - * - * \return Currently set core frequency. - */ - uint32_t (*get_core_curr_freq)(uint32_t lcore_id); - - /** - * Increase core frequency to next available one. - * - * \param lcore_id Core number. - * - * \return 1 on success, 0 already at max frequency, negative on error. - */ - int (*core_freq_up)(uint32_t lcore_id); - - /** - * Decrease core frequency to next available one. - * - * \param lcore_id Core number. - * - * \return 1 on success, 0 already at min frequency, negative on error. - */ - int (*core_freq_down)(uint32_t lcore_id); - - /** - * Set core frequency to maximum available. - * - * \param lcore_id Core number. - * - * \return 1 on success, 0 already at max frequency, negative on error. - */ - int (*set_core_freq_max)(uint32_t lcore_id); - - /** - * Set core frequency to minimum available. - * - * \param lcore_id Core number. - * - * \return 1 on success, 0 already at min frequency, negative on error. - */ - int (*set_core_freq_min)(uint32_t lcore_id); - - /** - * Get capabilities of a given core. - * - * \param lcore_id Core number. - * \param capabilities Structure to fill with capabilities data. - * - * \return 0 on success, negative on error. - */ - int (*get_core_capabilities)(uint32_t lcore_id, struct spdk_governor_capabilities *capabilities); - - /** - * Initialize a governor. - * - * \return 0 on success, non-zero on error. - */ - int (*init)(void); - - /** - * Deinitialize a governor. - */ - void (*deinit)(void); - - TAILQ_ENTRY(spdk_governor) link; -}; - -/** - * Set the current governor. - * - * Always deinitalizes previously set governor. - * No governor will be set if name parameter is NULL. - * This function should be invoked on scheduling reactor. - * - * \param name Name of the governor to be used. - * - * \return 0 on success or non-zero on failure. - */ -int _spdk_governor_set(const char *name); - -/** - * Get currently set governor. - * - * \return a pointer to spdk governor or NULL if none is set. - */ -struct spdk_governor *_spdk_governor_get(void); - -/** - * Add the given governor to the list of registered governors. - * This function should be invoked by referencing the macro - * SPDK_GOVERNOR_REGISTER in the governor c file. - * - * \param governor Governor to be added. - * - * \return 0 on success or non-zero on failure. - */ -void _spdk_governor_register(struct spdk_governor *governor); - -/** - * Macro used to register new governors. - */ -#define SPDK_GOVERNOR_REGISTER(governor) \ - static void __attribute__((constructor)) _spdk_governor_register_ ## governor(void) \ - { \ - _spdk_governor_register(&governor); \ - } \ - -/** - * Structure representing thread used for scheduling. - */ -struct spdk_scheduler_thread_info { - uint32_t lcore; - uint64_t thread_id; - /* stats over a lifetime of a thread */ - struct spdk_thread_stats total_stats; - /* stats during the last scheduling period */ - struct spdk_thread_stats current_stats; -}; - -/** - * A list of cores and threads which is used for scheduling. - */ -struct spdk_scheduler_core_info { - /* stats over a lifetime of a core */ - uint64_t total_idle_tsc; - uint64_t total_busy_tsc; - /* stats during the last scheduling period */ - uint64_t current_idle_tsc; - uint64_t current_busy_tsc; - - uint32_t lcore; - uint32_t threads_count; - bool interrupt_mode; - struct spdk_scheduler_thread_info *thread_infos; -}; - -/** - * Thread scheduler. - * Functions from this structure are invoked from scheduling reactor. - */ -struct spdk_scheduler { - const char *name; - - /** - * This function is called to initialize a scheduler. - * - * \return 0 on success or non-zero on failure. - */ - int (*init)(void); - - /** - * This function is called to deinitialize a scheduler. - */ - void (*deinit)(void); - - /** - * Function to balance threads across cores by modifying - * the value of their lcore field. - * - * \param core_info Structure describing cores and threads on them. - * \param count Size of the core_info array. - */ - void (*balance)(struct spdk_scheduler_core_info *core_info, uint32_t count); - - TAILQ_ENTRY(spdk_scheduler) link; -}; - -/** - * Change current scheduler. If another scheduler was used prior, - * it will be deinitalized. No scheduler will be set if name parameter - * is NULL. - * This function should be invoked from scheduling reactor. - * - * \param name Name of the scheduler to be used. - * - * \return 0 on success or non-zero on failure. - */ -int _spdk_scheduler_set(const char *name); - -/** - * Get currently set scheduler. - * - * \return a pointer to spdk scheduler or NULL if none is set. - */ -struct spdk_scheduler *_spdk_scheduler_get(void); - -/** - * Change current scheduling period. - * Setting period to 0 disables scheduling. - * - * \param period Period to set in microseconds. - */ -void _spdk_scheduler_set_period(uint64_t period); - -/** - * Get scheduling period of currently set scheduler. - * - * \return Scheduling period in microseconds. - */ -uint64_t _spdk_scheduler_get_period(void); - -/** - * Add the given scheduler to the list of registered schedulers. - * This function should be invoked by referencing the macro - * SPDK_SCHEDULER_REGISTER in the scheduler c file. - * - * \param scheduler Scheduler to be added. - */ -void _spdk_scheduler_register(struct spdk_scheduler *scheduler); - -/* - * Macro used to register new scheduler. - */ -#define SPDK_SCHEDULER_REGISTER(scheduler) \ -static void __attribute__((constructor)) _spdk_scheduler_register_ ## scheduler (void) \ -{ \ - _spdk_scheduler_register(&scheduler); \ -} \ - #ifdef __cplusplus } #endif diff --git a/lib/event/Makefile b/lib/event/Makefile index 84640b789..02b9664bc 100644 --- a/lib/event/Makefile +++ b/lib/event/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 9 -SO_MINOR := 0 +SO_MINOR := 1 CFLAGS += $(ENV_CFLAGS) @@ -43,15 +43,6 @@ LIBNAME = event C_SRCS = app.c reactor.c log_rpc.c \ app_rpc.c scheduler_static.c -# Do not compile schedulers and governors based on DPDK env -# if non-DPDK env is used. -ENV_NAME := $(notdir $(CONFIG_ENV)) -ifeq ($(ENV_NAME),env_dpdk) -ifeq ($(OS),Linux) -C_SRCS += gscheduler.c dpdk_governor.c scheduler_dynamic.c -endif -endif - SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_event.map) include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/event/app.c b/lib/event/app.c index f48e07517..cfdefd781 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -44,6 +44,7 @@ #include "spdk/thread.h" #include "spdk/trace.h" #include "spdk/string.h" +#include "spdk/scheduler.h" #include "spdk/rpc.h" #include "spdk/util.h" @@ -620,7 +621,6 @@ app_stop(void *arg1) spdk_rpc_finish(); g_spdk_app.stopped = true; - _spdk_scheduler_set_period(0); _start_subsystem_fini(NULL); } diff --git a/lib/event/app_rpc.c b/lib/event/app_rpc.c index e435bf3ef..883c86abb 100644 --- a/lib/event/app_rpc.c +++ b/lib/event/app_rpc.c @@ -38,6 +38,7 @@ #include "spdk/string.h" #include "spdk/util.h" #include "spdk/env.h" +#include "spdk/scheduler.h" #include "spdk/thread.h" #include "spdk/log.h" @@ -399,7 +400,8 @@ _rpc_framework_get_reactors(void *arg1, void *arg2) spdk_json_write_named_uint64(ctx->w, "busy", reactor->busy_tsc); spdk_json_write_named_uint64(ctx->w, "idle", reactor->idle_tsc); spdk_json_write_named_bool(ctx->w, "in_interrupt", reactor->in_interrupt); - governor = _spdk_governor_get(); + + governor = spdk_governor_get(); if (governor != NULL) { /* Governor returns core freqs in kHz, we want MHz. */ curr_core_freq = governor->get_core_curr_freq(current_core) / 1000; @@ -491,10 +493,10 @@ rpc_framework_set_scheduler(struct spdk_jsonrpc_request *request, } if (req.period != 0) { - _spdk_scheduler_set_period(req.period); + spdk_scheduler_set_period(req.period); } - ret = _spdk_scheduler_set(req.name); + ret = spdk_scheduler_set(req.name); if (ret) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(ret)); @@ -513,9 +515,9 @@ rpc_framework_get_scheduler(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct spdk_json_write_ctx *w; - struct spdk_scheduler *scheduler = _spdk_scheduler_get(); - uint64_t scheduler_period = _spdk_scheduler_get_period(); - struct spdk_governor *governor = _spdk_governor_get(); + struct spdk_scheduler *scheduler = spdk_scheduler_get(); + uint64_t scheduler_period = spdk_scheduler_get_period(); + struct spdk_governor *governor = spdk_governor_get(); if (params) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, diff --git a/lib/event/reactor.c b/lib/event/reactor.c index cdf6aa1d1..3732c3f40 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -40,6 +40,7 @@ #include "spdk/thread.h" #include "spdk/env.h" #include "spdk/util.h" +#include "spdk/scheduler.h" #include "spdk/string.h" #include "spdk/fd_group.h" @@ -69,7 +70,7 @@ TAILQ_HEAD(, spdk_scheduler) g_scheduler_list static struct spdk_scheduler *g_scheduler = NULL; static struct spdk_reactor *g_scheduling_reactor; bool g_scheduling_in_progress = false; -static uint64_t g_scheduler_period; +static uint64_t g_scheduler_period = 0; static uint32_t g_scheduler_core_number; static struct spdk_scheduler_core_info *g_core_infos = NULL; @@ -96,7 +97,7 @@ _scheduler_find(const char *name) } int -_spdk_scheduler_set(const char *name) +spdk_scheduler_set(const char *name) { struct spdk_scheduler *scheduler; int rc = 0; @@ -132,27 +133,27 @@ _spdk_scheduler_set(const char *name) } struct spdk_scheduler * -_spdk_scheduler_get(void) +spdk_scheduler_get(void) { return g_scheduler; } uint64_t -_spdk_scheduler_get_period(void) +spdk_scheduler_get_period(void) { /* Convert from ticks to microseconds */ return (g_scheduler_period * SPDK_SEC_TO_USEC / spdk_get_ticks_hz()); } void -_spdk_scheduler_set_period(uint64_t period) +spdk_scheduler_set_period(uint64_t period) { /* Convert microseconds to ticks */ g_scheduler_period = period * spdk_get_ticks_hz() / SPDK_SEC_TO_USEC; } void -_spdk_scheduler_register(struct spdk_scheduler *scheduler) +spdk_scheduler_register(struct spdk_scheduler *scheduler) { if (_scheduler_find(scheduler->name)) { SPDK_ERRLOG("scheduler named '%s' already registered.\n", scheduler->name); @@ -281,12 +282,6 @@ spdk_reactors_init(void) assert(reactor != NULL); g_scheduling_reactor = reactor; - /* set default scheduling period to one second */ - g_scheduler_period = spdk_get_ticks_hz(); - - rc = _spdk_scheduler_set("static"); - assert(rc == 0); - g_reactor_state = SPDK_REACTOR_STATE_INITIALIZED; return 0; @@ -302,8 +297,6 @@ spdk_reactors_fini(void) return; } - _spdk_scheduler_set(NULL); - spdk_thread_lib_fini(); SPDK_ENV_FOREACH_CORE(i) { @@ -767,7 +760,7 @@ _reactors_scheduler_cancel(void *arg1, void *arg2) static void _reactors_scheduler_balance(void *arg1, void *arg2) { - struct spdk_scheduler *scheduler = _spdk_scheduler_get(); + struct spdk_scheduler *scheduler = spdk_scheduler_get(); if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING || scheduler == NULL) { _reactors_scheduler_cancel(NULL, NULL); @@ -1493,7 +1486,7 @@ _governor_find(const char *name) } int -_spdk_governor_set(const char *name) +spdk_governor_set(const char *name) { struct spdk_governor *governor; int rc = 0; @@ -1528,13 +1521,13 @@ _spdk_governor_set(const char *name) } struct spdk_governor * -_spdk_governor_get(void) +spdk_governor_get(void) { return g_governor; } void -_spdk_governor_register(struct spdk_governor *governor) +spdk_governor_register(struct spdk_governor *governor) { if (_governor_find(governor->name)) { SPDK_ERRLOG("governor named '%s' already registered.\n", governor->name); diff --git a/lib/event/scheduler_static.c b/lib/event/scheduler_static.c index a29a9218c..4941e14cb 100644 --- a/lib/event/scheduler_static.c +++ b/lib/event/scheduler_static.c @@ -36,6 +36,7 @@ #include "spdk/event.h" #include "spdk/log.h" #include "spdk/env.h" +#include "spdk/scheduler.h" #include "spdk_internal/event.h" diff --git a/lib/event/spdk_event.map b/lib/event/spdk_event.map index b4a30f67c..2d6d0dd4e 100644 --- a/lib/event/spdk_event.map +++ b/lib/event/spdk_event.map @@ -17,6 +17,16 @@ spdk_framework_enable_context_switch_monitor; spdk_framework_context_switch_monitor_enabled; + # Public scheduler functions + spdk_scheduler_set; + spdk_scheduler_get; + spdk_scheduler_register; + spdk_scheduler_set_period; + spdk_scheduler_get_period; + spdk_governor_set; + spdk_governor_get; + spdk_governor_register; + # Functions used by other SPDK libraries spdk_reactors_init; spdk_reactors_fini; diff --git a/mk/spdk.lib.mk b/mk/spdk.lib.mk index 915e9d825..54992ba64 100644 --- a/mk/spdk.lib.mk +++ b/mk/spdk.lib.mk @@ -88,6 +88,7 @@ endif MODULES-bdev = spdk_bdev_modules MODULES-sock = spdk_sock_modules MODULES-accel = spdk_accel_modules +MODULES-scheduler = spdk_scheduler_modules ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV)) MODULES-event = spdk_env_dpdk_rpc endif diff --git a/mk/spdk.lib_deps.mk b/mk/spdk.lib_deps.mk index 7b35573c6..6fc6ac1c1 100644 --- a/mk/spdk.lib_deps.mk +++ b/mk/spdk.lib_deps.mk @@ -127,6 +127,15 @@ DEPDIRS-env_dpdk_rpc := log $(JSON_LIBS) DEPDIRS-sock_posix := log sock util DEPDIRS-sock_uring := log sock util +# module/scheduler +DEPDIRS-scheduler_dynamic := event log thread util +ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV)) +ifeq ($(OS),Linux) +DEPDIRS-scheduler_dpdk_governor := event log +DEPDIRS-scheduler_gscheduler := event log +endif +endif + # module/bdev DEPDIRS-bdev_gpt := bdev json log thread util @@ -166,10 +175,12 @@ DEPDIRS-event_vmd := init vmd $(JSON_LIBS) log thread DEPDIRS-event_bdev := init bdev event_accel event_vmd event_sock +DEPDIRS-event_scheduler := event init + DEPDIRS-event_nbd := init nbd event_bdev -DEPDIRS-event_nvmf := init nvmf event_bdev event_sock thread log bdev util $(JSON_LIBS) +DEPDIRS-event_nvmf := init nvmf event_bdev event_scheduler event_sock thread log bdev util $(JSON_LIBS) DEPDIRS-event_scsi := init scsi event_bdev -DEPDIRS-event_iscsi := init iscsi event_scsi event_sock -DEPDIRS-event_vhost := init vhost event_scsi +DEPDIRS-event_iscsi := init iscsi event_scheduler event_scsi event_sock +DEPDIRS-event_vhost := init vhost event_scheduler event_scsi DEPDIRS-event_sock := init sock diff --git a/mk/spdk.modules.mk b/mk/spdk.modules.mk index db177d81f..b944ea62b 100644 --- a/mk/spdk.modules.mk +++ b/mk/spdk.modules.mk @@ -118,7 +118,14 @@ ifeq ($(CONFIG_IDXD),y) ACCEL_MODULES_LIST += accel_idxd idxd endif +SCHEDULER_MODULES_LIST = scheduler_dynamic +ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV)) +ifeq ($(OS),Linux) +SCHEDULER_MODULES_LIST += env_dpdk scheduler_dpdk_governor scheduler_gscheduler +endif +endif + EVENT_BDEV_SUBSYSTEM = event_bdev event_accel event_vmd event_sock -ALL_MODULES_LIST = $(BLOCKDEV_MODULES_LIST) $(ACCEL_MODULES_LIST) $(SOCK_MODULES_LIST) +ALL_MODULES_LIST = $(BLOCKDEV_MODULES_LIST) $(ACCEL_MODULES_LIST) $(SCHEDULER_MODULES_LIST) $(SOCK_MODULES_LIST) SYS_LIBS += $(BLOCKDEV_MODULES_PRIVATE_LIBS) diff --git a/module/Makefile b/module/Makefile index 98b4b7757..3a509ca80 100644 --- a/module/Makefile +++ b/module/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk -DIRS-y = bdev blob blobfs accel event sock +DIRS-y = bdev blob blobfs accel event sock scheduler ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV)) DIRS-y += env_dpdk endif @@ -44,6 +44,7 @@ DEPDIRS-blob := DEPDIRS-accel := DEPDIRS-env_dpdk := DEPDIRS-sock := +DEPDIRS-scheduler := DEPDIRS-bdev := blob DEPDIRS-blobfs := blob DEPDIRS-event := bdev blob @@ -53,6 +54,7 @@ DEPDIRS-event := bdev blob BDEV_MODULES_PKGCONFIG = $(call pkgconfig_filename,spdk_bdev_modules) ACCEL_MODULES_PKGCONFIG = $(call pkgconfig_filename,spdk_accel_modules) SOCK_MODULES_PKGCONFIG = $(call pkgconfig_filename,spdk_sock_modules) +SCHEDULER_MODULES_PKGCONFIG = $(call pkgconfig_filename,spdk_scheduler_modules) SYSLIBS_PKGCONFIG = $(call pkgconfig_filename,spdk_syslibs) PRIVATE_SYSLIBS = $(SYS_LIBS) @@ -62,6 +64,7 @@ endif MODULES_PKGCONFIG = $(BDEV_MODULES_PKGCONFIG) $(ACCEL_MODULES_PKGCONFIG) MODULES_PKGCONFIG += $(SOCK_MODULES_PKGCONFIG) $(SYSLIBS_PKGCONFIG) +MODULES_PKGCONFIG += $(SCHEDULER_MODULES_PKGCONFIG) $(BDEV_MODULES_PKGCONFIG): $(Q)$(SPDK_ROOT_DIR)/scripts/pc_modules.sh bdev "$(BLOCKDEV_MODULES_LIST:%=spdk_%)" > $@ @@ -72,6 +75,9 @@ $(ACCEL_MODULES_PKGCONFIG): $(SOCK_MODULES_PKGCONFIG): $(Q)$(SPDK_ROOT_DIR)/scripts/pc_modules.sh sock "$(SOCK_MODULES_LIST:%=spdk_%)" > $@ +$(SCHEDULER_MODULES_PKGCONFIG): + $(Q)$(SPDK_ROOT_DIR)/scripts/pc_modules.sh scheduler "$(SCHEDULER_MODULES_LIST:%=spdk_%)" > $@ + $(SYSLIBS_PKGCONFIG): $(Q)$(SPDK_ROOT_DIR)/scripts/pc_libs.sh "" "$(PRIVATE_SYSLIBS)" System spdk_syslibs > $@ diff --git a/module/event/subsystems/Makefile b/module/event/subsystems/Makefile index 69c649cd7..971197d29 100644 --- a/module/event/subsystems/Makefile +++ b/module/event/subsystems/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y += bdev accel iscsi nvmf scsi vmd sock +DIRS-y += bdev accel iscsi nvmf scsi vmd scheduler sock ifeq ($(OS),Linux) DIRS-y += nbd diff --git a/module/event/subsystems/scheduler/Makefile b/module/event/subsystems/scheduler/Makefile new file mode 100644 index 000000000..0dc3443b7 --- /dev/null +++ b/module/event/subsystems/scheduler/Makefile @@ -0,0 +1,45 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +SO_VER := 1 +SO_MINOR := 0 + +C_SRCS = scheduler.c +LIBNAME = event_scheduler + +SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/module/event/subsystems/scheduler/scheduler.c b/module/event/subsystems/scheduler/scheduler.c new file mode 100644 index 000000000..cac7978bd --- /dev/null +++ b/module/event/subsystems/scheduler/scheduler.c @@ -0,0 +1,72 @@ +/*- + * 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/env.h" +#include "spdk/scheduler.h" + +#include "spdk_internal/event.h" +#include "spdk_internal/init.h" + +static void +scheduler_subsystem_init(void) +{ + int rc = 0; + + /* Set the defaults */ + if (spdk_scheduler_get() == NULL) { + rc = spdk_scheduler_set("static"); + } + if (spdk_scheduler_get_period() == 0) { + spdk_scheduler_set_period(SPDK_SEC_TO_USEC); + } + + spdk_subsystem_init_next(rc); +} + +static void +scheduler_subsystem_fini(void) +{ + spdk_scheduler_set_period(0); + spdk_scheduler_set(NULL); + + spdk_subsystem_fini_next(); +} + +static struct spdk_subsystem g_spdk_subsystem_scheduler = { + .name = "scheduler", + .init = scheduler_subsystem_init, + .fini = scheduler_subsystem_fini, +}; + +SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_scheduler); diff --git a/module/scheduler/Makefile b/module/scheduler/Makefile new file mode 100644 index 000000000..f4b08651b --- /dev/null +++ b/module/scheduler/Makefile @@ -0,0 +1,53 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +DIRS-y = scheduler_dynamic + +# Do not compile schedulers and governors based on DPDK env +# if non-DPDK env is used. +ENV_NAME := $(notdir $(CONFIG_ENV)) +ifeq ($(ENV_NAME),env_dpdk) +ifeq ($(OS),Linux) +DIRS-y += dpdk_governor gscheduler +endif +endif + +.PHONY: all clean $(DIRS-y) + +all: $(DIRS-y) +clean: $(DIRS-y) + +include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk diff --git a/module/scheduler/dpdk_governor/Makefile b/module/scheduler/dpdk_governor/Makefile new file mode 100644 index 000000000..5acf4ab3f --- /dev/null +++ b/module/scheduler/dpdk_governor/Makefile @@ -0,0 +1,47 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +SO_VER := 1 +SO_MINOR := 0 + +CFLAGS += $(ENV_CFLAGS) + +LIBNAME = scheduler_dpdk_governor +C_SRCS = dpdk_governor.c + +SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/event/dpdk_governor.c b/module/scheduler/dpdk_governor/dpdk_governor.c similarity index 99% rename from lib/event/dpdk_governor.c rename to module/scheduler/dpdk_governor/dpdk_governor.c index 3fcd4ebf6..53ce83181 100644 --- a/lib/event/dpdk_governor.c +++ b/module/scheduler/dpdk_governor/dpdk_governor.c @@ -35,6 +35,7 @@ #include "spdk/log.h" #include "spdk/env.h" #include "spdk/event.h" +#include "spdk/scheduler.h" #include "spdk_internal/event.h" diff --git a/module/scheduler/gscheduler/Makefile b/module/scheduler/gscheduler/Makefile new file mode 100644 index 000000000..8dc119c61 --- /dev/null +++ b/module/scheduler/gscheduler/Makefile @@ -0,0 +1,45 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +SO_VER := 1 +SO_MINOR := 0 + +LIBNAME = scheduler_gscheduler +C_SRCS = gscheduler.c + +SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/event/gscheduler.c b/module/scheduler/gscheduler/gscheduler.c similarity index 88% rename from lib/event/gscheduler.c rename to module/scheduler/gscheduler/gscheduler.c index cd2e17749..5c304f9a7 100644 --- a/lib/event/gscheduler.c +++ b/module/scheduler/gscheduler/gscheduler.c @@ -39,17 +39,18 @@ #include "spdk/log.h" #include "spdk/env.h" +#include "spdk/scheduler.h" static int init(void) { - return _spdk_governor_set("dpdk_governor"); + return spdk_governor_set("dpdk_governor"); } static void deinit(void) { - _spdk_governor_set(NULL); + spdk_governor_set(NULL); } static void @@ -61,7 +62,7 @@ balance(struct spdk_scheduler_core_info *cores, uint32_t core_count) uint32_t i; int rc; - governor = _spdk_governor_get(); + governor = spdk_governor_get(); assert(governor != NULL); /* Gather active/idle statistics */ @@ -79,29 +80,21 @@ balance(struct spdk_scheduler_core_info *cores, uint32_t core_count) if (rc < 0) { SPDK_ERRLOG("setting to minimal frequency for core %u failed\n", core->lcore); } - - SPDK_DEBUGLOG(reactor, "setting to minimal frequency for core: %u\n", core->lcore); } else if (core->total_idle_tsc > core->total_busy_tsc) { rc = governor->core_freq_down(core->lcore); if (rc < 0) { SPDK_ERRLOG("lowering frequency for core %u failed\n", core->lcore); } - - SPDK_DEBUGLOG(reactor, "lowering frequency for core: %u\n", core->lcore); } else if (core->total_idle_tsc < (core->total_busy_tsc / 1000)) { rc = governor->set_core_freq_max(core->lcore); if (rc < 0) { SPDK_ERRLOG("setting to maximal frequency for core %u failed\n", core->lcore); } - - SPDK_DEBUGLOG(reactor, "setting to maximum frequency for core: %u\n", core->lcore); } else { rc = governor->core_freq_up(core->lcore); if (rc < 0) { SPDK_ERRLOG("increasing frequency for core %u failed\n", core->lcore); } - - SPDK_DEBUGLOG(reactor, "increasing frequency for core: %u\n", core->lcore); } } } diff --git a/module/scheduler/scheduler_dynamic/Makefile b/module/scheduler/scheduler_dynamic/Makefile new file mode 100644 index 000000000..7bb47657e --- /dev/null +++ b/module/scheduler/scheduler_dynamic/Makefile @@ -0,0 +1,45 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +SO_VER := 1 +SO_MINOR := 0 + +LIBNAME = scheduler_dynamic +C_SRCS = scheduler_dynamic.c + +SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/event/scheduler_dynamic.c b/module/scheduler/scheduler_dynamic/scheduler_dynamic.c similarity index 98% rename from lib/event/scheduler_dynamic.c rename to module/scheduler/scheduler_dynamic/scheduler_dynamic.c index c460678b1..475a5e32a 100644 --- a/lib/event/scheduler_dynamic.c +++ b/module/scheduler/scheduler_dynamic/scheduler_dynamic.c @@ -39,6 +39,7 @@ #include "spdk/thread.h" #include "spdk_internal/event.h" +#include "spdk/scheduler.h" static uint32_t g_main_lcore; @@ -224,7 +225,7 @@ init(void) { g_main_lcore = spdk_env_get_current_core(); - if (_spdk_governor_set("dpdk_governor") != 0) { + if (spdk_governor_set("dpdk_governor") != 0) { SPDK_NOTICELOG("Unable to initialize dpdk governor\n"); } @@ -242,8 +243,7 @@ deinit(void) { free(g_cores); g_cores = NULL; - - _spdk_governor_set(NULL); + spdk_governor_set(NULL); } static void @@ -312,7 +312,7 @@ balance(struct spdk_scheduler_core_info *cores_info, uint32_t cores_count) } } - governor = _spdk_governor_get(); + governor = spdk_governor_get(); if (governor == NULL) { return; } diff --git a/test/event/scheduler/Makefile b/test/event/scheduler/Makefile index cd58c27e8..1a8130258 100644 --- a/test/event/scheduler/Makefile +++ b/test/event/scheduler/Makefile @@ -38,6 +38,6 @@ include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk APP = scheduler C_SRCS := scheduler.c -SPDK_LIB_LIST = $(ALL_MODULES_LIST) event event_bdev conf +SPDK_LIB_LIST = $(ALL_MODULES_LIST) event event_bdev conf event_scheduler include $(SPDK_ROOT_DIR)/mk/spdk.app.mk diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index 15e8e7e74..3bfbd0f6e 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -37,8 +37,9 @@ #include "common/lib/test_env.c" #include "event/reactor.c" #include "spdk/thread.h" +#include "spdk_internal/thread.h" #include "event/scheduler_static.c" -#include "event/scheduler_dynamic.c" +#include "../module/scheduler/scheduler_dynamic/scheduler_dynamic.c" struct spdk_thread * _spdk_get_app_thread(void) @@ -576,7 +577,7 @@ test_scheduler(void) CU_ASSERT(spdk_reactors_init() == 0); - _spdk_scheduler_set("dynamic"); + spdk_scheduler_set("dynamic"); for (i = 0; i < 3; i++) { spdk_cpuset_set_cpu(&g_reactor_core_mask, i, true); @@ -794,13 +795,14 @@ test_governor(void) MOCK_SET(spdk_env_get_current_core, 0); g_curr_freq = last_freq; - _spdk_governor_register(&governor); + spdk_governor_register(&governor); allocate_cores(2); CU_ASSERT(spdk_reactors_init() == 0); - _spdk_scheduler_set("dynamic"); + spdk_scheduler_set("dynamic"); + spdk_governor_set("dpdk_governor"); for (i = 0; i < 2; i++) { spdk_cpuset_set_cpu(&g_reactor_core_mask, i, true);