Received: by 10.223.164.221 with SMTP id h29csp1026532wrb; Wed, 1 Nov 2017 09:13:39 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RyXUPnvf4pfBXidSXL3zs+BIFvQuaQYim2e+WL+K/zXkP8BIPuyLj6EHGLpyWl4nmjxsVj X-Received: by 10.159.253.9 with SMTP id p9mr118322pls.323.1509552819897; Wed, 01 Nov 2017 09:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509552819; cv=none; d=google.com; s=arc-20160816; b=PKW3DJvUUQVawTuNUxUesoTTjfZZPLDfbsVOvTYPsUh5tjdhGezsbgIUBZdmbCix7g dwr3Wm6Ugz/EhK69Ldv+8Gu8YgWFhlK7fynDfplv69H5xvEW0ZWtY9CKG1HPUI0sK8q4 ZIZlNiJZqlm+Sz93SaQoEdlBR5vITtlUW4cGF0Mf9RlzaGw10CT3F5ctFzHUTgVDa5ze wUXPc3Pcb97v3IjUzKXMkbE7tS4f/mRgfqzz+I7n/keuMgXPntIfINz7nsXRqLxZJcSb MZ/KBbrEJjJBqDKWAXNFQGkJnB6AgHO8kps4eBJwUQA1c2D/r28yOowKpjfhzJcDB22U C0uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=y3cBolhu5hhSdSn/Y/C0w7waIcAG8RT1rxvANXpS0wM=; b=egJKpNs6HbQ27LCAUquWov+VlofK5es0ufQu2bwO4oVnaz6xwHo53BfU9a4RhL8wig j6uSl0r34PqAJZxsh9ypY7RFhAQ+IuwHib+u0fjLX4o6h+fQRSJmsuwe1oBlZN//ss3f Wdi+5BhP9obBhlTT01+A7+1bYKtf1e6VxkxGujNl4Xx0wbOh/dxTFE3k1AoayK9fm2Ip P56IaMCWk2TSMo0DPgcvB9RO9asYjFCC4P+fPEPOl9P7H5pe+YRLnJdiKaqs5tjrWiVS ZU/2bSlhCqRsixoar7lVjgfqppifOZ5HjFmxLfe+otUKQK1+ll1d+Uv7yd6oa8EpUMKf yw5g== 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 t16si1438165pgo.542.2017.11.01.09.13.24; Wed, 01 Nov 2017 09:13:39 -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 S933055AbdKAQMo (ORCPT + 99 others); Wed, 1 Nov 2017 12:12:44 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:39735 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932481AbdKAQMn (ORCPT ); Wed, 1 Nov 2017 12:12:43 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CB49A52E02EB2; Thu, 2 Nov 2017 00:12:29 +0800 (CST) Received: from [127.0.0.1] (10.111.194.139) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.361.1; Thu, 2 Nov 2017 00:12:27 +0800 Subject: Re: [PATCH 1/2] perf mmap: Fix perf backward recording To: "Liang, Kan" , Namhyung Kim References: <20171101055327.141281-1-wangnan0@huawei.com> <20171101055327.141281-2-wangnan0@huawei.com> <20171101094929.GB25146@danjae.aot.lge.com> <20171101120007.GA26623@danjae.aot.lge.com> <109f02ef-5dc2-94f9-e850-572c498781ee@huawei.com> <37D7C6CF3E00A74B8858931C1DB2F077537DC1FA@SHSMSX103.ccr.corp.intel.com> CC: "linux-kernel@vger.kernel.org" , "acme@kernel.org" , "jolsa@redhat.com" , "kernel-team@lge.com" From: "Wangnan (F)" Message-ID: <226626ec-4f96-d3f4-a6d5-62c17c897f32@huawei.com> Date: Thu, 2 Nov 2017 00:12:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <37D7C6CF3E00A74B8858931C1DB2F077537DC1FA@SHSMSX103.ccr.corp.intel.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.194.139] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/11/1 21:57, Liang, Kan wrote: >> On 2017/11/1 20:00, Namhyung Kim wrote: >>> On Wed, Nov 01, 2017 at 06:32:50PM +0800, Wangnan (F) wrote: >>>> On 2017/11/1 17:49, Namhyung Kim wrote: >>>>> Hi, >>>>> >>>>> On Wed, Nov 01, 2017 at 05:53:26AM +0000, Wang Nan wrote: >>>>>> perf record backward recording doesn't work as we expected: it never >>>>>> overwrite when ring buffer full. >>>>>> >>>>>> Test: >>>>>> >>>>>> (Run a busy printing python task background like this: >>>>>> >>>>>> while True: >>>>>> print 123 >>>>>> >>>>>> send SIGUSR2 to perf to capture snapshot.) >>>> [SNIP] >>>> >>>>>> Signed-off-by: Wang Nan >>>>>> --- >>>>>> tools/perf/util/evlist.c | 8 +++++++- >>>>>> 1 file changed, 7 insertions(+), 1 deletion(-) >>>>>> >>>>>> 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); >>>>>> -- >>>>> What about this instead (not tested)? >>>>> >>>>> >>>>> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c >>>>> index c6c891e154a6..27ebe355e794 100644 >>>>> --- a/tools/perf/util/evlist.c >>>>> +++ b/tools/perf/util/evlist.c >>>>> @@ -838,6 +838,11 @@ static int perf_evlist__mmap_per_evsel(struct >> perf_evlist *evlist, int idx, >>>>> if (*output == -1) { >>>>> *output = fd; >>>>> + if (evsel->attr.write_backward) >>>>> + mp->prot = PROT_READ; >>>>> + else >>>>> + mp->prot = PROT_READ | PROT_WRITE; >>>>> + >>>> If evlist->overwrite is true, PROT_WRITE should be unset even if >>>> write_backward is >>>> not set. If you want to delay the setting of mp->prot, you need to consider >>>> both evlist->overwrite and evsel->attr.write_backward. >>> I thought evsel->attr.write_backward should be set when >>> evlist->overwrite is set. Do you mean following case? >>> >>> perf record --overwrite -e 'cycles/no-overwrite/' >>> >> No. evlist->overwrite is unrelated to '--overwrite'. This is why I >> said the concept of 'overwrite' and 'backward' is ambiguous. >> > Yes, I think we should make it clear. > > As we discussed previously, there are four possible combinations > to access ring buffer , 'forward non-overwrite', 'forward overwrite', > 'backward non-overwrite' and 'backward overwrite'. > > Actually, not all of the combinations are necessary. > - 'forward overwrite' mode brings some problems which were mentioned > in commit ID 9ecda41acb97 ("perf/core: Add ::write_backward attribute > to perf event"). > - 'backward non-overwrite' mode is very similar as 'forward non-overwrite'. > There is no extra advantage. Only keep one non-overwrite mode is enough. > So 'forward non-overwrite' and 'backward overwrite' are enough for all perf tools. > > Furthermore, 'forward' and 'backward' only indicate the direction of the > ring buffer. They don't impact the result and performance. It is not > important as the concept of overwrite/non-overwrite. > > To simplify the concept, only 'non-overwrite' mode and 'overwrite' mode should > be kept. 'non-overwrite' mode indicates the forward ring buffer. 'overwrite' mode > indicates the backward ring buffer. > >> perf record never sets 'evlist->overwrite'. What '--overwrite' actually >> does is setting write_backward. Some testcases needs overwrite evlist. >> > There are only four test cases which set overwrite, sw-clock,task-exit, > mmap-basic, backward-ring-buffer. > Only backward-ring-buffer is 'backward overwrite'. > The rest three are all 'forward overwrite'. We just need to set write_backward > to convert them to 'backward overwrite'. > I think it's not hard to clean up. If we add a new rule that overwrite ring buffers are always backward then it is not hard to cleanup. However, the support of forward overwrite ring buffer has a long history and the code is not written by me. I'd like to check if there is some reason to keep support this configuration? Thank you. From 1582872369286961737@xxx Wed Nov 01 13:58:44 +0000 2017 X-GM-THRID: 1582841972981207976 X-Gmail-Labels: Inbox,Category Forums