git: 869bb2bbb780 - main - hwpmc: use the PerfMonV2 DF encoding on Family 19h
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 04 Nov 2026 17:47:59 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=869bb2bbb7809e79cd672a6adc46bdc79a38f382
commit 869bb2bbb7809e79cd672a6adc46bdc79a38f382
Author: Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-04 17:43:15 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-04 17:47:57 +0000
hwpmc: use the PerfMonV2 DF encoding on Family 19h
Family 19h processors with PerfMonV2 use the Family 1Ah DF encoding.
Selecting it by family alone drops the upper unit mask bits, and most
DF events count zero.
Reviewed by: Ali Mashtizadeh <ali@mashtizadeh.com>
Sponsored by: AMD
MFC after: 1 week
Signed-off-by: Osvaldo Janeri Filho <ojanerif@amd.com>
Differential Revision: https://reviews.freebsd.org/D60769
---
lib/libpmc/libpmc_pmu_util.c | 21 ++++++++++++++++++++-
sys/dev/hwpmc/hwpmc_amd.c | 2 +-
sys/dev/hwpmc/hwpmc_amd.h | 4 ++--
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c
index e0fac9884b77..6472dd8311de 100644
--- a/lib/libpmc/libpmc_pmu_util.c
+++ b/lib/libpmc/libpmc_pmu_util.c
@@ -34,6 +34,12 @@
#include <sys/errno.h>
#include <sys/pmc.h>
#include <sys/sysctl.h>
+
+#if defined(__amd64__) || defined(__i386__)
+#include <machine/cpufunc.h>
+#endif
+
+#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
@@ -520,6 +526,18 @@ pmc_pmu_print_counter_full(const char *ev)
}
#if defined(__amd64__) || defined(__i386__)
+static bool
+pmu_events_amd_perfmonv2(void)
+{
+ u_int regs[4];
+
+ do_cpuid(0x80000000, regs);
+ if (regs[0] < CPUID_EXTPERFMON)
+ return (false);
+ do_cpuid(CPUID_EXTPERFMON, regs);
+ return (EXTPERFMON_PERFMONV2(regs[0]) != 0);
+}
+
static int
pmc_pmu_amd_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm,
struct pmu_event_desc *ped)
@@ -581,7 +599,8 @@ pmc_pmu_amd_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm,
}
} else if (strcmp("amd_df", pe->pmu) == 0) {
amd->pm_amd_sub_class = PMC_AMD_SUB_CLASS_DATA_FABRIC;
- if (cpu_family <= 0x19) {
+ if (cpu_family < 0x19 ||
+ (cpu_family == 0x19 && !pmu_events_amd_perfmonv2())) {
amd->pm_amd_config |=
AMD_PMC_DF1_TO_EVENTMASK(ped->ped_event);
amd->pm_amd_config |=
diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c
index 14e850ee7410..dac50207656d 100644
--- a/sys/dev/hwpmc/hwpmc_amd.c
+++ b/sys/dev/hwpmc/hwpmc_amd.c
@@ -250,7 +250,7 @@ amd_init_policy(void)
amd_l3_allowed_mask = (family <= 0x17) ?
AMD_PMC_L3_FAMILY17_MASK : AMD_PMC_L3_FAMILY19_MASK;
- amd_df_allowed_mask = (family <= 0x19) ?
+ amd_df_allowed_mask = (family <= 0x19 && !amd_perfmon_v2) ?
AMD_PMC_DF_FAMILY17_MASK : AMD_PMC_DF_FAMILY1A_MASK;
amd_umc_allowed_mask = AMD_PMC_UMC_MASK;
diff --git a/sys/dev/hwpmc/hwpmc_amd.h b/sys/dev/hwpmc/hwpmc_amd.h
index 4936ea620884..e12ef90bb51a 100644
--- a/sys/dev/hwpmc/hwpmc_amd.h
+++ b/sys/dev/hwpmc/hwpmc_amd.h
@@ -158,8 +158,8 @@
PMC_CAP_QUALIFIER | PMC_CAP_DOMWIDE)
/*
- * DF counters change their encoding between Family 19h and Family 1Ah
- * processors.
+ * DF counters change their encoding between Family 19h processors without
+ * PerfMonV2 and later processors.
*
* Refer to the same documents as the L3 counters.
*/