[PATCH v2] selftests/ftrace: Account for 8-byte aligned trace_marker_raw events

Sarah Emery sarah.emery at canonical.com
Sat Oct 10 16:46:45 PDT 2026


trace_marker_raw.tc expects the length of each raw event to be rounded
up to a multiple of 4 bytes. That is not the case when the ring buffer
forces 8-byte alignment of events (CONFIG_HAVE_64BIT_ALIGNED_ACCESS):
the id plus the data is rounded up to a multiple of 8 bytes instead, so
trace_pipe shows 8 * N + 4 items. This was seen on riscv64.

Make the test accept either rounding.

Fixes: 37f46601383a ("selftests/tracing: Add basic test for trace_marker_raw file")
Reported-by: Hui Wang <hui.wang at canonical.com>
Closes: https://lore.kernel.org/all/20260607072431.125633-3-hui.wang@canonical.com/
Signed-off-by: Sarah Emery <sarah.emery at canonical.com>
---
Original v1 patch from Hui Wang was posted in June and only patch 1/2
was merged (commit c37e0a4b79a6).
This is a v2 for commit 2/2, addressing reviews.

Changes since v1:
 - Drop kconfig_enabled() and the CONFIG_HAVE_64BIT_ALIGNED_ACCESS
   lookup. The review of v1 objected that it depends on the kernel config
   being readable from the test environment. The test now accepts the
   4 and 8 byte roundings based on what trace_pipe prints.
 - The expected length for the 8 byte case is unchanged (8 * N + 4).
 - Rebase on 65f26d15f7db ("selftests/ftrace: Fix trace_marker_raw test
   on 64K page kernels"), which changed how the test writes its events.

diff --git a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
index f985ff391463..dd2b94be0947 100644
--- a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
+++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
@@ -67,7 +67,8 @@ test_multiple_writes() {
 	# add a little buffer
 	echo stop > trace_marker
 
-	# Check to make sure the number of entries is the id (rounded up by 4)
+	# Check to make sure the number of entries is the id (rounded up by 4,
+	# or by 8 on architectures forcing 8 byte alignment of ring buffer events)
 	awk '/.*: # [0-9a-f]* / {
 			print;
 			cnt = -1;
@@ -77,9 +78,12 @@ test_multiple_writes() {
 					i++;
 					cnt = strtonum("0x" $i);
 					num = NF - (i + 1);
-					# The number of items is always rounded up by 4
+					# The number of items is rounded up by 4
-					cnt2 = int((cnt + 3) / 4) * 4;
+					cnt4 = int((cnt + 3) / 4) * 4;
-					if (cnt2 != num) {
+					# With forced 8 byte alignment, the id (4 bytes) plus the data
+					# is rounded up to a multiple of 8, and the id is not counted
+					cnt8 = int((cnt + 3) / 8) * 8 + 4;
+					if (num != cnt4 && num != cnt8) {
 						exit 1;
 					}
 					break;
-- 
2.43.0




More information about the linux-riscv mailing list