]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf header: Refactor get_cpuid to take a CPU for ARM
authorIan Rogers <irogers@google.com>
Thu, 7 Nov 2024 16:20:30 +0000 (08:20 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 16 Nov 2024 19:37:54 +0000 (16:37 -0300)
ARM BIG.little has no notion of a constant CPUID for both core
types. To reflect this reality, change the get_cpuid function to also
pass in a possibly unused logical cpu.

If the dummy value (-1) is passed in then ARM can, as currently happens,
select the first logical CPU's "CPUID".

The changes to ARM getcpuid happen in a follow up change.

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-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/arm64/util/header.c
tools/perf/arch/loongarch/util/header.c
tools/perf/arch/powerpc/util/header.c
tools/perf/arch/riscv/util/header.c
tools/perf/arch/s390/util/header.c
tools/perf/arch/x86/util/auxtrace.c
tools/perf/arch/x86/util/header.c
tools/perf/builtin-kvm.c
tools/perf/util/env.c
tools/perf/util/header.c
tools/perf/util/header.h

index 741df3614a09acb21c05f23864251d27926564d5..760c21784713b5778010737125f0a4765cd987f7 100644 (file)
@@ -50,7 +50,7 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
        return ret;
 }
 
-int get_cpuid(char *buf, size_t sz)
+int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus();
        int ret;
index d962dff55512b39c9d6adfb4f5ad76f9857df404..f1f0b116962d3a6f1d2594485a47ca52cb9dc7da 100644 (file)
@@ -70,7 +70,7 @@ out_free:
        return cpuid;
 }
 
-int get_cpuid(char *buffer, size_t sz)
+int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        int ret = 0;
        char *cpuid = _get_cpuid();
index 251cdbf58a4de6a0f28993968f3db9dfb9463ead..6d1a63a2922f84e4149a47911cc90c11baf4a9b6 100644 (file)
@@ -24,7 +24,7 @@ static bool is_compat_mode(void)
 }
 
 int
-get_cpuid(char *buffer, size_t sz)
+get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        unsigned long pvr;
        int nb;
index 1b29030021eeba71e34eeb8adcf69278f11a1dda..ebac294c877f0ba6c7de258819ee48982fda65e4 100644 (file)
@@ -81,7 +81,7 @@ free:
        return cpuid;
 }
 
-int get_cpuid(char *buffer, size_t sz)
+int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        char *cpuid = _get_cpuid();
        int ret = 0;
index 7933f6871c8180e73a5fb33b57e14a65cbffda5e..2add1a5612420aea01c6433359b8c4090e3eab83 100644 (file)
@@ -27,7 +27,7 @@
 #define SYSINFO                "/proc/sysinfo"
 #define SRVLVL         "/proc/service_levels"
 
-int get_cpuid(char *buffer, size_t sz)
+int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        char *cp, *line = NULL, *line2;
        char type[8], model[33], version[8], manufacturer[32], authorization[8];
index 354780ff1605dba58c68191e30b9081aca315d3d..ecbf61a7eb3a3edc4d925c3a8daaa8f997021790 100644 (file)
@@ -55,11 +55,12 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
                                              int *err)
 {
        char buffer[64];
+       struct perf_cpu cpu = perf_cpu_map__min(evlist->core.all_cpus);
        int ret;
 
        *err = 0;
 
-       ret = get_cpuid(buffer, sizeof(buffer));
+       ret = get_cpuid(buffer, sizeof(buffer), cpu);
        if (ret) {
                *err = ret;
                return NULL;
index a51444a77a5f2bc3146c1937f8e6fd1eceadc9c9..690f86cbbb1ca3d993240fa4a1c1d25a8399b96e 100644 (file)
@@ -58,7 +58,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt)
 }
 
 int
-get_cpuid(char *buffer, size_t sz)
+get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
 {
        return __get_cpuid(buffer, sz, "%s,%u,%u,%u$");
 }
index 099ce3ebf67ce6eef823e3330a67743d1fb6b9f4..274568d712d12f9ada0ce141518b2eb526cb9537 100644 (file)
@@ -1226,7 +1226,9 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm)
        int err;
 
        if (kvm->live) {
-               err = get_cpuid(buf, sizeof(buf));
+               struct perf_cpu cpu = {-1};
+
+               err = get_cpuid(buf, sizeof(buf), cpu);
                if (err != 0) {
                        pr_err("Failed to look up CPU type: %s\n",
                               str_error_r(err, buf, sizeof(buf)));
index ccb46402664289471e11667923c51c50f259d374..93cabdd7ff4321bfb2e3a4624ed3e8434dc606cf 100644 (file)
@@ -373,7 +373,8 @@ error:
 int perf_env__read_cpuid(struct perf_env *env)
 {
        char cpuid[128];
-       int err = get_cpuid(cpuid, sizeof(cpuid));
+       struct perf_cpu cpu = {-1};
+       int err = get_cpuid(cpuid, sizeof(cpuid), cpu);
 
        if (err)
                return err;
index c7552a78a7be22795dcc3e50a416a3331c2174f1..ecf08b458b056bd58688cfef95585d2bb0088aa3 100644 (file)
@@ -856,18 +856,19 @@ int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid)
  * default get_cpuid(): nothing gets recorded
  * actual implementation must be in arch/$(SRCARCH)/util/header.c
  */
-int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused)
+int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused,
+                    struct perf_cpu cpu __maybe_unused)
 {
        return ENOSYS; /* Not implemented */
 }
 
-static int write_cpuid(struct feat_fd *ff,
-                      struct evlist *evlist __maybe_unused)
+static int write_cpuid(struct feat_fd *ff, struct evlist *evlist)
 {
+       struct perf_cpu cpu = perf_cpu_map__min(evlist->core.all_cpus);
        char buffer[64];
        int ret;
 
-       ret = get_cpuid(buffer, sizeof(buffer));
+       ret = get_cpuid(buffer, sizeof(buffer), cpu);
        if (ret)
                return -1;
 
index e91e89d225371feb587ca8f494a4857aede2b4fe..b77f89de12dde12e81fc34501c5df41fe176de05 100644 (file)
@@ -201,7 +201,7 @@ int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cntp);
 /*
  * arch specific callback
  */
-int get_cpuid(char *buffer, size_t sz);
+int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu);
 
 char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
 int strcmp_cpuid_str(const char *s1, const char *s2);