Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf arm64 header: Use cpu argument in get_cpuid

Use the cpu to read the MIDR file requested. If the "any" value (-1) is
passed that keep the behavior of returning the first MIDR file that can
be read.

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Xu Yang <xu.yang_2@nxp.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ben Zong-You Xie <ben717@andestech.com>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Clément Le Goffic <clement.legoffic@foss.st.com>
Cc: Dima Kogan <dima@secretsauce.net>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-riscv@lists.infradead.org
Link: https://lore.kernel.org/r/20241107162035.52206-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
538737da cec0d657

+31 -33
+30 -33
tools/perf/arch/arm64/util/header.c
··· 14 14 #define MIDR_REVISION_MASK GENMASK(3, 0) 15 15 #define MIDR_VARIANT_MASK GENMASK(23, 20) 16 16 17 - static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) 17 + static int _get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) 18 18 { 19 + char path[PATH_MAX]; 20 + FILE *file; 19 21 const char *sysfs = sysfs__mountpoint(); 20 - struct perf_cpu cpu; 21 - int idx, ret = EINVAL; 22 22 23 + assert(cpu.cpu != -1); 23 24 if (!sysfs || sz < MIDR_SIZE) 24 25 return EINVAL; 25 26 26 - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { 27 - char path[PATH_MAX]; 28 - FILE *file; 27 + scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, sysfs, cpu.cpu); 29 28 30 - scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, 31 - sysfs, cpu.cpu); 32 - 33 - file = fopen(path, "r"); 34 - if (!file) { 35 - pr_debug("fopen failed for file %s\n", path); 36 - continue; 37 - } 38 - 39 - if (!fgets(buf, MIDR_SIZE, file)) { 40 - fclose(file); 41 - continue; 42 - } 43 - fclose(file); 44 - 45 - /* got midr break loop */ 46 - ret = 0; 47 - break; 29 + file = fopen(path, "r"); 30 + if (!file) { 31 + pr_debug("fopen failed for file %s\n", path); 32 + return EINVAL; 48 33 } 49 34 50 - return ret; 35 + if (!fgets(buf, MIDR_SIZE, file)) { 36 + pr_debug("Failed to read file %s\n", path); 37 + fclose(file); 38 + return EINVAL; 39 + } 40 + fclose(file); 41 + return 0; 51 42 } 52 43 53 - int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused) 44 + int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) 54 45 { 55 - struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); 56 - int ret; 46 + struct perf_cpu_map *cpus; 47 + int idx; 57 48 49 + if (cpu.cpu != -1) 50 + return _get_cpuid(buf, sz, cpu); 51 + 52 + cpus = perf_cpu_map__new_online_cpus(); 58 53 if (!cpus) 59 54 return EINVAL; 60 55 61 - ret = _get_cpuid(buf, sz, cpus); 56 + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { 57 + int ret = _get_cpuid(buf, sz, cpu); 62 58 63 - perf_cpu_map__put(cpus); 64 - 65 - return ret; 59 + if (ret == 0) 60 + return 0; 61 + } 62 + return EINVAL; 66 63 } 67 64 68 65 char *get_cpuid_str(struct perf_pmu *pmu) ··· 75 78 return NULL; 76 79 77 80 /* read midr from list of cpus mapped to this pmu */ 78 - res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus); 81 + res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus)); 79 82 if (res) { 80 83 pr_err("failed to get cpuid string for PMU %s\n", pmu->name); 81 84 free(buf);
+1
tools/perf/util/header.h
··· 11 11 #include <linux/types.h> 12 12 #include "env.h" 13 13 #include "pmu.h" 14 + #include <perf/cpumap.h> 14 15 15 16 enum { 16 17 HEADER_RESERVED = 0, /* always cleared */