xref: /linux/tools/testing/selftests/ublk/test_generic_12.sh (revision ec2e0fb07d789976c601bec19ecced7a501c3705)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5
6TID="generic_12"
7ERR_CODE=0
8
9if ! _have_program bpftrace; then
10	exit "$UBLK_SKIP_CODE"
11fi
12
13if ! _have_program fio; then
14	exit "$UBLK_SKIP_CODE"
15fi
16
17_prep_test "null" "do imbalanced load, it should be balanced over I/O threads"
18
19NTHREADS=6
20dev_id=$(_add_ublk_dev -t null -q 4 -d 16 --nthreads $NTHREADS --per_io_tasks)
21_check_add_dev $TID $?
22
23dev_t=$(_get_disk_dev_t "$dev_id")
24bpftrace trace/count_ios_per_tid.bt "$dev_t" > "$UBLK_TMP" 2>&1 &
25btrace_pid=$!
26sleep 2
27
28if ! kill -0 "$btrace_pid" > /dev/null 2>&1; then
29	_cleanup_test "null"
30	exit "$UBLK_SKIP_CODE"
31fi
32
33# do imbalanced I/O on the ublk device
34# pin to cpu 0 to prevent migration/only target one queue
35fio --name=write_seq \
36    --filename=/dev/ublkb"${dev_id}" \
37    --ioengine=libaio --iodepth=16 \
38    --rw=write \
39    --size=512M \
40    --direct=1 \
41    --bs=4k \
42    --cpus_allowed=0 > /dev/null 2>&1
43ERR_CODE=$?
44kill "$btrace_pid"
45wait
46
47# check that every task handles some I/O, even though all I/O was issued
48# from a single CPU. when ublk gets support for round-robin tag
49# allocation, this check can be strengthened to assert that every thread
50# handles the same number of I/Os
51NR_THREADS_THAT_HANDLED_IO=$(grep -c '@' ${UBLK_TMP})
52if [[ $NR_THREADS_THAT_HANDLED_IO -ne $NTHREADS ]]; then
53        echo "only $NR_THREADS_THAT_HANDLED_IO handled I/O! expected $NTHREADS"
54        cat "$UBLK_TMP"
55        ERR_CODE=255
56fi
57
58_cleanup_test "null"
59_show_result $TID $ERR_CODE
60