The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=c215eef345501ce7dda374909b3195d9d69a4e9f
commit c215eef345501ce7dda374909b3195d9d69a4e9f Author: Ali Mashtizadeh <[email protected]> AuthorDate: 2026-01-23 05:34:13 +0000 Commit: Mitchell Horne <[email protected]> CommitDate: 2026-02-03 15:21:50 +0000 libpmc: Fix the L3 counters for AMD Zen 1-4 On AMD processors libpmc was using the topic field (based on filename) to determine the counter's subclass. Unfortunately, the JSON definitions for AMD Zen 1-4 have the L3 counters in files shared with other counters. This change has libpmc to use the pmu field (which is derived from the Unit field in JSON) to determine the correct counter subclass. Reviewed by: mhorne MFC after: 2 weeks Sponsored by: Netflix Pull Request: https://github.com/freebsd/freebsd-src/pull/1984 --- lib/libpmc/libpmc_pmu_util.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c index 74a93ae963d7..de642aa71a18 100644 --- a/lib/libpmc/libpmc_pmu_util.c +++ b/lib/libpmc/libpmc_pmu_util.c @@ -498,18 +498,7 @@ pmc_pmu_amd_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm, pm->pm_class = PMC_CLASS_K8; pe = pmu_event_get(NULL, event_name, &idx); - if (strcmp("l3cache", pe->topic) == 0){ - amd->pm_amd_config |= AMD_PMC_TO_EVENTMASK(ped->ped_event); - amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_L3_CACHE; - amd->pm_amd_config |= AMD_PMC_TO_L3SLICE(ped->ped_l3_slice); - amd->pm_amd_config |= AMD_PMC_TO_L3CORE(ped->ped_l3_thread); - } - else if (strcmp("data fabric", pe->topic) == 0){ - - amd->pm_amd_config |= AMD_PMC_TO_EVENTMASK_DF(ped->ped_event); - amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_DATA_FABRIC; - } - else{ + if (pe->pmu == NULL) { amd->pm_amd_config |= AMD_PMC_TO_EVENTMASK(ped->ped_event); amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_CORE; if ((pm->pm_caps & (PMC_CAP_USER|PMC_CAP_SYSTEM)) == 0 || @@ -526,7 +515,19 @@ pmc_pmu_amd_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm, amd->pm_amd_config |= AMD_PMC_INVERT; if (pm->pm_caps & PMC_CAP_INTERRUPT) amd->pm_amd_config |= AMD_PMC_INT; + } else if (strcmp("amd_l3", pe->pmu) == 0) { + amd->pm_amd_config |= AMD_PMC_TO_EVENTMASK(ped->ped_event); + amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_L3_CACHE; + amd->pm_amd_config |= AMD_PMC_TO_L3SLICE(ped->ped_l3_slice); + amd->pm_amd_config |= AMD_PMC_TO_L3CORE(ped->ped_l3_thread); + } else if (strcmp("amd_df", pe->pmu) == 0) { + amd->pm_amd_config |= AMD_PMC_TO_EVENTMASK_DF(ped->ped_event); + amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_DATA_FABRIC; + } else { + printf("PMC pmu '%s' is not supported!\n", pe->pmu); + return (EOPNOTSUPP); } + return (0); }
