Linux block layer
 help / color / mirror / Atom feed
* [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing
@ 2026-11-24 13:50 Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 1/5] blktrace: add blktrace ABI compatibility check test Johannes Thumshirn
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

Add test cases for blktrace's ioprio tracing.

The kernel part can be found here:
https://lore.kernel.org/linux-block/20261124133553.152463-1-johannes.thumshirn@wdc.com/

The user-space part here:
https://lore.kernel.org/linux-block/20261124134602.153239-1-johannes.thumshirn@wdc.com/

Johannes Thumshirn (5):
  blktrace: add blktrace ABI compatibility check test
  blktrace: add iotprio recording test
  blktrace: check that ioprio tracing is opt-in only
  blktrace: check ioprio output of ftrace blk tracer
  blktrace: test bio and request tracepoints record ioprio

 src/.gitignore         |   1 +
 src/Makefile           |   1 +
 src/blktrace-setup.c   | 108 +++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/003     |  51 +++++++++++++++++++
 tests/blktrace/003.out |   8 +++
 tests/blktrace/004     | 107 ++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/004.out |  13 +++++
 tests/blktrace/005     |  79 ++++++++++++++++++++++++++++++
 tests/blktrace/005.out |   4 ++
 tests/blktrace/006     |  77 +++++++++++++++++++++++++++++
 tests/blktrace/006.out |   4 ++
 tests/blktrace/007     |  84 ++++++++++++++++++++++++++++++++
 tests/blktrace/007.out |  14 ++++++
 tests/blktrace/rc      |  96 ++++++++++++++++++++++++++++++++++++
 14 files changed, 647 insertions(+)
 create mode 100644 src/blktrace-setup.c
 create mode 100755 tests/blktrace/003
 create mode 100644 tests/blktrace/003.out
 create mode 100755 tests/blktrace/004
 create mode 100644 tests/blktrace/004.out
 create mode 100755 tests/blktrace/005
 create mode 100644 tests/blktrace/005.out
 create mode 100755 tests/blktrace/006
 create mode 100644 tests/blktrace/006.out
 create mode 100755 tests/blktrace/007
 create mode 100644 tests/blktrace/007.out

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] blktrace: add blktrace ABI compatibility check test
  2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
