Commit 5c61089c authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/scheduler: Rewrite the balanced() test



Simplify the test to follow the scheduler period in order to check if
target thread is properly balanced among selected cpus.

Signed-off-by: default avatarMichal Berger <michalx.berger@intel.com>
Change-Id: I326ad1171ca00c3d171aebe95266c5e4998abad3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6337


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 23c8f667
Loading
Loading
Loading
Loading
+29 −39
Original line number Diff line number Diff line
@@ -85,10 +85,11 @@ busy() {
}

balanced() {
	xtrace_disable

	local thread cpu
	local extra_threads
	local sched_period=1 # default, 1s
	local active_cpu

	# Exclude main cpu
	fold_list_onto_array selected_cpus "${cpus[@]:1}"
@@ -99,53 +100,42 @@ balanced() {
		extra_threads+=("$(create_thread -n "thread_cpu_$cpu" -m "$(mask_cpus "$cpu")" -a 100)")
	done

	while ((samples++ < 5)); do
		# Change active state of the thread0 to make sure scheduler rebalances it across
		# avaialable cpus.
		if ((samples % 2)); then
	# thread0 is idle, wait for scheduler to run (2x scheduling period) and check if it is on main core
	sleep $((2 * sched_period))
	reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
	[[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework"

	# thread0 is active, wait for scheduler to run (2x) and check if it is not on main core
	active_thread "$thread0" 100
		else
			active_thread "$thread0" 0
		fi
	sleep $((2 * sched_period))
	reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')

		# Give scheduler some time to spin the cpu down|up
		sleep 0.5s
	[[ -z $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework"
	# Get the cpu thread was scheduled onto
	for cpu in "${selected_cpus[@]}"; do
		[[ -n $(jq -r "select(.lcore == $cpu) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework" && active_cpu=$cpu
	done
	[[ -n ${selected_cpus[active_cpu]} ]]

	# thread0 is idle, wait for scheduler to run (2x) and check if it is on main core
	active_thread "$thread0" 0
	sleep $((2 * sched_period))
	reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
		printf '* Sample %u\n' "$samples"
		# Include main cpu to check if thread is put back on it
		for cpu in "$spdk_main_core" "${selected_cpus[@]}"; do
			threads=($(jq -r "select(.lcore == $cpu) | .lw_threads[].id" <<< "$reactor_framework"))

			if ((${#threads[@]} == 0)); then
				printf '  No threads found on cpu%u\n' "$cpu"
				continue
			fi
	[[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework"

			get_thread_stats
	# thread0 is active, wait for scheduler to run (2x) and check if it is not on main core, nor the core from 2)
	active_thread "$thread0" 100
	sleep $((2 * sched_period))
	reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')

			for thread in "${threads[@]}"; do
				load=$((busy[thread] * 100 / (busy[thread] + idle[thread])))
				printf '  Thread %u (%s) on cpu%u; load: %u%%\n' \
					"$thread" "${thread_map[thread]}" "$cpu" "$load"
				eval "${thread_map[thread]}_cpus[$cpu]=$cpu"
			done
		done
	done
	[[ -z $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framewrk"
	[[ -z $(jq -r "select(.lcore == $active_cpu) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framewrk"

	destroy_thread "$thread0"
	for thread in "${extra_threads[@]}"; do
		destroy_thread "$thread"
	done

	# main cpu + at least 2 designated cpus
	((${#thread0_cpus[@]} > 2))
	# main cpu must be present
	[[ -n ${thread0_cpus[spdk_main_core]} ]]
	printf 'Thread %u (%s) rebalanced across cpus: %s\n' \
		"$thread0" "${thread_map[thread0]}" "${thread0_cpus[*]}"

	xtrace_restore
}

exec_under_dynamic_scheduler "$scheduler" -m "$spdk_cpusmask" --main-core "$spdk_main_core"