From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756262AbcAYJ6S (ORCPT ); Mon, 25 Jan 2016 04:58:18 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:26502 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753807AbcAYJ6P (ORCPT ); Mon, 25 Jan 2016 04:58:15 -0500 From: Wang Nan To: Alexei Starovoitov , Arnaldo Carvalho de Melo CC: Brendan Gregg , Daniel Borkmann , "David S. Miller" , He Kuang , Jiri Olsa , Li Zefan , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , , Will Deacon , , Wang Nan Subject: [PATCH 43/54] perf tools: Operate multiple channels Date: Mon, 25 Jan 2016 09:56:30 +0000 Message-ID: <1453715801-7732-44-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1453715801-7732-1-git-send-email-wangnan0@huawei.com> References: <1453715801-7732-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.56A5F1A1.00C3,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5fb2e203bb69ba9065eebf005b0b76d5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before this patch perf operates on only the first channel. Make perf mmap and read from multiple channels. Signed-off-by: Wang Nan Signed-off-by: He Kuang Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li 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 30a3c5c..a471ca6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -466,8 +466,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 10eeacf..a363466 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