@ 2026-11-24 13:50 ` Johannes Thumshirn
  2026-11-25 22:58   ` Chaitanya Kulkarni
  2026-11-24 13:50 ` [PATCH 2/5] blktrace: add iotprio recording test Johannes Thumshirn
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

Check the BLKTRACESETUP2 flags ABI: BLKTRACE_FLAG_IOPRIO is accepted,
unknown flag bits are still rejected with -EINVAL and the existing v1
and v2 setups without flags keep working.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 src/.gitignore         |   1 +
 src/Makefile           |   1 +
 src/blktrace-setup.c   | 108 +++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/003     |  51 +++++++++++++++++++
 tests/blktrace/003.out |   8 +++
 tests/blktrace/rc      |  26 ++++++++++
 6 files changed, 195 insertions(+)
 create mode 100644 src/blktrace-setup.c
 create mode 100755 tests/blktrace/003
 create mode 100644 tests/blktrace/003.out

diff --git a/src/.gitignore b/src/.gitignore
index c299ecf..cbe70ec 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -2,6 +2,7 @@
 /bio-bounce-read
 /bio-full-trim
 /bio-trim-pin-leak
+/blktrace-setup
 /dio-fallback-race
 /dio-offsets
 /discontiguous-io
diff --git a/src/Makefile b/src/Makefile
index 5af0c9f..e5888b8 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,6 +17,7 @@ C_TARGETS := \
 	bio-bounce-read \
 	bio-full-trim \
 	bio-trim-pin-leak \
+	blktrace-setup \
 	dio-offsets \
 	loblksize \
 	loop_get_status_null \
diff --git a/src/blktrace-setup.c b/src/blktrace-setup.c
new file mode 100644
index 0000000..bb4c57a
--- /dev/null
+++ b/src/blktrace-setup.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-3.0+
+// Copyright (C) 2026 Western Digital Corporation or its affiliates.
+//
+// Issue BLKTRACESETUP (v1) or BLKTRACESETUP2 (v2) with the given setup flags
+// on a block device, print the result as "0" or "-<errno>" and tear the trace
+// down again.
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <linux/types.h>
+
+/*
+ * Private copies of the UAPI definitions, so that this builds against kernel
+ * headers which do not have BLKTRACESETUP2 yet and does not clash with headers
+ * which do.
+ */
+struct bt_user_trace_setup {
+	char name[32];
+	__u16 act_mask;
+	__u32 buf_size;
+	__u32 buf_nr;
+	__u64 start_lba;
+	__u64 end_lba;
+	__u32 pid;
+};
+
+struct bt_user_trace_setup2 {
+	char name[64];
+	__u64 act_mask;
+	__u32 buf_size;
+	__u32 buf_nr;
+	__u64 start_lba;
+	__u64 end_lba;
+	__u32 pid;
+	__u32 flags;
+	__u64 reserved[11];
+};
+
+#define BT_SETUP	_IOWR(0x12, 115, struct bt_user_trace_setup)
+#define BT_TEARDOWN	_IO(0x12, 118)
+#define BT_SETUP2	_IOWR(0x12, 142, struct bt_user_trace_setup2)
+
+static void usage(const char *progname)
+{
+	fprintf(stderr, "usage: %s <device> v1|v2 [flags]\n", progname);
+	exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+	struct bt_user_trace_setup2 buts2;
+	struct bt_user_trace_setup buts;
+	unsigned long flags = 0;
+	char *end;
+	int fd, ret;
+
+	if (argc < 3 || argc > 4)
+		usage(argv[0]);
+
+	if (argc == 4) {
+		errno = 0;
+		flags = strtoul(argv[3], &end, 0);
+		if (errno || *end || flags > 0xffffffffUL)
+			usage(argv[0]);
+	}
+
+	fd = open(argv[1], O_RDONLY);
+	if (fd < 0) {
+		perror("open");
+		return EXIT_FAILURE;
+	}
+
+	if (strcmp(argv[2], "v1") == 0) {
+		if (flags)
+			usage(argv[0]);
+		memset(&buts, 0, sizeof(buts));
+		buts.buf_size = 4096;
+		buts.buf_nr = 2;
+		ret = ioctl(fd, BT_SETUP, &buts);
+	} else if (strcmp(argv[2], "v2") == 0) {
+		memset(&buts2, 0, sizeof(buts2));
+		buts2.buf_size = 4096;
+		buts2.buf_nr = 2;
+		buts2.flags = flags;
+		ret = ioctl(fd, BT_SETUP2, &buts2);
+	} else {
+		usage(argv[0]);
+	}
+
+	if (ret < 0) {
+		printf("%d\n", -errno);
+	} else {
+		printf("0\n");
+		if (ioctl(fd, BT_TEARDOWN) < 0) {
+			perror("BLKTRACETEARDOWN");
+			close(fd);
+			return EXIT_FAILURE;
+		}
+	}
+
+	close(fd);
+	return EXIT_SUCCESS;
+}
diff --git a/tests/blktrace/003 b/tests/blktrace/003
new file mode 100755
index 0000000..b89b803
--- /dev/null
+++ b/tests/blktrace/003
@@ -0,0 +1,51 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# Check the BLKTRACESETUP2 flags ABI: BLKTRACE_FLAG_IOPRIO is accepted, unknown
+# flag bits are still rejected with -EINVAL and the existing v1 and v2 setups
+# without flags keep working.
+
+. tests/blktrace/rc
+. common/null_blk
+
+DESCRIPTION="blktrace setup flags ABI for I/O priority tracing"
+QUICK=1
+
+requires() {
+	_have_null_blk
+	_have_src_program blktrace-setup
+}
+
+# $1: label, $2: v1 or v2, $3: setup flags (v2 only)
+try_setup() {
+	local label=$1
+	shift
+
+	echo "${label}: $("$SRCDIR/blktrace-setup" "$dev" "$@")"
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local dev=/dev/nullb1
+
+	if ! _configure_null_blk nullb1 power=1; then
+		return 1
+	fi
+
+	if _require_blktrace_ioprio_kernel "$dev"; then
+		try_setup "v1" v1
+		try_setup "v2 no flags" v2 0
+		try_setup "v2 ioprio" v2 "$BLKTRACE_FLAG_IOPRIO"
+		try_setup "v2 unknown flag" v2 $((1 << 31))
+		try_setup "v2 ioprio + unknown flag" v2 \
+			$((BLKTRACE_FLAG_IOPRIO | (1 << 31)))
+		try_setup "v2 all unknown flags" v2 \
+			$((0xffffffff & ~BLKTRACE_FLAG_IOPRIO))
+	fi
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/blktrace/003.out b/tests/blktrace/003.out
new file mode 100644
index 0000000..5fa47cd
--- /dev/null
+++ b/tests/blktrace/003.out
@@ -0,0 +1,8 @@
+Running blktrace/003
+v1: 0
+v2 no flags: 0
+v2 ioprio: 0
+v2 unknown flag: -22
+v2 ioprio + unknown flag: -22
+v2 all unknown flags: -22
+Test complete
diff --git a/tests/blktrace/rc b/tests/blktrace/rc
index 04c599f..5b521ab 100644
--- a/tests/blktrace/rc
+++ b/tests/blktrace/rc
@@ -11,3 +11,29 @@ group_requires() {
 	_have_blktrace
 	_have_program blkparse
 }
+
+# blk_user_trace_setup2.flags bit requesting I/O priority recording.
+BLKTRACE_FLAG_IOPRIO=$((1 << 0))
+
+# Check that the blktrace user space tools support I/O priority tracing.
+_have_blktrace_ioprio_userspace() {
+	if ! blktrace 2>&1 | grep -q -- '--ioprio'; then
+		SKIP_REASONS+=("blktrace does not support --ioprio")
+		return 1
+	fi
+	return 0
+}
+
+# Check that the kernel accepts BLKTRACE_FLAG_IOPRIO for BLKTRACESETUP2 on
+# block device $1. This needs an existing device, so call it from test() or
+# test_device().
+_require_blktrace_ioprio_kernel() {
+	local ret
+
+	ret=$("$SRCDIR/blktrace-setup" "$1" v2 "$BLKTRACE_FLAG_IOPRIO")
+	if [[ "$ret" != 0 ]]; then
+		SKIP_REASONS+=("kernel does not support BLKTRACE_FLAG_IOPRIO (${ret})")
+		return 1
+	fi
+	return 0
+}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] blktrace: add iotprio recording test
  2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 1/5] blktrace: add blktrace ABI compatibility check test Johannes Thumshirn
@ 2026-11-24 13:50 ` Johannes Thumshirn
  2026-11-25 22:58   ` Chaitanya Kulkarni
  2026-11-25 23:01   ` Chaitanya Kulkarni
  2026-11-24 13:50 ` [PATCH 3/5] blktrace: check that ioprio tracing is opt-in only Johannes Thumshirn
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

Check that blktrace --ioprio records the I/O priority of bio and request
based events in the v2 trace format. Every SCSI command duration limit
(CDL) hint (IOPRIO_HINT_DEV_DURATION_LIMIT_1..7), no hint, and the RT
and IDLE classes are covered. The hint is passed through the block layer
as is, so no CDL capable device is needed for this.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 tests/blktrace/004     | 107 +++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/004.out |  13 +++++
 tests/blktrace/rc      |  70 +++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100755 tests/blktrace/004
 create mode 100644 tests/blktrace/004.out

diff --git a/tests/blktrace/004 b/tests/blktrace/004
new file mode 100755
index 0000000..4f863da
--- /dev/null
+++ b/tests/blktrace/004
@@ -0,0 +1,107 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# Check that blktrace --ioprio records the I/O priority of bio and request
+# based events in the v2 trace format. Every SCSI command duration limit (CDL)
+# hint (IOPRIO_HINT_DEV_DURATION_LIMIT_1..7), no hint, and the RT and IDLE
+# classes are covered. The hint is passed through the block layer as is, so no
+# CDL capable device is needed for this.
+
+. tests/blktrace/rc
+. common/null_blk
+. common/fio
+
+DESCRIPTION="blktrace records I/O priorities and CDL hints"
+QUICK=1
+
+requires() {
+	_have_null_blk
+	_have_src_program blktrace-setup
+	_have_blktrace_ioprio_userspace
+	_have_fio_ver 3 36
+}
+
+# "class level hint" per job, job i reads 64k at offset i MiB
+JOBS=(
+	"be 4 0"
+	"be 4 1"
+	"be 4 2"
+	"be 4 3"
+	"be 4 4"
+	"be 4 5"
+	"be 4 6"
+	"be 4 7"
+	"rt 1 3"
+	"idle 0 2"
+)
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local dev=/dev/nullb1 i class level hint
+
+	if ! _configure_null_blk nullb1 size=1024 power=1; then
+		return 1
+	fi
+	echo none > /sys/block/nullb1/queue/scheduler
+
+	if ! _require_blktrace_ioprio_kernel "$dev"; then
+		_exit_null_blk
+		return 0
+	fi
+
+	if ! _blktrace_start "$dev" ioprio --ioprio; then
+		_exit_null_blk
+		return 1
+	fi
+
+	for i in "${!JOBS[@]}"; do
+		read -r class level hint <<< "${JOBS[$i]}"
+		if ! _ioprio_read_job "$dev" "$class" "$level" "$hint" "$i"; then
+			echo "fio ${JOBS[$i]} failed"
+		fi
+	done
+
+	_blktrace_stop
+
+	_blkparse ioprio -f "%a %S %i\n" > "$TMPDIR/fmt"
+	_blkparse ioprio > "$TMPDIR/default"
+	cat "$TMPDIR/default" >> "$FULL"
+
+	for i in "${!JOBS[@]}"; do
+		read -r class level hint <<< "${JOBS[$i]}"
+		awk -v idx="$i" -v want="${class},${hint},${level}" '
+		FNR == NR {
+			# "%a %S %i" output, 2048 sectors per MiB
+			if ($1 ~ /^[QGIDC]$/ && int($2 / 2048) == idx) {
+				if ($3 == want)
+					ok[$1]++
+				else
+					bad++
+			}
+			next
+		}
+		# Default output: the ioprio token follows the RWBS column.
+		$6 == "D" && int($9 / 2048) == idx {
+			if ($8 == want)
+				dflt++
+			else
+				bad++
+		}
+		END {
+			printf "%s: queue=%d issue=%d complete=%d default=%d mismatch=%d\n",
+			       want, (ok["Q"] > 0), (ok["D"] > 0),
+			       (ok["C"] > 0), (dflt > 0), bad
+		}' "$TMPDIR/fmt" "$TMPDIR/default"
+	done
+
+	# Plug and unplug events have no bio, so they must not carry an ioprio.
+	awk '$1 ~ /^(P|U|UT)$/ && $3 != "-" { n++ }
+	     END { printf "plug/unplug events with ioprio: %d\n", n }' \
+		"$TMPDIR/fmt"
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/blktrace/004.out b/tests/blktrace/004.out
new file mode 100644
index 0000000..1b36040
--- /dev/null
+++ b/tests/blktrace/004.out
@@ -0,0 +1,13 @@
+Running blktrace/004
+be,0,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,1,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,2,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,3,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,4,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,5,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,6,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+be,7,4: queue=1 issue=1 complete=1 default=1 mismatch=0
+rt,3,1: queue=1 issue=1 complete=1 default=1 mismatch=0
+idle,2,0: queue=1 issue=1 complete=1 default=1 mismatch=0
+plug/unplug events with ioprio: 0
+Test complete
diff --git a/tests/blktrace/rc b/tests/blktrace/rc
index 5b521ab..de61e13 100644
--- a/tests/blktrace/rc
+++ b/tests/blktrace/rc
@@ -37,3 +37,73 @@ _require_blktrace_ioprio_kernel() {
 	fi
 	return 0
 }
+
+# Start blktrace in the background on whole disk $1, writing to
+# "$TMPDIR/$2.blktrace.*". The remaining arguments are passed to blktrace.
+# Returns once the trace is running.
+_blktrace_start() {
+	local dev=$1 name=$2 debugfs_dir i
+	shift 2
+
+	debugfs_dir=/sys/kernel/debug/block/$(basename "$(realpath "$dev")")
+	blktrace -d "$dev" -D "$TMPDIR" -o "$name" "$@" >> "$FULL" 2>&1 &
+	BLKTRACE_PID=$!
+
+	for ((i = 0; i < 100; i++)); do
+		if ! kill -0 "$BLKTRACE_PID" 2>/dev/null; then
+			wait "$BLKTRACE_PID"
+			echo "blktrace $* failed to start ($?)"
+			unset BLKTRACE_PID
+			return 1
+		fi
+		if compgen -G "${debugfs_dir}/trace[0-9]*" > /dev/null; then
+			# Give blktrace time to issue BLKTRACESTART.
+			sleep 0.5
+			return 0
+		fi
+		sleep 0.1
+	done
+
+	echo "timed out waiting for blktrace to start"
+	_blktrace_stop
+	return 1
+}
+
+_blktrace_stop() {
+	if [[ -n "$BLKTRACE_PID" ]]; then
+		kill -INT "$BLKTRACE_PID" 2>/dev/null
+		wait "$BLKTRACE_PID" 2>/dev/null
+		unset BLKTRACE_PID
+	fi
+}
+
+# Run blkparse quietly on trace $1 in $TMPDIR. Remaining arguments are passed
+# to blkparse.
+_blkparse() {
+	local name=$1
+	shift
+
+	blkparse -q -D "$TMPDIR" -i "$name" "$@" 2>> "$FULL"
+}
+
+# Run a small direct read job with I/O priority $2 (class), $3 (level) and
+# $4 (hint) on $1, starting at MiB offset $5. Remaining arguments are passed to
+# fio. The resulting ioprio is printed by the kernel and blkparse as the token
+# "class,hint,level".
+_ioprio_read_job() {
+	local dev=$1 class=$2 level=$3 hint=$4 offset_mb=$5 prioclass
+	shift 5
+
+	case "$class" in
+	rt) prioclass=1 ;;
+	be) prioclass=2 ;;
+	idle) prioclass=3 ;;
+	*) echo "bad class $class"; return 1 ;;
+	esac
+
+	fio --name="ioprio-${class}-${level}-${hint}" --filename="$dev" \
+		--rw=read --bs=4k --size=64k --offset="${offset_mb}M" \
+		--direct=1 --ioengine=psync --numjobs=1 \
+		--prioclass="$prioclass" --prio="$level" --priohint="$hint" \
+		"$@" >> "$FULL" 2>&1
+}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] blktrace: check that ioprio tracing is opt-in only
  2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 1/5] blktrace: add blktrace ABI compatibility check test Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 2/5] blktrace: add iotprio recording test Johannes Thumshirn
@ 2026-11-24 13:50 ` Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer Johannes Thumshirn
  2026-11-24 13:50 ` [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio Johannes Thumshirn
  4 siblings, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

I/O priority tracing is opt-in. Check that traces taken without
--ioprio, with both the v1 and the v2 trace protocol, carry no I/O
priority and that the default blkparse output keeps its old layout. Also
check that --ioprio is refused together with the v1 protocol, which
cannot carry it.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 tests/blktrace/005     | 79 ++++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/005.out |  4 +++
 2 files changed, 83 insertions(+)
 create mode 100755 tests/blktrace/005
 create mode 100644 tests/blktrace/005.out

diff --git a/tests/blktrace/005 b/tests/blktrace/005
new file mode 100755
index 0000000..8fddfae
--- /dev/null
+++ b/tests/blktrace/005
@@ -0,0 +1,79 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# I/O priority tracing is opt-in. Check that traces taken without --ioprio,
+# with both the v1 and the v2 trace protocol, carry no I/O priority and that
+# the default blkparse output keeps its old layout. Also check that --ioprio
+# is refused together with the v1 protocol, which cannot carry it.
+
+. tests/blktrace/rc
+. common/null_blk
+. common/fio
+
+DESCRIPTION="blktrace output without --ioprio is unchanged"
+QUICK=1
+
+requires() {
+	_have_null_blk
+	_have_blktrace_ioprio_userspace
+	_have_fio_ver 3 36
+}
+
+# $1: trace name, remaining arguments are passed to blktrace
+trace_without_ioprio() {
+	local name=$1
+	shift
+
+	_blktrace_start "$dev" "$name" "$@" || return 1
+	_ioprio_read_job "$dev" be 4 5 1 || echo "fio failed"
+	_blktrace_stop
+
+	_blkparse "$name" -f "%a %S %i\n" > "$TMPDIR/${name}.fmt"
+	_blkparse "$name" > "$TMPDIR/${name}.default"
+	cat "$TMPDIR/${name}.default" >> "$FULL"
+
+	awk -v name="$name" '
+	FNR == NR {
+		if ($1 ~ /^[QGIDC]$/) {
+			events++
+			if ($3 != "-")
+				bad++
+		}
+		next
+	}
+	# Old layout: "maj,min cpu seq time pid act rwbs sector + n [comm]"
+	$6 ~ /^[QDC]$/ && / \+ / {
+		if ($8 ~ /^[0-9]+$/ && $9 == "+")
+			dflt++
+		else
+			bad++
+	}
+	END {
+		printf "%s: events=%d default=%d mismatch=%d\n", name,
+		       (events > 0), (dflt > 0), bad
+	}' "$TMPDIR/${name}.fmt" "$TMPDIR/${name}.default"
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local dev=/dev/nullb1
+
+	if ! _configure_null_blk nullb1 size=1024 power=1; then
+		return 1
+	fi
+	echo none > /sys/block/nullb1/queue/scheduler
+
+	trace_without_ioprio v2 --trace-version=2
+	trace_without_ioprio v1 --trace-version=1
+
+	if timeout 10 blktrace -d "$dev" -D "$TMPDIR" -o v1ioprio -w 1 \
+		--trace-version=1 --ioprio >> "$FULL" 2>&1; then
+		echo "--ioprio with --trace-version=1 was accepted"
+	fi
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/blktrace/005.out b/tests/blktrace/005.out
new file mode 100644
index 0000000..ffcd687
--- /dev/null
+++ b/tests/blktrace/005.out
@@ -0,0 +1,4 @@
+Running blktrace/005
+v2: events=1 default=1 mismatch=0
+v1: events=1 default=1 mismatch=0
+Test complete
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer
  2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
                   ` (2 preceding siblings ...)
  2026-11-24 13:50 ` [PATCH 3/5] blktrace: check that ioprio tracing is opt-in only Johannes Thumshirn
@ 2026-11-24 13:50 ` Johannes Thumshirn
  2026-11-25 23:01   ` Chaitanya Kulkarni
  2026-11-24 13:50 ` [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio Johannes Thumshirn
  4 siblings, 1 reply; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

Check the I/O priority output of the ftrace blk tracer. With the
blk_ioprio tracer option set, events carry the "class,hint,level" token
after the RWBS column. Without it the output must be unchanged. In
neither case may the trace contain "Unknown action" entries, which would
show that the __BLK_TA_IOPRIO action flag is not masked when decoding
actions.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 tests/blktrace/006     | 77 ++++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/006.out |  4 +++
 2 files changed, 81 insertions(+)
 create mode 100755 tests/blktrace/006
 create mode 100644 tests/blktrace/006.out

diff --git a/tests/blktrace/006 b/tests/blktrace/006
new file mode 100755
index 0000000..4e9158b
--- /dev/null
+++ b/tests/blktrace/006
@@ -0,0 +1,77 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# Check the I/O priority output of the ftrace blk tracer. With the blk_ioprio
+# tracer option set, events carry the "class,hint,level" token after the RWBS
+# column. Without it the output must be unchanged. In neither case may the
+# trace contain "Unknown action" entries, which would show that the
+# __BLK_TA_IOPRIO action flag is not masked when decoding actions.
+
+. tests/blktrace/rc
+. common/null_blk
+. common/fio
+
+DESCRIPTION="blk ftrace tracer prints I/O priorities and CDL hints"
+QUICK=1
+
+requires() {
+	_have_null_blk
+	_have_tracefs
+	_have_fio_ver 3 36
+}
+
+# $1: value of the blk_ioprio option
+trace_ioprio() {
+	local opt=$1 lines
+
+	echo 0 > "$trace_dir/tracing_on"
+	echo > "$trace_dir/trace"
+	echo "$opt" > "$trace_dir/options/blk_ioprio"
+	echo 1 > "$trace_dir/tracing_on"
+	_ioprio_read_job "$dev" be 4 5 1 || echo "fio failed"
+	echo 0 > "$trace_dir/tracing_on"
+
+	lines=$(grep -v '^#' "$trace_dir/trace")
+	echo "$lines" >> "$FULL"
+	echo "blk_ioprio=${opt}:" \
+		"issue=$(grep -cE ' D +[A-Z]+ ' <<< "$lines")" \
+		"without=$(grep -E ' D +[A-Z]+ ' <<< "$lines" |
+			   grep -cvE ' D +[A-Z]+ [a-z]+,[0-9]+,[0-7] ')" \
+		"match=$(grep -cE ' D +[A-Z]+ be,5,4 ' <<< "$lines")" \
+		"unknown=$(grep -c 'Unknown action' <<< "$lines")" |
+		sed -E 's/(issue|without|match)=[1-9][0-9]*/\1=N/g'
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local trace_dir=/sys/kernel/debug/tracing
+	local dev=/dev/nullb1
+
+	if ! _configure_null_blk nullb1 size=1024 power=1; then
+		return 1
+	fi
+	echo none > /sys/block/nullb1/queue/scheduler
+
+	echo 0 > "$trace_dir/tracing_on"
+	echo nop > "$trace_dir/current_tracer"
+	echo 1 > /sys/block/nullb1/trace/enable
+	echo blk > "$trace_dir/current_tracer"
+
+	if [[ -e "$trace_dir/options/blk_ioprio" ]]; then
+		trace_ioprio 1
+		trace_ioprio 0
+	else
+		SKIP_REASONS+=("blk tracer has no blk_ioprio option")
+	fi
+
+	echo 0 > "$trace_dir/tracing_on"
+	echo nop > "$trace_dir/current_tracer"
+	echo > "$trace_dir/trace"
+	echo 0 > /sys/block/nullb1/trace/enable
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/blktrace/006.out b/tests/blktrace/006.out
new file mode 100644
index 0000000..3396640
--- /dev/null
+++ b/tests/blktrace/006.out
@@ -0,0 +1,4 @@
+Running blktrace/006
+blk_ioprio=1: issue=N without=0 match=N unknown=0
+blk_ioprio=0: issue=N without=N match=0 unknown=0
+Test complete
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio
  2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
                   ` (3 preceding siblings ...)
  2026-11-24 13:50 ` [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer Johannes Thumshirn
@ 2026-11-24 13:50 ` Johannes Thumshirn
  2026-11-25 23:01   ` Chaitanya Kulkarni
  4 siblings, 1 reply; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-24 13:50 UTC (permalink / raw)
  To: Shinichiro Kawasaki
  Cc: linux-block, Christoph Hellwig, Damien Le Moal,
	Chaitanya Kulkarni, Niklas Cassel, Hannes Reinecke,
	Johannes Thumshirn

Check that the bio and request based block tracepoints report the I/O
priority, including the CDL hint, as "class,hint,level".

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 tests/blktrace/007     | 84 ++++++++++++++++++++++++++++++++++++++++++
 tests/blktrace/007.out | 14 +++++++
 2 files changed, 98 insertions(+)
 create mode 100755 tests/blktrace/007
 create mode 100644 tests/blktrace/007.out

diff --git a/tests/blktrace/007 b/tests/blktrace/007
new file mode 100755
index 0000000..cc2dd34
--- /dev/null
+++ b/tests/blktrace/007
@@ -0,0 +1,84 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# Check that the bio and request based block tracepoints report the I/O
+# priority, including the CDL hint, as "class,hint,level".
+
+. tests/blktrace/rc
+. common/null_blk
+. common/fio
+
+DESCRIPTION="block tracepoints report I/O priorities and CDL hints"
+QUICK=1
+
+requires() {
+	_have_null_blk
+	_have_tracefs
+	_have_fio_ver 3 36
+	_have_tracepoint block/block_bio_queue
+	_have_tracepoint block/block_getrq
+	_have_tracepoint block/block_rq_issue
+	_have_tracepoint block/block_rq_complete
+}
+
+EVENTS=(block_bio_queue block_getrq block_rq_issue block_rq_complete)
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local trace_dir=/sys/kernel/debug/tracing
+	local dev=/dev/nullb1 devt ev lines
+
+	if ! grep -q 'ioprio;' "$trace_dir/events/block/block_bio_queue/format"; then
+		SKIP_REASONS+=("block_bio_queue has no ioprio field")
+		return 0
+	fi
+
+	if ! _configure_null_blk nullb1 size=1024 power=1; then
+		return 1
+	fi
+	echo none > /sys/block/nullb1/queue/scheduler
+
+	# Kernel dev_t encoding used by the tracepoints.
+	devt=$(( ($(stat -L -c '%t' "$dev" | sed 's/^/0x/') << 20) |
+		 $(stat -L -c '%T' "$dev" | sed 's/^/0x/') ))
+
+	echo 0 > "$trace_dir/tracing_on"
+	echo nop > "$trace_dir/current_tracer"
+	echo > "$trace_dir/trace"
+	for ev in "${EVENTS[@]}"; do
+		echo "dev == ${devt}" > "$trace_dir/events/block/${ev}/filter"
+		echo 1 > "$trace_dir/events/block/${ev}/enable"
+	done
+	echo 1 > "$trace_dir/tracing_on"
+
+	for hint in 1 7; do
+		_ioprio_read_job "$dev" be 4 "$hint" "$hint" || echo "fio failed"
+	done
+
+	echo 0 > "$trace_dir/tracing_on"
+	lines=$(grep -v '^#' "$trace_dir/trace")
+	echo "$lines" >> "$FULL"
+
+	for ev in "${EVENTS[@]}"; do
+		echo 0 > "$trace_dir/events/block/${ev}/enable"
+		echo 0 > "$trace_dir/events/block/${ev}/filter"
+	done
+	echo > "$trace_dir/trace"
+
+	for ev in "${EVENTS[@]}"; do
+		for hint in 1 7; do
+			echo "${ev} be,${hint},4:" \
+			     "$(grep -cE " ${ev}: .* be,${hint},4 " <<< "$lines" |
+				sed -E 's/^[1-9][0-9]*$/N/')"
+		done
+		echo "${ev} without ioprio:" \
+		     "$(grep -E " ${ev}: " <<< "$lines" |
+			grep -cvE ' [a-z]+,[0-9]+,[0-7] ')"
+	done
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/blktrace/007.out b/tests/blktrace/007.out
new file mode 100644
index 0000000..abf792a
--- /dev/null
+++ b/tests/blktrace/007.out
@@ -0,0 +1,14 @@
+Running blktrace/007
+block_bio_queue be,1,4: N
+block_bio_queue be,7,4: N
+block_bio_queue without ioprio: 0
+block_getrq be,1,4: N
+block_getrq be,7,4: N
+block_getrq without ioprio: 0
+block_rq_issue be,1,4: N
+block_rq_issue be,7,4: N
+block_rq_issue without ioprio: 0
+block_rq_complete be,1,4: N
+block_rq_complete be,7,4: N
+block_rq_complete without ioprio: 0
+Test complete
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] blktrace: add blktrace ABI compatibility check test
  2026-11-24 13:50 ` [PATCH 1/5] blktrace: add blktrace ABI compatibility check test Johannes Thumshirn
@ 2026-11-25 22:58   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2026-11-25 22:58 UTC (permalink / raw)
  To: Johannes Thumshirn, Shinichiro Kawasaki
  Cc: linux-block@vger.kernel.org, Christoph Hellwig, Damien Le Moal,
	Niklas Cassel, Hannes Reinecke

On 11/24/26 5:50 AM, Johannes Thumshirn wrote:
> Check the BLKTRACESETUP2 flags ABI: BLKTRACE_FLAG_IOPRIO is accepted,
> unknown flag bits are still rejected with -EINVAL and the existing v1
> and v2 setups without flags keep working.
>
> Signed-off-by: Johannes Thumshirn<johannes.thumshirn@wdc.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] blktrace: add iotprio recording test
  2026-11-24 13:50 ` [PATCH 2/5] blktrace: add iotprio recording test Johannes Thumshirn
