Received: by 10.223.185.116 with SMTP id b49csp3560284wrg; Tue, 13 Feb 2018 04:19:35 -0800 (PST) X-Google-Smtp-Source: AH8x224WMxezcYU/1xr3pPltM9dTtB20gML3wncKlug8hd41wfZMdP61p3grWwUHPaI52uS4RY+x X-Received: by 2002:a17:902:526d:: with SMTP id z100-v6mr972185plh.396.1518524375506; Tue, 13 Feb 2018 04:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524375; cv=none; d=google.com; s=arc-20160816; b=nUwuOjAA3EizpDpY+QH3bJactOgEGxxtNn6WKFh29vFKuLHYv+/HGZpIkd+muyAD1c 2o3uy2BMB6nrrCVxm7w1RnUNr3rXwJg5TQeN2lLSKZssUmXy52Q+OQCB01/Ivd0foDac TJYCymLqCBMGbTYehe3OhT2uPcHQ2+sUdIIQItfJpudac4mvH6/AWoG194Dwbm7sOviW 3KApPsf/pfNmGrHFU7v4HVlGLyTG3aGrbsH/4o4m6Z0YZMn5XBPaKYVn5x6nH9+RGj5P IEkNewi/Rm7J38aJcj3OHvWylh3PuRf5S867W0cpYPkRMqvv6JiSHm9H6JK0Y4Pc+mU/ oycw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=++DAI4kg1JObUJFujsPVQZQwl1pc7N/k1uvxPbDtOiY=; b=mk2n7+kzt94urSpNcN7gsPk08WyylJRfTNNKbEsjOVfKxiHUw051UeSOVlxMu5AvAv LO4Og8WUuOAPLIP7C9s60MygvZNgW4h5k2T9Di1lq1SOHP3XRpehE91MhnA0GAtYqi9x kzT5DGGwanW+Ogs/+bTSNW/cupQq4R0wXMSVJHp3hy88pzqghDDcNRXI8FkPDlZhz55t dt9uzGFo52m1rwRwFvatRpeMT9pBtxLmPJMk05C8p9RAUQqFhA+12TWRVswuXVyzJz/B Svg8EgfcUpXtzUPdUfnWXHA3x+bCU4zlZtHEvzLr2eCtQMn6VJG9/lpjQ+lKya5NaOdm foog== 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 z1-v6si5612287pln.408.2018.02.13.04.19.21; Tue, 13 Feb 2018 04:19:35 -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 S935150AbeBMMRw (ORCPT + 99 others); Tue, 13 Feb 2018 07:17:52 -0500 Received: from terminus.zytor.com ([198.137.202.136]:38923 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934951AbeBMMRu (ORCPT ); Tue, 13 Feb 2018 07:17:50 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DC7SJ7028782; Tue, 13 Feb 2018 04:07:28 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DC7Rr8028779; Tue, 13 Feb 2018 04:07:27 -0800 Date: Tue, 13 Feb 2018 04:07:27 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: Cc: hpa@zytor.com, kan.liang@intel.com, tglx@linutronix.de, peterz@infradead.org, wangnan0@huawei.com, jolsa@kernel.org, acme@redhat.com, yao.jin@linux.intel.com, namhyung@kernel.org, mingo@kernel.org, ak@linux.intel.com, linux-kernel@vger.kernel.org Reply-To: hpa@zytor.com, tglx@linutronix.de, kan.liang@intel.com, jolsa@kernel.org, acme@redhat.com, wangnan0@huawei.com, peterz@infradead.org, yao.jin@linux.intel.com, namhyung@kernel.org, ak@linux.intel.com, mingo@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1516310792-208685-9-git-send-email-kan.liang@intel.com> References: <1516310792-208685-9-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf mmap: Introduce perf_mmap__read_event() Git-Commit-ID: 7257bb0efc6ab4b3a16e1c5154f70d30551e3a7b 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 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7257bb0efc6ab4b3a16e1c5154f70d30551e3a7b Gitweb: https://git.kernel.org/tip/7257bb0efc6ab4b3a16e1c5154f70d30551e3a7b Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:23 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 6 Feb 2018 10:11:50 -0300 perf mmap: Introduce perf_mmap__read_event() Except for 'perf record', the other perf tools read events one by one from the ring buffer using perf_mmap__read_forward(). But it only supports non-overwrite mode. Introduce perf_mmap__read_event() to support both non-overwrite and overwrite mode. Usage: perf_mmap__read_init() while(event = perf_mmap__read_event()) { //process the event perf_mmap__consume() } perf_mmap__read_done() It cannot use perf_mmap__read_backward(). Because it always reads the stale buffer which is already processed. Furthermore, the forward and backward concepts have been removed. The perf_mmap__read_backward() will be replaced and discarded later. Signed-off-by: Kan Liang Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Jin Yao Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1516310792-208685-9-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/mmap.c | 39 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/mmap.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 4f59eae..f804926 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -113,6 +113,45 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map) return perf_mmap__read(map, &map->prev, end); } +/* + * Read event from ring buffer one by one. + * Return one event for each call. + * + * Usage: + * perf_mmap__read_init() + * while(event = perf_mmap__read_event()) { + * //process the event + * perf_mmap__consume() + * } + * perf_mmap__read_done() + */ +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *startp, u64 end) +{ + union perf_event *event; + + /* + * Check if event was unmapped due to a POLLHUP/POLLERR. + */ + if (!refcount_read(&map->refcnt)) + return NULL; + + if (startp == NULL) + return NULL; + + /* non-overwirte doesn't pause the ringbuffer */ + if (!overwrite) + end = perf_mmap__read_head(map); + + event = perf_mmap__read(map, startp, end); + + if (!overwrite) + map->prev = *startp; + + return event; +} + void perf_mmap__read_catchup(struct perf_mmap *map) { u64 head; diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index 95549d4..2871854 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -89,6 +89,10 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail) union perf_event *perf_mmap__read_forward(struct perf_mmap *map); union perf_event *perf_mmap__read_backward(struct perf_mmap *map); +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *startp, u64 end); + int perf_mmap__push(struct perf_mmap *md, bool backward, void *to, int push(void *to, void *buf, size_t size));