perf env: Ensure failure broken topology file reads are always -1 encoded
authorIan Rogers <irogers@google.com>
Mon, 18 Nov 2024 22:53:39 +0000 (14:53 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2024 20:52:42 +0000 (17:52 -0300)
get_core_id returns 0 on success and a negative errno value on error.
Currently the error can only be -1, but fixing this to be any errno
value breaks perf:

  https://lore.kernel.org/lkml/Zzu4Sdebve-NXEMX@google.com/

To avoid this, make sure all error values are written as -1.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Paran Lee <p4ranlee@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Cc: Ze Gao <zegao2021@gmail.com>
Cc: Zixian Cai <fzczx123@gmail.com>
Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20241118225345.889810-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/env.c

index e2843ca2edd92ea5fa1c020ae92b183c496e975e..e890a52e01a6d1bf0f3a85095977f1c85d1658d1 100644 (file)
@@ -326,10 +326,13 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
 
        for (idx = 0; idx < nr_cpus; ++idx) {
                struct perf_cpu cpu = { .cpu = idx };
+               int core_id   = cpu__get_core_id(cpu);
+               int socket_id = cpu__get_socket_id(cpu);
+               int die_id    = cpu__get_die_id(cpu);
 
-               env->cpu[idx].core_id   = cpu__get_core_id(cpu);
-               env->cpu[idx].socket_id = cpu__get_socket_id(cpu);
-               env->cpu[idx].die_id    = cpu__get_die_id(cpu);
+               env->cpu[idx].core_id   = core_id >= 0 ? core_id : -1;
+               env->cpu[idx].socket_id = socket_id >= 0 ? socket_id : -1;
+               env->cpu[idx].die_id    = die_id >= 0 ? die_id : -1;
        }
 
        env->nr_cpus_avail = nr_cpus;