Before this patch, when using overwritable ring buffer on an old
kernel, error message is misleading:

 # ~/perf record -m 1 -e raw_syscalls:*/overwrite/ -a
 Error:
 The raw_syscalls:sys_enter event is not supported.

This patch output clear error message to tell user his/her kernel
is too old:

 # ~/perf record -m 1 -e raw_syscalls:*/overwrite/ -a
 Reading from overwrite event is not supported by this kernel
 Error:
 The raw_syscalls:sys_enter event is not supported.

Signed-off-by: Wang Nan <wangn...@huawei.com>
Cc: He Kuang <heku...@huawei.com>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Jiri Olsa <jo...@kernel.org>
Cc: Masami Hiramatsu <mhira...@kernel.org>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Zefan Li <lize...@huawei.com>
Cc: pi3or...@163.com
---
 tools/perf/util/evsel.c  | 17 +++++------------
 tools/perf/util/evsel.h  | 13 +++++++++++++
 tools/perf/util/record.c | 17 +++++++++++++++++
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ef223c7..59a69bb 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -29,17 +29,7 @@
 #include "trace-event.h"
 #include "stat.h"
 
-static struct {
-       bool sample_id_all;
-       bool exclude_guest;
-       bool mmap2;
-       bool cloexec;
-       bool clockid;
-       bool clockid_wrong;
-       bool lbr_flags;
-       bool write_backward;
-} perf_missing_features;
-
+struct perf_missing_features perf_missing_features;
 static clockid_t clockid;
 
 static int perf_evsel__no_extra_init(struct perf_evsel *evsel __maybe_unused)
@@ -690,8 +680,11 @@ static void apply_config_terms(struct perf_evsel *evsel,
         * possible to set overwrite globally, without config
         * terms.
         */
-       if (evsel->overwrite)
+       if (evsel->overwrite) {
+               WARN_ONCE(perf_missing_features.write_backward,
+                         "Reading from overwrite event is not supported by 
this kernel\n");
                attr->write_backward = 1;
+       }
 
        /* User explicitly set per-event callgraph, clear the old setting and 
reset. */
        if ((callgraph_buf != NULL) || (dump_size > 0) || max_stack) {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 55ff958..17e506a 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -11,6 +11,19 @@
 #include "cpumap.h"
 #include "counts.h"
 
+struct perf_missing_features {
+       bool sample_id_all;
+       bool exclude_guest;
+       bool mmap2;
+       bool cloexec;
+       bool clockid;
+       bool clockid_wrong;
+       bool lbr_flags;
+       bool write_backward;
+};
+
+extern struct perf_missing_features perf_missing_features;
+
 struct perf_evsel;
 
 /*
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 481792c..e3ab812 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -90,6 +90,11 @@ static void perf_probe_context_switch(struct perf_evsel 
*evsel)
        evsel->attr.context_switch = 1;
 }
 
+static void perf_probe_write_backward(struct perf_evsel *evsel)
+{
+       evsel->attr.write_backward = 1;
+}
+
 bool perf_can_sample_identifier(void)
 {
        return perf_probe_api(perf_probe_sample_identifier);
@@ -129,6 +134,17 @@ bool perf_can_record_cpu_wide(void)
        return true;
 }
 
+static void perf_check_write_backward(void)
+{
+       static bool checked = false;
+
+       if (!checked) {
+               perf_missing_features.write_backward =
+                       !perf_probe_api(perf_probe_write_backward);
+               checked = true;
+       }
+}
+
 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,
                         struct callchain_param *callchain)
 {
@@ -136,6 +152,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct 
record_opts *opts,
        bool use_sample_identifier = false;
        bool use_comm_exec;
 
+       perf_check_write_backward();
        /*
         * Set the evsel leader links before we configure attributes,
         * since some might depend on this info.
-- 
1.8.3.4

Reply via email to