Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp632509iog; Mon, 13 Jun 2022 09:31:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHfI4+165vwuBevKFTM9UV3MYX+A4zpqcepJIkq5OuRB33gB0chEkIneo7AvR29qJO/qHf X-Received: by 2002:a63:5f53:0:b0:3fc:c510:c4a0 with SMTP id t80-20020a635f53000000b003fcc510c4a0mr424130pgb.80.1655137915706; Mon, 13 Jun 2022 09:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137915; cv=none; d=google.com; s=arc-20160816; b=spGt1JsYxRgcW8qwtH4klSgi4OtL2hbmJ3J6lxFBW0b/WHFd4NjxNPH5YQZIbfEJgA GxOA1fyUHJ78QhHH+bTGSlGTsReeaoDO9pNhpY1dYQ93w6ul2a2I1YLD2/LaU5Vekmtk 6qVcDIFNkLRzmBRvKgVvVU/dIUDVhi1dP41kJoH5GGrh2dnLb3QrE+Nk9YxQI9joh5LM bt53Cgx8kf6NviNdGCWqLwrFxAr8nK0egV3yEjUm7N3Xe7pvweT2+211XVl4NtEhXt1G NsUXu5yWtvUQug5e64pP4flSGkjd76VHSYPryADArylNq8SpRMQ6u+/af8adol4CGYtV 6pEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lgQS+rsAhIvF0dgLNL9PvbuRSfnWN43sZYXr5Dr1szo=; b=ey2LFAL5eSvN82boKrH6WIeQAF3BbHnsQtBsqvCPXgvVuQjIUPzCQSTFnyeUv35y3W S5G0lMSCYpPhBDr/LEA1mG6p44f+Q1cGzSd1UpH/Jjw8ztR7Oy//34iUl9qiuxMzQt8g UhoezMb3R84wZd12ghpYdgetbcDE9q1O3M6UtWdhl5aAPBob8yifBDe10Rn4sT8RMe4R zzods79vCvcLM6l89xmaBsgiSvqTTj3E5FFux2a1OnXUQndqo/MTdsmkDzj7XG2OHrex tTKQdoxZczz2LWz+cHh54OvT5CXARx9XG5Jy4UhBksRlGDyz9ZBh3/JxZIi48d2aAl2Z 4neQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UUAlXZ6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ct19-20020a056a000f9300b0051c09f5253bsi8654198pfb.204.2022.06.13.09.31.43; Mon, 13 Jun 2022 09:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UUAlXZ6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379731AbiFMNo7 (ORCPT + 99 others); Mon, 13 Jun 2022 09:44:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379215AbiFMNkD (ORCPT ); Mon, 13 Jun 2022 09:40:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3915CE03; Mon, 13 Jun 2022 04:30:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A233FB80EA7; Mon, 13 Jun 2022 11:30:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE069C34114; Mon, 13 Jun 2022 11:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119810; bh=gJVcHejTKcyuP/psQJV5MtzjcY2RzC0c8YvPepU7RPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UUAlXZ6dRlwtnlzQVa+ExeLq5bQZ29PFHJ0v/J6KSzy4zLsU1/2gzuvUR3Ch+08W1 eK0hTu+Oz30BZMrhZISRDXmtgzAtsWMMR5UI5MMI2X/sTSeTqIBy05dqSX5y4Rrq12 GUP4V+uIWuXPlTm7IG7gfZhXLlq26O1cvUDCq6Hg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Kan Liang , Adrian Hunter , Andi Kleen , Ingo Molnar , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Xing Zhengjun , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.18 148/339] perf parse-events: Move slots event for the hybrid platform too Date: Mon, 13 Jun 2022 12:09:33 +0200 Message-Id: <20220613094931.172977154@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094926.497929857@linuxfoundation.org> References: <20220613094926.497929857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang [ Upstream commit e0e14cdff31d326f81e0edbd5140f788c870756c ] The commit 94dbfd6781a0e87b ("perf parse-events: Architecture specific leader override") introduced a feature to reorder the slots event to fulfill the restriction of the perf metrics topdown group. But the feature doesn't work on the hybrid machine. $ perf stat -e "{cpu_core/instructions/,cpu_core/slots/,cpu_core/topdown-retiring/}" -a sleep 1 Performance counter stats for 'system wide': cpu_core/instructions/ cpu_core/slots/ cpu_core/topdown-retiring/ 1.002871801 seconds time elapsed A hybrid platform has a different PMU name for the core PMUs, while current perf hard code the PMU name "cpu". Introduce a new function to check whether the system supports the perf metrics feature. The result is cached for the future usage. For X86, the core PMU name always has "cpu" prefix. With the patch: $ perf stat -e "{cpu_core/instructions/,cpu_core/slots/,cpu_core/topdown-retiring/}" -a sleep 1 Performance counter stats for 'system wide': 76,337,010 cpu_core/slots/ 10,416,809 cpu_core/instructions/ 11,692,372 cpu_core/topdown-retiring/ 1.002805453 seconds time elapsed Reviewed-by: Ian Rogers Signed-off-by: Kan Liang Cc: Adrian Hunter Cc: Andi Kleen Cc: Ingo Molnar Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Xing Zhengjun Link: https://lore.kernel.org/r/20220518143900.1493980-5-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/arch/x86/util/evlist.c | 5 +++-- tools/perf/arch/x86/util/topdown.c | 25 +++++++++++++++++++++++++ tools/perf/arch/x86/util/topdown.h | 7 +++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tools/perf/arch/x86/util/topdown.h diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/evlist.c index 75564a7df15b..68f681ad54c1 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -3,6 +3,7 @@ #include "util/pmu.h" #include "util/evlist.h" #include "util/parse-events.h" +#include "topdown.h" #define TOPDOWN_L1_EVENTS "{slots,topdown-retiring,topdown-bad-spec,topdown-fe-bound,topdown-be-bound}" #define TOPDOWN_L2_EVENTS "{slots,topdown-retiring,topdown-bad-spec,topdown-fe-bound,topdown-be-bound,topdown-heavy-ops,topdown-br-mispredict,topdown-fetch-lat,topdown-mem-bound}" @@ -25,12 +26,12 @@ struct evsel *arch_evlist__leader(struct list_head *list) first = list_first_entry(list, struct evsel, core.node); - if (!pmu_have_event("cpu", "slots")) + if (!topdown_sys_has_perf_metrics()) return first; /* If there is a slots event and a topdown event then the slots event comes first. */ __evlist__for_each_entry(list, evsel) { - if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") && evsel->name) { + if (evsel->pmu_name && !strncmp(evsel->pmu_name, "cpu", 3) && evsel->name) { if (strcasestr(evsel->name, "slots")) { slots = evsel; if (slots == first) diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/topdown.c index 2f3d96aa92a5..f4d5422e9960 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -3,6 +3,31 @@ #include "api/fs/fs.h" #include "util/pmu.h" #include "util/topdown.h" +#include "topdown.h" + +/* Check whether there is a PMU which supports the perf metrics. */ +bool topdown_sys_has_perf_metrics(void) +{ + static bool has_perf_metrics; + static bool cached; + struct perf_pmu *pmu; + + if (cached) + return has_perf_metrics; + + /* + * The perf metrics feature is a core PMU feature. + * The PERF_TYPE_RAW type is the type of a core PMU. + * The slots event is only available when the core PMU + * supports the perf metrics feature. + */ + pmu = perf_pmu__find_by_type(PERF_TYPE_RAW); + if (pmu && pmu_have_event(pmu->name, "slots")) + has_perf_metrics = true; + + cached = true; + return has_perf_metrics; +} /* * Check whether we can use a group for top down. diff --git a/tools/perf/arch/x86/util/topdown.h b/tools/perf/arch/x86/util/topdown.h new file mode 100644 index 000000000000..46bf9273e572 --- /dev/null +++ b/tools/perf/arch/x86/util/topdown.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOPDOWN_H +#define _TOPDOWN_H 1 + +bool topdown_sys_has_perf_metrics(void); + +#endif -- 2.35.1