From patchwork Mon Nov 13 01:38:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 118687 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1251395qgn; Sun, 12 Nov 2017 17:39:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMZVTDw5oWUMFfn1wxQIVJoOvuMuGlzpNw+OW/iTjTB4qwsXzmW5UP0BZP23Gk+zRkaE9KIO X-Received: by 10.99.120.7 with SMTP id t7mr6951307pgc.360.1510537192879; Sun, 12 Nov 2017 17:39:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510537192; cv=none; d=google.com; s=arc-20160816; b=IHZdVr7HCkOHcLsBzBvA987fyZweO84apNHA1KjRiWFya6C2CvvdcCfb5h99h7y1ht YKCXrADSisREeoA6Cz05IqFDCFjcgNhfeujYQCC12NG0yWvtlSSZkAcXQK9adcHB3SvW c81HBP3oZKF+e402eySI1cWcQpYu0Lq8oKKPWie6B6h7JqBIlynI6VpsXsZRttcfrBD0 tPWJZaARaQEgaRKjmGUDi3bfTvr1knLnsx4edtuP4BYuHeb3Lr6HOu5K4c4aeuWgb+Ml Xq8vlfF0fF9NtXBwUiZ3XSdBjBQzhtTpNvmHgwvZR00fPZ0cFvIVh0P9JwHCTnv+vmcN lmcg== 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=AilkLP65WJtXLX36fGeYTEjYTC9dRyLGd+aEAX7QDmg=; b=NfAWIGSWyF61+iFHZhEz+vpfDHKmi7K4P3plFGpximiBuhJ0jkyfYQKiYwCZ+SldCU lBPs0O2Lp0FaOSsC/7KZfqmpPXDOLi9UiixURGA6goC5KkPuiSRxLWvxFxvxR1pFh6/M Vtak1MQzQ4zmMqgdqlRRGyJX1fDNa/JdxSAOJvSLZXWo/F7lmk/s3Y95ZGTT2eXlvk0Y ZXoeivmOwL0q+fEU11uYSPN5nxcEskpT5zZU/8l7RE9aalWPwk5/CR/fpKbNWVwXNzpy HvmxeyTkfy2NsxaFRb+mnz5DRtTAYrnTD3WwcG+JWNIi5iZjbS9Itv8O8CqpuF1mI3nr T/TQ== 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 o6si9754690pll.591.2017.11.12.17.39.52; Sun, 12 Nov 2017 17:39:52 -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 S1751716AbdKMBji (ORCPT + 27 others); Sun, 12 Nov 2017 20:39:38 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10464 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751231AbdKMBjf (ORCPT ); Sun, 12 Nov 2017 20:39:35 -0500 Received: from 172.30.72.58 (EHLO DGGEMS403-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKS06504; Mon, 13 Nov 2017 09:39:24 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Mon, 13 Nov 2017 09:39:04 +0800 From: Wang Nan To: , , , , CC: Wang Nan Subject: [PATCH 1/7] perf mmap: Fix perf backward recording Date: Mon, 13 Nov 2017 01:38:03 +0000 Message-ID: <20171113013809.212417-2-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20171113013809.212417-1-wangnan0@huawei.com> References: <20171113013809.212417-1-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.5A08F7CC.002F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 033002f6874cb7a4148c8b0635151f06 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 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 2.10.1 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index c6c891e..4c5daba 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -799,22 +799,28 @@ perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused, } static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, - struct mmap_params *mp, int cpu_idx, + struct mmap_params *_mp, int cpu_idx, int thread, int *_output, int *_output_backward) { struct perf_evsel *evsel; int revent; int evlist_cpu = cpu_map__cpu(evlist->cpus, cpu_idx); + struct mmap_params *mp; evlist__for_each_entry(evlist, evsel) { struct perf_mmap *maps = evlist->mmap; + struct mmap_params rdonly_mp; int *output = _output; int fd; int cpu; + mp = _mp; if (evsel->attr.write_backward) { output = _output_backward; maps = evlist->backward_mmap; + rdonly_mp = *_mp; + rdonly_mp.prot &= ~PROT_WRITE; + mp = &rdonly_mp; if (!maps) { maps = perf_evlist__alloc_mmap(evlist);