Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1400559 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-05-13 10:00 +0200 |
| Last post | 2016-05-13 10:20 +0200 |
| Articles | 20 on this page of 28 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH 00/17] perf tools: Support overwritable ring buffer Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 15/17] perf record: Read from backward ring buffer Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
Re: [PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
[PATCH 09/17] perf tools: Detect avalibility of write_backward Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-20 17:40 +0200
Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 17:40 +0200
[PATCH 05/17] perf record: Prevent reading invalid data in record__mmap_read Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 17/17] perf tools: Don't warn about out of order event if write_backward is used Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 11/17] perf tools: Set write_backward attribut bit for overwrite events Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 04/17] perf tools: Operate multiple channels Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 08/17] perf record: Don't poll on overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
Re: [PATCH 08/17] perf record: Don't poll on overwrite channel Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:20 +0200
Re: [PATCH 08/17] perf record: Don't poll on overwrite channel "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-16 05:20 +0200
[PATCH 16/17] perf record: Toggle overwrite ring buffer for reading Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 10/17] perf tools: Enable overwrite settings Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
Re: [PATCH 10/17] perf tools: Enable overwrite settings Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-16 15:40 +0200
[PATCH 07/17] perf record: Don't read from and poll overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 12/17] perf tools: Record fd into perf_mmap Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 13/17] perf tools: Add API to pause a channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
[PATCH 14/17] perf record: Rename variable to make code clear Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:10 +0200
[PATCH 02/17] perf tools: Add evlist channel helpers Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:10 +0200
Re: [PATCH 02/17] perf tools: Add evlist channel helpers Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
Re: [PATCH 02/17] perf tools: Add evlist channel helpers "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-18 05:40 +0200
Re: [PATCH 02/17] perf tools: Add evlist channel helpers Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> - 2016-05-18 15:30 +0200
[PATCH 03/17] perf tools: Automatically add new channel according to evlist Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:20 +0200
[PATCH 06/17] perf tools: Squash overwrite setting into channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:20 +0200
Page 1 of 2 [1] 2 Next page →
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 00/17] perf tools: Support overwritable ring buffer |
| Message-ID | <rygaR-7tc-1@gated-at.bofh.it> |
This patch set enables daemonized perf recording by utilizing
overwritable backward ring buffer. With this feature one can
put perf background, and dump ring buffer records by a SIGUSR2
when he/she find something unusual. For example, following
command record system calls, schedule events and samples on cpu cycles
continously:
# perf record -g -e cycles -e raw_syscalls:*/call-graph=no/ \
-e sched:sched_switch/call-graph=no/ \
--switch-output --overwrite -a
Then by sending SIGUSR2 to perf when lagging is happen, we get multiple
perf.data output, each of them correspond a abnormal event, and the data
size is reasonable:
# ls -l ./perf.data*
-rw------- 1 root root 5122165 May 13 23:51 ./perf.data.2016051323511683
-rw------- 1 root root 5135093 May 13 23:51 ./perf.data.2016051323512107
-rw------- 1 root root 5135213 May 13 23:51 ./perf.data.2016051323512215
-rw------- 1 root root 5135157 May 13 23:51 ./perf.data.2016051323512387
Wang Nan (17):
perf tools: Extract __perf_evlist__mmap_read()
perf tools: Add evlist channel helpers
perf tools: Automatically add new channel according to evlist
perf tools: Operate multiple channels
perf record: Prevent reading invalid data in record__mmap_read
perf tools: Squash overwrite setting into channel
perf record: Don't read from and poll overwrite channel
perf record: Don't poll on overwrite channel
perf tools: Detect avalibility of write_backward
perf tools: Enable overwrite settings
perf tools: Set write_backward attribut bit for overwrite events
perf tools: Record fd into perf_mmap
perf tools: Add API to pause a channel
perf record: Rename variable to make code clear
perf record: Read from backward ring buffer
perf record: Toggle overwrite ring buffer for reading
perf tools: Don't warn about out of order event if write_backward is
used
tools/perf/builtin-record.c | 207 +++++++++++++++++++++++--
tools/perf/perf.h | 2 +
tools/perf/util/evlist.c | 332 ++++++++++++++++++++++++++++++++++++-----
tools/perf/util/evlist.h | 67 ++++++++-
tools/perf/util/evsel.c | 17 +++
tools/perf/util/evsel.h | 3 +
tools/perf/util/parse-events.c | 20 ++-
tools/perf/util/parse-events.h | 2 +
tools/perf/util/parse-events.l | 2 +
tools/perf/util/record.c | 11 ++
tools/perf/util/session.c | 22 ++-
11 files changed, 625 insertions(+), 60 deletions(-)
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
--
1.8.3.4
[toc] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 15/17] perf record: Read from backward ring buffer |
| Message-ID | <rygaR-7tc-3@gated-at.bofh.it> |
| In reply to | #1400559 |
Introduce rb_find_range() to find start and end position from a backward
ring buffer.
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/builtin-record.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9f4d3ad..e637ea2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -83,6 +83,61 @@ static int process_synthesized_event(struct perf_tool *tool,
return record__write(rec, event, event->header.size);
}
+static int
+backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
+{
+ struct perf_event_header *pheader;
+ u64 evt_head = head;
+ int size = mask + 1;
+
+ pr_debug2("backward_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
+ pheader = (struct perf_event_header *)(buf + (head & mask));
+ *start = head;
+ while (true) {
+ if (evt_head - head >= (unsigned int)size) {
+ pr_debug("Finshed reading backward ring buffer: rewind\n");
+ if (evt_head - head > (unsigned int)size)
+ evt_head -= pheader->size;
+ *end = evt_head;
+ return 0;
+ }
+
+ pheader = (struct perf_event_header *)(buf + (evt_head & mask));
+
+ if (pheader->size == 0) {
+ pr_debug("Finshed reading backward ring buffer: get start\n");
+ *end = evt_head;
+ return 0;
+ }
+
+ evt_head += pheader->size;
+ pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
+ }
+ WARN_ONCE(1, "Shouldn't get here\n");
+ return -1;
+}
+
+static int
+rb_find_range(struct perf_evlist *evlist, int idx,
+ void *data, int mask, u64 head, u64 old,
+ u64 *start, u64 *end)
+{
+ int channel;
+
+ channel = perf_evlist__idx_channel(evlist, idx);
+ if (!perf_evlist__channel_check(evlist, channel, RDONLY)) {
+ *start = old;
+ *end = head;
+ return 0;
+ }
+
+ if (perf_evlist__channel_check(evlist, channel, BACKWARD))
+ return backward_rb_find_range(data, mask, head, start, end);
+
+ WARN_ONCE(1, "Unable to find start position from a read-only ring buffer\n");
+ return -1;
+}
+
static int record__mmap_read(struct record *rec, int idx)
{
struct perf_mmap *md = &rec->evlist->mmap[idx];
@@ -94,6 +149,10 @@ static int record__mmap_read(struct record *rec, int idx)
void *buf;
int rc = 0;
+ if (rb_find_range(rec->evlist, idx, data, md->mask, head,
+ old, &start, &end))
+ return -1;
+
if (start == end)
return 0;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() |
| Message-ID | <rygaR-7tc-5@gated-at.bofh.it> |
| In reply to | #1400559 |
Extract event reader to __perf_evlist__mmap_read(). Future commit will
feed it with manually computed 'head' and 'old' pointers.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
tools/perf/util/evlist.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c4bfe11..5e86972 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -749,6 +749,13 @@ broken_event:
return event;
}
+static union perf_event *
+__perf_evlist__mmap_read(struct perf_mmap *md, bool overwrite, u64 head,
+ u64 old, u64 *prev)
+{
+ return perf_mmap__read(md, overwrite, old, head, prev);
+}
+
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
{
struct perf_mmap *md = &evlist->mmap[idx];
@@ -763,7 +770,8 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
head = perf_mmap__read_head(md);
- return perf_mmap__read(md, evlist->overwrite, old, head, &md->prev);
+ return __perf_evlist__mmap_read(md, evlist->overwrite, head,
+ old, &md->prev);
}
union perf_event *
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-05-13 15:10 +0200 |
| Subject | Re: [PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() |
| Message-ID | <ryl0R-3QE-1@gated-at.bofh.it> |
| In reply to | #1400561 |
Em Fri, May 13, 2016 at 07:55:58AM +0000, Wang Nan escreveu:
> Extract event reader to __perf_evlist__mmap_read(). Future commit will
> feed it with manually computed 'head' and 'old' pointers.
why not use the perf_mmap__read() directly then?
- Arnaldo
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> ---
> tools/perf/util/evlist.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index c4bfe11..5e86972 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -749,6 +749,13 @@ broken_event:
> return event;
> }
>
> +static union perf_event *
> +__perf_evlist__mmap_read(struct perf_mmap *md, bool overwrite, u64 head,
> + u64 old, u64 *prev)
> +{
> + return perf_mmap__read(md, overwrite, old, head, prev);
> +}
> +
> union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
> {
> struct perf_mmap *md = &evlist->mmap[idx];
> @@ -763,7 +770,8 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
>
> head = perf_mmap__read_head(md);
>
> - return perf_mmap__read(md, evlist->overwrite, old, head, &md->prev);
> + return __perf_evlist__mmap_read(md, evlist->overwrite, head,
> + old, &md->prev);
> }
>
> union perf_event *
> --
> 1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 09/17] perf tools: Detect avalibility of write_backward |
| Message-ID | <rygaS-7tc-25@gated-at.bofh.it> |
| In reply to | #1400559 |
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(+)
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);
}
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-05-13 15:10 +0200 |
| Subject | Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward |
| Message-ID | <ryl0S-3QE-17@gated-at.bofh.it> |
| In reply to | #1400563 |
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.
- Arnaldo
> 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(+)
>
> 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);
> }
>
> --
> 1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | "Wangnan (F)" <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-20 17:40 +0200 |
| Subject | Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward |
| Message-ID | <rAUGR-7fU-5@gated-at.bofh.it> |
| In reply to | #1400781 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-05-20 17:40 +0200 |
| Subject | Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward |
| Message-ID | <rAUGR-7fU-9@gated-at.bofh.it> |
| In reply to | #1404549 |
Em Fri, May 20, 2016 at 11:31:44PM +0800, Wangnan (F) escreveu: > > > 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. Conceptually 'perf_missing_features' shouldn't be strictly tied to fallbacking, its just a way to mark what perf features are missing in the current kernel, that info may be used for fallbacking, or for any other purpose. - Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 05/17] perf record: Prevent reading invalid data in record__mmap_read |
| Message-ID | <rygaS-7tc-17@gated-at.bofh.it> |
| In reply to | #1400559 |
When record__mmap_read() requires data more than the size of ring
buffer, drop those data to avoid accessing invalid memory.
This can happen when reading from overwritable ring buffer, which
should be avoided. However, check this for robustness.
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/builtin-record.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 21ef8a0..81c700d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -40,6 +40,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>
+#include <asm/bug.h>
struct record {
@@ -98,6 +99,13 @@ static int record__mmap_read(struct record *rec, int idx)
rec->samples++;
size = head - old;
+ if (size > (unsigned long)(md->mask) + 1) {
+ WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
+
+ md->prev = head;
+ perf_evlist__mmap_consume(rec->evlist, idx);
+ return 0;
+ }
if ((old & md->mask) + size != (head & md->mask)) {
buf = &data[old & md->mask];
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 17/17] perf tools: Don't warn about out of order event if write_backward is used |
| Message-ID | <rygaS-7tc-21@gated-at.bofh.it> |
| In reply to | #1400559 |
If write_backward attribute is set, records are written into kernel
ring buffer from end to beginning, but read from beginning to end.
To avoid 'XX out of order events recorded' warning message (timestamps
of records is in reverse order when using write_backward), suppress the
warning message if write_backward is selected by at lease one event.
Result:
Before this patch:
# perf record -m 1 -e raw_syscalls:sys_exit/overwrite/ \
-e raw_syscalls:sys_enter \
dd if=/dev/zero of=/dev/null count=300
300+0 records in
300+0 records out
153600 bytes (154 kB) copied, 0.000601617 s, 255 MB/s
[ perf record: Woken up 5 times to write data ]
Warning:
40 out of order events recorded.
[ perf record: Captured and wrote 0.096 MB perf.data (696 samples) ]
After this patch:
# perf record -m 1 -e raw_syscalls:sys_exit/overwrite/ \
-e raw_syscalls:sys_enter \
dd if=/dev/zero of=/dev/null count=300
300+0 records in
300+0 records out
153600 bytes (154 kB) copied, 0.000644873 s, 238 MB/s
[ perf record: Woken up 5 times to write data ]
[ perf record: Captured and wrote 0.096 MB perf.data (696 samples) ]
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/util/session.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 2335b28..8e3d9d4 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1495,10 +1495,27 @@ int perf_session__register_idle_thread(struct perf_session *session)
return err;
}
+static void
+perf_session__warn_order(const struct perf_session *session)
+{
+ const struct ordered_events *oe = &session->ordered_events;
+ struct perf_evsel *evsel;
+ bool should_warn = true;
+
+ evlist__for_each(session->evlist, evsel) {
+ if (evsel->attr.write_backward)
+ should_warn = false;
+ }
+
+ if (!should_warn)
+ return;
+ if (oe->nr_unordered_events != 0)
+ ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
+}
+
static void perf_session__warn_about_errors(const struct perf_session *session)
{
const struct events_stats *stats = &session->evlist->stats;
- const struct ordered_events *oe = &session->ordered_events;
if (session->tool->lost == perf_event__process_lost &&
stats->nr_events[PERF_RECORD_LOST] != 0) {
@@ -1555,8 +1572,7 @@ static void perf_session__warn_about_errors(const struct perf_session *session)
stats->nr_unprocessable_samples);
}
- if (oe->nr_unordered_events != 0)
- ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
+ perf_session__warn_order(session);
events_stats__auxtrace_error_warn(stats);
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 11/17] perf tools: Set write_backward attribut bit for overwrite events |
| Message-ID | <rygaS-7tc-35@gated-at.bofh.it> |
| In reply to | #1400559 |
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@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/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
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 04/17] perf tools: Operate multiple channels |
| Message-ID | <rygaS-7tc-27@gated-at.bofh.it> |
| In reply to | #1400559 |
Before this patch perf operates on only the first channel. Make perf
mmap and read from multiple channels.
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/builtin-record.c | 3 ++-
tools/perf/util/evlist.c | 52 ++++++++++++++++++++++++++++++++-------------
tools/perf/util/evlist.h | 2 +-
3 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3140378..21ef8a0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -426,8 +426,9 @@ static int record__mmap_read_all(struct record *rec)
u64 bytes_written = rec->bytes_written;
int i;
int rc = 0;
+ int total_mmaps = perf_evlist__mmap_nr(rec->evlist);
- for (i = 0; i < rec->evlist->nr_mmaps; i++) {
+ for (i = 0; i < total_mmaps; i++) {
struct auxtrace_mmap *mm = &rec->evlist->mmap[i].auxtrace_mmap;
if (rec->evlist->mmap[i].base) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 47a8f1f..eefa33b 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -947,6 +947,16 @@ static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
auxtrace_mmap__munmap(&evlist->mmap[idx].auxtrace_mmap);
}
+static void
+__perf_evlist__munmap_all(struct perf_evlist *evlist)
+{
+ int ch, i, idx = 0;
+
+ for (ch = 0; ch < perf_evlist__channel_nr(evlist); ch++)
+ for (i = 0; i < evlist->nr_mmaps; i++)
+ __perf_evlist__munmap(evlist, idx++);
+}
+
void perf_evlist__munmap(struct perf_evlist *evlist)
{
int i;
@@ -1054,26 +1064,38 @@ perf_evlist__channel_complete(struct perf_evlist *evlist)
return 0;
}
-static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
+static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
struct mmap_params *mp, int cpu,
- int thread, int *output)
+ int thread, int *outputs)
{
struct perf_evsel *evsel;
evlist__for_each(evlist, evsel) {
- int fd;
+ int fd, channel, idx, err;
+
+ channel = perf_evlist__channel_find(evlist, evsel, false);
+ if (channel < 0) {
+ pr_err("ERROR: unable to find suitable channel for %s\n",
+ evsel->name);
+ return -1;
+ }
+
+ idx = _idx;
+ err = perf_evlist__channel_idx(evlist, &channel, &idx);
+ if (err < 0)
+ return err;
if (evsel->system_wide && thread)
continue;
fd = FD(evsel, cpu, thread);
- if (*output == -1) {
- *output = fd;
- if (__perf_evlist__mmap(evlist, idx, mp, *output) < 0)
+ if (outputs[channel] == -1) {
+ outputs[channel] = fd;
+ if (__perf_evlist__mmap(evlist, idx, mp, outputs[channel]) < 0)
return -1;
} else {
- if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
+ if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, outputs[channel]) != 0)
return -1;
perf_evlist__mmap_get(evlist, idx);
@@ -1113,14 +1135,15 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
pr_debug2("perf event ring buffer mmapped per cpu\n");
for (cpu = 0; cpu < nr_cpus; cpu++) {
- int output = -1;
+ int outputs[PERF_EVLIST__NR_CHANNELS];
+ memset(outputs, -1, sizeof(outputs));
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
true);
for (thread = 0; thread < nr_threads; thread++) {
if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
- thread, &output))
+ thread, outputs))
goto out_unmap;
}
}
@@ -1128,8 +1151,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
return 0;
out_unmap:
- for (cpu = 0; cpu < nr_cpus; cpu++)
- __perf_evlist__munmap(evlist, cpu);
+ __perf_evlist__munmap_all(evlist);
return -1;
}
@@ -1141,21 +1163,21 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
pr_debug2("perf event ring buffer mmapped per thread\n");
for (thread = 0; thread < nr_threads; thread++) {
- int output = -1;
+ int outputs[PERF_EVLIST__NR_CHANNELS];
+ memset(outputs, -1, sizeof(outputs));
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
false);
if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
- &output))
+ outputs))
goto out_unmap;
}
return 0;
out_unmap:
- for (thread = 0; thread < nr_threads; thread++)
- __perf_evlist__munmap(evlist, thread);
+ __perf_evlist__munmap_all(evlist);
return -1;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 4cb5d3a..188f0c7 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -20,7 +20,7 @@ struct record_opts;
#define PERF_EVLIST__HLIST_BITS 8
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
-#define PERF_EVLIST__NR_CHANNELS 1
+#define PERF_EVLIST__NR_CHANNELS 2
enum perf_evlist_mmap_flag {
PERF_EVLIST__CHANNEL_ENABLED = 1,
};
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 08/17] perf record: Don't poll on overwrite channel |
| Message-ID | <rygaS-7tc-29@gated-at.bofh.it> |
| In reply to | #1400559 |
There's no need to receive events from overwritable ring buffer. Instead,
perf should make them run background until something happen. This patch
makes normal events from overwrite ring buffer ignored.
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/util/evlist.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index abce588..f0b0457 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -461,9 +461,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
return 0;
}
-static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
+static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent)
{
- int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
+ int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
/*
* Save the idx so that when we filter out fds POLLHUP'ed we can
* close the associated evlist->mmap[] entry.
@@ -479,7 +479,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
{
- return __perf_evlist__add_pollfd(evlist, fd, -1);
+ return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
}
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
@@ -1077,6 +1077,18 @@ perf_evlist__channel_complete(struct perf_evlist *evlist)
return 0;
}
+static bool
+perf_evlist__should_poll(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int channel)
+{
+ if (evsel->system_wide)
+ return false;
+ if (perf_evlist__channel_check(evlist, channel, RDONLY))
+ return false;
+ return true;
+}
+
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
struct mmap_params *mp, int cpu,
int thread, int *outputs)
@@ -1085,6 +1097,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
evlist__for_each(evlist, evsel) {
int fd, channel, idx, err;
+ short revent = POLLIN;
channel = perf_evlist__channel_find(evlist, evsel, false);
if (channel < 0) {
@@ -1114,6 +1127,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
perf_evlist__mmap_get(evlist, idx);
}
+ if (!perf_evlist__should_poll(evlist, evsel, channel))
+ revent = 0;
/*
* The system_wide flag causes a selected event to be opened
* always without a pid. Consequently it will never get a
@@ -1122,7 +1137,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
* Therefore don't add it for polling.
*/
if (!evsel->system_wide &&
- __perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
+ __perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) {
perf_evlist__mmap_put(evlist, idx);
return -1;
}
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-05-13 15:20 +0200 |
| Subject | Re: [PATCH 08/17] perf record: Don't poll on overwrite channel |
| Message-ID | <rylay-3Vi-19@gated-at.bofh.it> |
| In reply to | #1400568 |
Em Fri, May 13, 2016 at 07:56:05AM +0000, Wang Nan escreveu:
> There's no need to receive events from overwritable ring buffer. Instead,
> perf should make them run background until something happen. This patch
> makes normal events from overwrite ring buffer ignored.
>
> 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/util/evlist.c | 23 +++++++++++++++++++----
> 1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index abce588..f0b0457 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -461,9 +461,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
> return 0;
> }
>
> -static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
> +static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent)
> {
> - int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
> + int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
> /*
> * Save the idx so that when we filter out fds POLLHUP'ed we can
> * close the associated evlist->mmap[] entry.
> @@ -479,7 +479,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
>
> int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
> {
> - return __perf_evlist__add_pollfd(evlist, fd, -1);
> + return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
> }
>
> static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
> @@ -1077,6 +1077,18 @@ perf_evlist__channel_complete(struct perf_evlist *evlist)
> return 0;
> }
>
> +static bool
> +perf_evlist__should_poll(struct perf_evlist *evlist,
> + struct perf_evsel *evsel,
> + int channel)
> +{
> + if (evsel->system_wide)
> + return false;
So, what is the above doing in this patch? If we should not poll when in
syswide mode, then this should be in a separate patch, unrelated to
'channels'. No?
I.e. it would be an improvement that would be cherry pickable right now,
even before reviewing the channel concept.
- Arnaldo
> + if (perf_evlist__channel_check(evlist, channel, RDONLY))
> + return false;
> + return true;
> +}
> +
> static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
> struct mmap_params *mp, int cpu,
> int thread, int *outputs)
> @@ -1085,6 +1097,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
>
> evlist__for_each(evlist, evsel) {
> int fd, channel, idx, err;
> + short revent = POLLIN;
>
> channel = perf_evlist__channel_find(evlist, evsel, false);
> if (channel < 0) {
> @@ -1114,6 +1127,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
> perf_evlist__mmap_get(evlist, idx);
> }
>
> + if (!perf_evlist__should_poll(evlist, evsel, channel))
> + revent = 0;
> /*
> * The system_wide flag causes a selected event to be opened
> * always without a pid. Consequently it will never get a
> @@ -1122,7 +1137,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
> * Therefore don't add it for polling.
> */
> if (!evsel->system_wide &&
> - __perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
> + __perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) {
> perf_evlist__mmap_put(evlist, idx);
> return -1;
> }
> --
> 1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | "Wangnan (F)" <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-16 05:20 +0200 |
| Subject | Re: [PATCH 08/17] perf record: Don't poll on overwrite channel |
| Message-ID | <rzheB-1xy-99@gated-at.bofh.it> |
| In reply to | #1400788 |
On 2016/5/13 21:12, Arnaldo Carvalho de Melo wrote:
> Em Fri, May 13, 2016 at 07:56:05AM +0000, Wang Nan escreveu:
>> There's no need to receive events from overwritable ring buffer. Instead,
>> perf should make them run background until something happen. This patch
>> makes normal events from overwrite ring buffer ignored.
>>
>> 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/util/evlist.c | 23 +++++++++++++++++++----
>> 1 file changed, 19 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
>> index abce588..f0b0457 100644
>> --- a/tools/perf/util/evlist.c
>> +++ b/tools/perf/util/evlist.c
>> @@ -461,9 +461,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
>> return 0;
>> }
>>
>> -static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
>> +static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent)
>> {
>> - int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
>> + int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
>> /*
>> * Save the idx so that when we filter out fds POLLHUP'ed we can
>> * close the associated evlist->mmap[] entry.
>> @@ -479,7 +479,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
>>
>> int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
>> {
>> - return __perf_evlist__add_pollfd(evlist, fd, -1);
>> + return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
>> }
>>
>> static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
>> @@ -1077,6 +1077,18 @@ perf_evlist__channel_complete(struct perf_evlist *evlist)
>> return 0;
>> }
>>
>> +static bool
>> +perf_evlist__should_poll(struct perf_evlist *evlist,
>> + struct perf_evsel *evsel,
>> + int channel)
>> +{
>> + if (evsel->system_wide)
>> + return false;
> So, what is the above doing in this patch? If we should not poll when in
> syswide mode, then this should be in a separate patch, unrelated to
> 'channels'. No?
I think the name 'system_wide' is more or less missleading. It is not means
an event in 'perf record -a', but means "a selected event to be opened
always
without a pid when configured by perf_evsel__config().". See bf8e8f4b8.
Here we use similary logic in existing perf_evlist__mmap_per_evsel. It never
poll system_wide evsel:
/*
* The system_wide flag causes a selected event to be
opened
* always without a pid. Consequently it will never get a
* POLLHUP, but it is used for tracking in combination with
* other events, so it should not need to be polled anyway.
* Therefore don't add it for polling.
*/
if (!evsel->system_wide &&
__perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
perf_evlist__mmap_put(evlist, idx);
return -1;
}
Thank you.
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 16/17] perf record: Toggle overwrite ring buffer for reading |
| Message-ID | <rygaT-7tc-41@gated-at.bofh.it> |
| In reply to | #1400559 |
Reading from a overwrite ring buffer is unrelible.
perf_evlist__channel_toggle_paused() should be called before
reading from them.
Toggel overwrite_evt_paused director after receiving done or switch
output.
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/builtin-record.c | 94 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 92 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e637ea2..606fcd05 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -42,6 +42,11 @@
#include <sys/mman.h>
#include <asm/bug.h>
+enum overwrite_evt_state {
+ OVERWRITE_EVT_RUNNING,
+ OVERWRITE_EVT_DATA_PENDING,
+ OVERWRITE_EVT_EMPTY,
+};
struct record {
struct perf_tool tool;
@@ -60,6 +65,7 @@ struct record {
bool buildid_all;
bool timestamp_filename;
bool switch_output;
+ enum overwrite_evt_state overwrite_evt_state;
unsigned long long samples;
};
@@ -416,6 +422,7 @@ try_again:
session->evlist = evlist;
perf_session__set_id_hdr_size(session);
+ rec->overwrite_evt_state = OVERWRITE_EVT_RUNNING;
out:
return rc;
}
@@ -496,6 +503,52 @@ static struct perf_event_header finished_round_event = {
.type = PERF_RECORD_FINISHED_ROUND,
};
+static void
+record__toggle_overwrite_evsels(struct record *rec,
+ enum overwrite_evt_state state)
+{
+ struct perf_evlist *evlist = rec->evlist;
+ enum overwrite_evt_state old_state = rec->overwrite_evt_state;
+ enum action {
+ NONE,
+ PAUSE,
+ RESUME,
+ } action = NONE;
+ int ch, nr_channels;
+
+ switch (old_state) {
+ case OVERWRITE_EVT_RUNNING:
+ if (state != OVERWRITE_EVT_RUNNING)
+ action = PAUSE;
+ break;
+ case OVERWRITE_EVT_DATA_PENDING:
+ if (state == OVERWRITE_EVT_RUNNING)
+ action = RESUME;
+ break;
+ case OVERWRITE_EVT_EMPTY:
+ if (state == OVERWRITE_EVT_RUNNING)
+ action = RESUME;
+ if (state == OVERWRITE_EVT_DATA_PENDING)
+ state = OVERWRITE_EVT_EMPTY;
+ break;
+ default:
+ WARN_ONCE(1, "Shouldn't get there\n");
+ }
+
+ rec->overwrite_evt_state = state;
+
+ if (action == NONE)
+ return;
+
+ nr_channels = perf_evlist__channel_nr(evlist);
+ for (ch = 0; ch < nr_channels; ch++) {
+ if (!perf_evlist__channel_check(evlist, ch, RDONLY))
+ continue;
+ perf_evlist__channel_toggle_paused(evlist, ch,
+ action == PAUSE);
+ }
+}
+
static bool record__mmap_should_read(struct record *rec, int idx)
{
int channel = -1;
@@ -504,8 +557,13 @@ static bool record__mmap_should_read(struct record *rec, int idx)
return false;
if (perf_evlist__channel_idx(rec->evlist, &channel, &idx))
return false;
- if (perf_evlist__channel_check(rec->evlist, channel, RDONLY))
- return false;
+ if (perf_evlist__channel_check(rec->evlist, channel, RDONLY)) {
+ if (rec->overwrite_evt_state != OVERWRITE_EVT_DATA_PENDING)
+ return false;
+ if (!perf_evlist__channel_check(rec->evlist, channel, BACKWARD))
+ return false;
+ return true;
+ }
return true;
}
@@ -540,6 +598,8 @@ static int record__mmap_read_all(struct record *rec)
if (bytes_written != rec->bytes_written)
rc = record__write(rec, &finished_round_event, sizeof(finished_round_event));
+ if (rec->overwrite_evt_state == OVERWRITE_EVT_DATA_PENDING)
+ record__toggle_overwrite_evsels(rec, OVERWRITE_EVT_EMPTY);
out:
return rc;
}
@@ -917,6 +977,17 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
for (;;) {
unsigned long long hits = rec->samples;
+ /*
+ * rec->overwrite_evt_state is possible to be
+ * OVERWRITE_EVT_EMPTY here: when done == true and
+ * hits != rec->samples after previous reading.
+ *
+ * record__toggle_overwrite_evsels ensure we never
+ * convert OVERWRITE_EVT_EMPTY to OVERWRITE_EVT_DATA_PENDING.
+ */
+ if (trigger_is_hit(&switch_output_trigger) || done || draining)
+ record__toggle_overwrite_evsels(rec, OVERWRITE_EVT_DATA_PENDING);
+
if (record__mmap_read_all(rec) < 0) {
trigger_error(&auxtrace_snapshot_trigger);
trigger_error(&switch_output_trigger);
@@ -936,8 +1007,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
if (trigger_is_hit(&switch_output_trigger)) {
+ /*
+ * If switch_output_trigger is hit, the data in
+ * overwritable ring buffer should have been collected,
+ * so overwrite_evt_state should be set to
+ * OVERWRITE_EVT_EMPTY.
+ *
+ * If SIGUSR2 raise after or during record__mmap_read_all(),
+ * record__mmap_read_all() didn't collect data from
+ * overwritable ring buffer. Read again.
+ */
+ if (rec->overwrite_evt_state == OVERWRITE_EVT_RUNNING)
+ continue;
trigger_ready(&switch_output_trigger);
+ /*
+ * Reenable events in overwrite ring buffer after
+ * record__mmap_read_all(): we should have collected
+ * data from it.
+ */
+ record__toggle_overwrite_evsels(rec, OVERWRITE_EVT_RUNNING);
+
if (!quiet)
fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
waking);
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 10/17] perf tools: Enable overwrite settings |
| Message-ID | <rygaS-7tc-31@gated-at.bofh.it> |
| In reply to | #1400559 |
This patch allows following config terms and option:
Globally setting events to overwrite;
# perf record --overwrite ...
Set specific events to be overwrite or no-overwrite.
# perf record --event cycles/overwrite/ ...
# perf record --event cycles/no-overwrite/ ...
Add missing config terms and update config term array size because the
longest string length is changed.
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/builtin-record.c | 1 +
tools/perf/perf.h | 1 +
tools/perf/util/evsel.c | 4 ++++
tools/perf/util/evsel.h | 2 ++
tools/perf/util/parse-events.c | 20 ++++++++++++++++++--
tools/perf/util/parse-events.h | 2 ++
tools/perf/util/parse-events.l | 2 ++
7 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d9a92e0..939aa68 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1265,6 +1265,7 @@ struct option __record_options[] = {
OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
&record.opts.no_inherit_set,
"child tasks do not inherit counters"),
+ OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
OPT_CALLBACK('m', "mmap-pages", &record.opts, "pages[,pages]",
"number of mmap data pages and AUX area tracing mmap pages",
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index c35bcfd..386d030 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -59,6 +59,7 @@ struct record_opts {
bool record_switch_events;
bool all_kernel;
bool all_user;
+ bool overwrite;
unsigned int freq;
unsigned int mmap_pages;
unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index a23f547..be4fc25 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -670,6 +670,9 @@ static void apply_config_terms(struct perf_evsel *evsel,
*/
attr->inherit = term->val.inherit ? 1 : 0;
break;
+ case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
+ evsel->overwrite = term->val.overwrite ? 1 : 0;
+ break;
default:
break;
}
@@ -746,6 +749,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
attr->inherit = !opts->no_inherit;
+ evsel->overwrite = opts->overwrite;
perf_evsel__set_sample_bit(evsel, IP);
perf_evsel__set_sample_bit(evsel, TID);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index c1f1015..bce99fa 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -44,6 +44,7 @@ enum {
PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
PERF_EVSEL__CONFIG_TERM_STACK_USER,
PERF_EVSEL__CONFIG_TERM_INHERIT,
+ PERF_EVSEL__CONFIG_TERM_OVERWRITE,
PERF_EVSEL__CONFIG_TERM_MAX,
};
@@ -57,6 +58,7 @@ struct perf_evsel_config_term {
char *callgraph;
u64 stack_user;
bool inherit;
+ bool overwrite;
} val;
};
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index bcbc983..85f813d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -900,6 +900,8 @@ static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = {
[PARSE_EVENTS__TERM_TYPE_STACKSIZE] = "stack-size",
[PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit",
[PARSE_EVENTS__TERM_TYPE_INHERIT] = "inherit",
+ [PARSE_EVENTS__TERM_TYPE_OVERWRITE] = "overwrite",
+ [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite",
};
static bool config_term_shrinked;
@@ -992,6 +994,12 @@ do { \
case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
CHECK_TYPE_VAL(NUM);
break;
+ case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+ CHECK_TYPE_VAL(NUM);
+ break;
+ case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
+ CHECK_TYPE_VAL(NUM);
+ break;
case PARSE_EVENTS__TERM_TYPE_NAME:
CHECK_TYPE_VAL(STR);
break;
@@ -1040,6 +1048,8 @@ static int config_term_tracepoint(struct perf_event_attr *attr,
case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
case PARSE_EVENTS__TERM_TYPE_INHERIT:
case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
+ case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+ case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
return config_term_common(attr, term, err);
default:
if (err) {
@@ -1109,6 +1119,12 @@ do { \
case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1);
break;
+ case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+ ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0);
+ break;
+ case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
+ ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1);
+ break;
default:
break;
}
@@ -2322,9 +2338,9 @@ static void config_terms_list(char *buf, size_t buf_sz)
char *parse_events_formats_error_string(char *additional_terms)
{
char *str;
- /* "branch_type" is the longest name */
+ /* "no-overwrite" is the longest name */
char static_terms[__PARSE_EVENTS__TERM_TYPE_NR *
- (sizeof("branch_type") - 1)];
+ (sizeof("no-overwrite") - 1)];
config_terms_list(static_terms, sizeof(static_terms));
/* valid terms */
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index d740c3c..f341d9d 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -68,6 +68,8 @@ enum {
PARSE_EVENTS__TERM_TYPE_STACKSIZE,
PARSE_EVENTS__TERM_TYPE_NOINHERIT,
PARSE_EVENTS__TERM_TYPE_INHERIT,
+ PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
+ PARSE_EVENTS__TERM_TYPE_OVERWRITE,
__PARSE_EVENTS__TERM_TYPE_NR,
};
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 1477fbc..cc4c426 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -201,6 +201,8 @@ call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
+overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
+no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
, { return ','; }
"/" { BEGIN(INITIAL); return '/'; }
{name_minus} { return str(yyscanner, PE_NAME); }
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-05-16 15:40 +0200 |
| Subject | Re: [PATCH 10/17] perf tools: Enable overwrite settings |
| Message-ID | <rzqUx-7Dg-11@gated-at.bofh.it> |
| In reply to | #1400572 |
Em Fri, May 13, 2016 at 07:56:07AM +0000, Wang Nan escreveu:
> This patch allows following config terms and option:
>
> Globally setting events to overwrite;
>
> # perf record --overwrite ...
>
> Set specific events to be overwrite or no-overwrite.
>
> # perf record --event cycles/overwrite/ ...
> # perf record --event cycles/no-overwrite/ ...
>
> Add missing config terms and update config term array size because the
> longest string length is changed.
You forgot to add this to the documentation, please add it when you
respin this patch. If you done so in a separate patch, please yank it
from there and add it here.
- Arnaldo
> 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/builtin-record.c | 1 +
> tools/perf/perf.h | 1 +
> tools/perf/util/evsel.c | 4 ++++
> tools/perf/util/evsel.h | 2 ++
> tools/perf/util/parse-events.c | 20 ++++++++++++++++++--
> tools/perf/util/parse-events.h | 2 ++
> tools/perf/util/parse-events.l | 2 ++
> 7 files changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index d9a92e0..939aa68 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -1265,6 +1265,7 @@ struct option __record_options[] = {
> OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
> &record.opts.no_inherit_set,
> "child tasks do not inherit counters"),
> + OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
> OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
> OPT_CALLBACK('m', "mmap-pages", &record.opts, "pages[,pages]",
> "number of mmap data pages and AUX area tracing mmap pages",
> diff --git a/tools/perf/perf.h b/tools/perf/perf.h
> index c35bcfd..386d030 100644
> --- a/tools/perf/perf.h
> +++ b/tools/perf/perf.h
> @@ -59,6 +59,7 @@ struct record_opts {
> bool record_switch_events;
> bool all_kernel;
> bool all_user;
> + bool overwrite;
> unsigned int freq;
> unsigned int mmap_pages;
> unsigned int auxtrace_mmap_pages;
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index a23f547..be4fc25 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -670,6 +670,9 @@ static void apply_config_terms(struct perf_evsel *evsel,
> */
> attr->inherit = term->val.inherit ? 1 : 0;
> break;
> + case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
> + evsel->overwrite = term->val.overwrite ? 1 : 0;
> + break;
> default:
> break;
> }
> @@ -746,6 +749,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
>
> attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
> attr->inherit = !opts->no_inherit;
> + evsel->overwrite = opts->overwrite;
>
> perf_evsel__set_sample_bit(evsel, IP);
> perf_evsel__set_sample_bit(evsel, TID);
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index c1f1015..bce99fa 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -44,6 +44,7 @@ enum {
> PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
> PERF_EVSEL__CONFIG_TERM_STACK_USER,
> PERF_EVSEL__CONFIG_TERM_INHERIT,
> + PERF_EVSEL__CONFIG_TERM_OVERWRITE,
> PERF_EVSEL__CONFIG_TERM_MAX,
> };
>
> @@ -57,6 +58,7 @@ struct perf_evsel_config_term {
> char *callgraph;
> u64 stack_user;
> bool inherit;
> + bool overwrite;
> } val;
> };
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index bcbc983..85f813d 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -900,6 +900,8 @@ static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = {
> [PARSE_EVENTS__TERM_TYPE_STACKSIZE] = "stack-size",
> [PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit",
> [PARSE_EVENTS__TERM_TYPE_INHERIT] = "inherit",
> + [PARSE_EVENTS__TERM_TYPE_OVERWRITE] = "overwrite",
> + [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite",
> };
>
> static bool config_term_shrinked;
> @@ -992,6 +994,12 @@ do { \
> case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
> CHECK_TYPE_VAL(NUM);
> break;
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + CHECK_TYPE_VAL(NUM);
> + break;
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> + CHECK_TYPE_VAL(NUM);
> + break;
> case PARSE_EVENTS__TERM_TYPE_NAME:
> CHECK_TYPE_VAL(STR);
> break;
> @@ -1040,6 +1048,8 @@ static int config_term_tracepoint(struct perf_event_attr *attr,
> case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
> case PARSE_EVENTS__TERM_TYPE_INHERIT:
> case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> return config_term_common(attr, term, err);
> default:
> if (err) {
> @@ -1109,6 +1119,12 @@ do { \
> case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
> ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1);
> break;
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0);
> + break;
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> + ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1);
> + break;
> default:
> break;
> }
> @@ -2322,9 +2338,9 @@ static void config_terms_list(char *buf, size_t buf_sz)
> char *parse_events_formats_error_string(char *additional_terms)
> {
> char *str;
> - /* "branch_type" is the longest name */
> + /* "no-overwrite" is the longest name */
> char static_terms[__PARSE_EVENTS__TERM_TYPE_NR *
> - (sizeof("branch_type") - 1)];
> + (sizeof("no-overwrite") - 1)];
>
> config_terms_list(static_terms, sizeof(static_terms));
> /* valid terms */
> diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> index d740c3c..f341d9d 100644
> --- a/tools/perf/util/parse-events.h
> +++ b/tools/perf/util/parse-events.h
> @@ -68,6 +68,8 @@ enum {
> PARSE_EVENTS__TERM_TYPE_STACKSIZE,
> PARSE_EVENTS__TERM_TYPE_NOINHERIT,
> PARSE_EVENTS__TERM_TYPE_INHERIT,
> + PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
> + PARSE_EVENTS__TERM_TYPE_OVERWRITE,
> __PARSE_EVENTS__TERM_TYPE_NR,
> };
>
> diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
> index 1477fbc..cc4c426 100644
> --- a/tools/perf/util/parse-events.l
> +++ b/tools/perf/util/parse-events.l
> @@ -201,6 +201,8 @@ call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
> stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
> inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
> no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
> +overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
> +no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
> , { return ','; }
> "/" { BEGIN(INITIAL); return '/'; }
> {name_minus} { return str(yyscanner, PE_NAME); }
> --
> 1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 07/17] perf record: Don't read from and poll overwrite channel |
| Message-ID | <rygaT-7tc-37@gated-at.bofh.it> |
| In reply to | #1400559 |
Reading from overwritable ring buffer is unreliable. Introduce
record__mmap_should_read() and prevent reading from such ring
buffers in 'perf record'. The rule in record__mmap_should_read() will
be changed when perf support reading from backward writing ring buffer.
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/builtin-record.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5e87602..d9a92e0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -429,6 +429,19 @@ static struct perf_event_header finished_round_event = {
.type = PERF_RECORD_FINISHED_ROUND,
};
+static bool record__mmap_should_read(struct record *rec, int idx)
+{
+ int channel = -1;
+
+ if (!rec->evlist->mmap[idx].base)
+ return false;
+ if (perf_evlist__channel_idx(rec->evlist, &channel, &idx))
+ return false;
+ if (perf_evlist__channel_check(rec->evlist, channel, RDONLY))
+ return false;
+ return true;
+}
+
static int record__mmap_read_all(struct record *rec)
{
u64 bytes_written = rec->bytes_written;
@@ -439,7 +452,7 @@ static int record__mmap_read_all(struct record *rec)
for (i = 0; i < total_mmaps; i++) {
struct auxtrace_mmap *mm = &rec->evlist->mmap[i].auxtrace_mmap;
- if (rec->evlist->mmap[i].base) {
+ if (record__mmap_should_read(rec, i)) {
if (record__mmap_read(rec, i) != 0) {
rc = -1;
goto out;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-05-13 10:00 +0200 |
| Subject | [PATCH 12/17] perf tools: Record fd into perf_mmap |
| Message-ID | <rygaT-7tc-43@gated-at.bofh.it> |
| In reply to | #1400559 |
Add a fd field into perf_mmap so perf can track fd from mmap.
This feature will be used for toggling overwrite ring buffers.
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/util/evlist.c | 15 +++++++++++++--
tools/perf/util/evlist.h | 1 +
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dc2e509..4295d7e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -943,6 +943,7 @@ static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
if (evlist->mmap[idx].base != NULL) {
munmap(evlist->mmap[idx].base, evlist->mmap_len);
evlist->mmap[idx].base = NULL;
+ evlist->mmap[idx].fd = -1;
atomic_set(&evlist->mmap[idx].refcnt, 0);
}
auxtrace_mmap__munmap(&evlist->mmap[idx].auxtrace_mmap);
@@ -973,7 +974,7 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
{
- int total_mmaps;
+ int total_mmaps, i;
evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
if (cpu_map__empty(evlist->cpus))
@@ -984,7 +985,12 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
return -EINVAL;
evlist->mmap = zalloc(total_mmaps * sizeof(struct perf_mmap));
- return evlist->mmap != NULL ? 0 : -ENOMEM;
+ if (!evlist->mmap)
+ return -ENOMEM;
+
+ for (i = 0; i < total_mmaps; i++)
+ evlist->mmap[i].fd = -1;
+ return 0;
}
struct mmap_params {
@@ -1004,6 +1010,10 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
if (!perf_evlist__channel_check(evlist, channel, RDONLY))
prot |= PROT_WRITE;
+ if (evlist->mmap[idx].fd >= 0) {
+ pr_err("idx %d already mapped\n", idx);
+ return -1;
+ }
/*
* The last one will be done at perf_evlist__mmap_consume(), so that we
* make sure we don't prevent tools from consuming every last event in
@@ -1028,6 +1038,7 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
evlist->mmap[idx].base = NULL;
return -1;
}
+ evlist->mmap[idx].fd = fd;
if (auxtrace_mmap__mmap(&evlist->mmap[idx].auxtrace_mmap,
&mp->auxtrace_mp, evlist->mmap[idx].base, fd))
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index bdd8e98..ee17449 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -35,6 +35,7 @@ enum perf_evlist_mmap_flag {
struct perf_mmap {
void *base;
int mask;
+ int fd;
atomic_t refcnt;
u64 prev;
struct auxtrace_mmap auxtrace_mmap;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.kernel
csiph-web