Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3432661pxj; Mon, 7 Jun 2021 10:26:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU7rNUO4Nkl0qekS85GEYbtGTjUMYyVTwosg1zjLdLran1LoPsmyQpOAwqu/Cqjw7HVv3b X-Received: by 2002:a17:906:365a:: with SMTP id r26mr19160467ejb.340.1623086759823; Mon, 07 Jun 2021 10:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623086759; cv=none; d=google.com; s=arc-20160816; b=jQ2wMpxeKo1uBVz126yulN1OAgR9et/3MWFEp2pnM683vcElo1LpV0OmBixFZGXV5+ Uk0MClLPFo5gbToO4zR0OQEy0a2+sb9boOpGXqVkrJXnRHnyy7vKCdqhkIm+CC1Q5sIp rc+dPfKlnq89FMwuqyfGbjM4Iz1UePP6dePQDH8YDj+N15Rn8+RWc/U1BlgBp3y9X9Aa UaMr3XTUgSkVTvfrZj8v61yfHp4hJwPeMNQkN7RclOBUr0ZrhMrvGSAznJq7D3/3h1CS oyA41I08m6ixLPD1PjIKfqhzAVKoRh+FYabZ6JU3p8O7oO/OkCSgA2U3nLRCCpIZnSsQ SSUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=GpNa0Zah9tiz+nh92wXUAau7PeLSu7QMcjNw81fD6b4=; b=GOrCQ2EBtJFc+SfI0Wcq8peXP66fbLtBAXrpSnpAWF70FOtGGr7VhsCQ2vWGWS0U/A vK3KEJ8vLtR5Uv1CMmPdfqX14Jps7PGoGkea0ThsI2LZGMcmEDChOcmoxn0871BgcDcz vLcplb3s6Y0TAr93v3cEXD+SCuLcFcXI+sbB/3/fzjPqZSsQmOzk25p9PxfnELqp9nxl TagDB/qmTNO9S1iTYIwxbilIfcJEWBcdr1hki6gwDQOASjFwv4HicIZvmayhd0iqS3+c JShdJpAjZZnpdZCNDSQdUXBygmMzb53WM6eJfACMG4ZQkNAva/QlGD1X4iWzFcgaG3tW XoJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g26si12164329edm.102.2021.06.07.10.25.31; Mon, 07 Jun 2021 10:25:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231409AbhFGRXo (ORCPT + 99 others); Mon, 7 Jun 2021 13:23:44 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3164 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbhFGRXo (ORCPT ); Mon, 7 Jun 2021 13:23:44 -0400 Received: from fraeml711-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FzKbV20mjz6G7jF; Tue, 8 Jun 2021 01:09:10 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml711-chm.china.huawei.com (10.206.15.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 7 Jun 2021 19:21:51 +0200 Received: from [10.47.88.167] (10.47.88.167) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 7 Jun 2021 18:21:50 +0100 To: Arnaldo Carvalho de Melo , Jiri Olsa , "irogers@google.com" CC: "linux-kernel@vger.kernel.org" , "linux-perf-users@vger.kernel.org" From: John Garry Subject: perf tool: Issues with metricgroups Message-ID: Date: Mon, 7 Jun 2021 18:21:43 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.88.167] X-ClientProxiedBy: lhreml738-chm.china.huawei.com (10.201.108.188) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi guys, I am finding a couple of issues in metricgroup support. Firstly I have found a segfault (which I caused with my "fix" in commit 9c880c24cb0d), and a fix for that is at the bottom. Another issue is that the ordering of the metrics we supply for stat command causes an issue. On my broadwell, this works ok: sudo ./perf stat -vv -M backend_bound,retiring sleep 1 Using CPUID GenuineIntel-6-3D-4 metric expr 1 - ( (idq_uops_not_delivered.core / (4 * cycles)) + (( uops_issued.any - uops_retired.retire_slots + 4 * int_misc.recovery_cycles ) / (4 * cycles)) + (uops_retired.retire_slots / (4 * cycles)) ) for Backend_Bound found event uops_issued.any found event cycles found event idq_uops_not_delivered.core found event int_misc.recovery_cycles found event uops_retired.retire_slots metric expr uops_retired.retire_slots / (4 * cycles) for Retiring found event cycles found event uops_retired.retire_slots adding {uops_issued.any,cycles,idq_uops_not_delivered.core,int_misc.recovery_cycles,uops_retired.retire_slots}:W,{cycles,uops_retired.retire_slots}:W uops_issued.any -> cpu/umask=0x1,(null)=0x1e8483,event=0xe/ idq_uops_not_delivered.core -> cpu/umask=0x1,(null)=0x1e8483,event=0x9c/ int_misc.recovery_cycles -> cpu/umask=0x3,(null)=0x1e8483,cmask=0x1,event=0xd/ uops_retired.retire_slots -> cpu/umask=0x2,(null)=0x1e8483,event=0xc2/ uops_retired.retire_slots -> cpu/umask=0x2,(null)=0x1e8483,event=0xc2/ Control descriptor is not initialized uops_issued.any: 1655376 547221 547221 cycles: 1665343 547221 547221 idq_uops_not_delivered.core: 1983394 547221 547221 int_misc.recovery_cycles: 69571 547221 547221 uops_retired.retire_slots: 1311124 547221 547221 Performance counter stats for 'sleep 1': 1,655,376 uops_issued.any # 0.41 Backend_Bound 1,665,343 cycles # 0.20 Retiring 1,983,394 idq_uops_not_delivered.core 69,571 int_misc.recovery_cycles 1,311,124 uops_retired.retire_slots 1.000992470 seconds time elapsed 0.001031000 seconds user 0.000000000 seconds sys ----/--- But when I reorder the metrics, it fails: sudo ./perf stat -v -M retiring,backend_bound sleep 1 Using CPUID GenuineIntel-6-3D-4 metric expr uops_retired.retire_slots / (4 * cycles) for Retiring found event cycles found event uops_retired.retire_slots metric expr 1 - ( (idq_uops_not_delivered.core / (4 * cycles)) + (( uops_issued.any - uops_retired.retire_slots + 4 * int_misc.recovery_cycles ) / (4 * cycles)) + (uops_retired.retire_slots / (4 * cycles)) ) for Backend_Bound found event uops_issued.any found event cycles found event idq_uops_not_delivered.core found event int_misc.recovery_cycles found event uops_retired.retire_slots adding {cycles,uops_retired.retire_slots}:W,{uops_issued.any,cycles,idq_uops_not_delivered.core,int_misc.recovery_cycles,uops_retired.retire_slots}:W uops_retired.retire_slots -> cpu/umask=0x2,(null)=0x1e8483,event=0xc2/ uops_issued.any -> cpu/umask=0x1,(null)=0x1e8483,event=0xe/ idq_uops_not_delivered.core -> cpu/umask=0x1,(null)=0x1e8483,event=0x9c/ int_misc.recovery_cycles -> cpu/umask=0x3,(null)=0x1e8483,cmask=0x1,event=0xd/ uops_retired.retire_slots -> cpu/umask=0x2,(null)=0x1e8483,event=0xc2/ Control descriptor is not initialized cycles: 1695223 563189 563189 uops_retired.retire_slots: 1343463 563189 563189 uops_issued.any: 0 563189 0 cycles: 0 563189 0 idq_uops_not_delivered.core: 0 563189 0 int_misc.recovery_cycles: 0 563189 0 uops_retired.retire_slots: 0 563189 0 Performance counter stats for 'sleep 1': 1,695,223 cycles # 0.20 Retiring 1,343,463 uops_retired.retire_slots uops_issued.any (0.00%) cycles (0.00%) idq_uops_not_delivered.core (0.00%) int_misc.recovery_cycles (0.00%) uops_retired.retire_slots (0.00%) 1.000980001 seconds time elapsed 0.001028000 seconds user 0.000000000 seconds sys ----/--- I think that it may be related to changes when introducing hashmap for evsel (that's before I started fiddling with metricgroups). Specifically, it looks to be in metricgroup__setup_events() -> find_evsel_group(). We seem to be enabling wrong evsels. I'll continue to look at this, but any help would be appreciated. Thanks, John perf metricgroup: Fix find_evsel_group() The following command segfaults on my x86 broadwell: $ ./perf stat -M frontend_bound,retiring,backend_bound,bad_speculation sleep 1 WARNING: grouped events cpus do not match, disabling group: anon group { raw 0x10e } anon group { raw 0x10e } perf: util/evsel.c:1596: get_group_fd: Assertion `!(!leader->core.fd)' failed. Aborted (core dumped) The issue shows itself as a use-after-free in evlist__check_cpu_maps(), whereby the leader of an event selector (evsel) has been deleted (yet we still attempt to verify for an evsel). Fundamentally the problem comes from metricgroup__setup_events() -> find_evsel_group(), and has developed from the previous fix attempt in commit 9c880c24cb0d ("perf metricgroup: Fix for metrics containing duration_time"). The problem now is that the logic in checking if an evsel is in the same group is subtly broken for "cycles" event. For "cycles" event, the pmu_name is NULL; however the logic in find_evsel_group() may set an event matched against "cycles" as used, when it should not be. This leads to a condition where an evsel is set, yet its leader is not. Fix the check for evsel pmu_name by not matching evsels when either has a NULL pmu_name. Fixes: 9c880c24cb0d ("perf metricgroup: Fix for metrics containing duration_time") Signed-off-by: John Garry diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8336dd8e8098..c456fdeae06a 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -162,10 +162,10 @@ static bool contains_event(struct evsel **metric_events, int num_events, return false; } -static bool evsel_same_pmu(struct evsel *ev1, struct evsel *ev2) +static bool evsel_same_pmu_or_none(struct evsel *ev1, struct evsel *ev2) { if (!ev1->pmu_name || !ev2->pmu_name) - return false; + return true; return !strcmp(ev1->pmu_name, ev2->pmu_name); } @@ -288,7 +288,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, */ if (!has_constraint && ev->leader != metric_events[i]->leader && - evsel_same_pmu(ev->leader, metric_events[i]->leader)) + evsel_same_pmu_or_none(ev->leader, metric_events[i]->leader)) break; if (!strcmp(metric_events[i]->name, ev->name)) { set_bit(ev->idx, evlist_used); lines 25-63/63 (END)