@ 2026-11-25 22:58   ` Chaitanya Kulkarni
  2026-11-25 23:01   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2026-11-25 22:58 UTC (permalink / raw)
  To: Johannes Thumshirn, Shinichiro Kawasaki
  Cc: linux-block@vger.kernel.org, Christoph Hellwig, Damien Le Moal,
	Niklas Cassel, Hannes Reinecke

On 11/24/26 5:50 AM, Johannes Thumshirn wrote:
> Check that blktrace --ioprio records the I/O priority of bio and request
> based events in the v2 trace format. Every SCSI command duration limit
> (CDL) hint (IOPRIO_HINT_DEV_DURATION_LIMIT_1..7), no hint, and the RT
> and IDLE classes are covered. The hint is passed through the block layer
> as is, so no CDL capable device is needed for this.
>
> Signed-off-by: Johannes Thumshirn<johannes.thumshirn@wdc.com>
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] blktrace: add iotprio recording test
  2026-11-24 13:50 ` [PATCH 2/5] blktrace: add iotprio recording test Johannes Thumshirn
  2026-11-25 22:58   ` Chaitanya Kulkarni
@ 2026-11-25 23:01   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2026-11-25 23:01 UTC (permalink / raw)
  To: Johannes Thumshirn, Shinichiro Kawasaki
  Cc: linux-block@vger.kernel.org, Christoph Hellwig, Damien Le Moal,
	Niklas Cassel, Hannes Reinecke

On 11/24/26 5:50 AM, Johannes Thumshirn wrote:
> Check that blktrace --ioprio records the I/O priority of bio and request
> based events in the v2 trace format. Every SCSI command duration limit
> (CDL) hint (IOPRIO_HINT_DEV_DURATION_LIMIT_1..7), no hint, and the RT
> and IDLE classes are covered. The hint is passed through the block layer
> as is, so no CDL capable device is needed for this.
>
> Signed-off-by: Johannes Thumshirn<johannes.thumshirn@wdc.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer
  2026-11-24 13:50 ` [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer Johannes Thumshirn
@ 2026-11-25 23:01   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2026-11-25 23:01 UTC (permalink / raw)
  To: Johannes Thumshirn, Shinichiro Kawasaki
  Cc: linux-block@vger.kernel.org, Christoph Hellwig, Damien Le Moal,
	Niklas Cassel, Hannes Reinecke

On 11/24/26 5:50 AM, Johannes Thumshirn wrote:
> Check the I/O priority output of the ftrace blk tracer. With the
> blk_ioprio tracer option set, events carry the "class,hint,level" token
> after the RWBS column. Without it the output must be unchanged. In
> neither case may the trace contain "Unknown action" entries, which would
> show that the __BLK_TA_IOPRIO action flag is not masked when decoding
> actions.
>
> Signed-off-by: Johannes Thumshirn<johannes.thumshirn@wdc.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio
  2026-11-24 13:50 ` [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio Johannes Thumshirn
@ 2026-11-25 23:01   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2026-11-25 23:01 UTC (permalink / raw)
  To: Johannes Thumshirn, Shinichiro Kawasaki
  Cc: linux-block@vger.kernel.org, Christoph Hellwig, Damien Le Moal,
	Niklas Cassel, Hannes Reinecke

On 11/24/26 5:50 AM, Johannes Thumshirn wrote:
> Check that the bio and request based block tracepoints report the I/O
> priority, including the CDL hint, as "class,hint,level".
>
> Signed-off-by: Johannes Thumshirn<johannes.thumshirn@wdc.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-25 23:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 13:50 [PATCH blktests 0/5] blktrace: Add tests for blktrace's ioprio tracing Johannes Thumshirn
2026-11-24 13:50 ` [PATCH 1/5] blktrace: add blktrace ABI compatibility check test Johannes Thumshirn
2026-11-25 22:58   ` Chaitanya Kulkarni
2026-11-24 13:50 ` [PATCH 2/5] blktrace: add iotprio recording test Johannes Thumshirn
2026-11-25 22:58   ` Chaitanya Kulkarni
2026-11-25 23:01   ` Chaitanya Kulkarni
2026-11-24 13:50 ` [PATCH 3/5] blktrace: check that ioprio tracing is opt-in only Johannes Thumshirn
2026-11-24 13:50 ` [PATCH 4/5] blktrace: check ioprio output of ftrace blk tracer Johannes Thumshirn
2026-11-25 23:01   ` Chaitanya Kulkarni
2026-11-24 13:50 ` [PATCH 5/5] blktrace: test bio and request tracepoints record ioprio Johannes Thumshirn
2026-11-25 23:01   ` Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox