Received: by 10.223.185.116 with SMTP id b49csp1019714wrg; Fri, 16 Feb 2018 10:56:38 -0800 (PST) X-Google-Smtp-Source: AH8x226lUd4aw0e76ev+czzvR7Be2SgnkQqMkY7mnnq805tWtddWj1owxvbuTYZQXXcWqoBpKui3 X-Received: by 2002:a17:902:7586:: with SMTP id j6-v6mr5732643pll.301.1518807398790; Fri, 16 Feb 2018 10:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807398; cv=none; d=google.com; s=arc-20160816; b=C18jhPefgBP7zfZTofE5uJT6Ri/tWx9rl3JDVGl4PRI1V6ob0QPPSRxKSfOCYVlpSO 4g4ihThlYKOPI4Rfbh9OBEV53QMePArhoTcNRxQUAB661yJNUKYtXhoS23lgi88hh2bp V8b1FCUeBDhgXx2WjASuyR+tmNgeWollxMOlMTuvQIqNlnMB5EjIZZZiqS886Lmsy1TQ AsCQI3zKxKLdTn5EE0rnTTT2EUUoAG3i1xyd6xnpYVyzUIIjzXlVdGg7o5StFFr3/vvt rBX5a2XGh9ICgA7xcCr+CFRx8VpYaWvloVAEwFOkr/dmb/rA1OSce3eF6/7TKrtkEEi5 gq1Q== 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=t/TTjo6r6o9ggzy59L9nH5VMUeCIliJlZk7naohMuXA=; b=g5YZX6MbQHZnoDkwBfyZ9OU6BEl8lUFF50AoAPGcvL0gdd3Tx7620uChwtS2Hjw74D Px/ryh0pGGa+i6PcD2/cx7t+6IGtpdjeYXf3vaR2P7gxv+CfxMAY3lLhHSWYxv8MwaSb UtLVa/Hoor4JbE36iTkz3RJl2VjxSVgAHe7jsXLYUroWRtrimMlFrpXHC4lEJWdhWmyG Vm/wCp6IppvaXz4JG8zX7OQN7KsMssgfqPpvkRE0nNumVdMVocKXA8cR8AvgrZgjYsHP e4+EfXhx2mzrgc4ql2aWaY+UBILtL00dRhZeNu/zpmYhXbv+wcGZThq6hhlbuzEhCUzG HKSQ== 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 b2-v6si4144740plm.172.2018.02.16.10.56.24; Fri, 16 Feb 2018 10:56:38 -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 S932908AbeBPJwe (ORCPT + 99 others); Fri, 16 Feb 2018 04:52:34 -0500 Received: from terminus.zytor.com ([198.137.202.136]:55091 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677AbeBPJw3 (ORCPT ); Fri, 16 Feb 2018 04:52:29 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1G9blLE021892; Fri, 16 Feb 2018 01:37:47 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1G9blkJ021889; Fri, 16 Feb 2018 01:37:47 -0800 Date: Fri, 16 Feb 2018 01:37:47 -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: jolsa@kernel.org, mingo@kernel.org, ak@linux.intel.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, kan.liang@intel.com, wangnan0@huawei.com, hpa@zytor.com, yao.jin@linux.intel.com, peterz@infradead.org, acme@redhat.com, tglx@linutronix.de Reply-To: yao.jin@linux.intel.com, hpa@zytor.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, wangnan0@huawei.com, kan.liang@intel.com, acme@redhat.com, tglx@linutronix.de, peterz@infradead.org, jolsa@kernel.org, ak@linux.intel.com, mingo@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: 7bb45972952db9298fe5cc440160dcad1a66bfbc 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: 7bb45972952db9298fe5cc440160dcad1a66bfbc Gitweb: https://git.kernel.org/tip/7bb45972952db9298fe5cc440160dcad1a66bfbc Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:23 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 15 Feb 2018 09:53:40 -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));