From patchwork Mon Dec 4 16:51:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 120573 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4667177qgn; Mon, 4 Dec 2017 08:53:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMaUpDjmGA88DZTqj975k7am7Dw4BOtr/Y+zFSdymt1kILfnGM9LTNLdMYKrhoEyHSbJcDSQ X-Received: by 10.99.111.4 with SMTP id k4mr6460853pgc.101.1512406407866; Mon, 04 Dec 2017 08:53:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512406407; cv=none; d=google.com; s=arc-20160816; b=xwk+95yC01N/2MSekd513OvZZD8UAnNc/4iLpFBKTECD0q12sE62FXXhsch6qWVlYN sNf633+3qIihvw3une5J6yooDuHgn7G4oLsWIxbWyD17w2OBqfJ5WyFULjjZlhJHmmwn DG17yhnblXPozwygFnlpLhtDHCaJnX5pEtHUVo3tI7KyBBg4xAoFE2j1XxE2IfbhrJIe djZUjudcf95nqrNnZBqxk22OKitmyTTjeW49g2p6cM+r4iSK1MC74amtMnXsM7JWrL0f NCGGEkH3ZIzO6pDQLT5sUP20JKSvip21wfiiZH87F9YIUNiLj/u9NJu69suK4ujWBEv6 VFCQ== 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=19TgjLfbXuDTINquVEvFG5/c5Jku1AN/OFukgvaHl2o=; b=EWs/QFiIdr4ta7B6Q3qPBsZFfJT5p66RfUY5T1BIxj+UiU0Rl4RgHvajYgE/6xfpDz 1HY+MhoMJrma5ZhO3Je/lXY6m/wbuOp31b/I36lXGsUolsMe1TSHQx+JxtwG3sEk3XXn n6whJ/OIZBBD9BRcOR6WLQ9IgQpL/Y4TrJwOFKEoBFH9JRuIx5ci3Yk9vnkWPSkcib6c LXNmW9r+X3i3BakkTxjTXPfXYDqqU5cffNIKmaQM2+gnvJYswe/QX4dWsbp2bCJm9dW5 mWOxQhFQUL0NVgj/BgFBkEKZRljvthpTJpR/0/4ZFDisA9Fht5nTOWLbHPUD1bT6jGdX 6UsQ== 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 p128si9603181pga.364.2017.12.04.08.53.27; Mon, 04 Dec 2017 08:53:27 -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 S1753387AbdLDQxZ (ORCPT + 28 others); Mon, 4 Dec 2017 11:53:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2203 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752255AbdLDQxN (ORCPT ); Mon, 4 Dec 2017 11:53:13 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 682F1873C902F; Tue, 5 Dec 2017 00:52:57 +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; Tue, 5 Dec 2017 00:52:51 +0800 From: Wang Nan To: , , , , CC: , Wang Nan Subject: [PATCH v3 1/3] perf mmap: Fix perf backward recording Date: Mon, 4 Dec 2017 16:51:05 +0000 Message-ID: <20171204165107.95327-2-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20171204165107.95327-1-wangnan0@huawei.com> References: <20171204165107.95327-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 backward recording doesn't work as we expected: it never overwrite when ring buffer full. Test: (Run a busy python printing task background like this: while True: print 123 send SIGUSR2 to perf to capture snapshot.) # ./perf record --overwrite -e raw_syscalls:sys_enter -e raw_syscalls:sys_exit --exclude-perf -a --switch-output [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101520743 ] [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101521251 ] [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101521692 ] ^C[ perf record: Woken up 1 times to write data ] [ perf record: Dump perf.data.2017110101521936 ] [ perf record: Captured and wrote 0.826 MB perf.data. ] # ./perf script -i ./perf.data.2017110101520743 | head -n3 perf 2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0) perf 2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0) python 2545 [000] 12449.310800: raw_syscalls:sys_exit: NR 1 = 4 # ./perf script -i ./perf.data.2017110101521251 | head -n3 perf 2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0) perf 2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0) python 2545 [000] 12449.310800: raw_syscalls:sys_exit: NR 1 = 4 # ./perf script -i ./perf.data.2017110101521692 | head -n3 perf 2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0) perf 2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0) python 2545 [000] 12449.310800: raw_syscalls:sys_exit: NR 1 = 4 Timestamps are never change, but my background task is a dead loop, can easily overwhelme the ring buffer. This patch fix it by force unsetting PROT_WRITE for backward ring buffer, so all backward ring buffer become overwrite ring buffer. Test result: # ./perf record --overwrite -e raw_syscalls:sys_enter -e raw_syscalls:sys_exit --exclude-perf -a --switch-output [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101285323 ] [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101290053 ] [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2017110101290446 ] ^C[ perf record: Woken up 1 times to write data ] [ perf record: Dump perf.data.2017110101290837 ] [ perf record: Captured and wrote 0.826 MB perf.data. ] # ./perf script -i ./perf.data.2017110101285323 | head -n3 python 2545 [000] 11064.268083: raw_syscalls:sys_exit: NR 1 = 4 python 2545 [000] 11064.268084: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0) python 2545 [000] 11064.268086: raw_syscalls:sys_exit: NR 1 = 4 # ./perf script -i ./perf.data.2017110101290 | head -n3 failed to open ./perf.data.2017110101290: No such file or directory # ./perf script -i ./perf.data.2017110101290053 | head -n3 python 2545 [000] 11071.564062: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0) python 2545 [000] 11071.564064: raw_syscalls:sys_exit: NR 1 = 4 python 2545 [000] 11071.564066: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0) # ./perf script -i ./perf.data.2017110101290 | head -n3 perf.data.2017110101290053 perf.data.2017110101290446 perf.data.2017110101290837 # ./perf script -i ./perf.data.2017110101290446 | head -n3 sshd 1321 [000] 11075.499473: raw_syscalls:sys_exit: NR 14 = 0 sshd 1321 [000] 11075.499474: raw_syscalls:sys_enter: NR 14 (2, 7ffe98899490, 0, 8, 0, 3000) sshd 1321 [000] 11075.499474: raw_syscalls:sys_exit: NR 14 = 0 # ./perf script -i ./perf.data.2017110101290837 | head -n3 python 2545 [000] 11079.280844: raw_syscalls:sys_exit: NR 1 = 4 python 2545 [000] 11079.280847: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0) python 2545 [000] 11079.280850: raw_syscalls:sys_exit: NR 1 = 4 Signed-off-by: Wang Nan --- tools/perf/util/evlist.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.10.1 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 68c1f95..b1cea71 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -812,6 +812,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, int fd; int cpu; + mp->prot = PROT_READ | PROT_WRITE; if (evsel->attr.write_backward) { output = _output_backward; maps = evlist->backward_mmap; @@ -824,6 +825,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY) perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING); } + mp->prot &= ~PROT_WRITE; } if (evsel->system_wide && thread) @@ -1058,9 +1060,12 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, struct perf_evsel *evsel; const struct cpu_map *cpus = evlist->cpus; const struct thread_map *threads = evlist->threads; - struct mmap_params mp = { - .prot = PROT_READ | PROT_WRITE, - }; + /* + * Delay setting mp.prot: set it before calling perf_mmap__mmap. + * Its value is decided by evsel's write_backward. + * So &mp should not be passed through const pointer. + */ + struct mmap_params mp; if (!evlist->mmap) evlist->mmap = perf_evlist__alloc_mmap(evlist);