Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5489364ybp; Mon, 14 Oct 2019 23:48:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvyWJEY7skiQKY2TLY0UPYuONZ5yh5I0ohUkjdWLjtVHgs3Gi7wJuPaA9urDtC+52yQJ/J X-Received: by 2002:a17:906:28ce:: with SMTP id p14mr33078293ejd.164.1571122117888; Mon, 14 Oct 2019 23:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571122117; cv=none; d=google.com; s=arc-20160816; b=cFPcpr/8PEu428jgRxVygxhjzc/kK00hoRh/YSBnbT1JLzFOnUAt/xTU1BL5JZ5/wT 3urIKr0XFTM11mPzwKH2srHEwtMQ+37oAhSrQemOR32DHMLKHZx0g8Z+TWTgRV+cK4fm zClZUByETQDFO/2aFS4+6nKP80QRXfGy2fQT9l34eNyq4LL/hlFMdwZD7GB2ACRd7OtE oPIoYMy0OVtosJppES9grxt+IcrFIUDj8pJ+utnQdDA2hALSeNrdBoUoIbCr7ehT66P+ R/aGVprcApFOgc+ZXga043CUVY3Qo5/qIu4KjFDtfwLR/GQ9NMLulmA05IsPH+vDxib+ QdlA== 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=1SLl/0h68IOukDt9oY6O7yvXrNgyaHUnOgQhqnB00l8=; b=06swkVPVMIu34a6lRvj593bIoVwVeTdlK57q5GCoTI2hoC7ezn08+EbngSxJ9KsffF xVqn/xgEKvaJIABUebjDZpAMeYHd8Z1tpRamH+Wz422bBMUcXXpnY/v6ws40+4RsIjWM HZKamIJvqHoJIF59QLIG1KyGkjgz780KjMEmZqLU83DOojHagVYbFwbODubfsbPQFDkh z+uantRjSxIq1C5jaGubUyRWQwE0MeyHRrexXck+uQ0K08BuBIoR1IcJ2mytVB2xsX+0 T4JlTOK78GlPLH+htb6noMOyWwunYf9wWl6+S8IuyZty9BMQKw5wWs4NTrcTfMdKM0Yt BMiw== 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 j21si12747412eja.5.2019.10.14.23.48.14; Mon, 14 Oct 2019 23:48:37 -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 S1728374AbfJOFbu (ORCPT + 99 others); Tue, 15 Oct 2019 01:31:50 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:41878 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728173AbfJOFbt (ORCPT ); Tue, 15 Oct 2019 01:31:49 -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 1iKFQo-0008Sp-CY; Tue, 15 Oct 2019 07:31:38 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 17A8C1C0450; Tue, 15 Oct 2019 07:31:38 +0200 (CEST) Date: Tue, 15 Oct 2019 05:31:37 -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: Introduce perf_evlist_mmap_ops::mmap callback Cc: Jiri Olsa , Alexander Shishkin , Michael Petlan , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191007125344.14268-18-jolsa@kernel.org> References: <20191007125344.14268-18-jolsa@kernel.org> MIME-Version: 1.0 Message-ID: <157111749790.12254.16074880570008173641.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: b5911e7ac28cb34f21b7380915ce98518078f114 Gitweb: https://git.kernel.org/tip/b5911e7ac28cb34f21b7380915ce98518078f114 Author: Jiri Olsa AuthorDate: Mon, 07 Oct 2019 14:53:25 +02:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Thu, 10 Oct 2019 12:22:21 -03:00 libperf: Introduce perf_evlist_mmap_ops::mmap callback Add the perf_evlist_mmap_ops::mmap callback to be called in mmap_per_evsel() to actually mmap the map. Add libperf's perf_evlist__mmap_cb_mmap() function as libperf's mmap callback. New mmaped map gets refcount set to 2 in mmap__mmap(), we follow that in mmap callback. We will move this to common place after we switch to perf_evlist__mmap(). Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20191007125344.14268-18-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/evlist.c | 29 ++++++++++++++++++++--- tools/perf/lib/include/internal/evlist.h | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 4f49de5..b697226 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -359,6 +359,28 @@ perf_evlist__mmap_cb_get(struct perf_evlist *evlist, bool overwrite, int idx) #define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y)) static int +perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *mp, + int output, int cpu) +{ + /* + * The last one will be done at perf_mmap__consume(), so that we + * make sure we don't prevent tools from consuming every last event in + * the ring buffer. + * + * I.e. we can get the POLLHUP meaning that the fd doesn't exist + * anymore, but the last events for it are still in the ring buffer, + * waiting to be consumed. + * + * Tools can chose to ignore this at their own discretion, but the + * evlist layer can't just drop it when filtering events in + * perf_evlist__filter_pollfd(). + */ + refcount_set(&map->refcnt, 2); + + return perf_mmap__mmap(map, mp, output, cpu); +} + +static int mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, int idx, struct perf_mmap_param *mp, int cpu_idx, int thread, int *_output, int *_output_overwrite) @@ -396,7 +418,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, if (*output == -1) { *output = fd; - if (perf_mmap__mmap(map, mp, *output, evlist_cpu) < 0) + if (ops->mmap(map, mp, *output, evlist_cpu) < 0) return -1; } else { if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) @@ -488,7 +510,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist, const struct perf_cpu_map *cpus = evlist->cpus; const struct perf_thread_map *threads = evlist->threads; - if (!ops || !ops->get) + if (!ops || !ops->get || !ops->mmap) return -EINVAL; if (!evlist->mmap) @@ -513,7 +535,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages) { struct perf_mmap_param mp; struct perf_evlist_mmap_ops ops = { - .get = perf_evlist__mmap_cb_get, + .get = perf_evlist__mmap_cb_get, + .mmap = perf_evlist__mmap_cb_mmap, }; evlist->mmap_len = (pages + 1) * page_size; diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h index 9bc3a21..b201970 100644 --- a/tools/perf/lib/include/internal/evlist.h +++ b/tools/perf/lib/include/internal/evlist.h @@ -31,10 +31,13 @@ typedef void (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool); typedef struct perf_mmap* (*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int); +typedef int +(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, int); struct perf_evlist_mmap_ops { perf_evlist_mmap__cb_idx_t idx; perf_evlist_mmap__cb_get_t get; + perf_evlist_mmap__cb_mmap_t mmap; }; int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);