Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4922711ybg; Mon, 21 Oct 2019 17:08:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4Xg2AOUHOYo5XDw1ACGRcho+xqr1IFOM+6qNxp4l5C8CMwxl12wi3qtL64AcA42nZCY7o X-Received: by 2002:aa7:d6ca:: with SMTP id x10mr11325560edr.27.1571702920939; Mon, 21 Oct 2019 17:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571702920; cv=none; d=google.com; s=arc-20160816; b=ZkQxveu1R4Ta4uZYCAbxtOIWAuw+dzYG2cQhEespkgD97jldyVcgOqnm9j+f1LNL6l R1OHZRYN8XZnaJL8kU41DYQT0GwJ/WgpLZKY/JVC4jXatA5/S4awE3C31bZehuL2PllO Fx7cjurG3EmH+Za0bS10Z8zvCxm3CeYgFFC1ilaDVnlD4W0nelYKLBOVVsH0qe2UFIr6 hDAHruhjXgTNEx6IGraWlFp6dNiIVEBTewggcisuI0bzozW4jqbvmLVQLNuLlrhA97se VdFA0P3zGc9F4n6dMnsHJKK1sFL+3KEaC4f1ObKEhMw4H0tj3QF+Iw9NjeUxsAJyx97n XC/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=EWGeayrus82LkcWueM0iv5ASo5HP519HYYcWLkCDtxM=; b=QiBhmYCgPjDRQO2B3MTE3xGh+Se8pZzh4AqScSXF0yeecMN00I6suYrAta20xu03cn r7MPEi9kG6N+eg3VNHSsZyBhUnOQI7nTzvUi3kzObc4MFIlnbYGqbaEes0ke6tUOKwXD eZo06kvh0R6QefFlAHIQhdHYlw5YD+/UwheQi5ODLu9R6p2rV3QDPVIEKVxoIbhV4Ay+ HfgXs3GSKK7JTBauh0e1sjcP+iXJYSnw3dg/P+EHu7ImkpBcktvKmnRiDEAJxGmas6fd l0ITrYOZlEqOZVDnF3sSATmGrsyjDZi6Mn1OHNEbUJGpZpYB/k+MNlzRDoelWbDY9eMM sEIg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h50si11038897ede.423.2019.10.21.17.08.17; Mon, 21 Oct 2019 17:08:40 -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 S2387625AbfJVAFS (ORCPT + 99 others); Mon, 21 Oct 2019 20:05:18 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38895 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387566AbfJVAFQ (ORCPT ); Mon, 21 Oct 2019 20:05:16 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iMgwv-0003tO-Nk; Tue, 22 Oct 2019 01:18:54 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 2D3381C0489; Tue, 22 Oct 2019 01:18:53 +0200 (CEST) Date: Mon, 21 Oct 2019 23:18:52 -0000 From: "tip-bot2 for Jiri Olsa" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] libperf: Move mmap allocation to perf_evlist__mmap_ops::get Cc: Jiri Olsa , Alexander Shishkin , Alexey Budankov , Andi Kleen , Jin Yao , Michael Petlan , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191017105918.20873-3-jolsa@kernel.org> References: <20191017105918.20873-3-jolsa@kernel.org> MIME-Version: 1.0 Message-ID: <157169993270.29376.15194593020616946024.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 3805e4f303314c2b53fb217dd8549a5b9eb06b11 Gitweb: https://git.kernel.org/tip/3805e4f303314c2b53fb217dd8549a5b9eb06b11 Author: Jiri Olsa AuthorDate: Thu, 17 Oct 2019 12:59:10 +02:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Sat, 19 Oct 2019 15:35:01 -03:00 libperf: Move mmap allocation to perf_evlist__mmap_ops::get Move allocation of the mmap array into perf_evlist__mmap_ops::get, to centralize the mmap allocation. Also move nr_mmap setup to perf_evlist__mmap_ops so it's centralized and shared by both perf and libperf mmap code. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Jin Yao Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20191017105918.20873-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/evlist.c | 42 +++++++++++++++++++++++---------------- tools/perf/util/evlist.c | 24 ++++++++-------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 854efff..73aac6b 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -338,10 +338,6 @@ static struct perf_mmap* perf_evlist__alloc_mmap(struct perf_evlist *evlist, boo int i; struct perf_mmap *map; - evlist->nr_mmaps = perf_cpu_map__nr(evlist->cpus); - if (perf_cpu_map__empty(evlist->cpus)) - evlist->nr_mmaps = perf_thread_map__nr(evlist->threads); - map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap)); if (!map) return NULL; @@ -384,18 +380,22 @@ static void perf_evlist__set_sid_idx(struct perf_evlist *evlist, static struct perf_mmap* perf_evlist__mmap_cb_get(struct perf_evlist *evlist, bool overwrite, int idx) { - struct perf_mmap *map = &evlist->mmap[idx]; + struct perf_mmap *maps; - if (overwrite) { - if (!evlist->mmap_ovw) { - evlist->mmap_ovw = perf_evlist__alloc_mmap(evlist, true); - if (!evlist->mmap_ovw) - return NULL; - } - map = &evlist->mmap_ovw[idx]; + maps = overwrite ? evlist->mmap_ovw : evlist->mmap; + + if (!maps) { + maps = perf_evlist__alloc_mmap(evlist, overwrite); + if (!maps) + return NULL; + + if (overwrite) + evlist->mmap_ovw = maps; + else + evlist->mmap = maps; } - return map; + return &maps[idx]; } #define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y)) @@ -556,6 +556,17 @@ out_unmap: return -1; } +static int perf_evlist__nr_mmaps(struct perf_evlist *evlist) +{ + int nr_mmaps; + + nr_mmaps = perf_cpu_map__nr(evlist->cpus); + if (perf_cpu_map__empty(evlist->cpus)) + nr_mmaps = perf_thread_map__nr(evlist->threads); + + return nr_mmaps; +} + int perf_evlist__mmap_ops(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, struct perf_mmap_param *mp) @@ -567,10 +578,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist, if (!ops || !ops->get || !ops->mmap) return -EINVAL; - if (!evlist->mmap) - evlist->mmap = perf_evlist__alloc_mmap(evlist, false); - if (!evlist->mmap) - return -ENOMEM; + evlist->nr_mmaps = perf_evlist__nr_mmaps(evlist); perf_evlist__for_each_entry(evlist, evsel) { if ((evsel->attr.read_format & PERF_FORMAT_ID) && diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 6cda5a3..5cded4e 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -599,9 +599,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist, int i; struct mmap *map; - evlist->core.nr_mmaps = perf_cpu_map__nr(evlist->core.cpus); - if (perf_cpu_map__empty(evlist->core.cpus)) - evlist->core.nr_mmaps = perf_thread_map__nr(evlist->core.threads); map = zalloc(evlist->core.nr_mmaps * sizeof(struct mmap)); if (!map) return NULL; @@ -639,19 +636,21 @@ static struct perf_mmap* perf_evlist__mmap_cb_get(struct perf_evlist *_evlist, bool overwrite, int idx) { struct evlist *evlist = container_of(_evlist, struct evlist, core); - struct mmap *maps = evlist->mmap; + struct mmap *maps; - if (overwrite) { - maps = evlist->overwrite_mmap; + maps = overwrite ? evlist->overwrite_mmap : evlist->mmap; - if (!maps) { - maps = evlist__alloc_mmap(evlist, true); - if (!maps) - return NULL; + if (!maps) { + maps = evlist__alloc_mmap(evlist, overwrite); + if (!maps) + return NULL; + if (overwrite) { evlist->overwrite_mmap = maps; if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY) perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING); + } else { + evlist->mmap = maps; } } @@ -812,11 +811,6 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages, .mmap = perf_evlist__mmap_cb_mmap, }; - if (!evlist->mmap) - evlist->mmap = evlist__alloc_mmap(evlist, false); - if (!evlist->mmap) - return -ENOMEM; - evlist->core.mmap_len = evlist__mmap_size(pages); pr_debug("mmap size %zuB\n", evlist->core.mmap_len); mp.core.mask = evlist->core.mmap_len - page_size - 1;