Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf ftrace: Detect whether ftrace is enabled on system

To make error messages more accurate, this change detects whether ftrace is
enabled on system by checking trace file "set_ftrace_pid".

Before:

# perf ftrace
failed to reset ftrace
#

After:

# perf ftrace
ftrace is not supported on this system
#

Committer testing:

Doing it in an unprivileged toolbox container on Fedora 40:

Before:

acme@number:~/git/perf-tools-next$ toolbox enter perf
⬢[acme@toolbox perf-tools-next]$ sudo su -
⬢[root@toolbox ~]# ~acme/bin/perf ftrace
failed to reset ftrace
⬢[root@toolbox ~]#

After this patch:

⬢[root@toolbox ~]# ~acme/bin/perf ftrace
ftrace is not supported on this system
⬢[root@toolbox ~]#

Maybe we could check if we are in such as situation, inside an
unprivileged container, and provide a HINT line?

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Changbin Du <changbin.du@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240911100126.900779-1-changbin.du@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Changbin Du and committed by
Arnaldo Carvalho de Melo
74298dd8 83420d5f

+23
+23
tools/perf/builtin-ftrace.c
··· 80 80 return false; 81 81 } 82 82 83 + static bool is_ftrace_supported(void) 84 + { 85 + char *file; 86 + bool supported = false; 87 + 88 + file = get_tracing_file("set_ftrace_pid"); 89 + if (!file) { 90 + pr_debug("cannot get tracing file set_ftrace_pid\n"); 91 + return false; 92 + } 93 + 94 + if (!access(file, F_OK)) 95 + supported = true; 96 + 97 + put_tracing_file(file); 98 + return supported; 99 + } 100 + 83 101 static int __write_tracing_file(const char *name, const char *val, bool append) 84 102 { 85 103 char *file; ··· 1600 1582 1601 1583 if (!check_ftrace_capable()) 1602 1584 return -1; 1585 + 1586 + if (!is_ftrace_supported()) { 1587 + pr_err("ftrace is not supported on this system\n"); 1588 + return -ENOTSUP; 1589 + } 1603 1590 1604 1591 ret = perf_config(perf_ftrace_config, &ftrace); 1605 1592 if (ret < 0)