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