mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
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>
This commit is contained in:
parent
cec0d6572a
commit
538737da96
@ -14,55 +14,52 @@
|
||||
#define MIDR_REVISION_MASK GENMASK(3, 0)
|
||||
#define MIDR_VARIANT_MASK GENMASK(23, 20)
|
||||
|
||||
static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
|
||||
static int _get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
FILE *file;
|
||||
const char *sysfs = sysfs__mountpoint();
|
||||
struct perf_cpu cpu;
|
||||
int idx, ret = EINVAL;
|
||||
|
||||
assert(cpu.cpu != -1);
|
||||
if (!sysfs || sz < MIDR_SIZE)
|
||||
return EINVAL;
|
||||
|
||||
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
|
||||
char path[PATH_MAX];
|
||||
FILE *file;
|
||||
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, sysfs, cpu.cpu);
|
||||
|
||||
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR,
|
||||
sysfs, cpu.cpu);
|
||||
|
||||
file = fopen(path, "r");
|
||||
if (!file) {
|
||||
pr_debug("fopen failed for file %s\n", path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fgets(buf, MIDR_SIZE, file)) {
|
||||
fclose(file);
|
||||
continue;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
/* got midr break loop */
|
||||
ret = 0;
|
||||
break;
|
||||
file = fopen(path, "r");
|
||||
if (!file) {
|
||||
pr_debug("fopen failed for file %s\n", path);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
if (!fgets(buf, MIDR_SIZE, file)) {
|
||||
pr_debug("Failed to read file %s\n", path);
|
||||
fclose(file);
|
||||
return EINVAL;
|
||||
}
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused)
|
||||
int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
|
||||
{
|
||||
struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus();
|
||||
int ret;
|
||||
struct perf_cpu_map *cpus;
|
||||
int idx;
|
||||
|
||||
if (cpu.cpu != -1)
|
||||
return _get_cpuid(buf, sz, cpu);
|
||||
|
||||
cpus = perf_cpu_map__new_online_cpus();
|
||||
if (!cpus)
|
||||
return EINVAL;
|
||||
|
||||
ret = _get_cpuid(buf, sz, cpus);
|
||||
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
|
||||
int ret = _get_cpuid(buf, sz, cpu);
|
||||
|
||||
perf_cpu_map__put(cpus);
|
||||
|
||||
return ret;
|
||||
if (ret == 0)
|
||||
return 0;
|
||||
}
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
char *get_cpuid_str(struct perf_pmu *pmu)
|
||||
@ -78,7 +75,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
|
||||
return NULL;
|
||||
|
||||
/* read midr from list of cpus mapped to this pmu */
|
||||
res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus);
|
||||
res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus));
|
||||
if (res) {
|
||||
pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
|
||||
free(buf);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <linux/types.h>
|
||||
#include "env.h"
|
||||
#include "pmu.h"
|
||||
#include <perf/cpumap.h>
|
||||
|
||||
enum {
|
||||
HEADER_RESERVED = 0, /* always cleared */
|
||||
|
Loading…
Reference in New Issue
Block a user