Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1306221 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-01-11 14:50 +0100 |
| Last post | 2016-01-11 15:30 +0100 |
| Articles | 20 on this page of 94 — 11 participants |
Back to article view | Back to linux.kernel
[PATCH 00/53] perf tools: Bugfix, BPF improvement and perf record flight record mode Wang Nan <wangnan0@huawei.com> - 2016-01-11 14:50 +0100
[PATCH 44/53] perf tools: Automatically add new channel according to evlist Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 01/53] perf tools: Add -lutil in python lib list for broken python-config Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
Re: [PATCH 01/53] perf tools: Add -lutil in python lib list for broken python-config Jiri Olsa <jolsa@redhat.com> - 2016-01-12 10:50 +0100
[tip:perf/urgent] perf tools: Add -lutil in python lib list for broken python-config tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:10 +0100
[PATCH 09/53] perf: bpf: Fix build breakage due to libbpf Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[tip:perf/urgent] perf bpf: Fix build breakage due to libbpf "tip-bot for Naveen N. Rao" <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 52/53] perf record: Toggle tailsize ring buffer for reading Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 17/53] perf test: Improve bp_signal Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
Re: [PATCH 17/53] perf test: Improve bp_signal Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 22:40 +0100
Re: [PATCH 17/53] perf test: Improve bp_signal "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-12 05:20 +0100
Re: [PATCH 17/53] perf test: Improve bp_signal Jiri Olsa <jolsa@redhat.com> - 2016-01-12 10:30 +0100
Re: [PATCH 17/53] perf test: Improve bp_signal Will Deacon <will.deacon@arm.com> - 2016-01-12 15:20 +0100
Re: [PATCH 17/53] perf test: Improve bp_signal Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-12 15:20 +0100
[PATCH 47/53] perf record: Don't read from and poll overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 28/53] perf tools: Move timestamp creation to util Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 39/53] perf record: Re-synthesize tracking events after output switching Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 33/53] perf record: Introduce record__finish_output() to finish a perf.data Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 46/53] perf tools: Squash overwrite setting into channel Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 34/53] perf record: Use OPT_BOOLEAN_SET for buildid cache related options Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 43/53] perf tools: Add evlist channel helpers Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 51/53] perf record: Read from tailsize ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-01-11 15:30 +0100
Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-01-11 16:10 +0100
Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-01-11 16:10 +0100
[PATCH 40/53] perf record: Generate tracking events for process forked by perf Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 41/53] perf record: Ensure return non-zero rc when mmap fail Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 49/53] perf tools: Consider TAILSIZE bit when caclulate is_pos Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 31/53] perf tools: Add perf_data_file__switch() helper Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 50/53] perf tools: Set tailsize attribut bit for overwrite events Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 45/53] perf tools: Operate multiple channels Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 30/53] perf record: Extract synthesize code to record__synthesize() Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
Re: [PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 15:20 +0100
[tip:perf/urgent] tools: Move Makefile.arch from perf/ config to tools/scripts tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 53/53] perf record: Allow generate tracking events at the end of output Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 48/53] perf tools: Enable overwrite settings Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:00 +0100
[PATCH 11/53] perf test: Fix false TEST_OK result for 'perf test hist' Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 11/53] perf test: Fix false TEST_OK result for 'perf test hist' Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-01-11 15:30 +0100
Re: [PATCH 11/53] perf test: Fix false TEST_OK result for 'perf test hist' Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-01-11 16:00 +0100
Re: [PATCH 11/53] perf test: Fix false TEST_OK result for 'perf test hist' Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 16:40 +0100
[tip:perf/urgent] perf test: Fix false TEST_OK result for ' perf test hist' tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 15/53] perf tools: Fix symbols searching for offline module in buildid-cache Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 06/53] perf tools: Fix PowerPC native building Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[tip:perf/urgent] perf tools: Fix PowerPC native building tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 23/53] perf tools: Support setting different slots in a BPF map separately Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 02/53] perf tools: Fix phony build target for build-test Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[tip:perf/urgent] perf tools: Fix phony build target for build-test tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 19/53] perf tools: Enable BPF object configure syntax Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 05/53] perf tools: Test correct path of perf in build-test Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 16:30 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 23:10 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 23:40 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 23:50 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-12 08:20 +0100
Re: [PATCH 05/53] perf tools: Test correct path of perf in build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-12 15:10 +0100
[PATCH 20/53] perf record: Apply config to BPF objects before recording Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 14/53] perf test: Check environment before start real BPF test Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 14/53] perf test: Check environment before start real BPF test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 23:00 +0100
Re: [PATCH 14/53] perf test: Check environment before start real BPF test "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-12 08:50 +0100
[PATCH 26/53] perf data: Support converting data from bpf_perf_event_output() Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 36/53] perf record: Split output into multiple files via '--switch-output' Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 12/53] perf test: Reset err after using it hold errcode in hist testcases Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[tip:perf/urgent] perf test: Reset err after using it hold errcode in hist testcases tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 29/53] perf tools: Make ordered_events reusable Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 29/53] perf tools: Make ordered_events reusable Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 22:40 +0100
[PATCH 04/53] perf tools: Pass O option to Makefile.perf in build-test Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 32/53] perf record: Turns auxtrace_snapshot_enable into 3 states Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 16/53] perf tools: Fix mmap2 event allocation in synthesize code Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
Re: [PATCH 16/53] perf tools: Fix mmap2 event allocation in synthesize code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 22:10 +0100
[PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code Wang Nan <wangnan0@huawei.com> - 2016-01-12 11:20 +0100
RE: [PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code 平松雅巳 / HIRAMATU,MASAMI <masami.hiramatsu.pt@hitachi.com> - 2016-01-12 11:50 +0100
Re: [PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-12 12:00 +0100
Re: [PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code "acme@kernel.org" <acme@kernel.org> - 2016-01-12 15:30 +0100
RE: [PATCH 16/53 v2] perf tools: Fix mmap2 event allocation in synthesize code 平松雅巳 / HIRAMATU,MASAMI <masami.hiramatsu.pt@hitachi.com> - 2016-01-13 01:50 +0100
[tip:perf/urgent] perf tools: Fix mmap2 event allocation in synthesize code tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-13 10:50 +0100
[PATCH 08/53] perf tools: Add missing sources in perf's MANIFEST Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 21/53] perf tools: Enable passing event to BPF object Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:10 +0100
[PATCH 25/53] perf tools: Introduce bpf-output event Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 18/53] perf tools: Add API to config maps in bpf object Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 24/53] perf tools: Enable indices setting syntax for BPF maps Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 22/53] perf tools: Support perf event alias name Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 13/53] perf tools: Prevent calling machine__delete() on non-allocated machine Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
Re: [PATCH 13/53] perf tools: Prevent calling machine__delete() on non-allocated machine Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-11 16:50 +0100
Re: [PATCH 13/53] perf tools: Prevent calling machine__delete() on non-allocated machine "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-12 08:10 +0100
Re: [PATCH 13/53] perf tools: Prevent calling machine__delete() on non-allocated machine Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-01-12 15:10 +0100
[PATCH 10/53] tools build: Add BPF feature check to test-all Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[tip:perf/urgent] tools build: Add BPF feature check to test-all tip-bot for Wang Nan <tipbot@zytor.com> - 2016-01-12 11:20 +0100
[PATCH 37/53] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 03/53] perf tools: Set parallel making options build-test Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:20 +0100
[PATCH 35/53] perf record: Add '--timestamp-filename' option to append timestamp to output filename Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:30 +0100
[PATCH 38/53] perf record: Disable buildid cache options by default in switch output mode Wang Nan <wangnan0@huawei.com> - 2016-01-11 15:30 +0100
Page 2 of 5 — ← Prev page 1 [2] 3 4 5 Next page →
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 43/53] perf tools: Add evlist channel helpers |
| Message-ID | <qPLaQ-38k-43@gated-at.bofh.it> |
| In reply to | #1306221 |
In this commit sereval helpers are introduced to support the principle
of channel. Channels hold different groups of evsels which configured
differently. It will be used for overwritable evsels, which allows perf
record some events continuously while capture snapshot for other events
when something happen. Tracking events (mmap, mmap2, fork, exit ...)
are another possible events worth to be put into a separated channel.
Channels are represented by an array with channel flags. Each channel
contains evlist->nr_mmaps mmaps. Channels are configured before
perf_evlist__mmap_ex(). During that function nr_mmaps mmaps for each
channel are allocated together as a big array.
perf_evlist__channel_idx() converts index in the big array and the
channel number. For API functions which accept idx, _ex() versions are
introduced to accept selecting an mmap from a channel.
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 | 6 ++
tools/perf/util/evlist.c | 132 ++++++++++++++++++++++++++++++++++++++++++--
tools/perf/util/evlist.h | 58 +++++++++++++++++++
3 files changed, 190 insertions(+), 6 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3f58426..21da64d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -355,6 +355,12 @@ try_again:
goto out;
}
+ perf_evlist__channel_reset(evlist);
+ rc = perf_evlist__channel_add(evlist, 0, true);
+ if (rc < 0)
+ goto out;
+ rc = 0;
+
if (perf_evlist__mmap_ex(evlist, opts->mmap_pages, false,
opts->auxtrace_mmap_pages,
opts->auxtrace_snapshot_mode) < 0) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 890b08b..ff1beac 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -679,14 +679,51 @@ static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
return NULL;
}
-union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
+int perf_evlist__channel_idx(struct perf_evlist *evlist,
+ int *p_channel, int *p_idx)
+{
+ int channel = *p_channel;
+ int _idx = *p_idx;
+
+ if (_idx < 0)
+ return -EINVAL;
+ /*
+ * Negative channel means caller explicitly use real index.
+ */
+ if (channel < 0) {
+ channel = perf_evlist__idx_channel(evlist, _idx);
+ _idx = _idx % evlist->nr_mmaps;
+ }
+ if (channel < 0)
+ return channel;
+ if (channel >= PERF_EVLIST__NR_CHANNELS)
+ return -E2BIG;
+ if (_idx >= evlist->nr_mmaps)
+ return -E2BIG;
+
+ *p_channel = channel;
+ *p_idx = evlist->nr_mmaps * channel + _idx;
+ return 0;
+}
+
+union perf_event *perf_evlist__mmap_read_ex(struct perf_evlist *evlist,
+ int channel, int idx)
{
+ int err = perf_evlist__channel_idx(evlist, &channel, &idx);
struct perf_mmap *md = &evlist->mmap[idx];
u64 head;
- u64 old = md->prev;
- unsigned char *data = md->base + page_size;
+ u64 old;
+ unsigned char *data;
union perf_event *event = NULL;
+ if (err || !perf_evlist__channel_is_enabled(evlist, channel)) {
+ pr_err("ERROR: invalid mmap index: channel %d, idx: %d\n",
+ channel, idx);
+ return NULL;
+ }
+ old = md->prev;
+ data = md->base + page_size;
+
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
*/
@@ -748,6 +785,11 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
return event;
}
+union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
+{
+ return perf_evlist__mmap_read_ex(evlist, -1, idx);
+}
+
static bool perf_mmap__empty(struct perf_mmap *md)
{
return perf_mmap__read_head(md) == md->prev && !md->auxtrace_mmap.base;
@@ -766,10 +808,18 @@ static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
__perf_evlist__munmap(evlist, idx);
}
-void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
+void perf_evlist__mmap_consume_ex(struct perf_evlist *evlist,
+ int channel, int idx)
{
+ int err = perf_evlist__channel_idx(evlist, &channel, &idx);
struct perf_mmap *md = &evlist->mmap[idx];
+ if (err || !perf_evlist__channel_is_enabled(evlist, channel)) {
+ pr_err("ERROR: invalid mmap index: channel %d, idx: %d\n",
+ channel, idx);
+ return;
+ }
+
if (!evlist->overwrite) {
u64 old = md->prev;
@@ -780,6 +830,11 @@ void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
perf_evlist__mmap_put(evlist, idx);
}
+void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
+{
+ perf_evlist__mmap_consume_ex(evlist, -1, idx);
+}
+
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
struct auxtrace_mmap_params *mp __maybe_unused,
void *userpg __maybe_unused,
@@ -825,7 +880,7 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
if (evlist->mmap == NULL)
return;
- for (i = 0; i < evlist->nr_mmaps; i++)
+ for (i = 0; i < perf_evlist__mmap_nr(evlist); i++)
__perf_evlist__munmap(evlist, i);
zfree(&evlist->mmap);
@@ -833,10 +888,17 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
{
+ int total_mmaps;
+
evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
if (cpu_map__empty(evlist->cpus))
evlist->nr_mmaps = thread_map__nr(evlist->threads);
- evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
+
+ total_mmaps = perf_evlist__mmap_nr(evlist);
+ if (!total_mmaps)
+ return -EINVAL;
+
+ evlist->mmap = zalloc(total_mmaps * sizeof(struct perf_mmap));
return evlist->mmap != NULL ? 0 : -ENOMEM;
}
@@ -1137,6 +1199,12 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
bool overwrite)
{
+ int err;
+
+ perf_evlist__channel_reset(evlist);
+ err = perf_evlist__channel_add(evlist, 0, true);
+ if (err < 0)
+ return err;
return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);
}
@@ -1739,3 +1807,55 @@ perf_evlist__find_evsel_by_str(struct perf_evlist *evlist,
return NULL;
}
+
+int perf_evlist__channel_nr(struct perf_evlist *evlist)
+{
+ int i;
+
+ for (i = PERF_EVLIST__NR_CHANNELS - 1; i >= 0; i--) {
+ unsigned long flags = evlist->channel_flags[i];
+
+ if (flags & PERF_EVLIST__CHANNEL_ENABLED)
+ return i + 1;
+ }
+ return 0;
+}
+
+int perf_evlist__mmap_nr(struct perf_evlist *evlist)
+{
+ return evlist->nr_mmaps * perf_evlist__channel_nr(evlist);
+}
+
+void perf_evlist__channel_reset(struct perf_evlist *evlist)
+{
+ int i;
+
+ BUG_ON(evlist->mmap);
+
+ for (i = 0; i < PERF_EVLIST__NR_CHANNELS; i++)
+ evlist->channel_flags[i] = 0;
+}
+
+int perf_evlist__channel_add(struct perf_evlist *evlist,
+ unsigned long flag,
+ bool is_default)
+{
+ int n = perf_evlist__channel_nr(evlist);
+ unsigned long *flags = evlist->channel_flags;
+
+ BUG_ON(evlist->mmap);
+
+ if (n >= PERF_EVLIST__NR_CHANNELS) {
+ pr_debug("ERROR: too many channels. Increase PERF_EVLIST__NR_CHANNELS\n");
+ return -ENOSPC;
+ }
+
+ if (is_default) {
+ memmove(&flags[1], &flags[0],
+ sizeof(evlist->channel_flags) -
+ sizeof(evlist->channel_flags[0]));
+ n = 0;
+ }
+ flags[n] = flag | PERF_EVLIST__CHANNEL_ENABLED;
+ return n;
+}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index a0d1522..1812652 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -20,6 +20,11 @@ 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
+enum perf_evlist_mmap_flag {
+ PERF_EVLIST__CHANNEL_ENABLED = 1,
+};
+
/**
* struct perf_mmap - perf's ring buffer mmap details
*
@@ -52,6 +57,7 @@ struct perf_evlist {
pid_t pid;
} workload;
struct fdarray pollfd;
+ unsigned long channel_flags[PERF_EVLIST__NR_CHANNELS];
struct perf_mmap *mmap;
struct thread_map *threads;
struct cpu_map *cpus;
@@ -116,9 +122,61 @@ struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
+union perf_event *perf_evlist__mmap_read_ex(struct perf_evlist *evlist,
+ int channel, int idx);
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
+void perf_evlist__mmap_consume_ex(struct perf_evlist *evlist,
+ int channel, int idx);
void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
+int perf_evlist__mmap_nr(struct perf_evlist *evlist);
+
+int perf_evlist__channel_nr(struct perf_evlist *evlist);
+void perf_evlist__channel_reset(struct perf_evlist *evlist);
+int perf_evlist__channel_add(struct perf_evlist *evlist,
+ unsigned long flag,
+ bool is_default);
+
+static inline bool
+__perf_evlist__channel_check(struct perf_evlist *evlist, int channel,
+ enum perf_evlist_mmap_flag bits)
+{
+ if (channel >= PERF_EVLIST__NR_CHANNELS)
+ return false;
+
+ return (evlist->channel_flags[channel] & bits) ? true : false;
+}
+#define perf_evlist__channel_check(e, c, b) \
+ __perf_evlist__channel_check(e, c, PERF_EVLIST__CHANNEL_##b)
+
+static inline bool
+perf_evlist__channel_is_enabled(struct perf_evlist *evlist, int channel)
+{
+ return perf_evlist__channel_check(evlist, channel, ENABLED);
+}
+
+static inline int
+perf_evlist__idx_channel(struct perf_evlist *evlist, int idx)
+{
+ int channel = idx / evlist->nr_mmaps;
+
+ if (channel >= PERF_EVLIST__NR_CHANNELS)
+ return -E2BIG;
+ return channel;
+}
+
+int perf_evlist__channel_idx(struct perf_evlist *evlist,
+ int *p_channel, int *p_idx);
+
+static inline struct perf_mmap *
+perf_evlist__get_mmap(struct perf_evlist *evlist,
+ int channel, int idx)
+{
+ if (perf_evlist__channel_idx(evlist, &channel, &idx))
+ return NULL;
+
+ return &evlist->mmap[idx];
+}
int perf_evlist__open(struct perf_evlist *evlist);
void perf_evlist__close(struct perf_evlist *evlist);
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 51/53] perf record: Read from tailsize ring buffer |
| Message-ID | <qPLaR-38k-51@gated-at.bofh.it> |
| In reply to | #1306221 |
tailsize_rb_find_start() introduced to find the first available event
from a tailsize ring buffer through tailsize. event with '/overwrite/'
setting is able to be read. record__mmap_should_read() is changed
accordingly.
Reading a active tailsize ring buffer is unsafe. A global tailsize ring
buffer director is introduced into 'struct record'
record__mmap_should_read() returns true if tailsize_evt_stopped is true.
Following patch whould turn off events attached to tailsize ring buffer
and toggle this director.
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 | 69 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8e56f92..6c8905b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -56,6 +56,7 @@ struct record {
bool no_buildid_cache_set;
bool timestamp_filename;
bool switch_output;
+ bool tailsize_evt_stopped;
unsigned long long samples;
};
@@ -79,6 +80,63 @@ static int process_synthesized_event(struct perf_tool *tool,
return record__write(rec, event, event->header.size);
}
+static int
+tailsize_rb_find_start(void *buf, u64 head, int mask, u64 *p_evt_head)
+{
+ int buf_size = mask + 1;
+ u64 evt_head = head;
+ u64 *pevt_size;
+
+ pr_debug("start reading tailsize, head=%"PRId64"\n", head);
+ while (true) {
+ struct perf_event_header *pheader;
+
+ pevt_size = buf + ((evt_head - sizeof(*pevt_size)) & mask);
+ pr_debug4("read tailsize: size: %"PRId64"\n", *pevt_size);
+
+ if (*pevt_size % sizeof(u64) != 0) {
+ pr_warning("Tailsize ring buffer corrupted: unaligned\n");
+ return -1;
+ }
+
+ if (!*pevt_size) {
+ if (evt_head) {
+ pr_warning("Tailsize ring buffer corrupted: size is 0 but evt_head (0x%"PRIx64") is not 0\n",
+ (unsigned long)evt_head);
+ return -1;
+ }
+ *p_evt_head = evt_head;
+ return 0;
+ }
+
+ if (evt_head < *pevt_size) {
+ pr_warning("Tailsize ring buffer corrupted: head (%"PRId64") < size (%"PRId64")\n",
+ evt_head, *pevt_size);
+ return -1;
+ }
+
+ evt_head -= *pevt_size;
+
+ if (evt_head + buf_size < head) {
+ evt_head += *pevt_size;
+ pr_debug("Finish reading tailsize buffer, evt_head=%"PRIx64", head=%"PRIx64"\n",
+ evt_head, head);
+ *p_evt_head = evt_head;
+ return 0;
+ }
+
+ pheader = (struct perf_event_header *)(buf + (evt_head & mask));
+ if (pheader->size != *pevt_size) {
+ pr_warning("Tailsize ring buffer corrupted: found size mismatch: %d vs %"PRId64"\n",
+ pheader->size, *pevt_size);
+ return -1;
+ }
+ }
+
+ pr_warning("ERROR: shouldn't get there\n");
+ return -1;
+}
+
static int record__mmap_read(struct record *rec, int idx)
{
struct perf_mmap *md = &rec->evlist->mmap[idx];
@@ -88,10 +146,17 @@ static int record__mmap_read(struct record *rec, int idx)
unsigned long size;
void *buf;
int rc = 0;
+ int channel;
if (old == head)
return 0;
+ channel = perf_evlist__idx_channel(rec->evlist, idx);
+ if (perf_evlist__channel_check(rec->evlist, channel, TAILSIZE)) {
+ if (tailsize_rb_find_start(data, head, md->mask, &old))
+ return -1;
+ }
+
rec->samples++;
size = head - old;
@@ -462,7 +527,8 @@ static bool record__mmap_should_read(struct record *rec, int idx)
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, TAILSIZE))
+ return rec->tailsize_evt_stopped;
return true;
}
@@ -1226,6 +1292,7 @@ static struct record record = {
.mmap2 = perf_event__process_mmap2,
.ordered_events = true,
},
+ .tailsize_evt_stopped = false,
};
const char record_callchain_help[] = CALLCHAIN_RECORD_HELP
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read |
| Message-ID | <qPLaR-38k-53@gated-at.bofh.it> |
| In reply to | #1306221 |
When record__mmap_read() require data more than the size of ring
buffer, drop those data to avoid access 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 b65b41f..3f58426 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>
+#include <asm/bug.h>
struct record {
@@ -94,6 +95,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, "WARNING: 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 | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2016-01-11 15:30 +0100 |
| Subject | Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read |
| Message-ID | <qPLDQ-3yx-15@gated-at.bofh.it> |
| In reply to | #1306240 |
Hello.
On 01/11/2016 04:48 PM, Wang Nan wrote:
> When record__mmap_read() require data more than the size of ring
> buffer, drop those data to avoid access 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 b65b41f..3f58426 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -37,6 +37,7 @@
> #include <unistd.h>
> #include <sched.h>
> #include <sys/mman.h>
> +#include <asm/bug.h>
>
>
> struct record {
> @@ -94,6 +95,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, "WARNING: failed to keep up with mmap data. (warn only once)\n");
WARNING is already printed by WARN*(), no?
[...]
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@redhat.com> |
|---|---|
| Date | 2016-01-11 16:10 +0100 |
| Subject | Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read |
| Message-ID | <qPMgx-434-3@gated-at.bofh.it> |
| In reply to | #1306308 |
Em Mon, Jan 11, 2016 at 01:00:07PM -0200, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 11, 2016 at 05:21:44PM +0300, Sergei Shtylyov escreveu:
> > On 01/11/2016 04:48 PM, Wang Nan wrote:
> > > size = head - old;
> > >+ if (size > (unsigned long)(md->mask) + 1) {
> > >+ WARN_ONCE(1, "WARNING: failed to keep up with mmap data. (warn only once)\n");
> >
> > WARNING is already printed by WARN*(), no?
>
> No, at least not in tools/include/asm/bug.h, perhaps include/asm/bug.h
> has this now and tools/ drifted? Checking now...
Indeed, need to bring it closer together again...
- Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@redhat.com> |
|---|---|
| Date | 2016-01-11 16:10 +0100 |
| Subject | Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read |
| Message-ID | <qPMgx-434-5@gated-at.bofh.it> |
| In reply to | #1306308 |
Em Mon, Jan 11, 2016 at 05:21:44PM +0300, Sergei Shtylyov escreveu:
> On 01/11/2016 04:48 PM, Wang Nan wrote:
> > size = head - old;
> >+ if (size > (unsigned long)(md->mask) + 1) {
> >+ WARN_ONCE(1, "WARNING: failed to keep up with mmap data. (warn only once)\n");
>
> WARNING is already printed by WARN*(), no?
No, at least not in tools/include/asm/bug.h, perhaps include/asm/bug.h
has this now and tools/ drifted? Checking now...
- Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 40/53] perf record: Generate tracking events for process forked by perf |
| Message-ID | <qPLaR-38k-57@gated-at.bofh.it> |
| In reply to | #1306221 |
With 'perf record --switch-output' without -a, record__synthesize() in
record__switch_output() won't generate tracking events because there's
no thread_map in evlist. Which causes newly created perf.data doesn't
contain map and comm information.
This patch creates a fake thread_map and directly call
perf_event__synthesize_thread_map() for those events.
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 | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5305a30..aaf3b0f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -563,6 +563,23 @@ record__switch_output(struct record *rec, bool at_exit)
perf_session__create_kernel_maps(rec->session);
perf_session__set_id_hdr_size(rec->session);
record__synthesize(rec);
+
+ if (target__none(&rec->opts.target)) {
+ struct {
+ struct thread_map map;
+ struct thread_map_data map_data;
+ } thread_map;
+
+ thread_map.map.nr = 1;
+ thread_map.map.map[0].pid = rec->evlist->workload.pid;
+ thread_map.map.map[0].comm = NULL;
+ perf_event__synthesize_thread_map(&rec->tool,
+ &thread_map.map,
+ process_synthesized_event,
+ &rec->session->machines.host,
+ rec->opts.sample_address,
+ rec->opts.proc_map_timeout);
+ }
}
return fd;
}
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 41/53] perf record: Ensure return non-zero rc when mmap fail |
| Message-ID | <qPLaR-38k-55@gated-at.bofh.it> |
| In reply to | #1306221 |
perf_evlist__mmap_ex() can fail without setting errno (for example,
fail in condition checking. In this case all syscall is success).
If this happen, record__open() incorrectly returns 0. Force setting
rc is a quick way to avoid this problem, or we have to follow all
possible code path in perf_evlist__mmap_ex() to make sure there's
at least one system call before returning an error.
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 | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index aaf3b0f..b65b41f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -361,7 +361,10 @@ try_again:
} else {
pr_err("failed to mmap with %d (%s)\n", errno,
strerror_r(errno, msg, sizeof(msg)));
- rc = -errno;
+ if (errno)
+ rc = -errno;
+ else
+ rc = -EINVAL;
}
goto out;
}
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 49/53] perf tools: Consider TAILSIZE bit when caclulate is_pos |
| Message-ID | <qPLaR-38k-63@gated-at.bofh.it> |
| In reply to | #1306221 |
evsel->is_pos indicates event id location in a event (count backward).
It is used to find id for tracking events (mmap, exit...). If TAILSIZE
is selected, this location should be changed accordingly.
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/evsel.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6932b8b..c59ea34 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -144,10 +144,10 @@ static int __perf_evsel__calc_id_pos(u64 sample_type)
*/
static int __perf_evsel__calc_is_pos(u64 sample_type)
{
- int idx = 1;
+ int idx = 1 + (sample_type & PERF_SAMPLE_TAILSIZE ? 1 : 0);
if (sample_type & PERF_SAMPLE_IDENTIFIER)
- return 1;
+ return idx;
if (!(sample_type & PERF_SAMPLE_ID))
return -1;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 31/53] perf tools: Add perf_data_file__switch() helper |
| Message-ID | <qPLaR-38k-65@gated-at.bofh.it> |
| In reply to | #1306221 |
perf_data_file__switch() closes current output file, renames it, then
open a new one to continue record. It will be used by perf record
to split output into multiple perf.data files.
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/data.c | 36 ++++++++++++++++++++++++++++++++++++
tools/perf/util/data.h | 11 ++++++++++-
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 1921942..bfded6a 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -136,3 +136,39 @@ ssize_t perf_data_file__write(struct perf_data_file *file,
{
return writen(file->fd, buf, size);
}
+
+int perf_data_file__switch(struct perf_data_file *file,
+ const char *postfix,
+ size_t pos, bool at_exit)
+{
+ char *new_filepath;
+ int ret;
+
+ if (check_pipe(file))
+ return -EINVAL;
+ if (perf_data_file__is_read(file))
+ return -EINVAL;
+
+ if (asprintf(&new_filepath, "%s.%s", file->path, postfix) < 0)
+ return -ENOMEM;
+
+ rename(file->path, new_filepath);
+
+ if (!at_exit) {
+ close(file->fd);
+ ret = perf_data_file__open(file);
+ if (ret < 0)
+ goto out;
+
+ if (lseek(file->fd, pos, SEEK_SET) == (off_t)-1) {
+ ret = -errno;
+ pr_debug("Failed to lseek to %zu: %s",
+ pos, strerror(errno));
+ goto out;
+ }
+ }
+ ret = file->fd;
+out:
+ free(new_filepath);
+ return ret;
+}
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 2b15d0c..7763300 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -46,5 +46,14 @@ int perf_data_file__open(struct perf_data_file *file);
void perf_data_file__close(struct perf_data_file *file);
ssize_t perf_data_file__write(struct perf_data_file *file,
void *buf, size_t size);
-
+/*
+ * If at_exit is set, only rename current perf.data to
+ * perf.data.<postfix>, continue write on original file.
+ * Used when flushing the last output.
+ *
+ * Return value is fd of new output.
+ */
+int perf_data_file__switch(struct perf_data_file *file,
+ const char *postfix,
+ size_t pos, bool at_exit);
#endif /* __PERF_DATA_H */
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 50/53] perf tools: Set tailsize attribut bit for overwrite events |
| Message-ID | <qPLaR-38k-69@gated-at.bofh.it> |
| In reply to | #1306221 |
PERF_SAMPLE_TAILSIZE pad the size of an event at the end of it in the
ring buffer, makes reading from overwrite ring buffer possible. This
patch set that bit if evsel->overwrite is selected explicitly by user.
Overwrite and tailsize 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/util/evlist.c | 2 ++
tools/perf/util/evlist.h | 1 +
tools/perf/util/evsel.c | 28 ++++++++++++++++++++++++++++
tools/perf/util/evsel.h | 1 +
4 files changed, 32 insertions(+)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0511fd2..510e960 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -973,6 +973,8 @@ perf_evlist__channel_for_evsel(struct perf_evsel *evsel)
if (evsel->overwrite)
flag |= PERF_EVLIST__CHANNEL_RDONLY;
+ if (evsel->tailsize)
+ flag |= PERF_EVLIST__CHANNEL_TAILSIZE;
return flag;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 21a8b85..4dfcd67 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_TAILSIZE = 4,
};
/**
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c59ea34..ae69a85 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -671,13 +671,33 @@ static void apply_config_terms(struct perf_evsel *evsel,
attr->inherit = term->val.inherit ? 1 : 0;
break;
case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
+ /*
+ * Let tailsize and overwrite controled by /overwrite/
+ * semultaneously because /overwrite/ can only be
+ * passed by user explicitly, in this case user should
+ * be able to read from that event so tailsize must
+ * set.
+ *
+ * (overwrite && !tailsize) can happen only when
+ * perf_evlist__mmap() is called with overwrite == true.
+ * In that case there's no chance to pass /overwrite/.
+ */
evsel->overwrite = term->val.overwrite ? 1 : 0;
+ evsel->tailsize = term->val.overwrite ? 1 : 0;
break;
default:
break;
}
}
+ /*
+ * Set tailsize sample bit after config term processing because
+ * it is possible to set overwrite globally, without config
+ * terms.
+ */
+ if (evsel->tailsize)
+ perf_evsel__set_sample_bit(evsel, TAILSIZE);
+
/* User explicitly set per-event callgraph, clear the old setting and reset. */
if ((callgraph_buf != NULL) || (dump_size > 0)) {
@@ -748,7 +768,15 @@ 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;
+
+ /*
+ * opts->overwrite can be set by user only.
+ * Always keeps evsel->overwrite == evsel->tailsize.
+ * (evsel->overwrite && !evsel->tailsize) can only happen
+ * when calling perf_evlist__mmap() with overwrite == true.
+ */
evsel->overwrite = opts->overwrite;
+ evsel->tailsize = 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 c76e385..d93ee02 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -118,6 +118,7 @@ struct perf_evsel {
bool per_pkg;
bool precise_max;
bool overwrite;
+ bool tailsize;
/* parse modifier helper */
int exclude_GH;
int nr_members;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 45/53] perf tools: Operate multiple channels |
| Message-ID | <qPLaR-38k-71@gated-at.bofh.it> |
| In reply to | #1306221 |
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 | 55 ++++++++++++++++++++++++++++++++++-----------
tools/perf/util/evlist.h | 2 +-
3 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1f9fb6e..fee5fd2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -458,8 +458,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 5a898be..9187747 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -873,6 +873,21 @@ static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
auxtrace_mmap__munmap(&evlist->mmap[idx].auxtrace_mmap);
}
+static void
+__perf_evlist__munmap_channels(struct perf_evlist *evlist, int _idx)
+{
+ int _ch;
+
+ for (_ch = 0; _ch < perf_evlist__channel_nr(evlist); _ch++) {
+ int err, idx = _idx, ch = _ch;
+
+ err = perf_evlist__channel_idx(evlist, &ch, &idx);
+ if (err < 0)
+ continue;
+ __perf_evlist__munmap(evlist, idx);
+ }
+}
+
void perf_evlist__munmap(struct perf_evlist *evlist)
{
int i;
@@ -980,26 +995,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);
@@ -1039,14 +1066,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;
}
}
@@ -1055,7 +1083,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
out_unmap:
for (cpu = 0; cpu < nr_cpus; cpu++)
- __perf_evlist__munmap(evlist, cpu);
+ __perf_evlist__munmap_channels(evlist, cpu);
return -1;
}
@@ -1067,13 +1095,14 @@ 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;
}
@@ -1081,7 +1110,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
out_unmap:
for (thread = 0; thread < nr_threads; thread++)
- __perf_evlist__munmap(evlist, thread);
+ __perf_evlist__munmap_channels(evlist, thread);
return -1;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 1812652..b652587 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-01-11 15:00 +0100 |
| Subject | [PATCH 30/53] perf record: Extract synthesize code to record__synthesize() |
| Message-ID | <qPLaS-38k-73@gated-at.bofh.it> |
| In reply to | #1306221 |
Create record__synthesize(). It can be used to creating tracking events
for each perf.data after perf supporting splitting into multiple
outputs.
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 | 132 +++++++++++++++++++++++++-------------------
1 file changed, 76 insertions(+), 56 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bd1692c..10f1349 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -475,6 +475,81 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
static void snapshot_sig_handler(int sig);
+static int record__synthesize(struct record *rec)
+{
+ struct perf_session *session = rec->session;
+ struct machine *machine = &session->machines.host;
+ struct perf_data_file *file = &rec->file;
+ struct record_opts *opts = &rec->opts;
+ struct perf_tool *tool = &rec->tool;
+ int fd = perf_data_file__fd(file);
+ int err = 0;
+ static bool warned_kmaps = false, warned_modules = false;
+
+ if (file->is_pipe) {
+ err = perf_event__synthesize_attrs(tool, session,
+ process_synthesized_event);
+ if (err < 0) {
+ pr_err("Couldn't synthesize attrs.\n");
+ goto out;
+ }
+
+ if (have_tracepoints(&rec->evlist->entries)) {
+ /*
+ * FIXME err <= 0 here actually means that
+ * there were no tracepoints so its not really
+ * an error, just that we don't need to
+ * synthesize anything. We really have to
+ * return this more properly and also
+ * propagate errors that now are calling die()
+ */
+ err = perf_event__synthesize_tracing_data(tool, fd, rec->evlist,
+ process_synthesized_event);
+ if (err <= 0) {
+ pr_err("Couldn't record tracing data.\n");
+ goto out;
+ }
+ rec->bytes_written += err;
+ }
+ }
+
+ if (rec->opts.full_auxtrace) {
+ err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
+ session, process_synthesized_event);
+ if (err)
+ goto out;
+ }
+
+ err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
+ machine);
+ if (err < 0 && !warned_kmaps) {
+ warned_kmaps = true;
+ pr_err("Couldn't record kernel reference relocation symbol\n"
+ "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
+ "Check /proc/kallsyms permission or run as root.\n");
+ }
+
+ err = perf_event__synthesize_modules(tool, process_synthesized_event,
+ machine);
+ if (err < 0 && !warned_modules) {
+ warned_modules = true;
+ pr_err("Couldn't record kernel module information.\n"
+ "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
+ "Check /proc/modules permission or run as root.\n");
+ }
+
+ if (perf_guest) {
+ machines__process_guests(&session->machines,
+ perf_event__synthesize_guest_os, tool);
+ }
+
+ err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
+ process_synthesized_event, opts->sample_address,
+ opts->proc_map_timeout);
+out:
+ return err;
+}
+
static int __cmd_record(struct record *rec, int argc, const char **argv)
{
int err;
@@ -569,63 +644,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
machine = &session->machines.host;
- if (file->is_pipe) {
- err = perf_event__synthesize_attrs(tool, session,
- process_synthesized_event);
- if (err < 0) {
- pr_err("Couldn't synthesize attrs.\n");
- goto out_child;
- }
-
- if (have_tracepoints(&rec->evlist->entries)) {
- /*
- * FIXME err <= 0 here actually means that
- * there were no tracepoints so its not really
- * an error, just that we don't need to
- * synthesize anything. We really have to
- * return this more properly and also
- * propagate errors that now are calling die()
- */
- err = perf_event__synthesize_tracing_data(tool, fd, rec->evlist,
- process_synthesized_event);
- if (err <= 0) {
- pr_err("Couldn't record tracing data.\n");
- goto out_child;
- }
- rec->bytes_written += err;
- }
- }
-
- if (rec->opts.full_auxtrace) {
- err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
- session, process_synthesized_event);
- if (err)
- goto out_delete_session;
- }
-
- err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
- machine);
- if (err < 0)
- pr_err("Couldn't record kernel reference relocation symbol\n"
- "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
- "Check /proc/kallsyms permission or run as root.\n");
-
- err = perf_event__synthesize_modules(tool, process_synthesized_event,
- machine);
+ err = record__synthesize(rec);
if (err < 0)
- pr_err("Couldn't record kernel module information.\n"
- "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
- "Check /proc/modules permission or run as root.\n");
-
- if (perf_guest) {
- machines__process_guests(&session->machines,
- perf_event__synthesize_guest_os, tool);
- }
-
- err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
- process_synthesized_event, opts->sample_address,
- opts->proc_map_timeout);
- if (err != 0)
goto out_child;
if (rec->realtime_prio) {
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts |
| Message-ID | <qPLaS-38k-77@gated-at.bofh.it> |
| In reply to | #1306221 |
After this patch other directories can use this architecture detector
without directly including it from perf's directory. Libbpf would
utilize it to get proper $(ARCH) so it can receive correct uapi include
directory.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org>
[Add missing srctree definition in tests/make]
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
tools/perf/config/Makefile | 2 +-
tools/perf/tests/make | 16 +++++++++++++++-
tools/{perf/config => scripts}/Makefile.arch | 0
3 files changed, 16 insertions(+), 2 deletions(-)
rename tools/{perf/config => scripts}/Makefile.arch (100%)
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 0793c76..7545ba60 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -17,7 +17,7 @@ detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
-include $(src-perf)/config/Makefile.arch
+include $(srctree)/tools/scripts/Makefile.arch
$(call detected_var,ARCH)
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 0f5afcb..1e59ce8 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -1,3 +1,5 @@
+include ../scripts/Makefile.include
+
ifndef MK
ifeq ($(MAKECMDGOALS),)
# no target specified, trigger the whole suite
@@ -31,7 +33,19 @@ ifeq ($(SET_PARALLEL),1)
PARALLEL_OPT="-j$(cores)"
endif
-include config/Makefile.arch
+# As per kernel Makefile, avoid funny character set dependencies
+unexport LC_ALL
+LC_COLLATE=C
+LC_NUMERIC=C
+export LC_COLLATE LC_NUMERIC
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(shell pwd)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))
+endif
+
+include $(srctree)/tools/scripts/Makefile.arch
# FIXME looks like x86 is the only arch running tests ;-)
# we need some IS_(32/64) flag to make this generic
diff --git a/tools/perf/config/Makefile.arch b/tools/scripts/Makefile.arch
similarity index 100%
rename from tools/perf/config/Makefile.arch
rename to tools/scripts/Makefile.arch
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | "Wangnan (F)" <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:10 +0100 |
| Subject | Re: [PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts |
| Message-ID | <qPLku-3rc-1@gated-at.bofh.it> |
| In reply to | #1306250 |
On 2016/1/11 21:47, Wang Nan wrote: > After this patch other directories can use this architecture detector > without directly including it from perf's directory. Libbpf would > utilize it to get proper $(ARCH) so it can receive correct uapi include > directory. > > Signed-off-by: Wang Nan <wangnan0@huawei.com> > Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org> > [Add missing srctree definition in tests/make] Hi Arnaldo, I guess you will be okay provide your SOB so I add it here. You didn't provide it on your original code. Thank you.
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-01-11 15:20 +0100 |
| Subject | Re: [PATCH 07/53] tools: Move Makefile.arch from perf/config to tools/scripts |
| Message-ID | <qPLub-3uR-23@gated-at.bofh.it> |
| In reply to | #1306254 |
Em Mon, Jan 11, 2016 at 09:52:38PM +0800, Wangnan (F) escreveu: > > > On 2016/1/11 21:47, Wang Nan wrote: > >After this patch other directories can use this architecture detector > >without directly including it from perf's directory. Libbpf would > >utilize it to get proper $(ARCH) so it can receive correct uapi include > >directory. > > > >Signed-off-by: Wang Nan <wangnan0@huawei.com> > >Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org> > >[Add missing srctree definition in tests/make] > Hi Arnaldo, I guess you will be okay provide your SOB so I add it here. > You didn't provide it on your original code. Sure, and I'll cherry pick this into perf/urgent, to get the PowerPC build fixed. - Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Wang Nan <tipbot@zytor.com> |
|---|---|
| Date | 2016-01-12 11:20 +0100 |
| Subject | [tip:perf/urgent] tools: Move Makefile.arch from perf/ config to tools/scripts |
| Message-ID | <qQ4du-7Y1-27@gated-at.bofh.it> |
| In reply to | #1306250 |
Commit-ID: 935e6bd310f20d3371ae6bd6f01dd3430a4123b6
Gitweb: http://git.kernel.org/tip/935e6bd310f20d3371ae6bd6f01dd3430a4123b6
Author: Wang Nan <wangnan0@huawei.com>
AuthorDate: Mon, 11 Jan 2016 13:47:58 +0000
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 11 Jan 2016 19:22:20 -0300
tools: Move Makefile.arch from perf/config to tools/scripts
After this patch other directories can use this architecture detector
without directly including it from perf's directory. Libbpf would
utilize it to get proper $(ARCH) so it can receive correct uapi include
directory.
Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452520124-2073-8-git-send-email-wangnan0@huawei.com
[ Add missing srctree definition in tests/make ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org>
---
tools/perf/config/Makefile | 2 +-
tools/perf/tests/make | 16 +++++++++++++++-
tools/{perf/config => scripts}/Makefile.arch | 0
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 0793c76..7545ba60 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -17,7 +17,7 @@ detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
-include $(src-perf)/config/Makefile.arch
+include $(srctree)/tools/scripts/Makefile.arch
$(call detected_var,ARCH)
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 130be7c..df38dec 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -1,3 +1,5 @@
+include ../scripts/Makefile.include
+
ifndef MK
ifeq ($(MAKECMDGOALS),)
# no target specified, trigger the whole suite
@@ -12,7 +14,19 @@ endif
else
PERF := .
-include config/Makefile.arch
+# As per kernel Makefile, avoid funny character set dependencies
+unexport LC_ALL
+LC_COLLATE=C
+LC_NUMERIC=C
+export LC_COLLATE LC_NUMERIC
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(shell pwd)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))
+endif
+
+include $(srctree)/tools/scripts/Makefile.arch
# FIXME looks like x86 is the only arch running tests ;-)
# we need some IS_(32/64) flag to make this generic
diff --git a/tools/perf/config/Makefile.arch b/tools/scripts/Makefile.arch
similarity index 100%
rename from tools/perf/config/Makefile.arch
rename to tools/scripts/Makefile.arch
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 53/53] perf record: Allow generate tracking events at the end of output |
| Message-ID | <qPLaS-38k-75@gated-at.bofh.it> |
| In reply to | #1306221 |
Before this patch tracking events are generated based on information in
/proc before all samples. However, with the introducing of overwrite
evsel in perf record, it becomes inconvenience: 'perf record' now can
executed as a daemon for sereval hours and only capture the last
snapshot when it receives SIGUSR2. The tracking events generated at
the head of output 'perf.data' becomes too old, but most of tracking
events during 'perf record' running are dropped.
This patch generates tracking events at the end of output. The output
events series would better reflecting status of system when SIGUSR2
received.
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 | 62 +++++++++++++++++++++++++++++++--------------
1 file changed, 43 insertions(+), 19 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 6ec0529..c1023ce 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -56,6 +56,7 @@ struct record {
bool no_buildid_cache_set;
bool timestamp_filename;
bool switch_output;
+ bool tail_tracking;
bool tailsize_evt_stopped;
unsigned long long samples;
};
@@ -639,6 +640,26 @@ record__finish_output(struct record *rec)
static int record__synthesize(struct record *rec);
+static void record__synthesize_target(struct record *rec)
+{
+ if (target__none(&rec->opts.target)) {
+ struct {
+ struct thread_map map;
+ struct thread_map_data map_data;
+ } thread_map;
+
+ thread_map.map.nr = 1;
+ thread_map.map.map[0].pid = rec->evlist->workload.pid;
+ thread_map.map.map[0].comm = NULL;
+ perf_event__synthesize_thread_map(&rec->tool,
+ &thread_map.map,
+ process_synthesized_event,
+ &rec->session->machines.host,
+ rec->opts.sample_address,
+ rec->opts.proc_map_timeout);
+ }
+}
+
static int
record__switch_output(struct record *rec, bool at_exit)
{
@@ -648,6 +669,11 @@ record__switch_output(struct record *rec, bool at_exit)
/* Same Size: "2015122520103046"*/
char timestamp[] = "InvalidTimestamp";
+ if (rec->tail_tracking) {
+ record__synthesize(rec);
+ record__synthesize_target(rec);
+ }
+
rec->samples = 0;
record__finish_output(rec);
err = fetch_current_timestamp(timestamp, sizeof(timestamp));
@@ -674,23 +700,10 @@ record__switch_output(struct record *rec, bool at_exit)
machines__init(&rec->session->machines);
perf_session__create_kernel_maps(rec->session);
perf_session__set_id_hdr_size(rec->session);
- record__synthesize(rec);
- if (target__none(&rec->opts.target)) {
- struct {
- struct thread_map map;
- struct thread_map_data map_data;
- } thread_map;
-
- thread_map.map.nr = 1;
- thread_map.map.map[0].pid = rec->evlist->workload.pid;
- thread_map.map.map[0].comm = NULL;
- perf_event__synthesize_thread_map(&rec->tool,
- &thread_map.map,
- process_synthesized_event,
- &rec->session->machines.host,
- rec->opts.sample_address,
- rec->opts.proc_map_timeout);
+ if (!rec->tail_tracking) {
+ record__synthesize(rec);
+ record__synthesize_target(rec);
}
}
return fd;
@@ -886,9 +899,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
machine = &session->machines.host;
- err = record__synthesize(rec);
- if (err < 0)
- goto out_child;
+ if (!rec->tail_tracking) {
+ err = record__synthesize(rec);
+ if (err < 0)
+ goto out_child;
+ }
if (rec->realtime_prio) {
struct sched_param param;
@@ -1021,6 +1036,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
disabled = true;
}
}
+
+ if (rec->tail_tracking) {
+ err = record__synthesize(rec);
+ if (err < 0)
+ goto out_child;
+ }
+
auxtrace_snapshot_disable();
if (forks && workload_exec_errno) {
@@ -1446,6 +1468,8 @@ struct option __record_options[] = {
"append timestamp to output filename"),
OPT_BOOLEAN(0, "switch-output", &record.switch_output,
"Switch output when receive SIGUSR2"),
+ OPT_BOOLEAN(0, "tail-tracking", &record.tail_tracking,
+ "Generate tracking events at the end of output"),
OPT_END()
};
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-01-11 15:00 +0100 |
| Subject | [PATCH 48/53] perf tools: Enable overwrite settings |
| Message-ID | <qPLaS-38k-81@gated-at.bofh.it> |
| In reply to | #1306221 |
This patch allows following config terms and option:
# perf record --overwrite ...
Globally set following events to overwrite;
# perf record --event cycles/overwrite/ ...
# perf record --event cycles/no-overwrite/ ...
Set specific events to be overwrite or no-overwrite.
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 | 14 ++++++++++++++
tools/perf/util/parse-events.h | 4 +++-
tools/perf/util/parse-events.l | 2 ++
7 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e55a23f..8e56f92 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1267,6 +1267,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 90129ac..71f305b 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -58,6 +58,7 @@ struct record_opts {
bool full_auxtrace;
bool auxtrace_snapshot_mode;
bool record_switch_events;
+ 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 f1b633e..6932b8b 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;
}
@@ -745,6 +748,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 8932a5c..c76e385 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 03d18f4..c1d4f39 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -855,6 +855,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;
@@ -892,6 +898,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) {
@@ -961,6 +969,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;
}
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index c34615f..29cc804 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -68,7 +68,9 @@ enum {
PARSE_EVENTS__TERM_TYPE_CALLGRAPH,
PARSE_EVENTS__TERM_TYPE_STACKSIZE,
PARSE_EVENTS__TERM_TYPE_NOINHERIT,
- PARSE_EVENTS__TERM_TYPE_INHERIT
+ PARSE_EVENTS__TERM_TYPE_INHERIT,
+ PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
+ PARSE_EVENTS__TERM_TYPE_OVERWRITE,
};
struct parse_events_array {
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 27d567f..2ef6f96 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -202,6 +202,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-01-11 15:10 +0100 |
| Subject | [PATCH 11/53] perf test: Fix false TEST_OK result for 'perf test hist' |
| Message-ID | <qPLku-3rc-9@gated-at.bofh.it> |
| In reply to | #1306221 |
Commit 71d6de64feddd4b455555326fba2111b3006d9e0 ('perf test: Fix hist
testcases when kptr_restrict is on') solves a double free problem when
'perf test hist' calling setup_fake_machine(). However, the result is
still incorrect. For example:
$ ./perf test -v 'filtering hist entries'
25: Test filtering hist entries :
--- start ---
test child forked, pid 4186
Cannot create kernel maps
test child finished with 0
---- end ----
Test filtering hist entries: Ok
In this case the body of this test is not get executed at all, but the
result is 'Ok'.
Actually, in setup_fake_machine() there's no need to create real kernel
maps. What we want is the fake maps. This patch removes the
machine__create_kernel_maps() in setup_fake_machine(), so it won't be
affected by kptr_restrict setting.
Test result:
$ cat /proc/sys/kernel/kptr_restrict
1
$ ~/perf test -v hist
15: Test matching and linking multiple hists :
--- start ---
test child forked, pid 24031
test child finished with 0
---- end ----
Test matching and linking multiple hists: Ok
[SNIP]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/tests/hists_common.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index bcfd081..071a8b5 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -87,11 +87,6 @@ struct machine *setup_fake_machine(struct machines *machines)
return NULL;
}
- if (machine__create_kernel_maps(machine)) {
- pr_debug("Cannot create kernel maps\n");
- return NULL;
- }
-
for (i = 0; i < ARRAY_SIZE(fake_threads); i++) {
struct thread *thread;
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
Page 2 of 5 — ← Prev page 1 [2] 3 4 5 Next page →
Back to top | Article view | linux.kernel
csiph-web