diff mbox series

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

Message ID 20240510043339.1238462-1-zlang@kernel.org (mailing list archive)
State New, archived
Headers show
Series common/tracing: use /sys/kernel/tracing at first | expand

Commit Message

Zorro Lang May 10, 2024, 4:33 a.m. UTC
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.

Signed-off-by: Zorro Lang <zlang@kernel.org>
---
 common/tracing | 13 +++++++++----
 tests/xfs/499  |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)

Comments

Darrick J. Wong May 10, 2024, 3:17 p.m. UTC | #1
On Fri, May 10, 2024 at 12:33:39PM +0800, Zorro Lang wrote:
> 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.
> 
> Signed-off-by: Zorro Lang <zlang@kernel.org>
> ---
>  common/tracing | 13 +++++++++----
>  tests/xfs/499  |  6 +++---
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/common/tracing b/common/tracing
> index b3051c27..8613d044 100644
> --- a/common/tracing
> +++ b/common/tracing
> @@ -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"

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

> +	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() {
> diff --git a/tests/xfs/499 b/tests/xfs/499
> index 9672f95d..883415dc 100755
> --- a/tests/xfs/499
> +++ b/tests/xfs/499
> @@ -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!
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

>  
>  # 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
> -- 
> 2.44.0
> 
>
Zorro Lang May 11, 2024, 4:46 a.m. UTC | #2
On Fri, May 10, 2024 at 08:17:54AM -0700, Darrick J. Wong wrote:
> On Fri, May 10, 2024 at 12:33:39PM +0800, Zorro Lang wrote:
> > 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.
> > 
> > Signed-off-by: Zorro Lang <zlang@kernel.org>
> > ---
> >  common/tracing | 13 +++++++++----
> >  tests/xfs/499  |  6 +++---
> >  2 files changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/common/tracing b/common/tracing
> > index b3051c27..8613d044 100644
> > --- a/common/tracing
> > +++ b/common/tracing
> > @@ -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"
> 
> 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.

> 
> > +	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() {
> > diff --git a/tests/xfs/499 b/tests/xfs/499
> > index 9672f95d..883415dc 100755
> > --- a/tests/xfs/499
> > +++ b/tests/xfs/499
> > @@ -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.

Sure, will change that when I merge it.

> 
> This looks good!
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Thanks,
Zorro

> 
> --D
> 
> >  
> >  # 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
> > -- 
> > 2.44.0
> > 
> > 
>
Darrick J. Wong May 11, 2024, 2:53 p.m. UTC | #3
On Sat, May 11, 2024 at 12:46:41PM +0800, Zorro Lang wrote:
> On Fri, May 10, 2024 at 08:17:54AM -0700, Darrick J. Wong wrote:
> > On Fri, May 10, 2024 at 12:33:39PM +0800, Zorro Lang wrote:
> > > 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.
> > > 
> > > Signed-off-by: Zorro Lang <zlang@kernel.org>
> > > ---
> > >  common/tracing | 13 +++++++++----
> > >  tests/xfs/499  |  6 +++---
> > >  2 files changed, 12 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/common/tracing b/common/tracing
> > > index b3051c27..8613d044 100644
> > > --- a/common/tracing
> > > +++ b/common/tracing
> > > @@ -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"
> > 
> > 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.

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

> > 
> > > +	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() {
> > > diff --git a/tests/xfs/499 b/tests/xfs/499
> > > index 9672f95d..883415dc 100755
> > > --- a/tests/xfs/499
> > > +++ b/tests/xfs/499
> > > @@ -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.
> 
> Sure, will change that when I merge it.
> 
> > 
> > This looks good!
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
> Thanks,
> Zorro
> 
> > 
> > --D
> > 
> > >  
> > >  # 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
> > > -- 
> > > 2.44.0
> > > 
> > > 
> > 
>
Darrick J. Wong May 17, 2024, 3:58 p.m. UTC | #4
On Sat, May 11, 2024 at 12:46:41PM +0800, Zorro Lang wrote:
> On Fri, May 10, 2024 at 08:17:54AM -0700, Darrick J. Wong wrote:
> > On Fri, May 10, 2024 at 12:33:39PM +0800, Zorro Lang wrote:
> > > 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.
> > > 
> > > Signed-off-by: Zorro Lang <zlang@kernel.org>
> > > ---
> > >  common/tracing | 13 +++++++++----
> > >  tests/xfs/499  |  6 +++---
> > >  2 files changed, 12 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/common/tracing b/common/tracing
> > > index b3051c27..8613d044 100644
> > > --- a/common/tracing
> > > +++ b/common/tracing
> > > @@ -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"
> > 
> > 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.

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

--D

> > 
> > > +	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() {
> > > diff --git a/tests/xfs/499 b/tests/xfs/499
> > > index 9672f95d..883415dc 100755
> > > --- a/tests/xfs/499
> > > +++ b/tests/xfs/499
> > > @@ -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.
> 
> Sure, will change that when I merge it.
> 
> > 
> > This looks good!
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
> Thanks,
> Zorro
> 
> > 
> > --D
> > 
> > >  
> > >  # 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
> > > -- 
> > > 2.44.0
> > > 
> > > 
> > 
> 
>
diff mbox series

Patch

diff --git a/common/tracing b/common/tracing
index b3051c27..8613d044 100644
--- a/common/tracing
+++ b/common/tracing
@@ -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() {
diff --git a/tests/xfs/499 b/tests/xfs/499
index 9672f95d..883415dc 100755
--- a/tests/xfs/499
+++ b/tests/xfs/499
@@ -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