Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbdLEWkQ (ORCPT ); Tue, 5 Dec 2017 17:40:16 -0500 Received: from mga14.intel.com ([192.55.52.115]:31183 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753026AbdLEWkC (ORCPT ); Tue, 5 Dec 2017 17:40:02 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,365,1508828400"; d="scan'208";a="1252269831" From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: jolsa@kernel.org, wangnan0@huawei.com, namhyung@kernel.org, ak@linux.intel.com, Kan Liang Subject: [PATCH 3/5] perf tools: reuse perf_mmap__read_catchup in perf_mmap__push Date: Tue, 5 Dec 2017 14:39:13 -0800 Message-Id: <1512513555-118798-4-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1512513555-118798-1-git-send-email-kan.liang@intel.com> References: <1512513555-118798-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 Content-Length: 1759 Lines: 68 From: Kan Liang perf_mmap__push uses the same codes as perf_mmap__read_catchup to calculate the ring buffer start, end and size. No funcational change. Signed-off-by: Kan Liang --- tools/perf/util/mmap.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index bf67460..61237eb 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -285,36 +285,16 @@ 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; + u64 end, start; unsigned char *data = md->base + page_size; unsigned long size; void *buf; - int rc = 0; + int rc; - start = overwrite ? head : old; - end = overwrite ? old : head; - if (start == end) - return 0; - - 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; - } + rc = perf_mmap__read_catchup(md, overwrite, &start, &end, &size); + if (rc < 1) + return rc; if ((start & md->mask) + size != (end & md->mask)) { buf = &data[start & md->mask]; @@ -338,6 +318,7 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite, md->prev = head; perf_mmap__consume(md, overwrite); + rc = 0; out: return rc; } -- 2.5.5