From nobody Mon Feb 9 10:24:11 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0723B33997 for ; Wed, 29 Jan 2025 15:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165690; cv=none; b=RBzZDaElzEOITOilDCPBZF44haSThZMzmsmSy02OKaMenwCRLU1iJ3SeudpvkOk+th56v7b/fxM7JWdqhITVVJJCqoNytm2JRZKXJgI35VaFOozj8hAMLPUZ/CcOw7qQh1qWerMOS9NNKOyGfa/5JNQ/jsy5vAT+44MtH1GIEPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165690; c=relaxed/simple; bh=s64cKgIaPu4saFifMwdX/Vl5ylPbrbaF472vL8wl9cg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J2lIfWvxqQOFEjGqEr0mAeKgQ3JXYw9AozmzK/azG5+ytBQARoV0FRm4wqdd1swhIKaf8sIgrhiNyX7D4s1OdySufVJgbietf7V55S7v1UUHbiIjdO6mOlN/T2sO+D+zQ8bO6jP9QMoccCqrFrHLx+E0rct31HrzgVSDsxqsH7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ArzGCCa7; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ArzGCCa7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738165689; x=1769701689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s64cKgIaPu4saFifMwdX/Vl5ylPbrbaF472vL8wl9cg=; b=ArzGCCa7/KagsOdqDy1j6zEySCrhlgHY4vSxDtPv9QNhlz1jcjzIu4XK 0EaArIC9jus2OXE+7Aaj9CXDt62AhxXWF0CbrIj3mkOH4vdxydekucyOL zL7XGvnJ5c/qnXfic/PJzTe5Bv2+HKbywJPiYC8mF7XnKeSBd6a2vcJY0 vZeQh3ylK48lxjIkudMwOzxKbF+Moz1jgcQy7N1Bw3tQf+zeOT1YXzhO4 veAUuZJFFSZrcLNFbBlwOsoNsdcUZDa+0oufU1w18KFOo0wZyr6HD+oEn 3xQ+qlXq5Q0aDga+8EdeE6EDFeL8pRSbIOQ26h8pQyBopk/RfUrcwqwHA g==; X-CSE-ConnectionGUID: 7sPZSg2iQSKEg7Y6ToFRvA== X-CSE-MsgGUID: aU4MjDHKT1ii7WYq/F87Rw== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="37882918" X-IronPort-AV: E=Sophos;i="6.13,243,1732608000"; d="scan'208";a="37882918" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 07:48:06 -0800 X-CSE-ConnectionGUID: 4cYR7tRqRaqBipx1PCUppA== X-CSE-MsgGUID: oJon+YFdS7OZUoIXxCtgnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="108927426" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orviesa010.jf.intel.com with ESMTP; 29 Jan 2025 07:48:06 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Cc: dapeng1.mi@linux.intel.com, Kan Liang Subject: [PATCH 1/3] perf/x86/intel: Clean up PEBS-via-PT on hybrid Date: Wed, 29 Jan 2025 07:48:18 -0800 Message-Id: <20250129154820.3755948-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250129154820.3755948-1-kan.liang@linux.intel.com> References: <20250129154820.3755948-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kan Liang The PEBS-via-PT feature is exposed for the e-core of some hybrid platforms, e.g., ADL and MTL. But it never works. $ dmesg | grep PEBS [ 1.793888] core: cpu_atom PMU driver: PEBS-via-PT $ perf record -c 1000 -e '{intel_pt/branch=3D0/, cpu_atom/cpu-cycles,aux-output/pp}' -C8 Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (cpu_atom/cpu-cycles,aux-output/pp). "dmesg | grep -i perf" may provide additional information. The "PEBS-via-PT" is printed if the corresponding bit of per-PMU capabilities is set. Since the feature is supported by the e-core HW, perf sets the bit for e-core. However, for Intel PT, if a feature is not supported on all CPUs, it is not supported at all. The PEBS-via-PT event cannot be created successfully. The PEBS-via-PT is no longer enumerated on the latest hybrid platform. It will be deprecated on future platforms with Arch PEBS. Let's remove it from the existing hybrid platforms. Fixes: d9977c43bff8 ("perf/x86: Register hybrid PMUs") Signed-off-by: Kan Liang Cc: Adrian Hunter Cc: Alexander Shishkin --- The original V1 patch can be found at https://lore.kernel.org/lkml/20250124183432.3565061-1-kan.liang@linux.intel= .com/ The patch only updates the comments. arch/x86/events/intel/core.c | 10 ---------- arch/x86/events/intel/ds.c | 10 +++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 7f1b6b90a5fb..0a1030eb6db8 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4981,11 +4981,6 @@ static void intel_pmu_check_hybrid_pmus(struct x86_h= ybrid_pmu *pmu) else pmu->intel_ctrl &=3D ~(1ULL << GLOBAL_CTRL_EN_PERF_METRICS); =20 - if (pmu->intel_cap.pebs_output_pt_available) - pmu->pmu.capabilities |=3D PERF_PMU_CAP_AUX_OUTPUT; - else - pmu->pmu.capabilities &=3D ~PERF_PMU_CAP_AUX_OUTPUT; - intel_pmu_check_event_constraints(pmu->event_constraints, pmu->cntr_mask64, pmu->fixed_cntr_mask64, @@ -5063,9 +5058,6 @@ static bool init_hybrid_pmu(int cpu) =20 pr_info("%s PMU driver: ", pmu->name); =20 - if (pmu->intel_cap.pebs_output_pt_available) - pr_cont("PEBS-via-PT "); - pr_cont("\n"); =20 x86_pmu_show_pmu_cap(&pmu->pmu); @@ -6420,11 +6412,9 @@ static __always_inline int intel_pmu_init_hybrid(enu= m hybrid_pmu_type pmus) pmu->intel_cap.capabilities =3D x86_pmu.intel_cap.capabilities; if (pmu->pmu_type & hybrid_small_tiny) { pmu->intel_cap.perf_metrics =3D 0; - pmu->intel_cap.pebs_output_pt_available =3D 1; pmu->mid_ack =3D true; } else if (pmu->pmu_type & hybrid_big) { pmu->intel_cap.perf_metrics =3D 1; - pmu->intel_cap.pebs_output_pt_available =3D 0; pmu->late_ack =3D true; } } diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 13a78a8a2780..46aaaeae0c8d 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -2742,7 +2742,15 @@ void __init intel_ds_init(void) } pr_cont("PEBS fmt%d%c%s, ", format, pebs_type, pebs_qual); =20 - if (!is_hybrid() && x86_pmu.intel_cap.pebs_output_pt_available) { + /* + * The PEBS-via-PT is not supported on hybrid platforms, + * because not all CPUs of a hybrid machine support it. + * The global x86_pmu.intel_cap, which only contains the + * common capabilities, is used to check the availability + * of the feature. The per-PMU pebs_output_pt_available + * in a hybrid machine should be ignored. + */ + if (x86_pmu.intel_cap.pebs_output_pt_available) { pr_cont("PEBS-via-PT, "); x86_get_pmu(smp_processor_id())->capabilities |=3D PERF_PMU_CAP_AUX_OU= TPUT; } --=20 2.38.1 From nobody Mon Feb 9 10:24:11 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96AEC1CB9EA; Wed, 29 Jan 2025 15:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165691; cv=none; b=nCC2zXzpy/B5cW8kfyFpjOFv6SZdUIHPpaJTjSS7WyBLLGbbqilNVKLyh+bVu8zgEyHaJZ0dG6+zdVdC5qA5ZQAdXRxPmY8vVSqR1QiQRoGA+O1qqQUJAux+iHwJnB4yGweZsATFquzNnhK+68j/G55NfftmsWWDmzewD+ycvog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165691; c=relaxed/simple; bh=a5xLFkIixG4demBHG/GQFB10Llx4qy/6C9pHVc2brF0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bKEfiG8kdUPgCh5XpyI0gAqDaXkB7J1em84FXHCuGyxZVfSpIA5bAg9bPXSLy8Kp4ZyWH601vrj5gPHLUniU6XxcAcIOvJqGBcDi9drxEpI/o2iM17xj2Wt6ZLBqiaTWGXrYPvp7FFD/0HSgrAsQ99dwh7pWT65zVEDNY2eBgMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KEy/zouT; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KEy/zouT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738165689; x=1769701689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a5xLFkIixG4demBHG/GQFB10Llx4qy/6C9pHVc2brF0=; b=KEy/zouTU+I49XaS71AI5oK9P7e+EebPYJh4SMX1dxpzQSksYnXKTCLN 9b3o8IJPM9SZu4Bb6TqNlIs/9ufTxI69ZYXTARew/+fMK3QbxAPZyWL2c 8qyYxvPcv9iNNJZDMDGuCAt+fs9OdBemLnN7xvrAbSYGbZV1yePmVwxz+ xEpONL4o9L3NV5hoDk0/63A0T/zbFxk1zdEOVLc/lOdMQQ56X95LiMhHi EcRV+nGHg7D5XJ+2q9s10+EC1Nqyd7NCjwoLfYO8BQyCtBz49QkUIcMRk runy8V5WfFee+ob0vYsTVHt6nQQepUPKt+plrt5e2hmdXB8Lm/48HU0GB A==; X-CSE-ConnectionGUID: DPgA8iR3R2ST7GfozVDZGQ== X-CSE-MsgGUID: IQ71ftDaRmqFU9sEb/2dkw== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="37882923" X-IronPort-AV: E=Sophos;i="6.13,243,1732608000"; d="scan'208";a="37882923" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 07:48:06 -0800 X-CSE-ConnectionGUID: xvpe4UMyRRyE1aQfqyXsrg== X-CSE-MsgGUID: XhrrMENjR8meaLROX8aOrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="108927429" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orviesa010.jf.intel.com with ESMTP; 29 Jan 2025 07:48:06 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Cc: dapeng1.mi@linux.intel.com, Kan Liang , stable@vger.kernel.org Subject: [PATCH 2/3] perf/x86/intel: Fix ARCH_PERFMON_NUM_COUNTER_LEAF Date: Wed, 29 Jan 2025 07:48:19 -0800 Message-Id: <20250129154820.3755948-3-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250129154820.3755948-1-kan.liang@linux.intel.com> References: <20250129154820.3755948-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kan Liang The EAX of the CPUID Leaf 023H enumerates the mask of valid sub-leaves. To tell the availability of the sub-leaf 1 (enumerate the counter mask), perf should check the bit 1 (0x2) of EAS, rather than bit 0 (0x1). The error is not user-visible on bare metal. Because the sub-leaf 0 and the sub-leaf 1 are always available. However, it may bring issues in a virtualization environment when a VMM only enumerates the sub-leaf 0. Introduce the cpuid35_e?x to replace the macros, which makes the implementation style consistent. Fixes: eb467aaac21e ("perf/x86/intel: Support Architectural PerfMon Extensi= on leaf") Signed-off-by: Kan Liang Cc: stable@vger.kernel.org --- arch/x86/events/intel/core.c | 18 ++++++++++-------- arch/x86/include/asm/perf_event.h | 28 +++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 0a1030eb6db8..120df9620951 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4945,20 +4945,22 @@ static inline bool intel_pmu_broken_perf_cap(void) =20 static void update_pmu_cap(struct x86_hybrid_pmu *pmu) { - unsigned int sub_bitmaps, eax, ebx, ecx, edx; + unsigned int cntr, fixed_cntr, ecx, edx; + union cpuid35_eax eax; + union cpuid35_ebx ebx; =20 - cpuid(ARCH_PERFMON_EXT_LEAF, &sub_bitmaps, &ebx, &ecx, &edx); + cpuid(ARCH_PERFMON_EXT_LEAF, &eax.full, &ebx.full, &ecx, &edx); =20 - if (ebx & ARCH_PERFMON_EXT_UMASK2) + if (ebx.split.umask2) pmu->config_mask |=3D ARCH_PERFMON_EVENTSEL_UMASK2; - if (ebx & ARCH_PERFMON_EXT_EQ) + if (ebx.split.eq) pmu->config_mask |=3D ARCH_PERFMON_EVENTSEL_EQ; =20 - if (sub_bitmaps & ARCH_PERFMON_NUM_COUNTER_LEAF_BIT) { + if (eax.split.cntr_subleaf) { cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF, - &eax, &ebx, &ecx, &edx); - pmu->cntr_mask64 =3D eax; - pmu->fixed_cntr_mask64 =3D ebx; + &cntr, &fixed_cntr, &ecx, &edx); + pmu->cntr_mask64 =3D cntr; + pmu->fixed_cntr_mask64 =3D fixed_cntr; } =20 if (!intel_pmu_broken_perf_cap()) { diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index adaeb8ca3a8a..9aef5d044706 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -194,11 +194,33 @@ union cpuid10_edx { * detection/enumeration details: */ #define ARCH_PERFMON_EXT_LEAF 0x00000023 -#define ARCH_PERFMON_EXT_UMASK2 0x1 -#define ARCH_PERFMON_EXT_EQ 0x2 -#define ARCH_PERFMON_NUM_COUNTER_LEAF_BIT 0x1 #define ARCH_PERFMON_NUM_COUNTER_LEAF 0x1 =20 +union cpuid35_eax { + struct { + unsigned int leaf0:1; + /* Counters Sub-Leaf */ + unsigned int cntr_subleaf:1; + /* Auto Counter Reload Sub-Leaf */ + unsigned int acr_subleaf:1; + /* Events Sub-Leaf */ + unsigned int events_subleaf:1; + unsigned int reserved:28; + } split; + unsigned int full; +}; + +union cpuid35_ebx { + struct { + /* UnitMask2 Supported */ + unsigned int umask2:1; + /* EQ-bit Supported */ + unsigned int eq:1; + unsigned int reserved:30; + } split; + unsigned int full; +}; + /* * Intel Architectural LBR CPUID detection/enumeration details: */ --=20 2.38.1 From nobody Mon Feb 9 10:24:11 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7B1D1DE4FE for ; Wed, 29 Jan 2025 15:48:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165692; cv=none; b=fAHphk6fO1y+Lace3SgkGxqDYzgBDQVGRsPA3d2eu5v+4ObBlFXEeYInxQMKL5LnZ0BSCDpGmTIPwkZgEv1UA04EXK2RzeTM9CUB2aE1jdNKdE+lsuiSDhbKbw2WKFH+W5if64jHa7aNkbl68tH2YeJn+EY8PhvAEKZnIEx374Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738165692; c=relaxed/simple; bh=ae/aVx65uzCdkhburPzWZzdopQc7+nWoSxUslirZboQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TkHnoTZureKn2nfBYYZWIq9MKJu1LQatvwRzb5vO8WHnOXqPrJ5xG+aus4Awx7FE04vUIMhU3KNeVrB+h32Ra22oeipM6TAg1e9LSnHpuLY8CLRzUZlEsOfDg4W/MvcquQO71Uj5ynD5zTVrliurP3nrsKQjp01yTZrLpt8YDJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jX1SM+PT; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jX1SM+PT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738165691; x=1769701691; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ae/aVx65uzCdkhburPzWZzdopQc7+nWoSxUslirZboQ=; b=jX1SM+PTBPINiKPVHMToxh6tsPo4tJlGiaKuJk22/T5xTzc9Mrn9dFPW nrTg1dOKn9QfzifWBooQkb3FljseAfLx0eU6U1l7W/0AG5tvwj0w9m9mO mBWcK1ZC2JFWyxOFx+c4vgi1Uzc18i/leTO+Uf4vXs/6yAZLg1reTtle7 VilJpYtLI2xpewhnd3vr62AW1Jsd9CoXQmn0Jy6jOqmmxpgJAIGHAe1z5 TvbX/Rj2QRjRuyH2EEADM2fwYhutHJwXZK1TD+JZ86iM0sV6NtQynRvlE 66x+P8TW/tMNtnrRi3wLaLTzxl6xxwo8SrYEHf5sUzUjrmIFkEF3C0JRq A==; X-CSE-ConnectionGUID: b5NSilNiSWyRJ6pxDWyIlw== X-CSE-MsgGUID: 4GIKdU2ERESYu6Kc62ZIcQ== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="37882929" X-IronPort-AV: E=Sophos;i="6.13,243,1732608000"; d="scan'208";a="37882929" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 07:48:06 -0800 X-CSE-ConnectionGUID: wWcqmhz5RdaGCqA1283LCA== X-CSE-MsgGUID: gW72CZO+SpWeKH9gi1addw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="108927432" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orviesa010.jf.intel.com with ESMTP; 29 Jan 2025 07:48:06 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Cc: dapeng1.mi@linux.intel.com, Kan Liang Subject: [PATCH 3/3] perf/x86/intel: Clean up counter information update and check Date: Wed, 29 Jan 2025 07:48:20 -0800 Message-Id: <20250129154820.3755948-4-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250129154820.3755948-1-kan.liang@linux.intel.com> References: <20250129154820.3755948-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kan Liang The counter-related PMU information may be updated in different places on different platforms. For hybrid machines, the accurate counter information can only be retrieved when the specific CPU is online. The information is updated in intel_pmu_cpu_starting()->init_hybrid_pmu(). For non-hybrid machines, the information is initialized in the intel_pmu_init() when booting CPU0. The counter information doesn't impact the PMU registration and should not necessarily be in intel_pmu_init(). Setup/update the counter-related PMU information in the CPU starting stage for all Intel platforms. The x86_pmu_show_pmu_cap() has to be delayed until all the information is updated. Add a PMU_FL_LATE_SETUP flag to indicate the late setup/update case. Signed-off-by: Kan Liang --- arch/x86/events/core.c | 10 ++-- arch/x86/events/intel/core.c | 112 ++++++++++++++++++----------------- arch/x86/events/perf_event.h | 1 + 3 files changed, 65 insertions(+), 58 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 7b6430e5a77b..e9e31dc49749 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2119,10 +2119,6 @@ static int __init init_hw_perf_events(void) perf_events_lapic_init(); register_nmi_handler(NMI_LOCAL, perf_event_nmi_handler, 0, "PMI"); =20 - unconstrained =3D (struct event_constraint) - __EVENT_CONSTRAINT(0, x86_pmu.cntr_mask64, - 0, x86_pmu_num_counters(NULL), 0, 0); - x86_pmu_format_group.attrs =3D x86_pmu.format_attrs; =20 if (!x86_pmu.events_sysfs_show) @@ -2130,8 +2126,12 @@ static int __init init_hw_perf_events(void) =20 pmu.attr_update =3D x86_pmu.attr_update; =20 - if (!is_hybrid()) + if (!(x86_pmu.flags & PMU_FL_LATE_SETUP)) { + unconstrained =3D (struct event_constraint) + __EVENT_CONSTRAINT(0, x86_pmu.cntr_mask64, + 0, x86_pmu_num_counters(NULL), 0, 0); x86_pmu_show_pmu_cap(NULL); + } =20 if (!x86_pmu.read) x86_pmu.read =3D _x86_pmu_read; diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 120df9620951..2a16bc94345c 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4943,8 +4943,9 @@ static inline bool intel_pmu_broken_perf_cap(void) return false; } =20 -static void update_pmu_cap(struct x86_hybrid_pmu *pmu) +static void update_pmu_cap(struct x86_hybrid_pmu *h_pmu) { + struct pmu *pmu =3D h_pmu ? &h_pmu->pmu : NULL; unsigned int cntr, fixed_cntr, ecx, edx; union cpuid35_eax eax; union cpuid35_ebx ebx; @@ -4952,43 +4953,46 @@ static void update_pmu_cap(struct x86_hybrid_pmu *p= mu) cpuid(ARCH_PERFMON_EXT_LEAF, &eax.full, &ebx.full, &ecx, &edx); =20 if (ebx.split.umask2) - pmu->config_mask |=3D ARCH_PERFMON_EVENTSEL_UMASK2; + hybrid(pmu, config_mask) |=3D ARCH_PERFMON_EVENTSEL_UMASK2; if (ebx.split.eq) - pmu->config_mask |=3D ARCH_PERFMON_EVENTSEL_EQ; + hybrid(pmu, config_mask) |=3D ARCH_PERFMON_EVENTSEL_EQ; =20 if (eax.split.cntr_subleaf) { cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF, &cntr, &fixed_cntr, &ecx, &edx); - pmu->cntr_mask64 =3D cntr; - pmu->fixed_cntr_mask64 =3D fixed_cntr; + hybrid(pmu, cntr_mask64) =3D cntr; + hybrid(pmu, fixed_cntr_mask64) =3D fixed_cntr; } =20 if (!intel_pmu_broken_perf_cap()) { /* Perf Metric (Bit 15) and PEBS via PT (Bit 16) are hybrid enumeration = */ - rdmsrl(MSR_IA32_PERF_CAPABILITIES, pmu->intel_cap.capabilities); + rdmsrl(MSR_IA32_PERF_CAPABILITIES, hybrid(pmu, intel_cap).capabilities); } } =20 -static void intel_pmu_check_hybrid_pmus(struct x86_hybrid_pmu *pmu) +static void intel_pmu_check_pmus(struct x86_hybrid_pmu *h_pmu) { - intel_pmu_check_counters_mask(&pmu->cntr_mask64, &pmu->fixed_cntr_mask64, - &pmu->intel_ctrl); - pmu->pebs_events_mask =3D intel_pmu_pebs_mask(pmu->cntr_mask64); - pmu->unconstrained =3D (struct event_constraint) - __EVENT_CONSTRAINT(0, pmu->cntr_mask64, - 0, x86_pmu_num_counters(&pmu->pmu), 0, 0); + struct pmu *pmu =3D h_pmu ? &h_pmu->pmu : NULL; =20 - if (pmu->intel_cap.perf_metrics) - pmu->intel_ctrl |=3D 1ULL << GLOBAL_CTRL_EN_PERF_METRICS; - else - pmu->intel_ctrl &=3D ~(1ULL << GLOBAL_CTRL_EN_PERF_METRICS); + intel_pmu_check_counters_mask(&hybrid(pmu, cntr_mask64), + &hybrid(pmu, fixed_cntr_mask64), + &hybrid(pmu, intel_ctrl)); + hybrid(pmu, pebs_events_mask) =3D intel_pmu_pebs_mask(hybrid(pmu, cntr_ma= sk64)); + hybrid_var(pmu, unconstrained) =3D (struct event_constraint) + __EVENT_CONSTRAINT(0, hybrid(pmu, cntr_mask64), + 0, x86_pmu_num_counters(pmu), + 0, 0); =20 - intel_pmu_check_event_constraints(pmu->event_constraints, - pmu->cntr_mask64, - pmu->fixed_cntr_mask64, - pmu->intel_ctrl); + if (hybrid(pmu, intel_cap).perf_metrics) + hybrid(pmu, intel_ctrl) |=3D 1ULL << GLOBAL_CTRL_EN_PERF_METRICS; + else + hybrid(pmu, intel_ctrl) &=3D ~(1ULL << GLOBAL_CTRL_EN_PERF_METRICS); =20 - intel_pmu_check_extra_regs(pmu->extra_regs); + intel_pmu_check_event_constraints(hybrid(pmu, event_constraints), + hybrid(pmu, cntr_mask64), + hybrid(pmu, fixed_cntr_mask64), + hybrid(pmu, intel_ctrl)); + intel_pmu_check_extra_regs(hybrid(pmu, extra_regs)); } =20 static struct x86_hybrid_pmu *find_hybrid_pmu_for_cpu(void) @@ -5036,37 +5040,50 @@ static struct x86_hybrid_pmu *find_hybrid_pmu_for_c= pu(void) return NULL; } =20 -static bool init_hybrid_pmu(int cpu) +static bool update_intel_pmu(int cpu) { struct cpu_hw_events *cpuc =3D &per_cpu(cpu_hw_events, cpu); - struct x86_hybrid_pmu *pmu =3D find_hybrid_pmu_for_cpu(); + struct x86_hybrid_pmu *h_pmu =3D find_hybrid_pmu_for_cpu(); + struct pmu *pmu =3D h_pmu ? &h_pmu->pmu : NULL; =20 - if (WARN_ON_ONCE(!pmu || (pmu->pmu.type =3D=3D -1))) { + if (WARN_ON_ONCE(is_hybrid() && (!h_pmu || h_pmu->pmu.type =3D=3D -1))) { cpuc->pmu =3D NULL; return false; } =20 - /* Only check and dump the PMU information for the first CPU */ - if (!cpumask_empty(&pmu->supported_cpus)) - goto end; + /* + * Only need to update and check for the first CPU. + * For non-bybird, it's always CPU 0. + */ + if (h_pmu) { + cpuc->pmu =3D &h_pmu->pmu; + if (!cpumask_empty(&h_pmu->supported_cpus)) { + cpumask_set_cpu(cpu, &h_pmu->supported_cpus); + return true; + } + } else if (cpu) + return true; =20 if (this_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT)) - update_pmu_cap(pmu); - - intel_pmu_check_hybrid_pmus(pmu); + update_pmu_cap(h_pmu); =20 - if (!check_hw_exists(&pmu->pmu, pmu->cntr_mask, pmu->fixed_cntr_mask)) - return false; + intel_pmu_check_pmus(h_pmu); =20 - pr_info("%s PMU driver: ", pmu->name); + /* Check and dump the PMU for each PMU on hybrid. */ + if (h_pmu) { + if (!check_hw_exists(pmu, hybrid(pmu, cntr_mask), + hybrid(pmu, fixed_cntr_mask))) { + cpuc->pmu =3D NULL; + return false; + } + cpumask_set_cpu(cpu, &h_pmu->supported_cpus); =20 - pr_cont("\n"); + pr_info("%s PMU driver: ", h_pmu->name); =20 - x86_pmu_show_pmu_cap(&pmu->pmu); + pr_cont("\n"); + } =20 -end: - cpumask_set_cpu(cpu, &pmu->supported_cpus); - cpuc->pmu =3D &pmu->pmu; + x86_pmu_show_pmu_cap(pmu); =20 return true; } @@ -5077,7 +5094,7 @@ static void intel_pmu_cpu_starting(int cpu) int core_id =3D topology_core_id(cpu); int i; =20 - if (is_hybrid() && !init_hybrid_pmu(cpu)) + if (!update_intel_pmu(cpu)) return; =20 init_debug_store_on_cpu(cpu); @@ -6545,6 +6562,8 @@ __init int intel_pmu_init(void) x86_pmu.pebs_events_mask =3D intel_pmu_pebs_mask(x86_pmu.cntr_mask64); x86_pmu.pebs_capable =3D PEBS_COUNTER_MASK; =20 + x86_pmu.flags |=3D PMU_FL_LATE_SETUP; + /* * Quirk: v2 perfmon does not report fixed-purpose events, so * assume at least 3 events, when not running in a hypervisor: @@ -7349,18 +7368,10 @@ __init int intel_pmu_init(void) x86_pmu.attr_update =3D hybrid_attr_update; } =20 - intel_pmu_check_counters_mask(&x86_pmu.cntr_mask64, - &x86_pmu.fixed_cntr_mask64, - &x86_pmu.intel_ctrl); - /* AnyThread may be deprecated on arch perfmon v5 or later */ if (x86_pmu.intel_cap.anythread_deprecated) x86_pmu.format_attrs =3D intel_arch_formats_attr; =20 - intel_pmu_check_event_constraints(x86_pmu.event_constraints, - x86_pmu.cntr_mask64, - x86_pmu.fixed_cntr_mask64, - x86_pmu.intel_ctrl); /* * Access LBR MSR may cause #GP under certain circumstances. * Check all LBR MSR here. @@ -7391,8 +7402,6 @@ __init int intel_pmu_init(void) } } =20 - intel_pmu_check_extra_regs(x86_pmu.extra_regs); - /* Support full width counters using alternative MSR range */ if (x86_pmu.intel_cap.full_width_write) { x86_pmu.max_period =3D x86_pmu.cntval_mask >> 1; @@ -7408,9 +7417,6 @@ __init int intel_pmu_init(void) x86_pmu.addr_offset =3D intel_pmu_v6_addr_offset; } =20 - if (!is_hybrid() && x86_pmu.intel_cap.perf_metrics) - x86_pmu.intel_ctrl |=3D 1ULL << GLOBAL_CTRL_EN_PERF_METRICS; - if (x86_pmu.intel_cap.pebs_timing_info) x86_pmu.flags |=3D PMU_FL_RETIRE_LATENCY; =20 diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index a698e6484b3b..cece99165cfb 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1066,6 +1066,7 @@ do { \ #define PMU_FL_MEM_LOADS_AUX 0x100 /* Require an auxiliary event for the c= omplete memory info */ #define PMU_FL_RETIRE_LATENCY 0x200 /* Support Retire Latency in PEBS */ #define PMU_FL_BR_CNTR 0x400 /* Support branch counter logging */ +#define PMU_FL_LATE_SETUP 0x800 /* Setup/Update PMU info when CPU starts */ =20 #define EVENT_VAR(_id) event_attr_##_id #define EVENT_PTR(_id) &event_attr_##_id.attr.attr --=20 2.38.1