git: 3dba72dfef75 - stable/15 - libpmc: Fix AMD L3 counter parameter parsing

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 03 Nov 2026 14:19:21 UTC
The branch stable/15 has been updated by mhorne:

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

commit 3dba72dfef7577c054cbe9ee551321b811106d8b
Author:     Ali Mashtizadeh <ali@mashtizadeh.com>
AuthorDate: 2026-07-31 02:11:17 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-03 14:18:51 +0000

    libpmc: Fix AMD L3 counter parameter parsing
    
    Fix two small bugs affecting the event parsing of AMD L3 counters.
    AMD's manual and JSON disagree about the naming scheme on recent
    processors.  I use the naming scheme present in the recent PPRs to be
    consistent, so in the JSON parser we rename 'allslices' to 'allsources'
    just as we already do with sliceid and sourceid.  Also ensure that we
    parse the 0x prefix present in the newer JSON files.
    
    Reviewed by:    mhorne
    Sponsored by:   Netflix
    MFC after:      1 week
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2180
    
    (cherry picked from commit d38b3a5ead0d3507080da5321144219b13d43aa9)
---
 lib/libpmc/libpmc_pmu_util.c    | 8 ++++----
 lib/libpmc/pmu-events/jevents.c | 9 ++++++++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c
index f0083258650d..6bac92b312ef 100644
--- a/lib/libpmc/libpmc_pmu_util.c
+++ b/lib/libpmc/libpmc_pmu_util.c
@@ -371,13 +371,13 @@ pmu_parse_event(struct pmu_event_desc *ped, const char *eventin)
 		else if (strcmp(key, "l3_slice_mask") == 0)
 			ped->ped_l3_slice = strtol(value, NULL, 16);
 		else if (strcmp(key, "sourceid") == 0)
-			ped->ped_sourceid = strtol(value, NULL, 16);
+			ped->ped_sourceid = strtol(value, NULL, 0);
 		else if (strcmp(key, "coreid") == 0)
-			ped->ped_coreid = strtol(value, NULL, 16);
+			ped->ped_coreid = strtol(value, NULL, 0);
 		else if (strcmp(key, "allcores") == 0)
-			ped->ped_allcores = strtol(value, NULL, 10);
+			ped->ped_allcores = strtol(value, NULL, 0);
 		else if (strcmp(key, "allsources") == 0)
-			ped->ped_allsources = strtol(value, NULL, 10);
+			ped->ped_allsources = strtol(value, NULL, 0);
 		else if (strcmp(key, "pebs") == 0)
 			ped->ped_pebs = strtol(value, NULL, 10);
 		else {
diff --git a/lib/libpmc/pmu-events/jevents.c b/lib/libpmc/pmu-events/jevents.c
index facec3361c70..b4d073f13708 100644
--- a/lib/libpmc/pmu-events/jevents.c
+++ b/lib/libpmc/pmu-events/jevents.c
@@ -623,7 +623,14 @@ static int json_events(const char *fn,
 			} else if (json_streq(map, field, "EnAllCores")) {
 				addfield(map, &allcores, "", "allcores=", val);
 			} else if (json_streq(map, field, "EnAllSlices")) {
-				addfield(map, &allslices, "", "allslices=", val);
+				/*
+				 * We use the AMD PPR Family 1Ah Model 70h
+				 * naming scheme of allsources rather than
+				 * slices.  The symbol EnAllSlices is not used
+				 * anywhere except in Zen 4+ for the L3
+				 * counters.
+				 */
+				addfield(map, &allslices, "", "allsources=", val);
 			} else if (json_streq(map, field, "SliceId")) {
 				/*
 				 * We use sourceid because there's a