From: Ian Rogers Date: Mon, 18 Nov 2024 22:53:39 +0000 (-0800) Subject: perf env: Ensure failure broken topology file reads are always -1 encoded X-Git-Tag: v6.14-rc1~29^2~163 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=925c25efcaf047ba6abe67dbef8581cc6c12b54c;p=linux-block.git perf env: Ensure failure broken topology file reads are always -1 encoded 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 Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Athira Rajeev Cc: Ben Gainey Cc: Colin Ian King Cc: Dominique Martinet Cc: Ilkka Koskinen Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Oliver Upton Cc: Paran Lee Cc: Peter Zijlstra Cc: Steinar H. Gunderson Cc: Steven Rostedt (VMware) Cc: Thomas Falcon Cc: Weilin Wang Cc: Yang Jihong Cc: Yang Li Cc: Ze Gao Cc: Zixian Cai Cc: zhaimingbing Link: https://lore.kernel.org/r/20241118225345.889810-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index e2843ca2edd9..e890a52e01a6 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -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;