git: db2dc24da9d6 - stable/14 - hwpmc: fix event allocation on pre-Zen AMD CPUs

Olivier Cochard <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a71b628.42184.fbe3620__49712.7354655945$1785837121$gmane$org@gitrepo.freebsd.org>
The branch stable/14 has been updated by olivier:

URL: https://cgit.FreeBSD.org/src/commit/?id=db2dc24da9d6fadd8cae0f36d8458f7ee5ab336b

commit db2dc24da9d6fadd8cae0f36d8458f7ee5ab336b
Author:     Olivier Cochard <[email protected]>
AuthorDate: 2026-07-28 19:06:27 +0000
Commit:     Olivier Cochard <[email protected]>
CommitDate: 2026-08-04 09:49:32 +0000

    hwpmc: fix event allocation on pre-Zen AMD CPUs
    
    amd_allocate_pmc() chose the pmu-events code path whenever pmc_cpuid was
    non-empty, and rejected any allocation lacking PMC_F_EV_PMU.
    But pmc_cpuid is set for every AMD CPU, while the pmu-events tables only cover
    Zen and later.
    On older families (K8, Bobcat, Jaguar/16h, Bulldozer) libpmc finds no
    pmu-events entry and falls back to the legacy path, which never sets
    PMC_F_EV_PMU.
    
    Reviewed by:    mhorne
    Approved by:    mhorne
    MFC after:      1 week
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D58468
    
    (cherry picked from commit 6c4d9b9af1a3b247bf82a4228c835d106f535613)
---
 sys/dev/hwpmc/hwpmc_amd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c
index fbbaf92a1547..8e1a6ad25be7 100644
--- a/sys/dev/hwpmc/hwpmc_amd.c
+++ b/sys/dev/hwpmc/hwpmc_amd.c
@@ -582,9 +582,6 @@ amd_allocate_pmc(int cpu, int ri, struct pmc *pm,
 	if (pd->pd_class != a->pm_class)
 		return EINVAL;
 
-	if ((a->pm_flags & PMC_F_EV_PMU) == 0)
-		return (EINVAL);
-
 	caps = pm->pm_caps;
 
 	PMCDBG2(MDP,ALL,1,"amd-allocate ri=%d caps=0x%x", ri, caps);
@@ -596,7 +593,8 @@ amd_allocate_pmc(int cpu, int ri, struct pmc *pm,
 	if((ri >= 12 && ri < 16) && !(a->pm_md.pm_amd.pm_amd_sub_class == PMC_AMD_SUB_CLASS_DATA_FABRIC))
 		return EINVAL;
 
-	if (strlen(pmc_cpuid) != 0) {
+	/* PMC_F_EV_PMU: config comes from pmu-events tables. */
+	if ((a->pm_flags & PMC_F_EV_PMU) != 0) {
 		pm->pm_md.pm_amd.pm_amd_evsel =
 			a->pm_md.pm_amd.pm_amd_config;
 		PMCDBG2(MDP,ALL,2,"amd-allocate ri=%d -> config=0x%x", ri, a->pm_md.pm_amd.pm_amd_config);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.