From: Yoav Cohen <yoav@nvidia.com>
To: Ming Lei <ming.lei@redhat.com>, Jens Axboe <axboe@kernel.dk>,
<linux-block@vger.kernel.org>, <csander@purestorage.com>
Cc: <jholzman@nvidia.com>, <omril@nvidia.com>, <ofer@nvidia.com>,
Yoav Cohen <yoav@nvidia.com>
Subject: [PATCH v4 2/2] selftests: ublk: add rq_affinity test
Date: Wed, 28 Oct 2026 15:18:29 +0200 [thread overview]
Message-ID: <20261028131829.45803-3-yoav@nvidia.com> (raw)
In-Reply-To: <20261028131829.45803-1-yoav@nvidia.com>
Add UBLK_F_SUPPORT_RQ_AFFINITY to kublk's feature table, a
--rq_affinity option, and a test that writes and verifies data on a
single-queue loop device with rq_affinity set to 0, 1 and 2.
kublk pins the queue thread to the first CPU of the hctx, so submit
from the last CPU in cpu_list. That way rq_affinity=2 always takes the
remote completion path.
Signed-off-by: Yoav Cohen <yoav@nvidia.com>
---
tools/testing/selftests/ublk/Makefile | 1 +
tools/testing/selftests/ublk/kublk.c | 6 ++-
.../testing/selftests/ublk/test_generic_19.sh | 49 +++++++++++++++++++
3 files changed, 55 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/ublk/test_generic_19.sh
diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile
index fc64b8f02833..21941071a35a 100644
--- a/tools/testing/selftests/ublk/Makefile
+++ b/tools/testing/selftests/ublk/Makefile
@@ -20,6 +20,7 @@ TEST_PROGS += test_generic_13.sh
TEST_PROGS += test_generic_16.sh
TEST_PROGS += test_generic_17.sh
TEST_PROGS += test_generic_18.sh
+TEST_PROGS += test_generic_19.sh
TEST_PROGS += test_batch_01.sh
TEST_PROGS += test_batch_02.sh
diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index 5a4ff689c1f7..ad42bb099d5b 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -1812,6 +1812,7 @@ static int cmd_dev_get_features(void)
FEAT_NAME(UBLK_F_NO_AUTO_PART_SCAN),
FEAT_NAME(UBLK_F_SHMEM_ZC),
FEAT_NAME(UBLK_F_IO_DESC_SIZE),
+ FEAT_NAME(UBLK_F_SUPPORT_RQ_AFFINITY),
};
struct ublk_dev *dev;
__u64 features = 0;
@@ -1909,7 +1910,7 @@ static void __cmd_create_help(char *exe, bool recovery)
printf("\t[--nthreads threads] [--per_io_tasks]\n");
printf("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
"[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n");
- printf("\t[--batch|-b] [--rotate_auto_buf] [--no_auto_part_scan]\n");
+ printf("\t[--batch|-b] [--rotate_auto_buf] [--no_auto_part_scan] [--rq_affinity]\n");
printf("\t[--io_desc_size SIZE]\n");
printf("\t[target options] [backfile1] [backfile2] ...\n");
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
@@ -1989,6 +1990,7 @@ int main(int argc, char *argv[])
{ "batch", 0, NULL, 'b'},
{ "rotate_auto_buf", 0, NULL, 0 },
{ "no_auto_part_scan", 0, NULL, 0 },
+ { "rq_affinity", 0, NULL, 0 },
{ "shmem_zc", 0, NULL, 0 },
{ "htlb", 1, NULL, 0 },
{ "rdonly_shmem_buf", 0, NULL, 0 },
@@ -2136,6 +2138,8 @@ int main(int argc, char *argv[])
ctx.safe_stop = 1;
if (!strcmp(longopts[option_idx].name, "no_auto_part_scan"))
ctx.flags |= UBLK_F_NO_AUTO_PART_SCAN;
+ if (!strcmp(longopts[option_idx].name, "rq_affinity"))
+ ctx.flags |= UBLK_F_SUPPORT_RQ_AFFINITY;
if (!strcmp(longopts[option_idx].name, "shmem_zc"))
ctx.flags |= UBLK_F_SHMEM_ZC;
if (!strcmp(longopts[option_idx].name, "htlb"))
diff --git a/tools/testing/selftests/ublk/test_generic_19.sh b/tools/testing/selftests/ublk/test_generic_19.sh
new file mode 100755
index 000000000000..1d412b4b3318
--- /dev/null
+++ b/tools/testing/selftests/ublk/test_generic_19.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
+
+ERR_CODE=0
+
+if ! _have_program fio; then
+ exit "$UBLK_SKIP_CODE"
+fi
+
+if ! _have_feature "SUPPORT_RQ_AFFINITY"; then
+ exit "$UBLK_SKIP_CODE"
+fi
+
+_prep_test "loop" "write and verify I/O across rq_affinity settings"
+
+_create_backfile 0 256M
+
+dev_id=$(_add_ublk_dev -q 1 -t loop --rq_affinity "${UBLK_BACKFILES[0]}")
+_check_add_dev $TID $?
+
+rq_affinity_path=/sys/block/ublkb"${dev_id}"/queue/rq_affinity
+cpu_list=$(tr -d ' ' < /sys/block/ublkb"${dev_id}"/mq/0/cpu_list)
+first_cpu=${cpu_list%%,*}
+last_cpu=${cpu_list##*,}
+
+if [ "${first_cpu}" = "${last_cpu}" ]; then
+ _cleanup_test
+ exit "$UBLK_SKIP_CODE"
+fi
+
+for affinity in 0 1 2; do
+ echo "${affinity}" > "${rq_affinity_path}"
+
+ # The queue thread runs on the first CPU, so submit from the last.
+ taskset -c "${last_cpu}" fio --name=verify --rw=randwrite --direct=1 \
+ --ioengine=libaio --bs=8k --iodepth=32 --verify=crc32c \
+ --do_verify=1 --verify_state_save=0 \
+ --filename=/dev/ublkb"${dev_id}" --size=256M > /dev/null
+ if [ $? -ne 0 ]; then
+ echo "fio verify failed with rq_affinity=${affinity}"
+ ERR_CODE=255
+ break
+ fi
+done
+
+_cleanup_test
+_show_result $TID $ERR_CODE
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-10-28 13:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 13:18 [PATCH v4 0/2] ublk: honor rq_affinity on request completion Yoav Cohen
2026-10-28 13:18 ` [PATCH v4 1/2] " Yoav Cohen
2026-10-28 14:43 ` Ming Lei
2026-10-28 13:18 ` Yoav Cohen [this message]
2026-10-28 14:44 ` [PATCH v4 2/2] selftests: ublk: add rq_affinity test Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261028131829.45803-3-yoav@nvidia.com \
--to=yoav@nvidia.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=jholzman@nvidia.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=ofer@nvidia.com \
--cc=omril@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.