From nobody Thu May 7 20:49:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFAFEC433FE for ; Wed, 18 May 2022 14:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238634AbiEROjQ (ORCPT ); Wed, 18 May 2022 10:39:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238731AbiEROjH (ORCPT ); Wed, 18 May 2022 10:39:07 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 473811666BE; Wed, 18 May 2022 07:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652884746; x=1684420746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LShm/2bXdPimwyzDNkg1nipd4zb3cOV1XRLu53Gf2Ss=; b=eUQ+09AkGSZkjbXMEvX3c1oEGPF0+ezpq72iB7meIhbjhRcNNC+cSCf9 Si5E3Nb0wtrsiNx6WCy44ujh39cN474ptmJkhsBJErDSM24Pn10Mv5Ky+ m1y8xN/rUkX1JU29dX9fKK8/bptn8tcs8IhERnqDarQx26HcaxIrIMXpM zQdmDUHIG5i5rG+Kzqur5HeEUMIqLn3Uaupl22F6rec5Ed+sYLlF+peXp kas+5Gsif3SZRqVA/kMhxBt2ui2ZB/fbkoqyve+Wl/rV7WFd9XvsUFKLf 0ICJFiGeU1h10US/Jv1ejcLdwOqODN/GW5VVuW0R9d9lP1DwiaGuM7wGJ w==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="332321835" X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="332321835" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 07:39:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="714455501" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga001.fm.intel.com with ESMTP; 18 May 2022 07:39:04 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, irogers@google.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: peterz@infradead.org, zhengjun.xing@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, Kan Liang Subject: [PATCH V3 1/4] perf evsel: Fixes topdown events in a weak group for the hybrid platform Date: Wed, 18 May 2022 07:38:57 -0700 Message-Id: <20220518143900.1493980-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220518143900.1493980-1-kan.liang@linux.intel.com> References: <20220518143900.1493980-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The patch ("perf evlist: Keep topdown counters in weak group") fixes the perf metrics topdown event issue when the topdown events are in a weak group on a non-hybrid platform. However, it doesn't work for the hybrid platform. $./perf stat -e '{cpu_core/slots/,cpu_core/topdown-bad-spec/, cpu_core/topdown-be-bound/,cpu_core/topdown-fe-bound/, cpu_core/topdown-retiring/,cpu_core/branch-instructions/, cpu_core/branch-misses/,cpu_core/bus-cycles/,cpu_core/cache-misses/, cpu_core/cache-references/,cpu_core/cpu-cycles/,cpu_core/instructions/, cpu_core/mem-loads/,cpu_core/mem-stores/,cpu_core/ref-cycles/, cpu_core/cache-misses/,cpu_core/cache-references/}:W' -a sleep 1 Performance counter stats for 'system wide': 751,765,068 cpu_core/slots/ (84.07%) cpu_core/topdown-bad-spec/ cpu_core/topdown-be-bound/ cpu_core/topdown-fe-bound/ cpu_core/topdown-retiring/ 12,398,197 cpu_core/branch-instructions/ (84.07%) 1,054,218 cpu_core/branch-misses/ (84.24%) 539,764,637 cpu_core/bus-cycles/ (84.64%) 14,683 cpu_core/cache-misses/ (84.87%) 7,277,809 cpu_core/cache-references/ (77.30%) 222,299,439 cpu_core/cpu-cycles/ (77.28%) 63,661,714 cpu_core/instructions/ (84.85%) 0 cpu_core/mem-loads/ (77.29%) 12,271,725 cpu_core/mem-stores/ (77.30%) 542,241,102 cpu_core/ref-cycles/ (84.85%) 8,854 cpu_core/cache-misses/ (76.71%) 7,179,013 cpu_core/cache-references/ (76.31%) 1.003245250 seconds time elapsed A hybrid platform has a different PMU name for the core PMUs, while the current perf hard code the PMU name "cpu". The evsel->pmu_name can be used to replace the "cpu" to fix the issue. For a hybrid platform, the pmu_name must be non-NULL. Because there are at least two core PMUs. The PMU has to be specified. For a non-hybrid platform, the pmu_name may be NULL. Because there is only one core PMU, "cpu". For a NULL pmu_name, we can safely assume that it is a "cpu" PMU. In case other PMUs also define the "slots" event, checking the PMU type as well. With the patch, $perf stat -e '{cpu_core/slots/,cpu_core/topdown-bad-spec/, cpu_core/topdown-be-bound/,cpu_core/topdown-fe-bound/, cpu_core/topdown-retiring/,cpu_core/branch-instructions/, cpu_core/branch-misses/,cpu_core/bus-cycles/,cpu_core/cache-misses/, cpu_core/cache-references/,cpu_core/cpu-cycles/,cpu_core/instructions/, cpu_core/mem-loads/,cpu_core/mem-stores/,cpu_core/ref-cycles/, cpu_core/cache-misses/,cpu_core/cache-references/}:W' -a sleep 1 Performance counter stats for 'system wide': 766,620,266 cpu_core/slots/ (84= .06%) 73,172,129 cpu_core/topdown-bad-spec/ # 9.5% bad speculation (84= .06%) 193,443,341 cpu_core/topdown-be-bound/ # 25.0% backend bound (84= .06%) 403,940,929 cpu_core/topdown-fe-bound/ # 52.3% frontend bound (84= .06%) 102,070,237 cpu_core/topdown-retiring/ # 13.2% retiring (84= .06%) 12,364,429 cpu_core/branch-instructions/ (84= .03%) 1,080,124 cpu_core/branch-misses/ (84= .24%) 564,120,383 cpu_core/bus-cycles/ (84= .65%) 36,979 cpu_core/cache-misses/ (84= .86%) 7,298,094 cpu_core/cache-references/ (77= .30%) 227,174,372 cpu_core/cpu-cycles/ (77= .31%) 63,886,523 cpu_core/instructions/ (84= .87%) 0 cpu_core/mem-loads/ (77= .31%) 12,208,782 cpu_core/mem-stores/ (77= .31%) 566,409,738 cpu_core/ref-cycles/ (84= .87%) 23,118 cpu_core/cache-misses/ (76= .71%) 7,212,602 cpu_core/cache-references/ (76= .29%) 1.003228667 seconds time elapsed Signed-off-by: Kan Liang Acked-by: Ian Rogers --- tools/perf/arch/x86/util/evsel.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 00cb4466b4ca..88306183d629 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -31,10 +31,29 @@ void arch_evsel__fixup_new_cycles(struct perf_event_att= r *attr) free(env.cpuid); } =20 +/* Check whether the evsel's PMU supports the perf metrics */ +static bool evsel__sys_has_perf_metrics(const struct evsel *evsel) +{ + const char *pmu_name =3D evsel->pmu_name ? evsel->pmu_name : "cpu"; + + /* + * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU + * on a non-hybrid machine, "cpu_core" PMU on a hybrid machine. + * The slots event is only available for the core PMU, which + * supports the perf metrics feature. + * Checking both the PERF_TYPE_RAW type and the slots event + * should be good enough to detect the perf metrics feature. + */ + if ((evsel->core.attr.type =3D=3D PERF_TYPE_RAW) && + pmu_have_event(pmu_name, "slots")) + return true; + + return false; +} + bool arch_evsel__must_be_in_group(const struct evsel *evsel) { - if ((evsel->pmu_name && strcmp(evsel->pmu_name, "cpu")) || - !pmu_have_event("cpu", "slots")) + if (!evsel__sys_has_perf_metrics(evsel)) return false; =20 return evsel->name && --=20 2.35.1 From nobody Thu May 7 20:49:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A42C433EF for ; Wed, 18 May 2022 14:39:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238775AbiEROjW (ORCPT ); Wed, 18 May 2022 10:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238748AbiEROjI (ORCPT ); Wed, 18 May 2022 10:39:08 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2521C0F38; Wed, 18 May 2022 07:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652884746; x=1684420746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=azzlWtN3/N+H67AfO794QZqeEtYcvV6vWBrUyjqwnbc=; b=agHCK1NDLmCMAyaA0pc0QuE+KihknAXe5/1b55E19yFtIexljd2DUKHB rQTwyAZueEbMBUR8gwC/Ii1mCMa3mUc3+nWnSPioN4uD5nRb7h9VXO7Gp 0Q+Hp/IGz/k6npAEfuI/9SPrmksEMx/KFFxAybasi7YP7950BErRycap0 BzKQWB3sJkBS+wqV3BK7fwkg4Y5NhCyqpeOyx7nyrUQuiX1FjV3tW7Bat z6eXwqFPUeqqtvXCoqa09j8xz0gCtURsn33w9xDe6KIzBfI/TcegPLjbz Uee8KzoWREblvDVelFFvGNaiHvxjpU/papYAXTs1gA4sj6qe794Mq9Yw2 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="332321840" X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="332321840" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 07:39:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="714455504" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga001.fm.intel.com with ESMTP; 18 May 2022 07:39:05 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, irogers@google.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: peterz@infradead.org, zhengjun.xing@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, Kan Liang Subject: [PATCH V3 2/4] perf stat: Always keep perf metrics topdown events in a group Date: Wed, 18 May 2022 07:38:58 -0700 Message-Id: <20220518143900.1493980-3-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220518143900.1493980-1-kan.liang@linux.intel.com> References: <20220518143900.1493980-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang If any member in a group has a different cpu mask than the other members, the current perf stat disables group. when the perf metrics topdown events are part of the group, the below error will be triggered. $ perf stat -e "{slots,topdown-retiring,uncore_imc_free_running_0/dclk/}" -= a sleep 1 WARNING: grouped events cpus do not match, disabling group: anon group { slots, topdown-retiring, uncore_imc_free_running_0/dclk/ } Performance counter stats for 'system wide': 141,465,174 slots topdown-retiring 1,605,330,334 uncore_imc_free_running_0/dclk/ The perf metrics topdown events must always be grouped with a slots event as leader. Factor out evsel__remove_from_group() to only remove the regular events from the group. Remove evsel__must_be_in_group(), since no one use it anymore. With the patch, the topdown events aren't broken from the group for the splitting. $ perf stat -e "{slots,topdown-retiring,uncore_imc_free_running_0/dclk/}" -= a sleep 1 WARNING: grouped events cpus do not match, disabling group: anon group { slots, topdown-retiring, uncore_imc_free_running_0/dclk/ } Performance counter stats for 'system wide': 346,110,588 slots 124,608,256 topdown-retiring 1,606,869,976 uncore_imc_free_running_0/dclk/ 1.003877592 seconds time elapsed Fixes: a9a1790247bd ("perf stat: Ensure group is defined on top of the same= cpu mask") Signed-off-by: Kan Liang Acked-by: Ian Rogers --- tools/perf/builtin-stat.c | 7 ++----- tools/perf/util/evlist.c | 6 +----- tools/perf/util/evsel.c | 13 +++++++++++-- tools/perf/util/evsel.h | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index a96f106dc93a..f058e8cddfa8 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -271,11 +271,8 @@ static void evlist__check_cpu_maps(struct evlist *evli= st) pr_warning(" %s: %s\n", evsel->name, buf); } =20 - for_each_group_evsel(pos, leader) { - evsel__set_leader(pos, pos); - pos->core.nr_members =3D 0; - } - evsel->core.leader->nr_members =3D 0; + for_each_group_evsel(pos, leader) + evsel__remove_from_group(pos, leader); } } =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index dfa65a383502..7fc544330fea 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1795,11 +1795,7 @@ struct evsel *evlist__reset_weak_group(struct evlist= *evsel_list, struct evsel * * them. Some events, like Intel topdown, require being * in a group and so keep these in the group. */ - if (!evsel__must_be_in_group(c2) && c2 !=3D leader) { - evsel__set_leader(c2, c2); - c2->core.nr_members =3D 0; - leader->core.nr_members--; - } + evsel__remove_from_group(c2, leader); =20 /* * Set this for all former members of the group diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b98882cbb286..deb428ee5e50 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3083,7 +3083,16 @@ bool __weak arch_evsel__must_be_in_group(const struc= t evsel *evsel __maybe_unuse return false; } =20 -bool evsel__must_be_in_group(const struct evsel *evsel) +/* + * Remove an event from a given group (leader). + * Some events, e.g., perf metrics Topdown events, + * must always be grouped. Ignore the events. + */ +void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader) { - return arch_evsel__must_be_in_group(evsel); + if (!arch_evsel__must_be_in_group(evsel) && evsel !=3D leader) { + evsel__set_leader(evsel, evsel); + evsel->core.nr_members =3D 0; + leader->core.nr_members--; + } } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a36172ed4cf6..47f65f8e7c74 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -483,7 +483,7 @@ bool evsel__has_leader(struct evsel *evsel, struct evse= l *leader); bool evsel__is_leader(struct evsel *evsel); void evsel__set_leader(struct evsel *evsel, struct evsel *leader); int evsel__source_count(const struct evsel *evsel); -bool evsel__must_be_in_group(const struct evsel *evsel); +void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader); =20 bool arch_evsel__must_be_in_group(const struct evsel *evsel); =20 --=20 2.35.1 From nobody Thu May 7 20:49:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6FBEC433F5 for ; Wed, 18 May 2022 14:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238723AbiEROjd (ORCPT ); Wed, 18 May 2022 10:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238759AbiEROjJ (ORCPT ); Wed, 18 May 2022 10:39:09 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB37C33378; Wed, 18 May 2022 07:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652884747; x=1684420747; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XFEeuqGOKYZbTkzW8wUdOuH8GKHFxQqzXqZIW5aoD3Q=; b=nYrAulNVveaRc8sdaoPcIcGcj/0Ane+YqASGu1vOjju/ejMPlfMhY0cM Iqf9G31e6225q6901G1UBjktLde5ztuAeB5I8I4rq7Wlwb6eWzUnKJTx9 YT22/GNeoAXQUUK1plTTZsJIy3xHoDuEb3rL6LQu0fXd2eW4NC01hXv00 lkLmcUmAdhavCN75wDlnZKvvciFjlO/ITW40STe+f5KXNvcw+HPazcMKw yKWenp0BANe8f/OiHVlbD2LchVyoAMD5i96xMFxr1XSji9UH3ASa/01aa FrDeXShKXOKBu1oquRGcatjgUOi0qmkYrN7aWgYJtnFVLsNMbLMWKu7+n Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="332321842" X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="332321842" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 07:39:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="714455507" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga001.fm.intel.com with ESMTP; 18 May 2022 07:39:05 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, irogers@google.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: peterz@infradead.org, zhengjun.xing@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, Kan Liang Subject: [PATCH V3 3/4] perf parse-events: Support different format of the topdown event name Date: Wed, 18 May 2022 07:38:59 -0700 Message-Id: <20220518143900.1493980-4-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220518143900.1493980-1-kan.liang@linux.intel.com> References: <20220518143900.1493980-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The evsel->name may have a different format for a topdown event, a pure topdown name (e.g., topdown-fe-bound), or a PMU name + a topdown name (e.g., cpu/topdown-fe-bound/). The cpu/topdown-fe-bound/ kind format isn't supported by the arch_evlist__leader(). This format is a very common format for a hybrid platform, which requires specifying the PMU name for each event. Without the patch, $perf stat -e '{instructions,slots,cpu/topdown-fe-bound/}' -a sleep 1 Performance counter stats for 'system wide': instructions slots cpu/topdown-fe-bound/ 1.003482041 seconds time elapsed Some events weren't counted. Try disabling the NMI watchdog: echo 0 > /proc/sys/kernel/nmi_watchdog perf stat ... echo 1 > /proc/sys/kernel/nmi_watchdog The events in group usually have to be from the same PMU. Try reorganizing = the group. With the patch, perf stat -e '{instructions,slots,cpu/topdown-fe-bound/}' -a sleep 1 Performance counter stats for 'system wide': 157,383,996 slots 25,011,711 instructions 27,441,686 cpu/topdown-fe-bound/ 1.003530890 seconds time elapsed Fixes: bc355822f0d9 ("perf parse-events: Move slots only with topdown") Reviewed-by: Ian Rogers Signed-off-by: Kan Liang --- tools/perf/arch/x86/util/evlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index cfc208d71f00..75564a7df15b 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -36,7 +36,7 @@ struct evsel *arch_evlist__leader(struct list_head *list) if (slots =3D=3D first) return first; } - if (!strncasecmp(evsel->name, "topdown", 7)) + if (strcasestr(evsel->name, "topdown")) has_topdown =3D true; if (slots && has_topdown) return slots; --=20 2.35.1 From nobody Thu May 7 20:49:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BAAEC433F5 for ; Wed, 18 May 2022 14:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238781AbiEROj0 (ORCPT ); Wed, 18 May 2022 10:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238761AbiEROjJ (ORCPT ); Wed, 18 May 2022 10:39:09 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0540143499; Wed, 18 May 2022 07:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652884748; x=1684420748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UF8OFjUHgq3QZdqoRaskADvHxlzGs9LNwPzkRVEIU1Q=; b=QytVEQlEcRlc1/vXiWz15irV60gqcbqCw6jF7sLLNxDKLHvItb3vIUEn zRFYxe25+Aesfz3mJfvj28YvI7f75jef+9P49kjf73AB0CtU9CdsEPXH3 7Q/US/767m7j5/7TdU+GWkn4x4/fojwmRdfVtqWKs2qA48jlgivROFRs+ eJ07C5RGG4kQALd90UAaPWSO4D8+byr80d1dKJccKMkwerTxRsdESPJRY AkMjrx73980E9AxhaS+F0EQOvUZkXcrJ4+yQ1RrRXAVd4ecC/glroJZtq XO7PorZswkRMqYquWlXmbI5TSgV/K3oBbgnpKKV64T6R9nfrtO9S/lpMf w==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="332321845" X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="332321845" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 07:39:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,235,1647327600"; d="scan'208";a="714455510" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga001.fm.intel.com with ESMTP; 18 May 2022 07:39:05 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, irogers@google.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: peterz@infradead.org, zhengjun.xing@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, Kan Liang Subject: [PATCH V3 4/4] perf parse-events: Move slots event for the hybrid platform too Date: Wed, 18 May 2022 07:39:00 -0700 Message-Id: <20220518143900.1493980-5-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220518143900.1493980-1-kan.liang@linux.intel.com> References: <20220518143900.1493980-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The commit 94dbfd6781a0 ("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-ret= iring/}" -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-ret= iring/}" -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 --- 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/e= vlist.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" =20 #define TOPDOWN_L1_EVENTS "{slots,topdown-retiring,topdown-bad-spec,topdow= n-fe-bound,topdown-be-bound}" #define TOPDOWN_L2_EVENTS "{slots,topdown-retiring,topdown-bad-spec,topdow= n-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 *lis= t) =20 first =3D list_first_entry(list, struct evsel, core.node); =20 - if (!pmu_have_event("cpu", "slots")) + if (!topdown_sys_has_perf_metrics()) return first; =20 /* If there is a slots event and a topdown event then the slots event com= es 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->nam= e) { if (strcasestr(evsel->name, "slots")) { slots =3D evsel; if (slots =3D=3D 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 =3D perf_pmu__find_by_type(PERF_TYPE_RAW); + if (pmu && pmu_have_event(pmu->name, "slots")) + has_perf_metrics =3D true; + + cached =3D true; + return has_perf_metrics; +} =20 /* * 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 --=20 2.35.1