From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752397AbcEMH4q (ORCPT ); Fri, 13 May 2016 03:56:46 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:28593 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751662AbcEMH4n (ORCPT ); Fri, 13 May 2016 03:56:43 -0400 From: Wang Nan To: CC: , , Wang Nan , He Kuang , "Arnaldo Carvalho de Melo" , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , "Zefan Li" , Subject: [PATCH 04/17] perf tools: Operate multiple channels Date: Fri, 13 May 2016 07:56:01 +0000 Message-ID: <1463126174-119290-5-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1463126174-119290-1-git-send-email-wangnan0@huawei.com> References: <1463126174-119290-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.0A020202.573588AF.0103,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 33f85f3f7fcc6debe6dbf82a2b94b065 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 | 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