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: Michal Berger <michalx.berger@intel.com>
Change-Id: I326ad1171ca00c3d171aebe95266c5e4998abad3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6337
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Michal Berger 2021-02-09 15:50:57 +01:00 committed by Tomasz Zawadzki
parent 23c8f667a2
commit 5c61089ca2

View File

@ -85,10 +85,11 @@ busy() {
} }
balanced() { balanced() {
xtrace_disable
local thread cpu local thread cpu
local extra_threads local extra_threads
local sched_period=1 # default, 1s
local active_cpu
# Exclude main cpu # Exclude main cpu
fold_list_onto_array selected_cpus "${cpus[@]:1}" 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)") extra_threads+=("$(create_thread -n "thread_cpu_$cpu" -m "$(mask_cpus "$cpu")" -a 100)")
done done
while ((samples++ < 5)); do # thread0 is idle, wait for scheduler to run (2x scheduling period) and check if it is on main core
# Change active state of the thread0 to make sure scheduler rebalances it across sleep $((2 * sched_period))
# avaialable cpus.
if ((samples % 2)); then
active_thread "$thread0" 100
else
active_thread "$thread0" 0
fi
# Give scheduler some time to spin the cpu down|up
sleep 0.5s
reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
printf '* Sample %u\n' "$samples" [[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework"
# 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 # thread0 is active, wait for scheduler to run (2x) and check if it is not on main core
printf ' No threads found on cpu%u\n' "$cpu" active_thread "$thread0" 100
continue sleep $((2 * sched_period))
fi reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
get_thread_stats [[ -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]} ]]
for thread in "${threads[@]}"; do # thread0 is idle, wait for scheduler to run (2x) and check if it is on main core
load=$((busy[thread] * 100 / (busy[thread] + idle[thread]))) active_thread "$thread0" 0
printf ' Thread %u (%s) on cpu%u; load: %u%%\n' \ sleep $((2 * sched_period))
"$thread" "${thread_map[thread]}" "$cpu" "$load" reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
eval "${thread_map[thread]}_cpus[$cpu]=$cpu"
done [[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.id == $thread0)") ]] <<< "$reactor_framework"
done
done # 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[]')
[[ -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" destroy_thread "$thread0"
for thread in "${extra_threads[@]}"; do for thread in "${extra_threads[@]}"; do
destroy_thread "$thread" destroy_thread "$thread"
done 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" exec_under_dynamic_scheduler "$scheduler" -m "$spdk_cpusmask" --main-core "$spdk_main_core"