Received: by 10.223.185.116 with SMTP id b49csp3559261wrg; Tue, 13 Feb 2018 04:18:46 -0800 (PST) X-Google-Smtp-Source: AH8x227s5cKPQgpKHRzytIWld4YQ1h9+ZBtwf0OL78Ktb6xa/zru7IEUhr4xQ++i7cVtnO5nkt7F X-Received: by 10.98.61.201 with SMTP id x70mr1058138pfj.133.1518524326452; Tue, 13 Feb 2018 04:18:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524326; cv=none; d=google.com; s=arc-20160816; b=Ucsh6T84WwH6IDYba6n0EPyFKwlGjVR7LmzSxcSm7L96pu6BCMZJNuFjED3bpImUtJ khC+hUkT6gL2/sRPPuihg6xXwk4+CgTy6YwHg4MH6e9vBgQVbzQnSsDDfpsvda0K2n1W yqnF0YMYWpTotHlx4MPmCBy70yyw4tWusq31vChSJOnSQKHz4DKqFIzFPNTTf3Rv2ipi yIslpkchHbtHoYR1aeghThLWuaUrwI0B/I+gSyFV37hTnxW6ifXUWR4wlMwWNl8cLBkE j0LRKlVgvKhUG25dUOt7fKW8a37PritMDsJTm86ErsU3eHlFn8Oz9UwmcOA8T6reRMVk 6UyA== 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=GYqAA+PMGKz+60fTwndbEsQc7krEEfp+rRO8Z5owmlI=; b=eBfWKfIg4o12fu/fWJjPpMr0tTICIgW08+84GkkgYXKwyp7T1vgE330A0S3qq8AlCx PUCuArtlvStB4PHsLrE7rafe7X6+aNIojtMwV49vQhOH4c6jIgys2aVgv/lP2Wa/FZoR KbBehNU+KaVCdcV1zKBqExqSc0DljbePUKQXdvu0KndJn80hthbxvYxtO3iWd75dzUOS cBNoLLJmZixnGfO1dVQ3XTwe9ynbBGoBtSzNDoNxd3eknRuwYWE+kVPI5FhQPFUURH75 D32/K84eTwJBiy/CPNWxX/ets718YTWxqBIqPIIhlde0DX7oynTLSQNd573dxzQCD5so n23g== 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 s65si1098938pfe.45.2018.02.13.04.18.32; Tue, 13 Feb 2018 04:18:46 -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 S935167AbeBMMQJ (ORCPT + 99 others); Tue, 13 Feb 2018 07:16:09 -0500 Received: from terminus.zytor.com ([198.137.202.136]:32993 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934898AbeBMMQH (ORCPT ); Tue, 13 Feb 2018 07:16:07 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DC5eg0028254; Tue, 13 Feb 2018 04:05:40 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DC5eGi028251; Tue, 13 Feb 2018 04:05:40 -0800 Date: Tue, 13 Feb 2018 04:05:40 -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: linux-kernel@vger.kernel.org, namhyung@kernel.org, mingo@kernel.org, jolsa@kernel.org, ak@linux.intel.com, wangnan0@huawei.com, kan.liang@intel.com, peterz@infradead.org, acme@redhat.com, yao.jin@linux.intel.com, tglx@linutronix.de, hpa@zytor.com Reply-To: tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, yao.jin@linux.intel.com, acme@redhat.com, wangnan0@huawei.com, kan.liang@intel.com, namhyung@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, ak@linux.intel.com, jolsa@kernel.org In-Reply-To: <1516310792-208685-5-git-send-email-kan.liang@intel.com> References: <1516310792-208685-5-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf mmap: Introduce perf_mmap__read_init() Git-Commit-ID: 701b3ef37c0a4a5168bc07cfd48b35727b5a922c 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: 701b3ef37c0a4a5168bc07cfd48b35727b5a922c Gitweb: https://git.kernel.org/tip/701b3ef37c0a4a5168bc07cfd48b35727b5a922c Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:19 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 6 Feb 2018 10:11:49 -0300 perf mmap: Introduce perf_mmap__read_init() The new function perf_mmap__read_init() is factored out from perf_mmap__push(). It is to calculate the 'start' and 'end' of the available data in ringbuffer. No functional change. 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-5-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/mmap.c | 37 +++++++++++++++++++++++++++---------- tools/perf/util/mmap.h | 2 ++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index fbbbe87..c19a4e6 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -267,24 +267,24 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u6 return -1; } -int perf_mmap__push(struct perf_mmap *md, bool overwrite, - void *to, int push(void *to, void *buf, size_t size)) +/* + * Report the start and end of the available data in ringbuffer + */ +int perf_mmap__read_init(struct perf_mmap *md, bool overwrite, + u64 *startp, u64 *endp) { u64 head = perf_mmap__read_head(md); u64 old = md->prev; - u64 end, start; unsigned char *data = md->base + page_size; unsigned long size; - void *buf; - int rc = 0; - start = overwrite ? head : old; - end = overwrite ? old : head; + *startp = overwrite ? head : old; + *endp = overwrite ? old : head; - if (start == end) + if (*startp == *endp) return 0; - size = end - start; + size = *endp - *startp; if (size > (unsigned long)(md->mask) + 1) { if (!overwrite) { WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); @@ -298,10 +298,27 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite, * Backward ring buffer is full. We still have a chance to read * most of data from it. */ - if (overwrite_rb_find_range(data, md->mask, head, &start, &end)) + if (overwrite_rb_find_range(data, md->mask, head, startp, endp)) return -1; } + return 1; +} + +int perf_mmap__push(struct perf_mmap *md, bool overwrite, + void *to, int push(void *to, void *buf, size_t size)) +{ + u64 head = perf_mmap__read_head(md); + u64 end, start; + unsigned char *data = md->base + page_size; + unsigned long size; + void *buf; + int rc = 0; + + rc = perf_mmap__read_init(md, overwrite, &start, &end); + if (rc < 1) + return rc; + size = end - start; if ((start & md->mask) + size != (end & md->mask)) { diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index e43d7b5..9ab2b48 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -94,4 +94,6 @@ int perf_mmap__push(struct perf_mmap *md, bool backward, size_t perf_mmap__mmap_len(struct perf_mmap *map); +int perf_mmap__read_init(struct perf_mmap *md, bool overwrite, + u64 *startp, u64 *endp); #endif /*__PERF_MMAP_H */