From patchwork Fri Jul 15 20:50:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 72135 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp820204qga; Fri, 15 Jul 2016 13:52:24 -0700 (PDT) X-Received: by 10.98.104.71 with SMTP id d68mr14196524pfc.163.1468615930872; Fri, 15 Jul 2016 13:52:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si1118874pfi.24.2016.07.15.13.52.10; Fri, 15 Jul 2016 13:52:10 -0700 (PDT) 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 S1752302AbcGOUwH (ORCPT + 29 others); Fri, 15 Jul 2016 16:52:07 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:44273 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826AbcGOUvX (ORCPT ); Fri, 15 Jul 2016 16:51:23 -0400 Received: from [179.235.155.208] (helo=jouet.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bOA4t-0008VO-Qe; Fri, 15 Jul 2016 20:51:20 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 06AE0143C7D; Fri, 15 Jul 2016 17:51:12 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , He Kuang , Masami Hiramatsu , Namhyung Kim , Nilay Vaish , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 15/24] perf evlist: Map backward events to backward_mmap Date: Fri, 15 Jul 2016 17:50:49 -0300 Message-Id: <1468615858-24936-16-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468615858-24936-1-git-send-email-acme@kernel.org> References: <1468615858-24936-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan In perf_evlist__mmap_per_evsel(), select backward_mmap for backward events. Utilize new perf_mmap APIs. Dynamically alloc backward_mmap. Remove useless functions. Signed-off-by: Wang Nan Acked-by: Jiri Olsa Cc: He Kuang Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Nilay Vaish Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1468485287-33422-9-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/backward-ring-buffer.c | 4 +-- tools/perf/util/evlist.c | 54 ++++++++++++++++----------------- 2 files changed, 29 insertions(+), 29 deletions(-) -- 2.7.4 diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c index 5cee3873f2b5..b2c634815f6b 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -31,8 +31,8 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count, for (i = 0; i < evlist->nr_mmaps; i++) { union perf_event *event; - perf_evlist__mmap_read_catchup(evlist, i); - while ((event = perf_evlist__mmap_read_backward(evlist, i)) != NULL) { + perf_mmap__read_catchup(&evlist->backward_mmap[i]); + while ((event = perf_mmap__read_backward(&evlist->backward_mmap[i])) != NULL) { const u32 type = event->header.type; switch (type) { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 24927e111d17..7570f903200e 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -27,7 +27,6 @@ #include #include -static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); static void perf_mmap__munmap(struct perf_mmap *map); static void perf_mmap__put(struct perf_mmap *map); @@ -692,8 +691,11 @@ static int perf_evlist__set_paused(struct perf_evlist *evlist, bool value) { int i; + if (!evlist->backward_mmap) + return 0; + for (i = 0; i < evlist->nr_mmaps; i++) { - int fd = evlist->mmap[i].fd; + int fd = evlist->backward_mmap[i].fd; int err; if (fd < 0) @@ -904,16 +906,6 @@ static void perf_mmap__put(struct perf_mmap *md) perf_mmap__munmap(md); } -static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx) -{ - perf_mmap__get(&evlist->mmap[idx]); -} - -static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx) -{ - perf_mmap__put(&evlist->mmap[idx]); -} - void perf_mmap__consume(struct perf_mmap *md, bool overwrite) { if (!overwrite) { @@ -1049,12 +1041,6 @@ static int perf_mmap__mmap(struct perf_mmap *map, return 0; } -static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx, - struct mmap_params *mp, int fd) -{ - return perf_mmap__mmap(&evlist->mmap[idx], mp, fd); -} - static bool perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused, struct perf_evsel *evsel) @@ -1066,16 +1052,27 @@ perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused, 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 *_output, int *_output_backward) { struct perf_evsel *evsel; int revent; evlist__for_each_entry(evlist, evsel) { + struct perf_mmap *maps = evlist->mmap; + int *output = _output; int fd; - if (!!evsel->attr.write_backward != (evlist->overwrite && evlist->backward)) - continue; + if (evsel->attr.write_backward) { + output = _output_backward; + maps = evlist->backward_mmap; + + if (!maps) { + maps = perf_evlist__alloc_mmap(evlist); + if (!maps) + return -1; + evlist->backward_mmap = maps; + } + } if (evsel->system_wide && thread) continue; @@ -1084,13 +1081,14 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, if (*output == -1) { *output = fd; - if (__perf_evlist__mmap(evlist, idx, mp, *output) < 0) + + if (perf_mmap__mmap(&maps[idx], mp, *output) < 0) return -1; } else { if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) return -1; - perf_evlist__mmap_get(evlist, idx); + perf_mmap__get(&maps[idx]); } revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0; @@ -1103,8 +1101,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, * Therefore don't add it for polling. */ if (!evsel->system_wide && - __perf_evlist__add_pollfd(evlist, fd, &evlist->mmap[idx], revent) < 0) { - perf_evlist__mmap_put(evlist, idx); + __perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) { + perf_mmap__put(&maps[idx]); return -1; } @@ -1130,13 +1128,14 @@ 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 output_backward = -1; 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, &output, &output_backward)) goto out_unmap; } } @@ -1157,12 +1156,13 @@ 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 output_backward = -1; auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread, false); if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread, - &output)) + &output, &output_backward)) goto out_unmap; }