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