[PATCH v1] perf arch x86: Zero-pad CPUID model for GenuineIntel in get_cpuid_str()

From: Chun-Tse Shao

Date: Wed Jul 15 2026 - 17:11:54 EST


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@xxxxxxxxxx>
---
tools/perf/arch/x86/util/header.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --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