mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chun-Tse Shao <ctshao@google.com>
To: irogers@google.com, acme@kernel.org, namhyung@kernel.org
Cc: peterz@infradead.org, mingo@redhat.com,
	alexander.shishkin@linux.intel.com,  jolsa@kernel.org,
	adrian.hunter@intel.com, james.clark@linaro.org,
	 afaerber@suse.de, mani@kernel.org, dapeng1.mi@linux.intel.com,
	 thomas.falcon@intel.com, linux-perf-users@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Chun-Tse Shao <ctshao@google.com>
Subject: [PATCH v1] perf arch x86: Zero-pad CPUID model for GenuineIntel in get_cpuid_str()
Date: Wed, 15 Jul 2026 14:11:44 -0700	[thread overview]
Message-ID: <20260715211144.3144895-1-ctshao@google.com> (raw)

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


                 reply	other threads:[~2026-07-15 21:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260715211144.3144895-1-ctshao@google.com \
    --to=ctshao@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=afaerber@suse.de \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=thomas.falcon@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome