[Patch v10 09/23] perf/x86/intel: Centralize PERF_PMU_CAP_EXTENDED_REGS updates

From: Dapeng Mi

Date: Tue Jul 21 2026 - 02:39:30 EST


PERF_PMU_CAP_EXTENDED_REGS is currently updated in multiple paths:
intel_ds_pebs_init() and __intel_update_pmu_caps() for adaptive and
architectural PEBS. This split makes the capability flow harder to
reason about and is awkward for upcoming XSAVES-based SIMD register
sampling, which also needs consistent capability setup and validation.

Refactor the update logic into a single helper,
__intel_update_pmu_xregs_caps(), so adaptive and architectural PEBS
share one implementation.

Call this helper from intel_update_pmu_caps() to keep PMU capability
handling centralized in one place and avoid duplicated or conflicting
updates.

Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 16 ++++++++--------
arch/x86/events/intel/ds.c | 1 -
2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index ee62b24d3fdf..aecaa109c31e 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -6187,11 +6187,14 @@ static inline bool intel_pmu_broken_perf_cap(void)
return false;
}

-static inline void __intel_update_pmu_caps(struct pmu *pmu)
+static inline void __intel_update_pmu_xregs_caps(struct pmu *pmu)
{
struct pmu *dest_pmu = pmu ? pmu : x86_get_pmu(smp_processor_id());
+ u64 caps = hybrid(pmu, arch_pebs_cap).caps;

- if (hybrid(pmu, arch_pebs_cap).caps & ARCH_PEBS_VECR_XMM)
+ if ((x86_pmu.arch_pebs && (caps & ARCH_PEBS_VECR_XMM)) ||
+ (!x86_pmu.arch_pebs && x86_pmu.intel_cap.pebs_format >= 4 &&
+ x86_pmu.intel_cap.pebs_baseline))
dest_pmu->capabilities |= PERF_PMU_CAP_EXTENDED_REGS;
}

@@ -6263,12 +6266,10 @@ static void update_pmu_cap_from_perfmonext(struct pmu *pmu)
hybrid(pmu, arch_pebs_cap).counters = pebs_mask;
hybrid(pmu, arch_pebs_cap).pdists = pdists_mask;

- if (WARN_ON((pebs_mask | pdists_mask) & ~cntrs_mask)) {
+ if (WARN_ON((pebs_mask | pdists_mask) & ~cntrs_mask))
x86_pmu.arch_pebs = 0;
- } else {
- __intel_update_pmu_caps(pmu);
+ else
__intel_update_large_pebs_flags(pmu);
- }
} else {
WARN_ON(x86_pmu.arch_pebs == 1);
x86_pmu.arch_pebs = 0;
@@ -6292,6 +6293,7 @@ static void intel_update_pmu_caps(struct pmu *pmu)
hybrid_pmu(pmu)->pmu_type == hybrid_big)
hybrid(pmu, intel_cap).perf_metrics = 1;
}
+ __intel_update_pmu_xregs_caps(pmu);
}

static void intel_pmu_check_hybrid_pmus(struct x86_hybrid_pmu *pmu)
@@ -6445,8 +6447,6 @@ static void intel_pmu_cpu_starting(int cpu)
}
}

- __intel_update_pmu_caps(cpuc->pmu);
-
if (!cpuc->shared_regs)
return;

diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 9355744a9258..d50d9de6c17f 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -3389,7 +3389,6 @@ static void __init intel_ds_pebs_init(void)
x86_pmu.flags |= PMU_FL_PEBS_ALL;
x86_pmu.pebs_capable = ~0ULL;
pebs_qual = "-baseline";
- x86_get_pmu(smp_processor_id())->capabilities |= PERF_PMU_CAP_EXTENDED_REGS;
} else {
/* Only basic record supported */
x86_pmu.large_pebs_flags &=
--
2.34.1