Commit 118c273a authored by Jim Harris's avatar Jim Harris Committed by Konrad Sztyber
Browse files

event: enable changing back to static scheduler



This requires saving the original core for each thread. Thankfully
it is very easy to just store it in the spdk_lw_thread. Then we
just run ->balance() once after the static scheduler is re-installed
to put all of the threads back to their original lcores, and take
all cores out of interrupt mode.

Note: 82c466 required bumping SO_VER due to adding trace_id to
struct spdk_reactor. But that didn't change the size of the structure.
For some unexplained reason, adding initial_lcore to the private
struct lw_thread in this patch results in abidiff no longer reporting
the trace_id change, and check_so_deps.sh fails saying the SO_VER
bump is no longer needed. A patch that simply adds the initial_lcore
member, with no other code changes, triggers the same error.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I9d1ace726617d95f89f42959c9c2c36602fb7f77
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24765


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 7e6d8079
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 15
SO_VER := 14
SO_MINOR := 0

CFLAGS += $(ENV_CFLAGS) -Wno-address-of-packed-member
+1 −12
Original line number Diff line number Diff line
@@ -464,7 +464,7 @@ rpc_framework_set_scheduler(struct spdk_jsonrpc_request *request,
			    const struct spdk_json_val *params)
{
	struct rpc_set_scheduler_ctx req = {NULL};
	struct spdk_scheduler *scheduler = NULL;
	struct spdk_scheduler *scheduler;
	bool has_custom_opts = false;
	int ret;

@@ -483,17 +483,6 @@ rpc_framework_set_scheduler(struct spdk_jsonrpc_request *request,
		goto end;
	}

	scheduler = spdk_scheduler_get();
	/* SPDK does not support changing scheduler back to static. */
	if (scheduler != NULL && (strcmp(req.name, "static") == 0) &&
	    strcmp(scheduler->name, "static") != 0) {
		spdk_jsonrpc_send_error_response(request,
						 SPDK_JSONRPC_ERROR_INVALID_PARAMS,
						 "Static scheduler cannot be re-enabled "
						 "after a different scheduler was selected");
		goto end;
	}

	if (req.period != 0) {
		spdk_scheduler_set_period(req.period);
	} else if (spdk_scheduler_get_period() == 0) {
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ struct spdk_lw_thread {
	TAILQ_ENTRY(spdk_lw_thread)	link;
	uint64_t			tsc_start;
	uint32_t                        lcore;
	uint32_t			initial_lcore;
	bool				resched;
	/* stats over a lifetime of a thread */
	struct spdk_thread_stats	total_stats;
+7 −1
Original line number Diff line number Diff line
@@ -1206,6 +1206,9 @@ _schedule_thread(void *arg1, void *arg2)
	spdk_thread_get_stats(&lw_thread->total_stats);
	spdk_set_thread(NULL);

	if (lw_thread->initial_lcore == SPDK_ENV_LCORE_ID_ANY) {
		lw_thread->initial_lcore = current_core;
	}
	lw_thread->lcore = current_core;

	TAILQ_INSERT_TAIL(&reactor->threads, lw_thread, link);
@@ -1231,7 +1234,7 @@ _schedule_thread(void *arg1, void *arg2)
static int
_reactor_schedule_thread(struct spdk_thread *thread)
{
	uint32_t core;
	uint32_t core, initial_core;
	struct spdk_lw_thread *lw_thread;
	struct spdk_event *evt = NULL;
	struct spdk_cpuset *cpumask;
@@ -1246,7 +1249,9 @@ _reactor_schedule_thread(struct spdk_thread *thread)
	lw_thread = spdk_thread_get_ctx(thread);
	assert(lw_thread != NULL);
	core = lw_thread->lcore;
	initial_core = lw_thread->initial_lcore;
	memset(lw_thread, 0, sizeof(*lw_thread));
	lw_thread->initial_lcore = initial_core;

	if (current_lcore != SPDK_ENV_LCORE_ID_ANY) {
		local_reactor = spdk_reactor_get(current_lcore);
@@ -1363,6 +1368,7 @@ reactor_thread_op(struct spdk_thread *thread, enum spdk_thread_op op)
	case SPDK_THREAD_OP_NEW:
		lw_thread = spdk_thread_get_ctx(thread);
		lw_thread->lcore = SPDK_ENV_LCORE_ID_ANY;
		lw_thread->initial_lcore = SPDK_ENV_LCORE_ID_ANY;
		return _reactor_schedule_thread(thread);
	case SPDK_THREAD_OP_RESCHED:
		_reactor_request_thread_reschedule(thread);
+38 −3
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2020 Intel Corporation.
 *   Copyright (C) 2024 Samsung Electronics Co., Ltd.
 *   All rights reserved.
 */

@@ -11,24 +12,58 @@
#include "spdk/scheduler.h"

#include "spdk_internal/event.h"
#include "event_internal.h"

static bool g_first_load = true;

static int
init_static(void)
{
	if (g_first_load) {
		/* There is no scheduling performed by static scheduler,
		 * do not set the scheduling period. */
		spdk_scheduler_set_period(0);
	} else {
		/* Schedule a balance to happen immediately, so that
		 * we can reset each thread's lcore back to its original
		 * state.
		 */
		spdk_scheduler_set_period(1);
	}

	return 0;
}

static void
deinit_static(void)
{
	g_first_load = false;
}

static void
balance_static(struct spdk_scheduler_core_info *cores, uint32_t core_count)
{
	struct spdk_scheduler_core_info *core_info;
	struct spdk_scheduler_thread_info *thread_info;
	struct spdk_lw_thread *lw_thread;
	struct spdk_thread *thread;
	uint32_t i, j;

	for (i = 0; i < core_count; i++) {
		core_info = &cores[i];
		core_info->interrupt_mode = false;
		for (j = 0; j < core_info->threads_count; j++) {
			thread_info = &core_info->thread_infos[j];
			thread = spdk_thread_get_by_id(thread_info->thread_id);
			lw_thread = spdk_thread_get_ctx(thread);
			thread_info->lcore = lw_thread->initial_lcore;
		}
	}

	/* We've restored the original state now, so we don't need to
	 * balance() anymore.
	 */
	spdk_scheduler_set_period(0);
}

static struct spdk_scheduler scheduler = {
Loading