diff mbox

[09/17] perf tools: Detect avalibility of write_backward

Message ID 1463126174-119290-10-git-send-email-wangnan0@huawei.com
State New
Headers show

Commit Message

Wang Nan May 13, 2016, 7:56 a.m. UTC
Detect avalibility of write_backward and save the result into
record_opts. With write_backward the start pointer of a ring
buffer mapped read only can be found reliably.

Signed-off-by: Wang Nan <wangnan0@huawei.com>

Signed-off-by: He Kuang <hekuang@huawei.com>

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/perf.h        |  1 +
 tools/perf/util/record.c | 11 +++++++++++
 2 files changed, 12 insertions(+)

-- 
1.8.3.4

Comments

Wang Nan May 20, 2016, 3:31 p.m. UTC | #1
On 2016/5/13 21:08, Arnaldo Carvalho de Melo wrote:
> Em Fri, May 13, 2016 at 07:56:06AM +0000, Wang Nan escreveu:

>> Detect avalibility of write_backward and save the result into

>> record_opts. With write_backward the start pointer of a ring

>> buffer mapped read only can be found reliably.

> We have perf_missing_features for that, please try to use it.


I'll try it, but write_backward can't fallback, if kernel doesn't
support it, I think we'd better throw an error earlier. Using
perf_missing_features we get error during opening the event, so if we want
to fail earlier we still need API probing.

Thank you.
diff mbox

Patch

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index cd8f1b1..c35bcfd 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -72,6 +72,7 @@  struct record_opts {
 	bool	     sample_transaction;
 	unsigned     initial_delay;
 	bool         use_clockid;
+	bool	     has_write_backward;
 	clockid_t    clockid;
 	unsigned int proc_map_timeout;
 };
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 481792c..bb871d8 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -85,6 +85,11 @@  static void perf_probe_comm_exec(struct perf_evsel *evsel)
 	evsel->attr.comm_exec = 1;
 }
 
+static void perf_probe_write_backward(struct perf_evsel *evsel)
+{
+	evsel->attr.write_backward = 1;
+}
+
 static void perf_probe_context_switch(struct perf_evsel *evsel)
 {
 	evsel->attr.context_switch = 1;
@@ -105,6 +110,11 @@  bool perf_can_record_switch_events(void)
 	return perf_probe_api(perf_probe_context_switch);
 }
 
+static bool perf_can_write_backward(void)
+{
+	return perf_probe_api(perf_probe_write_backward);
+}
+
 bool perf_can_record_cpu_wide(void)
 {
 	struct perf_event_attr attr = {
@@ -236,6 +246,7 @@  static int record_opts__config_freq(struct record_opts *opts)
 
 int record_opts__config(struct record_opts *opts)
 {
+	opts->has_write_backward = perf_can_write_backward();
 	return record_opts__config_freq(opts);
 }