Received: by 10.213.65.68 with SMTP id h4csp324333imn; Tue, 13 Mar 2018 05:42:25 -0700 (PDT) X-Google-Smtp-Source: AG47ELu5ia+qMXD1wWokBwpIMK8bKBqyLmu48MuSBYHwzNCZqmgrlUPC6l+rRSsfRjC8wN9F16aB X-Received: by 10.101.75.199 with SMTP id p7mr425321pgr.0.1520944945066; Tue, 13 Mar 2018 05:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520944945; cv=none; d=google.com; s=arc-20160816; b=oJbpuH+MxxUIZ7rCOLRJGwzua4+AGngVwyFhAaGKGFNVJmqT/5g53GOmoPlRCKq0lg U4KcH0srf1Oe2TGMVzq9VP2soeCdyhLfgiNniNfSP6dBDt7Ju+/f2bNxZJPnZ30ns1t2 zfof6bJcyWek9byrmXT7pWrMrque1CIk9HSiahYqcCkiHsjwRnqUbLo/CthS3XEuT6qW XGrLOo6JuikF5oZBAnuskjlMmZtDkXyenlxTJzIwZfewXBJp/QE03b+6YqO36w9mk05G /9DsfzKIY62ybfwptBD6U3MmjJksDSPP96uMG+2XJt51v0ptfDc+QPsswGGj0b4DRDMq ITjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=PecHBfO0gpH+IFVURa0vgV9DgjzKeYdli4P6knhLTUM=; b=AzUIGgku/p3g58ox9oh3nG1e+WEYN6WXnBvv6jNeRes8YPNWQIjqqQXp/n8h+tVu1i UHfdRisMbNacSuDPhheeCXoXeblbUerw/nKm7MLqij390FzTj+YETgPkD6Z7C+8HH7i4 3vJCFJ7Kwtr6xDbDaftMQW5aSmE9BH/ctNnA232VtbsZrki2JzPViIIms0AqDnIIyjTU wWX4YjA5waG8d1FAoq7JsuQkHaVYa7PrsX1y0X09bVXibvt3GxysxAK2fPmgttwRH896 wp0tw1Ejb2+Hy21qgGwtfEfKAwhXMZfgBDIVOyLunGams20Isvsu+C45HR3SHB4bsnkz cWiw== 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 k196si55641pgc.775.2018.03.13.05.42.09; Tue, 13 Mar 2018 05:42:25 -0700 (PDT) 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 S932862AbeCMMlN (ORCPT + 99 others); Tue, 13 Mar 2018 08:41:13 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:55266 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752448AbeCMMlL (ORCPT ); Tue, 13 Mar 2018 08:41:11 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B4538DDF13E46; Tue, 13 Mar 2018 20:40:57 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.361.1; Tue, 13 Mar 2018 20:40:49 +0800 From: Yisheng Xie To: CC: , , , , , , , Yisheng Xie Subject: [PATCH v2 -perf/core 1/2] perf mmap: Discard head in overwrite_rb_find_range Date: Tue, 13 Mar 2018 20:31:13 +0800 Message-ID: <1520944274-37001-1-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In overwrite mode, start will be set to head in perf_mmap__read_init. Therefore, it is no need to set the start one more in overwrite_rb_find_range and *start can be used as head instead of passing head to overwrite_rb_find_range. Signed-off-by: Yisheng Xie --- v2: - rebase to perf/core tools/perf/util/mmap.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 074c4fd..38ca3ff 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -199,19 +199,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) return 0; } -static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end) +static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) { struct perf_event_header *pheader; - u64 evt_head = head; + u64 evt_head = *start; int size = mask + 1; - pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head); - pheader = (struct perf_event_header *)(buf + (head & mask)); - *start = head; + pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start); + pheader = (struct perf_event_header *)(buf + (*start & mask)); while (true) { - if (evt_head - head >= (unsigned int)size) { + if (evt_head - *start >= (unsigned int)size) { pr_debug("Finished reading overwrite ring buffer: rewind\n"); - if (evt_head - head > (unsigned int)size) + if (evt_head - *start > (unsigned int)size) evt_head -= pheader->size; *end = evt_head; return 0; @@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md) * 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, &md->start, &md->end)) + if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end)) return -EINVAL; } -- 1.7.12.4