Received: by 10.223.176.46 with SMTP id f43csp35929wra; Thu, 18 Jan 2018 13:32:55 -0800 (PST) X-Google-Smtp-Source: ACJfBovBjdsyPrpX1rEUiSXbQhMnS0giklzqGC0Gx4hwuxgLQQsa4jXr1zhvkjfYLEzUqVetnxyw X-Received: by 10.101.65.131 with SMTP id a3mr15060956pgq.99.1516311175606; Thu, 18 Jan 2018 13:32:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311175; cv=none; d=google.com; s=arc-20160816; b=FSCHWndOz5wQi6U7thKlxbNAAsWfxsM37kIEZjntAy1M5U6tLjAD/xEFdeTjeEk16k hzFCAiMawZARGp2aXF8rT5Q5/7F/RDQJnIi5A9AyPGPWBEzSfc9XIk67ntXX+mswRwbU OejCMJJ94EYpfi3XwRgAteKgXo9ZRr8wQSEg5DRV+6wnDJXG9RLkMB70VVHxfgGdNMwX iaEYQO2QxOgmSZcntNmJBAtT1EMI63KhIPvFkWqks5piz9BjMgegpVmPFztnQcaQ2+gV mczeGnw3sF4U451+TONf+Ue1CdV9hQKS1eRpkHmVLDD4m6eKkUX6RhW58XwL1EmVxKla z6vQ== 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=2PlF6y0UTUNoWahPqywhWNzRUMfC2XkeCJ5/vTC/hxE=; b=HrTFfGzgaWkCNmyqvri0TU0eToTRKZUtQu1ba0ePXR8AXCl0A91J8oUsFsIUxxztaj VOEvCqK0J3LBJiI4CucHOMdNzD+eSdXq/yuUzf2TEf8tCBU65LLFsx0SaPwiWCDUcJA3 nnSy1sdSKh2Z18cQXZSF1rwzFpDrIwXhSscLgZ72RrnkFuW6daaDNolU2ApTxwf66ONl GbKFyf0zxYkWLDAradBF2e0chy9+WkhMzq5rOx1dPI1vKevN3CkymLl+pTiuoK1dFrl8 tF4BMramNRU1Xop4i1kDwswp+eh/hMvF+CLtj3hS2LMFjDdGeaPWOM3HOqbxI8oSb5Cn bFaw== 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 l14si6787767pgc.42.2018.01.18.13.32.41; Thu, 18 Jan 2018 13:32:55 -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 S1755268AbeARVbl (ORCPT + 99 others); Thu, 18 Jan 2018 16:31:41 -0500 Received: from mga04.intel.com ([192.55.52.120]:47423 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754050AbeARV1e (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:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477242" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:32 -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 06/17] perf mmap: discard 'prev' in perf_mmap__read() Date: Thu, 18 Jan 2018 13:26:21 -0800 Message-Id: <1516310792-208685-7-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 'start' and 'prev' are duplicate in perf_mmap__read() Use 'map->prev' to replace 'start' in perf_mmap__read_*(). Suggested-by: Wang Nan Signed-off-by: Kan Liang --- tools/perf/util/mmap.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 38fa69d..125bfda 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -22,29 +22,27 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map) /* When check_messup is true, 'end' must points to a good entry */ static union perf_event *perf_mmap__read(struct perf_mmap *map, - u64 start, u64 end, u64 *prev) + u64 *startp, u64 end) { unsigned char *data = map->base + page_size; union perf_event *event = NULL; - int diff = end - start; + int diff = end - *startp; if (diff >= (int)sizeof(event->header)) { size_t size; - event = (union perf_event *)&data[start & map->mask]; + event = (union perf_event *)&data[*startp & map->mask]; size = event->header.size; - if (size < sizeof(event->header) || diff < (int)size) { - event = NULL; - goto broken_event; - } + if (size < sizeof(event->header) || diff < (int)size) + return NULL; /* * Event straddles the mmap boundary -- header should always * be inside due to u64 alignment of output. */ - if ((start & map->mask) + size != ((start + size) & map->mask)) { - unsigned int offset = start; + if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) { + unsigned int offset = *startp; unsigned int len = min(sizeof(*event), size), cpy; void *dst = map->event_copy; @@ -59,20 +57,15 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map, event = (union perf_event *)map->event_copy; } - start += size; + *startp += size; } -broken_event: - if (prev) - *prev = start; - return event; } union perf_event *perf_mmap__read_forward(struct perf_mmap *map) { u64 head; - u64 old = map->prev; /* * Check if event was unmapped due to a POLLHUP/POLLERR. @@ -82,13 +75,12 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *map) head = perf_mmap__read_head(map); - return perf_mmap__read(map, old, head, &map->prev); + return perf_mmap__read(map, &map->prev, head); } union perf_event *perf_mmap__read_backward(struct perf_mmap *map) { u64 head, end; - u64 start = map->prev; /* * Check if event was unmapped due to a POLLHUP/POLLERR. @@ -118,7 +110,7 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map) else end = head + map->mask + 1; - return perf_mmap__read(map, start, end, &map->prev); + return perf_mmap__read(map, &map->prev, end); } void perf_mmap__read_catchup(struct perf_mmap *map) -- 2.5.5