xref: /spdk/test/scheduler/interrupt.sh (revision eb53c23236cccb6b698b7ca70ee783da1c574b5f)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2021 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f "$(dirname "$0")")
7rootdir=$(readlink -f "$testdir/../../")
8
9source "$rootdir/test/common/autotest_common.sh"
10source "$testdir/common.sh"
11
12trap 'killprocess "$spdk_pid"' EXIT
13
14declare -a cpus=()
15declare -a cpus_to_collect=()
16
17fold_list_onto_array cpus $(parse_cpu_list <(echo "$spdk_cpus_csv"))
18# Normalize the indexes
19cpus=("${cpus[@]}")
20
21interrupt() {
22	local busy_cpus
23	local cpu thread
24
25	local reactor_framework
26
27	cpus_to_collect=("${cpus[@]}")
28	collect_cpu_idle
29
30	# Verify that each cpu, except the main cpu, has no threads assigned
31	reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
32	for cpu in "${cpus[@]:1}"; do
33		[[ -z $(jq -r "select(.lcore == $cpu) | .lw_threads[].id" <<< "$reactor_framework") ]]
34	done
35
36	# Standard scenario - spdk app is idle, all cpus, except the main cpu, should be
37	# switched into interrupt mode. main cpu should remain busy, all remaining cpus
38	# should become idle.
39	for cpu in "${!is_idle[@]}"; do
40		if ((cpu == spdk_main_core)); then
41			((is_idle[cpu] == 0)) # main cpu must not be idle
42		fi
43		if ((cpu != spdk_main_core)); then
44			((is_idle[cpu] == 1)) # all cpus except the main cpu must be idle
45		fi
46	done
47
48	# select 3 cpus except the main one
49	busy_cpus=("${cpus[@]:1:3}") threads=()
50
51	# Create busy thread on each of the selected cpus, then verify if given cpu has become busy
52	# and that newly created thread was assigned to a proper lcore.
53	for cpu in "${busy_cpus[@]}"; do
54		threads[cpu]=$(create_thread -n "thread$cpu" -m "$(mask_cpus "$cpu")" -a 100) cpus_to_collect=("$cpu")
55		collect_cpu_idle
56		reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
57		[[ -n $(jq -r "select(.lcore == $cpu) | .lw_threads[] | select(.name == \"thread$cpu\")" <<< "$reactor_framework") ]]
58		((is_idle[cpu] == 0))
59	done
60
61	# Make all the threads idle and verify if their cpus have become idle as well and if they were
62	# moved away out of their lcores.
63	for cpu in "${!threads[@]}"; do
64		active_thread "${threads[cpu]}" 0
65		cpus_to_collect=("$cpu")
66		collect_cpu_idle
67		reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]')
68		[[ -z $(jq -r "select(.lcore == $cpu) | .lw_threads[].id" <<< "$reactor_framework") ]]
69		[[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.name == \"thread$cpu\")" <<< "$reactor_framework") ]]
70		((is_idle[cpu] == 1))
71	done
72
73	for cpu in "${!threads[@]}"; do
74		destroy_thread "${threads[cpu]}"
75	done
76}
77
78exec_under_dynamic_scheduler "$scheduler" -m "$spdk_cpumask" --main-core "$spdk_main_core"
79
80interrupt
81