git: a01ea5156198 - main - libpmc: Map AMD Family 1Ah models 00h-0Fh to amdzen5

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Wed, 04 Nov 2026 17:54:29 UTC
The branch main has been updated by mhorne:

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

commit a01ea5156198fd6ae284a0d84b957b978fa017eb
Author:     Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-04 17:51:45 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-04 17:53:55 +0000

    libpmc: Map AMD Family 1Ah models 00h-0Fh to amdzen5
    
    178d0b5b8da7 adapted the Zen 5 pattern matching from Linux perf.
    However, Linux prints CPU models with a single digit when under 0xF
    (allowing |[[:xdigit:]] to match 0h-Fh), whereas hwpmc/libpmc formats
    model numbers with two leading hex digits (00h-0Fh).
    
    Fix the pattern to explicitly cover two-digit hex models in the 00h-0Fh
    range, and add a test case verifying table selection across Zen 5 and Zen 6
    cpuid strings.
    
    Reviewed by:    Ali Mashtizadeh <ali@mashtizadeh.com>
    Signed-off-by:  Osvaldo Janeri Filho <ojanerif@amd.com>
    Fixes:          178d0b5b8da7 ("libpmc: Import AMD Zen 6 PMU events.")
    Sponsored by:   Advanced Micro Devices, Inc.
    Differential Revision:  https://reviews.freebsd.org/D60625
---
 lib/libpmc/pmu-events/arch/x86/mapfile.csv |  2 +-
 tests/sys/pmc/Makefile                     |  1 +
 tests/sys/pmc/pmc_mapfile_test.c           | 87 ++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/lib/libpmc/pmu-events/arch/x86/mapfile.csv b/lib/libpmc/pmu-events/arch/x86/mapfile.csv
index 40e859b25f19..05480113bd1c 100644
--- a/lib/libpmc/pmu-events/arch/x86/mapfile.csv
+++ b/lib/libpmc/pmu-events/arch/x86/mapfile.csv
@@ -59,6 +59,6 @@ AuthenticAMD-23-[012][0-9A-F],v2,amdzen1,core
 AuthenticAMD-23-[[:xdigit:]]+,v1,amdzen2,core
 AuthenticAMD-25-[0245][[:xdigit:]],v1,amdzen3,core
 AuthenticAMD-25-[[:xdigit:]]+,v1,amdzen4,core
-AuthenticAMD-26-[12467][[:xdigit:]],v1,amdzen5,core
+AuthenticAMD-26-[012467][[:xdigit:]],v1,amdzen5,core
 AuthenticAMD-26-[[:xdigit:]]+,v1,amdzen6,core
 HygonGenuine-24-00,v2,amdzen1,core
diff --git a/tests/sys/pmc/Makefile b/tests/sys/pmc/Makefile
index d31103e11fb5..c44932483c9a 100644
--- a/tests/sys/pmc/Makefile
+++ b/tests/sys/pmc/Makefile
@@ -6,6 +6,7 @@ ATF_TESTS_C+=	pmc_detach_test
 ATF_TESTS_C+=	pmc_exec_test
 .if ${MACHINE_ARCH} == "amd64"
 ATF_TESTS_C+=	pmc_exterr_test
+ATF_TESTS_C+=	pmc_mapfile_test
 .endif
 ATF_TESTS_C+=	pmc_lifecycle_test
 ATF_TESTS_C+=	pmc_log_test
diff --git a/tests/sys/pmc/pmc_mapfile_test.c b/tests/sys/pmc/pmc_mapfile_test.c
new file mode 100644
index 000000000000..91a9d6e84bf7
--- /dev/null
+++ b/tests/sys/pmc/pmc_mapfile_test.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2026 Advanced Micro Devices, Inc.
+ *
+ * Author: Osvaldo Janeri Filho <ojanerif@amd.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * libpmc picks its pmu-events table by matching kern.hwpmc.cpuid against
+ * mapfile.csv.  hwpmc prints the model with two digits, so Turin (Family
+ * 1Ah, model 02h) is "AuthenticAMD-26-02-<stepping>".  For Zen 5 and Zen 6
+ * cpuid strings, look up an event that only one of amdzen5 and amdzen6 has.
+ * No PMC hardware is needed.
+ */
+
+#include <sys/param.h>
+
+#include <atf-c.h>
+#include <pmc.h>
+
+#define	ZEN5_ONLY_EVENT	"bp_l2_btb_correct"
+#define	ZEN6_ONLY_EVENT	"bp_fe_redir.all"
+
+static const char *const zen5_cpuids[] = {
+	"AuthenticAMD-26-02-0",
+	"AuthenticAMD-26-0F-0",
+	"AuthenticAMD-26-11-0",
+	"AuthenticAMD-26-2F-0",
+	"AuthenticAMD-26-44-0",
+	"AuthenticAMD-26-70-0",
+	"AuthenticAMD-26-7F-0",
+};
+
+static const char *const zen6_cpuids[] = {
+	"AuthenticAMD-26-50-0",
+	"AuthenticAMD-26-80-0",
+	"AuthenticAMD-26-C0-0",
+	"AuthenticAMD-26-D8-0",
+	"AuthenticAMD-26-EF-0",
+};
+
+static void
+check_table(const char *cpuid, const char *has, const char *lacks,
+    const char *table)
+{
+	ATF_CHECK_MSG(pmc_pmu_idx_get_by_event(cpuid, has) >= 0 &&
+	    pmc_pmu_idx_get_by_event(cpuid, lacks) < 0,
+	    "%s does not select %s", cpuid, table);
+}
+
+ATF_TC(zen5_models);
+ATF_TC_HEAD(zen5_models, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Zen 5 cpuid strings, including models 00h-0Fh, select amdzen5");
+}
+ATF_TC_BODY(zen5_models, tc)
+{
+	size_t i;
+
+	for (i = 0; i < nitems(zen5_cpuids); i++)
+		check_table(zen5_cpuids[i], ZEN5_ONLY_EVENT, ZEN6_ONLY_EVENT,
+		    "amdzen5");
+}
+
+ATF_TC(zen6_models);
+ATF_TC_HEAD(zen6_models, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Zen 6 cpuid strings select amdzen6");
+}
+ATF_TC_BODY(zen6_models, tc)
+{
+	size_t i;
+
+	for (i = 0; i < nitems(zen6_cpuids); i++)
+		check_table(zen6_cpuids[i], ZEN6_ONLY_EVENT, ZEN5_ONLY_EVENT,
+		    "amdzen6");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, zen5_models);
+	ATF_TP_ADD_TC(tp, zen6_models);
+
+	return (atf_no_error());
+}