Skip to contentSkip to conversation

perf header: exempt x86_64 from core id test

PATCH In review Anubhav Shelat 2 participants 3 messages Jun 17, 2025 – Jun 18, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf header: exempt x86_64 from core id test

On a VM running on an x86_64 architecture, it is possible for the socket id to be greater than the processor number. So exclude x86_64 arch from the core id test.

---
 tools/perf/util/header.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/header.c +4 -1
index e3cdc3b7b4ab..c1b4651d0c6a 100644
@@ -2618,9 +2618,12 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)
 	 * The socket_id number might be higher than the numbers of cpus.
 	 * This depends on the configuration.
 	 * AArch64 is the same.
+	 * It is also possible for a VM running x86_64 to have a larger
+	 * socket_id number than the number of cpus.
 	 */
 	if (ph->env.arch && (!strncmp(ph->env.arch, "s390", 4)
-			  || !strncmp(ph->env.arch, "aarch64", 7)))
+			  || !strncmp(ph->env.arch, "aarch64", 7)
+			  || !strncmp(ph->env.arch, "x86_64", 6)))
 		do_core_id_test = false;
 
 	for (i = 0; i < (u32)cpu_nr; i++) {
Signature · 1 line
2.49.0
reviewer
#1 lore raw
Quoted 16 lines · Anubhav Shelat

On a VM running on an x86_64 architecture, it is possible for the socket id to be greater than the processor number. So exclude x86_64 arch from the core id test.

---
 tools/perf/util/header.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/header.c +0 -0
index e3cdc3b7b4ab..c1b4651d0c6a 100644
@@ -2618,9 +2618,12 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)
         * The socket_id number might be higher than the numbers of cpus.

tools/perf/util/header.c static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) · line 2627

Quoted 10 lines
tools/perf/util/header.c +4 -1
         * This depends on the configuration.
         * AArch64 is the same.
+        * It is also possible for a VM running x86_64 to have a larger
+        * socket_id number than the number of cpus.
         */
        if (ph->env.arch && (!strncmp(ph->env.arch, "s390", 4)
-                         || !strncmp(ph->env.arch, "aarch64", 7)))
+                         || !strncmp(ph->env.arch, "aarch64", 7)
+                         || !strncmp(ph->env.arch, "x86_64", 6)))
                do_core_id_test = false;

Why do we have a boolean called do_core_id_test that is checking a value assigned to the socket_id? :-)
I think at this point the test:

```
                if (do_core_id_test && nr != (u32)-1 && nr > (u32)cpu_nr) {
                       pr_debug("socket_id number is too big."
                                "You may need to upgrade the perf tool.\n");
                       goto free_cpu;
               }
```

has no purpose and we can just delete it.

Thanks,
Ian

Quoted 5 lines
tools/perf/util/header.c +0 -1
        for (i = 0; i < (u32)cpu_nr; i++) {
--

2.49.0

#2 lore raw

Yeah that makes more sense. I can send a patch to delete the test.

Anubhav

Quoted 50 lines · Ian Rogers
Quoted 16 lines · Anubhav Shelat

On a VM running on an x86_64 architecture, it is possible for the socket id to be greater than the processor number. So exclude x86_64 arch from the core id test.

---
 tools/perf/util/header.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/header.c +0 -0
index e3cdc3b7b4ab..c1b4651d0c6a 100644
@@ -2618,9 +2618,12 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)
         * The socket_id number might be higher than the numbers of cpus.

tools/perf/util/header.c static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) · line 2627

Quoted 10 lines
tools/perf/util/header.c +4 -1
         * This depends on the configuration.
         * AArch64 is the same.
+        * It is also possible for a VM running x86_64 to have a larger
+        * socket_id number than the number of cpus.
         */
        if (ph->env.arch && (!strncmp(ph->env.arch, "s390", 4)
-                         || !strncmp(ph->env.arch, "aarch64", 7)))
+                         || !strncmp(ph->env.arch, "aarch64", 7)
+                         || !strncmp(ph->env.arch, "x86_64", 6)))
                do_core_id_test = false;

Why do we have a boolean called do_core_id_test that is checking a value assigned to the socket_id? :-)
I think at this point the test:

```
                if (do_core_id_test && nr != (u32)-1 && nr > (u32)cpu_nr) {
                       pr_debug("socket_id number is too big."
                                "You may need to upgrade the perf tool.\n");
                       goto free_cpu;
               }
```

has no purpose and we can just delete it.

Thanks,
Ian

Quoted 5 lines
tools/perf/util/header.c +0 -1
        for (i = 0; i < (u32)cpu_nr; i++) {
--

2.49.0