xref: /spdk/test/nvme/interrupt.sh (revision 9885e1d29461136e0bbecfbad884844ef094c5c8)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2024 Samsung Electronics Co., Ltd.
4#  All rights reserved.
5#
6testdir=$(readlink -f "$(dirname "$0")")
7rootdir=$(readlink -f "$testdir/../../")
8source "$rootdir/test/common/autotest_common.sh"
9source "$rootdir/test/scheduler/common.sh"
10
11CPU_UTIL_INTR_THRESHOLD=10
12CPU_UTIL_POLL_THRESHOLD=95
13
14bdev_nvme_attach_ctrlr() {
15	rpc_cmd bdev_nvme_attach_controller --name Nvme0 --trtype PCIe --traddr "$1"
16}
17
18# Abort the test in case no nvmes are found
19nvmes=($(nvme_in_userspace))
20nvme=${nvmes[0]}
21
22# Abort here as vfio-pci is hard dependency for interrupts
23[[ -e /sys/bus/pci/drivers/vfio-pci/$nvme/vfio-dev ]]
24
25nvme_pcie_intr_mode() {
26	local cpu_util_pre cpu_util_post cpu_util_io
27	local bdevperfpy_pid
28	$rootdir/build/examples/bdevperf -z -q 1 -o 262144 -t 10 -w read -m 0x1 --interrupt-mode &
29	bdevperf_pid=$!
30
31	waitforlisten $bdevperf_pid
32	trap 'killprocess $bdevperf_pid; exit 1' SIGINT SIGTERM EXIT
33
34	bdev_nvme_attach_ctrlr "$nvme"
35	cpu_util_pre=$(spdk_pid=$bdevperf_pid get_spdk_proc_time 5 0)
36
37	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
38	bdevperfpy_pid=$!
39	sleep 1
40
41	cpu_util_io=$(spdk_pid=$bdevperf_pid get_spdk_proc_time 8 0)
42	wait "$bdevperfpy_pid"
43	cpu_util_post=$(spdk_pid=$bdevperf_pid get_spdk_proc_time 5 0)
44
45	trap - SIGINT SIGTERM EXIT
46	killprocess $bdevperf_pid
47
48	cat <<- SUMMARY
49		pre CPU util: $cpu_util_pre
50		IO CPU util: $cpu_util_io
51		post CPU util: $cpu_util_post
52	SUMMARY
53
54	# Make sure that the main expectation of having low cpu load before and after tests is met.
55	# FIXME: Measuring cpu load during IO seems to be flaky and dependent on multiple factors.
56	# It's been noticed that even change in SPDK's cpu mask, io size, etc. may significantly
57	# impact the result. With that in mind, we verify only the base and for perform_tests we
58	# simply report the overall CPU usage for debugging purposes.
59	((cpu_util_pre < CPU_UTIL_INTR_THRESHOLD && cpu_util_post < CPU_UTIL_INTR_THRESHOLD))
60}
61
62nvme_pcie_poll_mode() {
63	local cpu_util
64	$rootdir/build/examples/bdevperf -z -q 1 -o 262144 -t 10 -w read -m 0x1 &
65	bdevperf_pid=$!
66
67	waitforlisten $bdevperf_pid
68	trap 'killprocess $bdevperf_pid; exit 1' SIGINT SIGTERM EXIT
69
70	bdev_nvme_attach_ctrlr "$nvme"
71	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
72	sleep 1
73
74	cpu_util=$(spdk_pid=$bdevperf_pid get_spdk_proc_time 8 0)
75
76	trap - SIGINT SIGTERM EXIT
77	killprocess $bdevperf_pid
78
79	if ((cpu_util < CPU_UTIL_POLL_THRESHOLD)); then
80		return 1
81	fi
82}
83
84run_test "nvme_pcie_intr_mode" nvme_pcie_intr_mode
85run_test "nvme_pcie_poll_mode" nvme_pcie_poll_mode
86