git: e59d51666a56 - main - hwpmc_amd: rename away from K8

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 14:09:36 UTC
The branch main has been updated by mhorne:

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

commit e59d51666a564113f9404c342fcb6029a7f05618
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2026-04-24 14:42:47 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-17 14:07:29 +0000

    hwpmc_amd: rename away from K8
    
    K8 is the ancient/initial 64-bit AMD processers. We are retaining
    support for these, but our AMD hwpmc class has grown substantially. We
    don't want to emphasize this old naming as it is a potential source of
    confusion.
    
    The PMC_CLASS_K8 name is retained as an alias, and still used in the K8
    code in libpmc.c.
    
    Reviewed by:    Andre Silva <andasilv@amd.com> (previous version)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D60100
---
 lib/libpmc/libpmc_pmu_util.c    |  2 +-
 lib/libpmc/pmc.3                |  8 ++++----
 sys/amd64/include/pmc_mdep.h    |  2 +-
 sys/dev/hwpmc/hwpmc_amd.c       | 34 +++++++++++++++++++---------------
 sys/i386/include/pmc_mdep.h     |  2 +-
 sys/sys/pmc.h                   |  5 ++++-
 tests/sys/pmc/pmc_exterr_test.c | 12 ++++++------
 7 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c
index 53d9d8766add..eca163ac5d92 100644
--- a/lib/libpmc/libpmc_pmu_util.c
+++ b/lib/libpmc/libpmc_pmu_util.c
@@ -583,7 +583,7 @@ pmc_pmu_amd_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm,
 	if (ped->ped_umask > 0) {
 		pm->pm_caps |= PMC_CAP_QUALIFIER;
 	}
