Add UBLK_F_SUPPORT_RQ_AFFINITY to kublk's feature table and a --rq_affinity flag to request it at ADD_DEV time, and add test_generic_18.sh: writes and verifies data on a loop device with I/O pinned to one CPU while cycling rq_affinity through 0, 1 and 2. Skipped on kernels without UBLK_F_SUPPORT_RQ_AFFINITY. Signed-off-by: Yoav Cohen --- tools/testing/selftests/ublk/Makefile | 1 + tools/testing/selftests/ublk/kublk.c | 6 ++- .../testing/selftests/ublk/test_generic_18.sh | 42 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/ublk/test_generic_18.sh diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index 37883e9d50ec..d12e9879b89a 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -19,6 +19,7 @@ TEST_PROGS += test_generic_12.sh 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_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 2400b4615766..e3afef0e7628 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -2083,6 +2083,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; @@ -2180,7 +2181,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"); @@ -2260,6 +2261,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 }, @@ -2407,6 +2409,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_18.sh b/tools/testing/selftests/ublk/test_generic_18.sh new file mode 100755 index 000000000000..c899a5bf0364 --- /dev/null +++ b/tools/testing/selftests/ublk/test_generic_18.sh @@ -0,0 +1,42 @@ +#!/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 -t loop --rq_affinity "${UBLK_BACKFILES[0]}") +_check_add_dev $TID $? + +rq_affinity_path=/sys/block/ublkb"${dev_id}"/queue/rq_affinity + +for affinity in 0 1 2; do + echo "${affinity}" > "${rq_affinity_path}" + + # Pin submission to a single CPU so rq_affinity has somewhere to + # redirect completion to. + taskset -c 0 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)