diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index af250556b33f9e0d56493aa390aaa826db6eb08a..2eb7378e4c4064e657be6c39cb4119bcb29c82a3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1191,8 +1191,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused, "Error:\t%s.\n" "Hint:\tCheck /proc/sys/kernel/perf_event_paranoid setting.", emsg); - if (filename__read_int("/proc/sys/kernel/perf_event_paranoid", &value)) - break; + value = perf_event_paranoid(); printed += scnprintf(buf + printed, size - printed, "\nHint:\t"); diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 4a57609c0b43ba1f89ae3fee149aea8cc2755d7a..8f63dba212d7f850350d8b2fad95034bad53827b 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -1,5 +1,6 @@ #include "../perf.h" #include "util.h" +#include "fs.h" #include #ifdef HAVE_BACKTRACE_SUPPORT #include @@ -8,6 +9,7 @@ #include #include #include +#include #include /* @@ -496,3 +498,20 @@ const char *get_filename_for_perf_kvm(void) return filename; } + +int perf_event_paranoid(void) +{ + char path[PATH_MAX]; + const char *procfs = procfs__mountpoint(); + int value; + + if (!procfs) + return INT_MAX; + + scnprintf(path, PATH_MAX, "%s/sys/kernel/perf_event_paranoid", procfs); + + if (filename__read_int(path, &value)) + return INT_MAX; + + return value; +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0171213d1d4db8c5cff8cda8a1458f1bf170735c..1e7d4136cc82aaeb0881907610d71b3cff1b3f61 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -321,6 +321,7 @@ void free_srcline(char *srcline); int filename__read_int(const char *filename, int *value); int filename__read_str(const char *filename, char **buf, size_t *sizep); +int perf_event_paranoid(void); const char *get_filename_for_perf_kvm(void); #endif /* GIT_COMPAT_UTIL_H */