Skip to contentSkip to conversation

common/tracing: use /sys/kernel/tracing at first

PATCH In review Zorro Lang 3 participants 5 messages May 10, 2024 – May 17, 2024

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH 1/1 common/tracing: use /sys/kernel/tracing at first

To avoid the dependence of debugfs, tracefs is mounted on another place -- /sys/kernel/tracing now. But for the compatibility, the /sys/kernel/debug/tracing is still there. So change _require_ftrace helper, try to use the new /sys/kernel/tracing path at first, or fallback to the old one if it's not supported.

xfs/499 uses ftrace, so call _require_ftrace in it.

---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)
common/tracing +9 -4
index b3051c27..8613d044 100644
@@ -4,11 +4,16 @@
 #
 # Routines for dealing with ftrace (or any other tracing).
 
-FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances/"
-
 _require_ftrace() {
-	test -d "$FTRACE_INSTANCES_DIR" || \
-		_notrun "kernel does not support ftrace"
+	if [ -d /sys/kernel/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/tracing/instances"
+	elif [ -d /sys/kernel/debug/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/debug/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances"
+	else
+		_notrun "The ftrace is not supported, or tracefs is not mounted"
+	fi
 }
 
 _ftrace_cleanup() {
tests/xfs/499 +3 -3
index 9672f95d..883415dc 100755
@@ -14,18 +14,18 @@ _begin_fstest auto quick
 _register_cleanup "_cleanup" BUS
 
 # Import common functions.
+. ./common/tracing
 
 # real QA test starts here
 _supported_fs xfs
+_require_ftrace
 _require_command "$CC_PROG" "cc"
 
 cprog=$tmp.ftrace.c
 oprog=$tmp.ftrace
 sedprog=$tmp.ftrace.sed
 
-ftrace_dir=$DEBUGFS_MNT/tracing/events/xfs
-
-test -d $ftrace_dir || _notrun "ftrace not enabled"
+ftrace_dir=$FTRACE_ROOT/events/xfs
 
 # The second argument to __print_symbolic is stringified in the tracepoint's
 # fmt file, so we look for "{ NUM, STRING }" and try to separate each of them
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Zorro Lang

To avoid the dependence of debugfs, tracefs is mounted on another place -- /sys/kernel/tracing now. But for the compatibility, the /sys/kernel/debug/tracing is still there. So change _require_ftrace helper, try to use the new /sys/kernel/tracing path at first, or fallback to the old one if it's not supported.

xfs/499 uses ftrace, so call _require_ftrace in it.

---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)
common/tracing +0 -0
index b3051c27..8613d044 100644
@@ -4,11 +4,16 @@
 #

common/tracing line 10

Quoted 10 lines
common/tracing +3 -4
 # Routines for dealing with ftrace (or any other tracing).
 
-FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances/"
-
 _require_ftrace() {
-	test -d "$FTRACE_INSTANCES_DIR" || \
-		_notrun "kernel does not support ftrace"
+	if [ -d /sys/kernel/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/tracing/instances"

To answer my own question, this new path has been in Debian since at least 2021.

Quoted 14 lines
common/tracing +6 -0
+	elif [ -d /sys/kernel/debug/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/debug/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances"
+	else
+		_notrun "The ftrace is not supported, or tracefs is not mounted"
+	fi
 }
 
 _ftrace_cleanup() {
tests/xfs/499 +0 -0
index 9672f95d..883415dc 100755

tests/xfs/499 _begin_fstest auto quick · line 17

Quoted 4 lines
tests/xfs/499 +1 -0
@@ -14,18 +14,18 @@ _begin_fstest auto quick
 _register_cleanup "_cleanup" BUS
 
 # Import common functions.
+. ./common/tracing

You could probably get rid of the "Import common functions" comment.

This looks good!

--D

Quoted 21 lines
tests/xfs/499 +2 -3
 # real QA test starts here
 _supported_fs xfs
+_require_ftrace
 _require_command "$CC_PROG" "cc"
 
 cprog=$tmp.ftrace.c
 oprog=$tmp.ftrace
 sedprog=$tmp.ftrace.sed
 
-ftrace_dir=$DEBUGFS_MNT/tracing/events/xfs
-
-test -d $ftrace_dir || _notrun "ftrace not enabled"
+ftrace_dir=$FTRACE_ROOT/events/xfs
 
 # The second argument to __print_symbolic is stringified in the tracepoint's
 # fmt file, so we look for "{ NUM, STRING }" and try to separate each of them
Signature · 1 line
2.44.0
#2 lore raw
Quoted 23 lines · Darrick J. Wong
Quoted 22 lines · Zorro Lang

To avoid the dependence of debugfs, tracefs is mounted on another place -- /sys/kernel/tracing now. But for the compatibility, the /sys/kernel/debug/tracing is still there. So change _require_ftrace helper, try to use the new /sys/kernel/tracing path at first, or fallback to the old one if it's not supported.

xfs/499 uses ftrace, so call _require_ftrace in it.

---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)
common/tracing +0 -0
index b3051c27..8613d044 100644
@@ -4,11 +4,16 @@
 #
 # Routines for dealing with ftrace (or any other tracing).
 
Quoted 11 lines

common/tracing line 10

Quoted 8 lines
common/tracing +3 -4
-FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances/"
-
 _require_ftrace() {
-	test -d "$FTRACE_INSTANCES_DIR" || \
-		_notrun "kernel does not support ftrace"
+	if [ -d /sys/kernel/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/tracing/instances"

To answer my own question, this new path has been in Debian since at least 2021.

Oh, I thought the /sys/kernel/tracing was created in linux v4.1 :
cc31004a4aa7 ("tracefs: Add directory /sys/kernel/tracing")

But might be used in different distro widely later.

Quoted 17 lines
Quoted 17 lines
common/tracing +6 -0
+	elif [ -d /sys/kernel/debug/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/debug/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances"
+	else
+		_notrun "The ftrace is not supported, or tracefs is not mounted"
+	fi
 }
 
 _ftrace_cleanup() {
tests/xfs/499 +0 -0
index 9672f95d..883415dc 100755
@@ -14,18 +14,18 @@ _begin_fstest auto quick
 _register_cleanup "_cleanup" BUS
 
Quoted 4 lines

tests/xfs/499 _begin_fstest auto quick · line 17

Quoted 2 lines
tests/xfs/499 +1 -0
 # Import common functions.
+. ./common/tracing

You could probably get rid of the "Import common functions" comment.

Sure, will change that when I merge it.

Quoted 3 lines

This looks good!

Thanks,
Zorro

Quoted 25 lines

--D

Quoted 21 lines
tests/xfs/499 +2 -3
 # real QA test starts here
 _supported_fs xfs
+_require_ftrace
 _require_command "$CC_PROG" "cc"
 
 cprog=$tmp.ftrace.c
 oprog=$tmp.ftrace
 sedprog=$tmp.ftrace.sed
 
-ftrace_dir=$DEBUGFS_MNT/tracing/events/xfs
-
-test -d $ftrace_dir || _notrun "ftrace not enabled"
+ftrace_dir=$FTRACE_ROOT/events/xfs
 
 # The second argument to __print_symbolic is stringified in the tracepoint's
 # fmt file, so we look for "{ NUM, STRING }" and try to separate each of them
Signature · 1 line
2.44.0
#3 lore raw
Quoted 36 lines · Zorro Lang
Quoted 23 lines · Darrick J. Wong
Quoted 22 lines · Zorro Lang

To avoid the dependence of debugfs, tracefs is mounted on another place -- /sys/kernel/tracing now. But for the compatibility, the /sys/kernel/debug/tracing is still there. So change _require_ftrace helper, try to use the new /sys/kernel/tracing path at first, or fallback to the old one if it's not supported.

xfs/499 uses ftrace, so call _require_ftrace in it.

---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)
common/tracing +0 -0
index b3051c27..8613d044 100644
@@ -4,11 +4,16 @@
 #
 # Routines for dealing with ftrace (or any other tracing).
 
Quoted 11 lines

common/tracing line 10

Quoted 8 lines
common/tracing +3 -4
-FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances/"
-
 _require_ftrace() {
-	test -d "$FTRACE_INSTANCES_DIR" || \
-		_notrun "kernel does not support ftrace"
+	if [ -d /sys/kernel/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/tracing/instances"

To answer my own question, this new path has been in Debian since at least 2021.

Quoted 4 lines

Oh, I thought the /sys/kernel/tracing was created in linux v4.1 :
cc31004a4aa7 ("tracefs: Add directory /sys/kernel/tracing")

But might be used in different distro widely later.

That creates an empty /sys/kernel/tracing directory, but userspace still has to mount something to it, hence /lib/systemd/system/sys-kernel-tracing.mount.

--D

Quoted 57 lines
Quoted 17 lines
Quoted 17 lines
common/tracing +6 -0
+	elif [ -d /sys/kernel/debug/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/debug/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances"
+	else
+		_notrun "The ftrace is not supported, or tracefs is not mounted"
+	fi
 }
 
 _ftrace_cleanup() {
tests/xfs/499 +0 -0
index 9672f95d..883415dc 100755
@@ -14,18 +14,18 @@ _begin_fstest auto quick
 _register_cleanup "_cleanup" BUS
 
Quoted 4 lines

tests/xfs/499 _begin_fstest auto quick · line 17

Quoted 2 lines
tests/xfs/499 +1 -0
 # Import common functions.
+. ./common/tracing

You could probably get rid of the "Import common functions" comment.

Sure, will change that when I merge it.

Quoted 3 lines

This looks good!

Thanks,
Zorro

Quoted 25 lines

--D

Quoted 21 lines
tests/xfs/499 +2 -3
 # real QA test starts here
 _supported_fs xfs
+_require_ftrace
 _require_command "$CC_PROG" "cc"
 
 cprog=$tmp.ftrace.c
 oprog=$tmp.ftrace
 sedprog=$tmp.ftrace.sed
 
-ftrace_dir=$DEBUGFS_MNT/tracing/events/xfs
-
-test -d $ftrace_dir || _notrun "ftrace not enabled"
+ftrace_dir=$FTRACE_ROOT/events/xfs
 
 # The second argument to __print_symbolic is stringified in the tracepoint's
 # fmt file, so we look for "{ NUM, STRING }" and try to separate each of them
Signature · 1 line
2.44.0
#4 lore raw
In reply to Zorro Lang
Quoted 36 lines · Zorro Lang
Quoted 23 lines · Darrick J. Wong
Quoted 22 lines · Zorro Lang

To avoid the dependence of debugfs, tracefs is mounted on another place -- /sys/kernel/tracing now. But for the compatibility, the /sys/kernel/debug/tracing is still there. So change _require_ftrace helper, try to use the new /sys/kernel/tracing path at first, or fallback to the old one if it's not supported.

xfs/499 uses ftrace, so call _require_ftrace in it.

---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)
common/tracing +0 -0
index b3051c27..8613d044 100644
@@ -4,11 +4,16 @@
 #
 # Routines for dealing with ftrace (or any other tracing).
 
Quoted 11 lines

common/tracing line 10

Quoted 8 lines
common/tracing +3 -4
-FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances/"
-
 _require_ftrace() {
-	test -d "$FTRACE_INSTANCES_DIR" || \
-		_notrun "kernel does not support ftrace"
+	if [ -d /sys/kernel/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/tracing/instances"

To answer my own question, this new path has been in Debian since at least 2021.

Quoted 4 lines

Oh, I thought the /sys/kernel/tracing was created in linux v4.1 :
cc31004a4aa7 ("tracefs: Add directory /sys/kernel/tracing")

But might be used in different distro widely later.

Yeah, it showed up in kernel v4.1, but systemd only added a .mount file for it a few years ago.

--D

Quoted 58 lines
Quoted 17 lines
Quoted 17 lines
common/tracing +6 -0
+	elif [ -d /sys/kernel/debug/tracing/instances/ ];then
+		FTRACE_ROOT="/sys/kernel/debug/tracing"
+		FTRACE_INSTANCES_DIR="/sys/kernel/debug/tracing/instances"
+	else
+		_notrun "The ftrace is not supported, or tracefs is not mounted"
+	fi
 }
 
 _ftrace_cleanup() {
tests/xfs/499 +0 -0
index 9672f95d..883415dc 100755
@@ -14,18 +14,18 @@ _begin_fstest auto quick
 _register_cleanup "_cleanup" BUS
 
Quoted 4 lines

tests/xfs/499 _begin_fstest auto quick · line 17

Quoted 2 lines
tests/xfs/499 +1 -0
 # Import common functions.
+. ./common/tracing

You could probably get rid of the "Import common functions" comment.

Sure, will change that when I merge it.

Quoted 3 lines

This looks good!

Thanks,
Zorro

Quoted 25 lines

--D

Quoted 21 lines
tests/xfs/499 +2 -3
 # real QA test starts here
 _supported_fs xfs
+_require_ftrace
 _require_command "$CC_PROG" "cc"
 
 cprog=$tmp.ftrace.c
 oprog=$tmp.ftrace
 sedprog=$tmp.ftrace.sed
 
-ftrace_dir=$DEBUGFS_MNT/tracing/events/xfs
-
-test -d $ftrace_dir || _notrun "ftrace not enabled"
+ftrace_dir=$FTRACE_ROOT/events/xfs
 
 # The second argument to __print_symbolic is stringified in the tracepoint's
 # fmt file, so we look for "{ NUM, STRING }" and try to separate each of them
Signature · 1 line
2.44.0