[PATCH 11/17] perf tools: Set write_backward attribut bit for overwrite events
From: Wang Nan
Date: Fri May 13 2016 - 03:58:49 EST
write_backward attribute makes kernel filling ring buffer from the end
of it, makes reading from overwrite ring buffer possible.
This patch selects this attribute if evsel->overwrite is selected
explicitly by user.
Overwrite and write_backward are still controled separatly for legacy
readonly mmap users (most of them are in perf/tests).
Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Cc: pi3orama@xxxxxxx
---
tools/perf/builtin-record.c | 7 +++++++
tools/perf/util/evlist.c | 2 ++
tools/perf/util/evlist.h | 1 +
tools/perf/util/evsel.c | 13 +++++++++++++
4 files changed, 23 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 939aa68..49c41c3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -300,6 +300,13 @@ static int record__open(struct record *rec)
perf_evlist__config(evlist, opts, &callchain_param);
evlist__for_each(evlist, pos) {
+ if (pos->overwrite) {
+ if (!pos->attr.write_backward) {
+ ui__warning("Unable to read from overwrite ring buffer\n\n");
+ rc = -ENOSYS;
+ goto out;
+ }
+ }
try_again:
if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f0b0457..dc2e509 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1043,6 +1043,8 @@ perf_evlist__channel_for_evsel(struct perf_evsel *evsel __maybe_unused)
if (evsel->overwrite)
flag |= PERF_EVLIST__CHANNEL_RDONLY;
+ if (evsel->attr.write_backward)
+ flag |= PERF_EVLIST__CHANNEL_BACKWARD;
return flag;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index c53bdbd..bdd8e98 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -24,6 +24,7 @@ struct record_opts;
enum perf_evlist_mmap_flag {
PERF_EVLIST__CHANNEL_ENABLED = 1,
PERF_EVLIST__CHANNEL_RDONLY = 2,
+ PERF_EVLIST__CHANNEL_BACKWARD = 4,
};
/**
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index be4fc25..f1b060b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -678,6 +678,19 @@ static void apply_config_terms(struct perf_evsel *evsel,
}
}
+ /*
+ * Set backward after config term processing because it is
+ * possible to set overwrite globally, without config
+ * terms.
+ */
+ if (evsel->overwrite) {
+ if (opts->has_write_backward)
+ attr->write_backward = 1;
+ else
+ pr_err("Reading from overwrite event %s is not supported\n",
+ evsel->name);
+ }
+
/* User explicitly set per-event callgraph, clear the old setting and reset. */
if ((callgraph_buf != NULL) || (dump_size > 0)) {
--
1.8.3.4