Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751293AbeAOU0y (ORCPT + 1 other); Mon, 15 Jan 2018 15:26:54 -0500 Received: from mga04.intel.com ([192.55.52.120]:59564 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbeAOUVt (ORCPT ); Mon, 15 Jan 2018 15:21:49 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,365,1511856000"; d="scan'208";a="22473478" 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 V4 03/15] perf mmap: use perf_mmap__read_init() in perf_mmap__push() Date: Mon, 15 Jan 2018 12:20:39 -0800 Message-Id: <1516047651-164336-4-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516047651-164336-1-git-send-email-kan.liang@intel.com> References: <1516047651-164336-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Kan Liang Apply the generic perf_mmap__read_init() to perf_mmap__push(). 'size' is needed for both perf_mmap__read_init() and perf_mmap__push(). Have to calculate in each function. Signed-off-by: Kan Liang --- tools/perf/util/mmap.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 414089f..7c5cbdc 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -313,38 +313,18 @@ int perf_mmap__read_init(struct perf_mmap *map, bool overwrite, 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 old = md->prev; - u64 end = head, start = old; unsigned char *data = md->base + page_size; + u64 head = perf_mmap__read_head(md); unsigned long size; + u64 end, start; void *buf; - int rc = 0; + int rc; - start = overwrite ? head : old; - end = overwrite ? old : head; - - if (start == end) - return 0; + rc = perf_mmap__read_init(md, overwrite, &start, &end); + if (rc < 0) + return (rc == -EAGAIN) ? 0 : -1; size = end - start; - if (size > (unsigned long)(md->mask) + 1) { - if (!overwrite) { - WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); - - md->prev = head; - perf_mmap__consume(md, overwrite); - return 0; - } - - /* - * 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)) - return -1; - } - if ((start & md->mask) + size != (end & md->mask)) { buf = &data[start & md->mask]; size = md->mask + 1 - (start & md->mask); -- 2.5.5