xref: /spdk/test/scheduler/idle.sh (revision 79c52a64269385b9a8b53c2fe03e2343160d38b3)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2020 Intel Corporation
4#  All rights reserved.
5#
6
7testdir=$(readlink -f "$(dirname "$0")")
8rootdir=$(readlink -f "$testdir/../../")
9
10source "$rootdir/test/common/autotest_common.sh"
11source "$testdir/common.sh"
12
13trap 'killprocess "$spdk_pid"' EXIT
14
15thread_stats() {
16	local thread load
17	busy_threads=0
18
19	get_thread_stats_current
20
21	# Simply verify if threads stay idle
22	for thread in "${!thread_map[@]}"; do
23		printf '[load:%3u%%, idle:%10u, busy:%10u] ' \
24			$((busy[thread] * 100 / (busy[thread] + idle[thread]))) \
25			"${idle[thread]}" "${busy[thread]}"
26		if ((idle[thread] < busy[thread])); then
27			printf 'Waiting for %s to become idle\n' "${thread_map[thread]}"
28			((++busy_threads))
29		else
30			printf '%s is idle\n' "${thread_map[thread]}"
31		fi
32	done
33}
34
35idle() {
36	local reactor_framework
37	local reactors thread
38	local thread_cpumask
39	local threads
40
41	exec_under_dynamic_scheduler "${SPDK_APP[@]}" -m "$spdk_cpumask" --main-core "$spdk_main_core"
42
43	# The expectation here is that when SPDK app is idle the following is true:
44	# - all threads are assigned to main lcore
45	# - threads are not being moved between lcores
46
47	# Get first set of stats, to exclude initialization from the busy/idle
48	get_thread_stats_current
49
50	xtrace_disable
51	while ((samples++ < 5)); do
52		cpumask=0
53		reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
54		threads=($(
55			jq -r "select(.lcore == $spdk_main_core) | .lw_threads[].name" <<< "$reactor_framework"
56		))
57
58		for thread in "${threads[@]}"; do
59			thread_cpumask=0x$(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.name == \"$thread\") | .cpumask" <<< "$reactor_framework")
60			printf 'SPDK cpumask: %s Thread %s cpumask: %s\n' "$spdk_cpumask" "$thread" "$thread_cpumask"
61		done
62
63		thread_stats
64
65		((busy_threads == 0))
66	done
67
68	xtrace_restore
69}
70
71idle
72