mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

On ARM the cpuid is dependent on the core type of the CPU in question. The PMU was passed for the sake of the CPU map but this means in places a temporary PMU is created just to pass a CPU value. Just pass the CPU and fix up the callers. As there are no longer PMU users in header.h, shuffle forward declarations earlier to work around build failures. 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-7-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
96 lines
1.7 KiB
C
96 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Implementation of get_cpuid().
|
|
*
|
|
* Author: Nikita Shubin <n.shubin@yadro.com>
|
|
* Bibo Mao <maobibo@loongson.cn>
|
|
* Huacai Chen <chenhuacai@loongson.cn>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <api/fs/fs.h>
|
|
#include <errno.h>
|
|
#include "util/debug.h"
|
|
#include "util/header.h"
|
|
|
|
/*
|
|
* Output example from /proc/cpuinfo
|
|
* CPU Family : Loongson-64bit
|
|
* Model Name : Loongson-3C5000
|
|
* CPU Revision : 0x10
|
|
* FPU Revision : 0x01
|
|
*/
|
|
#define CPUINFO_MODEL "Model Name"
|
|
#define CPUINFO "/proc/cpuinfo"
|
|
|
|
static char *_get_field(const char *line)
|
|
{
|
|
char *line2, *nl;
|
|
|
|
line2 = strrchr(line, ' ');
|
|
if (!line2)
|
|
return NULL;
|
|
|
|
line2++;
|
|
nl = strrchr(line, '\n');
|
|
if (!nl)
|
|
return NULL;
|
|
|
|
return strndup(line2, nl - line2);
|
|
}
|
|
|
|
static char *_get_cpuid(void)
|
|
{
|
|
unsigned long line_sz;
|
|
char *line, *model, *cpuid;
|
|
FILE *file;
|
|
|
|
file = fopen(CPUINFO, "r");
|
|
if (file == NULL)
|
|
return NULL;
|
|
|
|
line = model = cpuid = NULL;
|
|
while (getline(&line, &line_sz, file) != -1) {
|
|
if (strncmp(line, CPUINFO_MODEL, strlen(CPUINFO_MODEL)))
|
|
continue;
|
|
|
|
model = _get_field(line);
|
|
if (!model)
|
|
goto out_free;
|
|
break;
|
|
}
|
|
|
|
if (model && (asprintf(&cpuid, "%s", model) < 0))
|
|
cpuid = NULL;
|
|
|
|
out_free:
|
|
fclose(file);
|
|
free(model);
|
|
return cpuid;
|
|
}
|
|
|
|
int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
|
|
{
|
|
int ret = 0;
|
|
char *cpuid = _get_cpuid();
|
|
|
|
if (!cpuid)
|
|
return EINVAL;
|
|
|
|
if (sz < strlen(cpuid)) {
|
|
ret = ENOBUFS;
|
|
goto out_free;
|
|
}
|
|
|
|
scnprintf(buffer, sz, "%s", cpuid);
|
|
|
|
out_free:
|
|
free(cpuid);
|
|
return ret;
|
|
}
|
|
|
|
char *get_cpuid_str(struct perf_cpu cpu __maybe_unused)
|
|
{
|
|
return _get_cpuid();
|
|
}
|