Commit 2d79bf58 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Jim Harris
Browse files

scheduler_dynamic: balance idle threads in separate pass



Idle threads are always moved to main core, there are no
other considations. Doing it as separate first pass,
allows to have the core stats be up to date for second
pass for active threads.

Core load stats will be used later in the series to determine
optimal target core for an active thread.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I6a9bc11b86e954e461f7badebf3a6e4d1718f63c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8067


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent e209981d
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -205,21 +205,28 @@ deinit(struct spdk_governor *governor)
}

static void
_balance_thread(struct spdk_lw_thread *lw_thread)
_balance_idle(struct spdk_lw_thread *lw_thread)
{
	uint32_t target_lcore;
	uint8_t load;

	load = _get_thread_load(lw_thread);
	if (load < SCHEDULER_LOAD_LIMIT) {
	if (_get_thread_load(lw_thread) >= SCHEDULER_LOAD_LIMIT) {
		return;
	}
	/* This thread is idle, move it to the main core. */
	_move_thread(lw_thread, g_main_lcore);
	} else {
}

static void
_balance_active(struct spdk_lw_thread *lw_thread)
{
	uint32_t target_lcore;

	if (_get_thread_load(lw_thread) < SCHEDULER_LOAD_LIMIT) {
		return;
	}

	/* This thread is active. */
	target_lcore = _find_optimal_core(lw_thread);
	_move_thread(lw_thread, target_lcore);
}
}

static void
balance(struct spdk_scheduler_core_info *cores_info, int cores_count,
@@ -239,8 +246,11 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count,
	}
	main_core = &g_cores[g_main_lcore];

	/* Distribute active threads across all cores and move idle threads to main core */
	_foreach_thread(cores_info, _balance_thread);
	/* Distribute threads in two passes, to make sure updated core stats are considered on each pass.
	 * 1) Move all idle threads to main core. */
	_foreach_thread(cores_info, _balance_idle);
	/* 2) Distribute active threads across all cores. */
	_foreach_thread(cores_info, _balance_active);

	/* Switch unused cores to interrupt mode and switch cores to polled mode
	 * if they will be used after rebalancing */