Commit 494c403f authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str



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: default avatarJames Clark <james.clark@linaro.org>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarXu 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7463ee17
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "../../../util/debug.h"
#include "../../../util/auxtrace.h"
#include "../../../util/record.h"
#include "../../../util/header.h"
#include "../../../util/arm-spe.h"
#include <tools/libc_compat.h> // reallocarray

@@ -85,22 +86,11 @@ static int arm_spe_save_cpu_header(struct auxtrace_record *itr,
	struct arm_spe_recording *sper =
			container_of(itr, struct arm_spe_recording, itr);
	struct perf_pmu *pmu = NULL;
	struct perf_pmu tmp_pmu;
	char cpu_id_str[16];
	char *cpuid = NULL;
	u64 val;

	snprintf(cpu_id_str, sizeof(cpu_id_str), "%d", cpu.cpu);
	tmp_pmu.cpus = perf_cpu_map__new(cpu_id_str);
	if (!tmp_pmu.cpus)
		return -ENOMEM;

	/* Read CPU MIDR */
	cpuid = perf_pmu__getcpuid(&tmp_pmu);

	/* The CPU map will not be used anymore, release it */
	perf_cpu_map__put(tmp_pmu.cpus);

	cpuid = get_cpuid_allow_env_override(cpu);
	if (!cpuid)
		return -ENOMEM;
	val = strtol(cpuid, NULL, 16);
+4 −8
Original line number Diff line number Diff line
@@ -62,22 +62,18 @@ int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
	return EINVAL;
}

char *get_cpuid_str(struct perf_pmu *pmu)
char *get_cpuid_str(struct perf_cpu cpu)
{
	char *buf = NULL;
	char *buf = malloc(MIDR_SIZE);
	int res;

	if (!pmu || !pmu->cpus)
		return NULL;

	buf = malloc(MIDR_SIZE);
	if (!buf)
		return NULL;

	/* read midr from list of cpus mapped to this pmu */
	res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus));
	res = get_cpuid(buf, MIDR_SIZE, cpu);
	if (res) {
		pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
		pr_err("failed to get cpuid string for CPU %d\n", cpu.cpu);
		free(buf);
		buf = NULL;
	}
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
	return ret;
}

char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
char *get_cpuid_str(struct perf_cpu cpu __maybe_unused)
{
	return _get_cpuid();
}
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
}

char *
get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
get_cpuid_str(struct perf_cpu cpu __maybe_unused)
{
	char *bufp;
	unsigned long pvr;
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
}

char *
get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
get_cpuid_str(struct perf_cpu cpu __maybe_unused)
{
	return _get_cpuid();
}
Loading