Received: by 10.223.185.116 with SMTP id b49csp1019863wrg; Fri, 16 Feb 2018 10:56:53 -0800 (PST) X-Google-Smtp-Source: AH8x224OvwGOdFEBIRiTI6SGI1nEsJhMnV0eQUZ+TgUjNClSpw2TEzNnYaRAPVKBQmLM4NHXMSrn X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr6672934plo.380.1518807412921; Fri, 16 Feb 2018 10:56:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807412; cv=none; d=google.com; s=arc-20160816; b=N/eIHskkA21L+YFjj3pc5mBK3PhY9QJLijEzOfkL5zgbmOhzCXnk+pnnMLfqkqy9hc 0BwkhehG8xp07NzFp0JLbrP8HzQzK+c4+LMYSpKa0nf5oAWgnTJAimfiBBbLDESz7xyR s/igHSA9GTmdl2DxRJgBRYjhxupTdKc98Nf/O5pZZkMNXnp+u1+DgSW6iwHxOby8JbE0 nKvlRQRLqACw5dDyP7y2AW/oXqw9sHgZBayPmq+uBZUUvuIgVOhYMxw+SbQdaf7EyjKF n9q/kIcj46XniM+KpmcLlBPTirmjNstJ9EeCIgOGBCbx0kud+fqsDlRvFhf+70FmUHbg lHbQ== 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=2nGaoahXusjf1WQlkEFMSpa2+qdxGp93QaHUF+dcJKY=; b=lMZSZrADeAEDeJAqMfjOboT9iS9i0GhSH9SMdYeg1IdJ93XLw1umgkb9w5M8mHNd8U jJUmS6c5bv+nGirSG1PDby3edJbYLB6tK7oJ7uj2UteeH10SPh1gtgrvcvcYVgeKxdZ0 zVRCdw0porFW+yI2xMzR3pTzrVr1zVMD/ic8S/NZt2MOYeET9cZKU8NVsEAhSMGG1dp6 /FrvhAuu+aQflKhvXns0m0Hqk/ZZt6e9YaPUbQbdLNEIHxZ34UjfG5vZQ1pPZzafr3Cu DDcNpjRuwrCGF9cfSMqVTMuE2MrNcVnK2/uOJtkqVn+SOZAiwqs+YjIiWffo4Oq8vROM Ik/w== 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 71-v6si222390plc.713.2018.02.16.10.56.08; Fri, 16 Feb 2018 10:56:52 -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 S932680AbeBPJui (ORCPT + 99 others); Fri, 16 Feb 2018 04:50:38 -0500 Received: from terminus.zytor.com ([198.137.202.136]:38829 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932662AbeBPJug (ORCPT ); Fri, 16 Feb 2018 04:50:36 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1G9ZsBB021485; Fri, 16 Feb 2018 01:35:54 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1G9ZsTb021482; Fri, 16 Feb 2018 01:35:54 -0800 Date: Fri, 16 Feb 2018 01:35:54 -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, ak@linux.intel.com, yao.jin@linux.intel.com, namhyung@kernel.org, jolsa@kernel.org, hpa@zytor.com, acme@redhat.com, tglx@linutronix.de, kan.liang@intel.com, mingo@kernel.org, wangnan0@huawei.com, peterz@infradead.org Reply-To: hpa@zytor.com, jolsa@kernel.org, namhyung@kernel.org, yao.jin@linux.intel.com, linux-kernel@vger.kernel.org, ak@linux.intel.com, peterz@infradead.org, wangnan0@huawei.com, kan.liang@intel.com, mingo@kernel.org, acme@redhat.com, tglx@linutronix.de 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: 8872481bd04850b19e053dc579de5a11b83b16fc 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: 8872481bd04850b19e053dc579de5a11b83b16fc Gitweb: https://git.kernel.org/tip/8872481bd04850b19e053dc579de5a11b83b16fc Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:19 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 15 Feb 2018 09:52:22 -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 */