From patchwork Sun Dec 3 02:00:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 120445 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2904210qgn; Sat, 2 Dec 2017 18:04:16 -0800 (PST) X-Google-Smtp-Source: AGs4zMbjuDLCi+WY6d4I3jDIxY4WCpH2va1VJctvNEDDE84cxXB5XVOXMsLHF2GVciO8U026xEnk X-Received: by 10.98.200.20 with SMTP id z20mr15074261pff.108.1512266656541; Sat, 02 Dec 2017 18:04:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512266656; cv=none; d=google.com; s=arc-20160816; b=lc0S+CsgTZolOAaYKFZ9ihaA3IBdOyOFrvRMlgidM7t63yWDfstZ4m79jdFGPs06mm 3PaAnev2wNX835qswx3ncNK01X9sbFH7YJVeVvbPyqrxzyfb8z1YvyAq2pTwfzXERjCd FnhFz30BXWBJbuHRdGzV/qd1/n/UKrSxHM6jAxi9bZHgReBa4Xa7/MNas5mRb9PxmGbH /wTMrL1mfrTFeSz3Pi4ZfCHCgQ04i9NjG4qiaEK33sdT4QX0mAyuJhjECp8kUb9rEtyE rv0R3WBEYDywBhu4XtxTaiHEtIfsliq+al6CaOJL++1RYd5fUgCNfuQLmB8N5J7xzFIs MPIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=YPC0++37hdwQ8vN+PoZjJse9jOr8hE105o9adGPD3ao=; b=P347bIprfcN1mHF8nr2r6NsHnivd338f13yEN8YYYxCYYjkooGrKwIONa54SHlUnwg al2BPdiNh6ah1RSGtclrtN+UgDMPIMZGz45Iz/EUUHycEhfQhhvNsWBXEtNyTdenQDg9 XBbrXxFJc2WIJN+Bcl3X51ETOVbHChqy1hwOD0qnC8Lgs4YQ+iz0OEBiQfD3M+AxIkYc yXCkXiF3MQS2Ex7G9x9Q2OoEt6lbrE9dl55ct+uv0dp/YFSkC3tfj1ansaL3LrQPo63i iUyF2/Rtb1t4cfaehJme8sWAuUej4Nt75+sl45lQ3MeOZjskqB5W9c3DVpg0oXaRCc0J CBsw== 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 t2si7050711pgb.591.2017.12.02.18.04.16; Sat, 02 Dec 2017 18:04:16 -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 S1752771AbdLCCEN (ORCPT + 28 others); Sat, 2 Dec 2017 21:04:13 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2196 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752643AbdLCCDH (ORCPT ); Sat, 2 Dec 2017 21:03:07 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CB17F7CAD6B39; Sun, 3 Dec 2017 10:02:50 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.361.1; Sun, 3 Dec 2017 10:02:44 +0800 From: Wang Nan To: , , , , CC: Wang Nan Subject: [PATCH v2 7/8] perf tools: Don't discard prev in backward mode Date: Sun, 3 Dec 2017 02:00:43 +0000 Message-ID: <20171203020044.81680-8-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20171203020044.81680-1-wangnan0@huawei.com> References: <20171203020044.81680-1-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Perf record can switch output. The new output should only store the data after switching. However, in overwrite backward mode, the new output still have the data from old output. That also brings extra overhead. At the end of mmap_read, the position of processed ring buffer is saved in md->prev. Next mmap_read should be end in md->prev if it is not overwriten. That avoids to process duplicate data. However, the md->prev is discarded. So next mmap_read has to process whole valid ring buffer, which probably include the old processed data. Avoid calling backward_rb_find_range() when md->prev is still available. Signed-off-by: Wang Nan Tested-by: Kan Liang --- tools/perf/util/mmap.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) -- 2.10.1 diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 3f262e7..5f8cb15 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -267,18 +267,6 @@ static int backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 return -1; } -static int rb_find_range(void *data, int mask, u64 head, u64 old, - u64 *start, u64 *end, bool backward) -{ - if (!backward) { - *start = old; - *end = head; - return 0; - } - - return backward_rb_find_range(data, mask, head, start, end); -} - int perf_mmap__push(struct perf_mmap *md, bool backward, void *to, int push(void *to, void *buf, size_t size)) { @@ -290,19 +278,28 @@ int perf_mmap__push(struct perf_mmap *md, bool backward, void *buf; int rc = 0; - if (rb_find_range(data, md->mask, head, old, &start, &end, backward)) - return -1; + start = backward ? head : old; + end = backward ? old : head; if (start == end) return 0; size = end - start; if (size > (unsigned long)(md->mask) + 1) { - WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); + if (!backward) { + WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); - md->prev = head; - perf_mmap__consume(md, backward); - return 0; + md->prev = head; + perf_mmap__consume(md, backward); + return 0; + } + + /* + * Backward ring buffer is full. We still have a chance to read + * most of data from it. + */ + if (backward_rb_find_range(data, md->mask, head, &start, &end)) + return -1; } if ((start & md->mask) + size != (end & md->mask)) {