From patchwork Mon Feb 22 09:11:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 62480 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1111335lbl; Mon, 22 Feb 2016 01:13:34 -0800 (PST) X-Received: by 10.66.159.136 with SMTP id xc8mr36826134pab.71.1456132414215; Mon, 22 Feb 2016 01:13:34 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sk6si38460095pab.138.2016.02.22.01.13.33; Mon, 22 Feb 2016 01:13:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751892AbcBVJN3 (ORCPT + 30 others); Mon, 22 Feb 2016 04:13:29 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:48616 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751576AbcBVJNU (ORCPT ); Mon, 22 Feb 2016 04:13:20 -0500 Received: from 172.24.1.48 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BWL59829; Mon, 22 Feb 2016 17:12:08 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Mon, 22 Feb 2016 17:12:00 +0800 From: Wang Nan To: Alexei Starovoitov , Arnaldo Carvalho de Melo , Arnaldo Carvalho de Melo , Brendan Gregg CC: Adrian Hunter , Cody P Schafer , "David S. Miller" , He Kuang , =?UTF-8?q?J=C3=A9r=C3=A9mie=20Galarneau?= , Jiri Olsa , Kirill Smelkov , Li Zefan , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , , Wang Nan , Subject: [PATCH 35/48] perf tools: Operate multiple channels Date: Mon, 22 Feb 2016 09:11:02 +0000 Message-ID: <1456132275-98875-36-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1456132275-98875-1-git-send-email-wangnan0@huawei.com> References: <1456132275-98875-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.56CAD0E9.00CC, 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: ad9fee157405fcbbd04f4cc0a30dbd80 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk 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(-) -- 1.8.3.4 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index cf8f67a..a472950 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 d94f2c6..16f061c 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, };