* [PATCH v1] perf arch x86: Zero-pad CPUID model for GenuineIntel in get_cpuid_str()
@ 2026-07-15 21:11 Chun-Tse Shao
0 siblings, 0 replies; only message in thread
From: Chun-Tse Shao @ 2026-07-15 21:11 UTC (permalink / raw)
To: irogers, acme, namhyung
Cc: peterz, mingo, alexander.shishkin, jolsa, adrian.hunter,
james.clark, afaerber, mani, dapeng1.mi, thomas.falcon,
linux-perf-users, linux-kernel, Chun-Tse Shao
Change the model formatting in get_cpuid_str() for GenuineIntel CPUs from
"%X" to "%02X", while preserving unpadded "%X" for non-Intel vendors.
Intel vendor events in mapfile.csv (generated by create_perf_json.py
from the upstream perfmon repository) use 2-character hex model strings
(e.g. "GenuineIntel-6-9A", "GenuineIntel-6-BE", "GenuineIntel-18-01").
When an Intel model number is a single hex digit (e.g. 0x01 or 0x03),
formatting with "%X" yields "GenuineIntel-18-1", which fails to match
mapfile entries expecting "01".
Non-Intel vendors (such as AMD) use unpadded model numbers in mapfile.csv
(e.g. "AuthenticAMD-23-([12][0-9A-F]|[0-9A-F])"). Zero-padding non-Intel
vendors would break AMD CPUID matching by causing single-digit AMD models
(like Zen 1) to match "01" against "AuthenticAMD-23-[[:xdigit:]]+" (Zen 2).
Restricting "%02X" zero-padding specifically to GenuineIntel CPUs ensures
both Intel and AMD CPUID strings match their respective mapfile entries
without regressions.
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
| 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
--git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
index 412977f8aa83..4b6d619fb8f9 100644
--- a/tools/perf/arch/x86/util/header.c
+++ b/tools/perf/arch/x86/util/header.c
@@ -66,8 +66,17 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
char *get_cpuid_str(struct perf_cpu cpu __maybe_unused)
{
char *buf = malloc(128);
+ char vendor[16];
+ unsigned int lvl;
+
+ if (!buf)
+ return NULL;
+
+ get_cpuid_0(vendor, &lvl);
+ /* Intel mapfile entries use 2-character hex model numbers */
+ const char *fmt = !strcmp(vendor, "GenuineIntel") ? "%s-%u-%02X-%X$" : "%s-%u-%X-%X$";
- if (buf && __get_cpuid(buf, 128, "%s-%u-%X-%X$") < 0) {
+ if (__get_cpuid(buf, 128, fmt) < 0) {
free(buf);
return NULL;
}
--
2.55.0.141.g00534a21ce-goog
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-15 21:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-15 21:11 [PATCH v1] perf arch x86: Zero-pad CPUID model for GenuineIntel in get_cpuid_str() Chun-Tse Shao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox