Skip to content

Commit 236918d

Browse files
ps-ushankaraxboe
authored andcommitted
selftests: ublk: add functional test for per io daemons
Add a new test test_generic_12 which: - sets up a ublk server with per_io_tasks and a different number of ublk server threads and ublk_queues. This is possible now that these objects are decoupled - runs some I/O load from a single CPU - verifies that all the ublk server threads handle some I/O Before this changeset, this test fails, since I/O issued from one CPU is always handled by the one ublk server thread. After this changeset, the test passes. In the future, the last check above may be strengthened to "verify that all ublk server threads handle the same amount of I/O." However, this requires some adjustments/bugfixes to tag allocation, so this work is postponed to a followup. Signed-off-by: Uday Shankar <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent abe54c1 commit 236918d

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TEST_PROGS += test_generic_08.sh
1919
TEST_PROGS += test_generic_09.sh
2020
TEST_PROGS += test_generic_10.sh
2121
TEST_PROGS += test_generic_11.sh
22+
TEST_PROGS += test_generic_12.sh
2223

2324
TEST_PROGS += test_null_01.sh
2425
TEST_PROGS += test_null_02.sh
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_12"
7+
ERR_CODE=0
8+
9+
if ! _have_program bpftrace; then
10+
exit "$UBLK_SKIP_CODE"
11+
fi
12+
13+
_prep_test "null" "do imbalanced load, it should be balanced over I/O threads"
14+
15+
NTHREADS=6
16+
dev_id=$(_add_ublk_dev -t null -q 4 -d 16 --nthreads $NTHREADS --per_io_tasks)
17+
_check_add_dev $TID $?
18+
19+
dev_t=$(_get_disk_dev_t "$dev_id")
20+
bpftrace trace/count_ios_per_tid.bt "$dev_t" > "$UBLK_TMP" 2>&1 &
21+
btrace_pid=$!
22+
sleep 2
23+
24+
if ! kill -0 "$btrace_pid" > /dev/null 2>&1; then
25+
_cleanup_test "null"
26+
exit "$UBLK_SKIP_CODE"
27+
fi
28+
29+
# do imbalanced I/O on the ublk device
30+
# pin to cpu 0 to prevent migration/only target one queue
31+
fio --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
39+
ERR_CODE=$?
40+
kill "$btrace_pid"
41+
wait
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
47+
NR_THREADS_THAT_HANDLED_IO=$(grep -c '@' ${UBLK_TMP})
48+
if [[ $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
52+
fi
53+
54+
_cleanup_test "null"
55+
_show_result $TID $ERR_CODE
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Tabulates and prints I/O completions per thread for the given device
3+
*
4+
* $1: dev_t
5+
*/
6+
tracepoint:block:block_rq_complete
7+
{
8+
if (args.dev == $1) {
9+
@[tid] = count();
10+
}
11+
}

0 commit comments

Comments
 (0)