From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754905AbdKOBBf (ORCPT ); Tue, 14 Nov 2017 20:01:35 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10923 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752199AbdKOBBZ (ORCPT ); Tue, 14 Nov 2017 20:01:25 -0500 Subject: Re: [PATCH] perf parse events: Fix invalid precise_ip handling To: Jiri Olsa CC: , , , , , , References: <1510302517-33383-1-git-send-email-zhangmengting@huawei.com> <20171110103900.GA10233@krava> From: zhangmengting Message-ID: <6dc43edb-0c33-6d82-71a3-3d7cac10a881@huawei.com> Date: Wed, 15 Nov 2017 09:00:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20171110103900.GA10233@krava> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.177.28.139] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.5A0B91D6.0100,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: 6183b6487f454c0323a2180a6b747227 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiri, thanks for your detailed review, please see my comments inline. On 2017/11/10 18:39, Jiri Olsa wrote: > On Fri, Nov 10, 2017 at 04:28:37PM +0800, Mengting Zhang wrote: > > SNIP > >> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c >> index 39b1596..25225f4 100644 >> --- a/tools/perf/util/parse-events.c >> +++ b/tools/perf/util/parse-events.c >> @@ -1369,6 +1369,32 @@ struct event_modifier { >> int pinned; >> }; >> >> +static int perf_get_max_precise_ip(void) >> +{ >> + int max_precise_ip = 0; >> + struct perf_event_attr attr = { >> + .type = PERF_TYPE_HARDWARE, >> + .config = PERF_COUNT_HW_CPU_CYCLES, >> + }; >> + >> + event_attr_init(&attr); >> + >> + attr.precise_ip = 3; >> + attr.sample_period = 1; >> + >> + while (attr.precise_ip != 0) { >> + int fd = sys_perf_event_open(&attr, 0, -1, -1, 0); >> + if (fd != -1){ >> + close(fd); >> + break; >> + } >> + --attr.precise_ip; >> + } >> + max_precise_ip = attr.precise_ip; >> + >> + return max_precise_ip; >> +} > we already have a function for that, please check perf_event_attr__set_max_precise_ip Yeah, I've checked that function. But perf_event_attr__set_max_precise_ip() will change attr.precise_ip into the max precise ip available. In this case, perf should only check whether the user-specified precise_ip is greater than the max precise_ip without changing it into maximum. Here, introduce perf_get_max_precise_ip() to return the max precise ip and do not change attr.precise_ip. But you reminds me that perf_get_max_precise_ip() can be simplied. > also I think the precise level is not generic for all the events, > so you should check it for specific perf_event_attr later, when > the attr is ready, not in modifier parsing You are right, and I would check it for specific perf_event_attr. BTW, I have a question. If the user-specified precise_ip is greater than the max precise_ip, I wonder whether it is better to adjust the user-specified precise_ip to the maximum available. Thanks Mengting Zhang > thanks, > jirka > -- > To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > . >