From nobody Mon Apr 27 15:21:58 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 46C76C43334 for ; Mon, 13 Jun 2022 08:29:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240160AbiFMI3Q (ORCPT ); Mon, 13 Jun 2022 04:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240124AbiFMI3H (ORCPT ); Mon, 13 Jun 2022 04:29:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3984C1A074; Mon, 13 Jun 2022 01:29:06 -0700 (PDT) Date: Mon, 13 Jun 2022 08:29:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1655108944; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=El0/lmQHtq7omgI8LCcZHVTLCGcJfVYoNwsJAGUDouQ=; b=GJfmQ4cC2bu0hkKgUbrAHvR+ADMwnt7ByFgBTNDvX/LLZZels63OgGMt/hpm/4yldr2etP WmBSD+5S585CaSVifg9ot9qbsZbDJitd6/vwbtQpIzzDh8Ex4hXdj9V7SSfnagdC2+3/3C 9hRBnStw+gw6WM8h3ndUPrEJxpjESoEWVHjsQfYxy5KCA5GzCDeXUuhuRaCDjJmWyNFXjp GpHW9eehecjYLXw9VdwoIPTHaDlqW3zjXp3P/8mMfYPlTeZHMwN2gDY43cpMwZVbmQn8Gh rPiYRtCVKpGkatydUVgkxAFTFTv6aVSbYcWp8PXAeKXiRjUjFFOKTugjflcF8g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1655108944; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=El0/lmQHtq7omgI8LCcZHVTLCGcJfVYoNwsJAGUDouQ=; b=gErji1lM2j3dghtZjlTxW0ZesZWbhesKAIpRY1tXpCrstmjJ+rY5tqIiiTdrvwCp9jHFiQ xWt9M+QYOh8AEkBA== From: "tip-bot2 for Sandipan Das" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/amd/uncore: Detect available DF counters Cc: Sandipan Das , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Cbac7b2806561e03f2acc7fdc9db94f102df80e1d=2E16529?= =?utf-8?q?54372=2Egit=2Esandipan=2Edas=40amd=2Ecom=3E?= References: =?utf-8?q?=3Cbac7b2806561e03f2acc7fdc9db94f102df80e1d=2E165295?= =?utf-8?q?4372=2Egit=2Esandipan=2Edas=40amd=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <165510894372.4207.6081140723094981410.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 16b48c3f5ed85b8017526b1acacf5115461b489a Gitweb: https://git.kernel.org/tip/16b48c3f5ed85b8017526b1acacf51154= 61b489a Author: Sandipan Das AuthorDate: Thu, 19 May 2022 15:33:32 +05:30 Committer: Peter Zijlstra CommitterDate: Mon, 13 Jun 2022 10:15:13 +02:00 perf/x86/amd/uncore: Detect available DF counters If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, use CPUID leaf 0x80000022 EBX to detect the number of Data Fabric (DF) PMCs. This offers more flexibility if the counts change in later processor families. Signed-off-by: Sandipan Das Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/bac7b2806561e03f2acc7fdc9db94f102df80e1d.16= 52954372.git.sandipan.das@amd.com --- arch/x86/events/amd/uncore.c | 10 ++++++++++ arch/x86/include/asm/perf_event.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index c3e218d..233dd40 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -30,6 +30,7 @@ #undef pr_fmt #define pr_fmt(fmt) "amd_uncore: " fmt =20 +static int pmu_version; static int num_counters_llc; static int num_counters_nb; static bool l3_mask; @@ -629,6 +630,7 @@ static int __init amd_uncore_init(void) { struct attribute **df_attr =3D amd_uncore_df_format_attr; struct attribute **l3_attr =3D amd_uncore_l3_format_attr; + union cpuid_0x80000022_ebx ebx; int ret =3D -ENODEV; =20 if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && @@ -638,6 +640,9 @@ static int __init amd_uncore_init(void) if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) return -ENODEV; =20 + if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) + pmu_version =3D 2; + num_counters_nb =3D NUM_COUNTERS_NB; num_counters_llc =3D NUM_COUNTERS_L2; if (boot_cpu_data.x86 >=3D 0x17) { @@ -666,6 +671,11 @@ static int __init amd_uncore_init(void) if (ret) goto fail_nb; =20 + if (pmu_version >=3D 2) { + ebx.full =3D cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); + num_counters_nb =3D ebx.split.num_df_pmc; + } + pr_info("%d %s %s counters detected\n", num_counters_nb, boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON ? "HYGON" : "", amd_nb_pmu.name); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 409725e..af157aa 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -194,6 +194,9 @@ union cpuid_0x80000022_ebx { struct { /* Number of Core Performance Counters */ unsigned int num_core_pmc:4; + unsigned int reserved:6; + /* Number of Data Fabric Counters */ + unsigned int num_df_pmc:6; } split; unsigned int full; };