-	pm->pm_class = PMC_CLASS_K8;
+	pm->pm_class = PMC_CLASS_AMD;
 	pe = pmu_event_get(NULL, event_name, &idx);
 
 	if (pe->pmu == NULL) {
diff --git a/lib/libpmc/pmc.3 b/lib/libpmc/pmc.3
index bb051b87ec13..39bcbb421a0f 100644
--- a/lib/libpmc/pmc.3
+++ b/lib/libpmc/pmc.3
@@ -21,7 +21,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd June 23, 2023
+.Dd November 17, 2026
 .Dt PMC 3
 .Os
 .Sh NAME
@@ -229,9 +229,9 @@ performance measurement architecture version 1 and later.
 Instruction Based Sampling (IBS) counters present in
 .Tn AMD
 Family 10h and above.
-.It Li PMC_CLASS_K8
+.It Li PMC_CLASS_AMD
 Programmable hardware counters present in
-.Tn "AMD Athlon64"
+.Tn "AMD"
 CPUs.
 .It Li PMC_CLASS_PERF
 MPERF and APERF counters present in
@@ -509,7 +509,7 @@ following manual pages:
 .It Li PMC_CLASS_IAF    Ta Xr pmc.iaf 3
 .It Li PMC_CLASS_IAP    Ta Xr pmc.atom 3 , Xr pmc.core 3 , Xr pmc.core2 3
 .It Li PMC_CLASS_IBS    Ta Xr pmc.ibs 3
-.It Li PMC_CLASS_K8     Ta Xr pmc.amd 3
+.It Li PMC_CLASS_AMD    Ta Xr pmc.amd 3
 .It Li PMC_CLASS_RAPL   Ta Xr pmc.rapl 3
 .It Li PMC_CLASS_PERF   Ta Xr pmc.perf 3
 .It Li PMC_CLASS_TSC    Ta Xr pmc.tsc 3
diff --git a/sys/amd64/include/pmc_mdep.h b/sys/amd64/include/pmc_mdep.h
index f073d1f7594c..812e63edddb9 100644
--- a/sys/amd64/include/pmc_mdep.h
+++ b/sys/amd64/include/pmc_mdep.h
@@ -53,7 +53,7 @@ struct pmc_mdep;
  * IAF, IAP, UCF and UCP.
  */
 #define	PMC_MDEP_CLASS_INDEX_TSC	1
-#define	PMC_MDEP_CLASS_INDEX_K8		2
+#define	PMC_MDEP_CLASS_INDEX_AMD	2
 #define	PMC_MDEP_CLASS_INDEX_IBS	3
 #define	PMC_MDEP_CLASS_INDEX_P4		2
 #define	PMC_MDEP_CLASS_INDEX_IAP	2
diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c
index e85a3af7cba8..7f505e568c68 100644
--- a/sys/dev/hwpmc/hwpmc_amd.c
+++ b/sys/dev/hwpmc/hwpmc_amd.c
@@ -30,7 +30,11 @@
  * SUCH DAMAGE.
  */
 
-/* Support for the AMD K8 and later processors */
+/*
+ * Support for 64-bit AMD processors:
+ *  - Zen families of microarchitectures
+ *  - (legacy) K8-K10, up to Bulldozer and Jaguar families
+ */
 
 #include <sys/param.h>
 #include <sys/lock.h>
@@ -57,7 +61,7 @@
 
 DPCPU_DEFINE_STATIC(uint32_t, nmi_counter);
 
-/* AMD K8 PMCs */
+/* AMD PMC decriptors */
 struct amd_descr {
 	struct pmc_descr pm_descr;   /* "base class" */
 	uint32_t	pm_evsel;    /* address of EVSEL register */
@@ -1281,7 +1285,7 @@ amd_pcpu_init(struct pmc_mdep *md, int cpu)
 	 * state and initialize pointers in the MI per-cpu descriptor.
 	 */
 	pc = pmc_pcpu[cpu];
-	first_ri = md->pmd_classdep[PMC_MDEP_CLASS_INDEX_K8].pcd_ri;
+	first_ri = md->pmd_classdep[PMC_MDEP_CLASS_INDEX_AMD].pcd_ri;
 
 	KASSERT(pc != NULL, ("[amd,%d] NULL per-cpu pointer", __LINE__));
 
@@ -1340,7 +1344,7 @@ amd_pcpu_fini(struct pmc_mdep *md, int cpu)
 	pc = pmc_pcpu[cpu];
 	KASSERT(pc != NULL, ("[amd,%d] NULL per-cpu state", __LINE__));
 
-	first_ri = md->pmd_classdep[PMC_MDEP_CLASS_INDEX_K8].pcd_ri;
+	first_ri = md->pmd_classdep[PMC_MDEP_CLASS_INDEX_AMD].pcd_ri;
 
 	/*
 	 * Reset pointers in the MI 'per-cpu' state.
@@ -1629,8 +1633,8 @@ pmc_amd_initialize(void)
 	for (i = 0; i < amd_core_npmcs; i++) {
 		d = &amd_pmcdesc[i];
 		snprintf(d->pm_descr.pd_name, PMC_NAME_MAX,
-		    "K8-%d", i);
-		d->pm_descr.pd_class = PMC_CLASS_K8;
+		    "AMD-%d", i);
+		d->pm_descr.pd_class = PMC_CLASS_AMD;
 		d->pm_descr.pd_caps = AMD_PMC_CAPS;
 		/*
 		 * Zen 5 can precisely count retire events.
@@ -1660,8 +1664,8 @@ pmc_amd_initialize(void)
 		for (i = 0; i < amd_l3_npmcs; i++) {
 			d = &amd_pmcdesc[amd_npmcs + i];
 			snprintf(d->pm_descr.pd_name, PMC_NAME_MAX,
-			    "K8-L3-%d", i);
-			d->pm_descr.pd_class = PMC_CLASS_K8;
+			    "AMD-L3-%d", i);
+			d->pm_descr.pd_class = PMC_CLASS_AMD;
 			d->pm_descr.pd_caps = AMD_PMC_L3_CAPS;
 			d->pm_descr.pd_width = 48;
 			d->pm_evsel = AMD_PMC_L3_BASE + 2 * i;
@@ -1676,8 +1680,8 @@ pmc_amd_initialize(void)
 		for (i = 0; i < amd_df_npmcs; i++) {
 			d = &amd_pmcdesc[amd_npmcs + i];
 			snprintf(d->pm_descr.pd_name, PMC_NAME_MAX,
-			    "K8-DF-%d", i);
-			d->pm_descr.pd_class = PMC_CLASS_K8;
+			    "AMD-DF-%d", i);
+			d->pm_descr.pd_class = PMC_CLASS_AMD;
 			d->pm_descr.pd_caps = AMD_PMC_DF_CAPS;
 			d->pm_descr.pd_width = 48;
 			d->pm_evsel = AMD_PMC_DF_BASE + 2 * i;
@@ -1700,8 +1704,8 @@ pmc_amd_initialize(void)
 			hw = ch * pmcs_per_umc + j;
 			d = &amd_pmcdesc[amd_npmcs + i];
 			snprintf(d->pm_descr.pd_name, PMC_NAME_MAX,
-			    "K8-UMC%d-%d", ch, i);
-			d->pm_descr.pd_class = PMC_CLASS_K8;
+			    "AMD-UMC%d-%d", ch, i);
+			d->pm_descr.pd_class = PMC_CLASS_AMD;
 			d->pm_descr.pd_caps = AMD_PMC_UMC_CAPS;
 			d->pm_descr.pd_width = 48;
 			d->pm_evsel = AMD_PMC_UMC_BASE + 2 * hw;
@@ -1776,11 +1780,11 @@ pmc_amd_initialize(void)
 	if (error != 0)
 		goto error;
 
-	/* Initialize AMD K8 PMC handling. */
-	pcd = &pmc_mdep->pmd_classdep[PMC_MDEP_CLASS_INDEX_K8];
+	/* Initialize AMD PMC handling. */
+	pcd = &pmc_mdep->pmd_classdep[PMC_MDEP_CLASS_INDEX_AMD];
 
 	pcd->pcd_caps		= AMD_PMC_CAPS;
-	pcd->pcd_class		= PMC_CLASS_K8;
+	pcd->pcd_class		= PMC_CLASS_AMD;
 	pcd->pcd_num		= amd_npmcs;
 	pcd->pcd_ri		= pmc_mdep->pmd_npmc;
 	pcd->pcd_width		= 48;
diff --git a/sys/i386/include/pmc_mdep.h b/sys/i386/include/pmc_mdep.h
index e8c500e4b81d..741048b13d76 100644
--- a/sys/i386/include/pmc_mdep.h
+++ b/sys/i386/include/pmc_mdep.h
@@ -62,7 +62,7 @@ struct pmc_mdep;
  * IAF, IAP, UCF and UCP.
  */
 #define	PMC_MDEP_CLASS_INDEX_TSC	1
-#define	PMC_MDEP_CLASS_INDEX_K8		2
+#define	PMC_MDEP_CLASS_INDEX_AMD	2
 #define	PMC_MDEP_CLASS_INDEX_IBS	3
 #define	PMC_MDEP_CLASS_INDEX_IAP	2
 #define	PMC_MDEP_CLASS_INDEX_IAF	3
diff --git a/sys/sys/pmc.h b/sys/sys/pmc.h
index 05e73bbcc337..4e3d16c2687d 100644
--- a/sys/sys/pmc.h
+++ b/sys/sys/pmc.h
@@ -141,7 +141,7 @@ enum pmc_cputype {
  */
 #define	__PMC_CLASSES()								\
     __PMC_CLASS(TSC,		0x00,	"CPU Timestamp counter")		\
-    __PMC_CLASS(K8,		0x02,	"AMD K8 performance counters")		\
+    __PMC_CLASS(AMD,		0x02,	"AMD performance counters")		\
     __PMC_CLASS(IBS,		0x03,	"AMD IBS performance counters")		\
     __PMC_CLASS(IAF,		0x06,	"Intel Core2/Atom, fixed function")	\
     __PMC_CLASS(IAP,		0x07,	"Intel Core...Atom, programmable")	\
@@ -169,6 +169,9 @@ enum pmc_class {
 #define	PMC_CLASS_FIRST	PMC_CLASS_TSC
 #define	PMC_CLASS_LAST	PMC_CLASS_PERF
 
+/* Compat for the old name. */
+#define	PMC_CLASS_K8	PMC_CLASS_AMD
+
 /*
  * A PMC can be in the following states:
  *
diff --git a/tests/sys/pmc/pmc_exterr_test.c b/tests/sys/pmc/pmc_exterr_test.c
index bc4d260f2ed4..69b721445d45 100644
--- a/tests/sys/pmc/pmc_exterr_test.c
+++ b/tests/sys/pmc/pmc_exterr_test.c
@@ -254,11 +254,11 @@ ATF_TC_BODY(amd_invalid_subclass, tc)
 
 	ATF_REQUIRE_FEATURE("exterr_strings");
 	require_hwpmc();
-	require_class(PMC_CLASS_K8, "AMD");
+	require_class(PMC_CLASS_AMD, "AMD");
 	clear_exterr();
 
 	memset(&pa, 0, sizeof(pa));
-	pa.pm_class = PMC_CLASS_K8;
+	pa.pm_class = PMC_CLASS_AMD;
 	pa.pm_mode = PMC_MODE_TC;
 	pa.pm_cpu = PMC_CPU_ANY;
 	pa.pm_flags = PMC_F_EV_PMU;
@@ -276,13 +276,13 @@ ATF_TC_BODY(amd_invalid_config_bits, tc)
 
 	ATF_REQUIRE_FEATURE("exterr_strings");
 	require_hwpmc();
-	require_class(PMC_CLASS_K8, "AMD");
+	require_class(PMC_CLASS_AMD, "AMD");
 	if (!pmc_pmu_enabled())
 		atf_tc_skip("AMD PMU raw allocation path is unavailable");
 	clear_exterr();
 
 	memset(&pa, 0, sizeof(pa));
-	pa.pm_class = PMC_CLASS_K8;
+	pa.pm_class = PMC_CLASS_AMD;
 	pa.pm_mode = PMC_MODE_TC;
 	pa.pm_cpu = PMC_CPU_ANY;
 	pa.pm_flags = PMC_F_EV_PMU;
@@ -315,13 +315,13 @@ ATF_TC_BODY(amd_invalid_df_config_bits, tc)
 
 	ATF_REQUIRE_FEATURE("exterr_strings");
 	require_hwpmc();
-	require_class(PMC_CLASS_K8, "AMD");
+	require_class(PMC_CLASS_AMD, "AMD");
 	if (!pmc_pmu_enabled())
 		atf_tc_skip("AMD PMU raw allocation path is unavailable");
 	clear_exterr();
 
 	memset(&pa, 0, sizeof(pa));
-	pa.pm_class = PMC_CLASS_K8;
+	pa.pm_class = PMC_CLASS_AMD;
 	pa.pm_mode = PMC_MODE_SC;
 	pa.pm_cpu = 0;
 	pa.pm_flags = PMC_F_EV_PMU;