Received: by 10.223.176.46 with SMTP id f43csp32858wra; Thu, 18 Jan 2018 13:29:40 -0800 (PST) X-Google-Smtp-Source: ACJfBovZTokU3x3ewaA6SCoHgYe7oEqSP04q1wN7CcEA8q2e7A/wipIrP1kFwHC3lrHjs7khI/Nn X-Received: by 10.101.92.9 with SMTP id u9mr21514772pgr.440.1516310980636; Thu, 18 Jan 2018 13:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516310980; cv=none; d=google.com; s=arc-20160816; b=MJtdn9ul24Mf14bjDZFTHce577wFkwCl1jUNvyLbrdkUcAWNqPu2G9hHHrwLXvmByj 3Wac9oljPsAGOeOP1ZGiyrc27uLoNTWiFO2c92Ph5n1NFyhzgH0+6DB3fEF0VF3Y4Xu2 RED7K20T7/HCmritr4Qrui6HPv5PRe75Wqbb5cTD2f8O9aPoj4M5DmGfjwkE55nYg4GD 3mFgp8Rwju2eG/L9hw1U88FjszqUQ48WDtkxX6QUNK+omtRGGgIloqPpOXeFILlEtFdi eMo9dbNEW7yNQgU/sGjbXI8vLZ+tTAIoY2ZiidNbTpl7oeR46OrqbmmDlCjL3wxPSYY4 6TpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=g4LLZqOmbxM94rso+h2cuZxreBzvWt0K/KqCQ9CH7qY=; b=rb4sJRkMhPBLYD1zC8nQ7vM8pDpWb4m+FmJWqwLB3SKH/rUq+YiyfSTX66GJqDsl+C CeZ9hCNS8t7sQEzlpvaFrXQA7QHO0Wm7L4OasiXvIJCD7vfWaRAwinYIj9vwvvGxTzXs rxYnNfOGhAZTiXsFf1CubuloEDFiQT956WlLhVYr1vtdQbew8n4ZmPr2JTZhxWFo4/W4 32/mtLSKV9cnjf31mD+QPPjfQE3aa4/Qxfdf4J3eCkpa36owX5QB3C3J1ZP6LiiVoAlU sgaA7vUr3DWa4LZodO2Sek9JHGFXO8XYlyn/+bMIyDf/biRI+9JHs4y1IayyL1+v4R0h +FkA== 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 n10si6836713pgc.801.2018.01.18.13.29.26; Thu, 18 Jan 2018 13:29:40 -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 S1754806AbeARV21 (ORCPT + 99 others); Thu, 18 Jan 2018 16:28:27 -0500 Received: from mga04.intel.com ([192.55.52.120]:47421 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753969AbeARV1e (ORCPT ); Thu, 18 Jan 2018 16:27:34 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2018 13:27:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477221" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:31 -0800 From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: wangnan0@huawei.com, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, Kan Liang Subject: [PATCH V5 04/17] perf mmap: introduce perf_mmap__read_init() Date: Thu, 18 Jan 2018 13:26:19 -0800 Message-Id: <1516310792-208685-5-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516310792-208685-1-git-send-email-kan.liang@intel.com> References: <1516310792-208685-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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 --- 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 */ -- 2.5.5