From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935679AbdGTJGd (ORCPT ); Thu, 20 Jul 2017 05:06:33 -0400 Received: from terminus.zytor.com ([65.50.211.136]:40485 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934928AbdGTJGa (ORCPT ); Thu, 20 Jul 2017 05:06:30 -0400 Date: Thu, 20 Jul 2017 02:01:50 -0700 From: tip-bot for David Carrillo-Cisneros Message-ID: Cc: peterz@infradead.org, linux-kernel@vger.kernel.org, hpa@zytor.com, davidcc@google.com, acme@redhat.com, tglx@linutronix.de, jolsa@kernel.org, sque@chromium.org, pjt@google.com, namhyung@kernel.org, ak@linux.intel.com, alexander.shishkin@linux.intel.com, wangnan0@huawei.com, hekuang@huawei.com, eranian@google.com, mingo@kernel.org, dsahern@gmail.com, mhiramat@kernel.org Reply-To: namhyung@kernel.org, mhiramat@kernel.org, dsahern@gmail.com, mingo@kernel.org, wangnan0@huawei.com, hekuang@huawei.com, eranian@google.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, acme@redhat.com, hpa@zytor.com, davidcc@google.com, peterz@infradead.org, linux-kernel@vger.kernel.org, pjt@google.com, sque@chromium.org, jolsa@kernel.org, tglx@linutronix.de In-Reply-To: <20170718042549.145161-12-davidcc@google.com> References: <20170718042549.145161-12-davidcc@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf header: Make write_pmu_mappings pipe-mode friendly Git-Commit-ID: a02c395cccc95e40b4c506c78857e24fdb049096 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a02c395cccc95e40b4c506c78857e24fdb049096 Gitweb: http://git.kernel.org/tip/a02c395cccc95e40b4c506c78857e24fdb049096 Author: David Carrillo-Cisneros AuthorDate: Mon, 17 Jul 2017 21:25:44 -0700 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 18 Jul 2017 23:14:34 -0300 perf header: Make write_pmu_mappings pipe-mode friendly In pipe-mode, we will operate over a buffer instead of a file descriptor but write_pmu_mappings uses lseek to move over the perf.data file. Refactor write_pmu_mappings to avoid the usage of lseek and allow reusing the same logic in pipe-mode (next patch). Signed-off-by: David Carrillo-Cisneros Acked-by: David Ahern Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: He Kuang Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Turner Cc: Peter Zijlstra Cc: Simon Que Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/r/20170718042549.145161-12-davidcc@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/header.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 14db9f2..d5359e33 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -797,11 +797,19 @@ static int write_pmu_mappings(struct feat_fd *ff, struct perf_evlist *evlist __maybe_unused) { struct perf_pmu *pmu = NULL; - off_t offset = lseek(ff->fd, 0, SEEK_CUR); - __u32 pmu_num = 0; + u32 pmu_num = 0; int ret; - /* write real pmu_num later */ + /* + * Do a first pass to count number of pmu to avoid lseek so this + * works in pipe mode as well. + */ + while ((pmu = perf_pmu__scan(pmu))) { + if (!pmu->name) + continue; + pmu_num++; + } + ret = do_write(ff, &pmu_num, sizeof(pmu_num)); if (ret < 0) return ret; @@ -809,7 +817,6 @@ static int write_pmu_mappings(struct feat_fd *ff, while ((pmu = perf_pmu__scan(pmu))) { if (!pmu->name) continue; - pmu_num++; ret = do_write(ff, &pmu->type, sizeof(pmu->type)); if (ret < 0) @@ -820,12 +827,6 @@ static int write_pmu_mappings(struct feat_fd *ff, return ret; } - if (pwrite(ff->fd, &pmu_num, sizeof(pmu_num), offset) != sizeof(pmu_num)) { - /* discard all */ - lseek(ff->fd, offset, SEEK_SET); - return -1; - } - return 0; }