xref: /spdk/test/interrupt/interrupt_common.sh (revision 32999ab917f67af61872f868585fd3d78ad6fb8a)
1testdir=$(readlink -f $(dirname $0))
2rootdir=$(readlink -f $testdir/../..)
3source $rootdir/test/common/autotest_common.sh
4
5rpc_py="$rootdir/scripts/rpc.py"
6
7r0_mask=0x1
8r1_mask=0x2
9r2_mask=0x4
10
11cpu_server_mask=0x07
12rpc_server_addr="/var/tmp/spdk.sock"
13
14function cleanup() {
15	rm -f "$SPDK_TEST_STORAGE/aiofile"
16}
17
18function start_intr_tgt() {
19	local rpc_addr="${1:-$rpc_server_addr}"
20	local cpu_mask="${2:-$cpu_server_mask}"
21
22	"$SPDK_EXAMPLE_DIR/interrupt_tgt" -m $cpu_mask -r $rpc_addr -E -g &
23	intr_tgt_pid=$!
24	trap 'killprocess "$intr_tgt_pid"; cleanup; exit 1' SIGINT SIGTERM EXIT
25	waitforlisten "$intr_tgt_pid" $rpc_addr
26}
27
28function reactor_is_busy_or_idle() {
29	local pid=$1
30	local idx=$2
31	local state=$3
32
33	if [[ $state != "busy" ]] && [[ $state != "idle" ]]; then
34		return 1
35	fi
36
37	if ! hash top; then
38		# Fail this test if top is missing from system.
39		return 1
40	fi
41
42	for ((j = 10; j != 0; j--)); do
43		top_reactor=$(top -bHn 1 -p $pid -w 256 | grep reactor_$idx)
44		cpu_rate=$(echo $top_reactor | sed -e 's/^\s*//g' | awk '{print $9}')
45		cpu_rate=${cpu_rate%.*}
46
47		if [[ $state = "busy" ]] && [[ $cpu_rate -lt 70 ]]; then
48			sleep 1
49		elif [[ $state = "idle" ]] && [[ $cpu_rate -gt 30 ]]; then
50			sleep 1
51		else
52			return 0
53		fi
54	done
55
56	if [[ $state = "busy" ]]; then
57		echo "cpu rate ${cpu_rate} of reactor $i probably is not busy polling"
58	else
59		echo "cpu rate ${cpu_rate} of reactor $i probably is not idle interrupt"
60	fi
61
62	return 1
63}
64
65function reactor_is_busy() {
66	reactor_is_busy_or_idle $1 $2 "busy"
67}
68
69function reactor_is_idle() {
70	reactor_is_busy_or_idle $1 $2 "idle"
71}
72
73function reactor_get_thread_ids() {
74	local reactor_cpumask=$1
75	local grep_str
76
77	reactor_cpumask=$((reactor_cpumask))
78	jq_str='.threads|.[]|select(.cpumask == $reactor_cpumask)|.id'
79
80	# shellcheck disable=SC2005
81	echo "$($rpc_py thread_get_stats | jq --arg reactor_cpumask "$reactor_cpumask" "$jq_str")"
82
83}
84
85function setup_bdev_mem() {
86	"$rpc_py" <<- RPC
87		bdev_malloc_create -b Malloc0 32 512
88		bdev_malloc_create -b Malloc1 32 512
89		bdev_malloc_create -b Malloc2 32 512
90	RPC
91}
92
93function setup_bdev_aio() {
94	if [[ $(uname -s) != "FreeBSD" ]]; then
95		dd if=/dev/zero of="$SPDK_TEST_STORAGE/aiofile" bs=2048 count=5000
96		"$rpc_py" bdev_aio_create "$SPDK_TEST_STORAGE/aiofile" AIO0 2048
97	fi
98}
99