[PATCH v3 12/14] perf arm_spe: Refactor arm_spe__get_metadata_by_cpu()
Leo Yan
leo.yan at arm.com
Mon Jul 7 06:39:34 PDT 2025
Handle "CPU=-1" (per-thread mode) in the arm_spe__get_metadata_by_cpu()
function. As a result, the function is more general and will be invoked
by a sequential change.
Signed-off-by: Leo Yan <leo.yan at arm.com>
---
tools/perf/util/arm-spe.c | 55 ++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 29 deletions(-)
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 87cbba941d6f3066697ff430d6ce8e085b173032..e89182b6d27d3d00357db72d804f1d22d5765937 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -317,15 +317,38 @@ static int arm_spe_set_tid(struct arm_spe_queue *speq, pid_t tid)
return 0;
}
-static u64 *arm_spe__get_metadata_by_cpu(struct arm_spe *spe, u64 cpu)
+static u64 *arm_spe__get_metadata_by_cpu(struct arm_spe *spe, int cpu)
{
+ struct perf_cpu_map *cpus;
+ struct perf_cpu perf_cpu;
u64 i;
if (!spe->metadata)
return NULL;
+ /* CPU ID is -1 for per-thread mode */
+ if (cpu < 0) {
+ /*
+ * On the heterogeneous system, due to CPU ID is -1,
+ * cannot confirm the data source packet is supported.
+ */
+ if (!spe->is_homogeneous)
+ return NULL;
+
+ cpus = perf_pmus__find_by_type(spe->pmu_type)->cpus;
+ if (!cpus)
+ return NULL;
+
+ /* In a homogeneous system, fetch the first CPU in the map. */
+ perf_cpu = perf_cpu_map__cpu(cpus, 0);
+ if (perf_cpu.cpu == -1)
+ return NULL;
+
+ cpu = perf_cpu.cpu;
+ }
+
for (i = 0; i < spe->metadata_nr_cpu; i++)
- if (spe->metadata[i][ARM_SPE_CPU] == cpu)
+ if (spe->metadata[i][ARM_SPE_CPU] == (u64)cpu)
return spe->metadata[i];
return NULL;
@@ -914,9 +937,6 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
union perf_mem_data_src *data_src)
{
struct arm_spe *spe = speq->spe;
- struct perf_cpu_map *cpus;
- struct perf_cpu perf_cpu;
- int16_t cpu_nr;
u64 *metadata = NULL;
u64 midr;
unsigned int i;
@@ -929,30 +949,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
cpuid = perf_env__cpuid(spe->session->evlist->env);
midr = strtol(cpuid, NULL, 16);
} else {
- /* CPU ID is -1 for per-thread mode */
- if (speq->cpu < 0) {
- /*
- * On the heterogeneous system, due to CPU ID is -1,
- * cannot confirm the data source packet is supported.
- */
- if (!spe->is_homogeneous)
- return false;
-
- cpus = perf_pmus__find_by_type(spe->pmu_type)->cpus;
- if (!cpus)
- return false;
-
- /* In a homogeneous system, fetch the first CPU in the map. */
- perf_cpu = perf_cpu_map__cpu(cpus, 0);
- if (perf_cpu.cpu == -1)
- return false;
-
- cpu_nr = perf_cpu.cpu;
- } else {
- cpu_nr = speq->cpu;
- }
-
- metadata = arm_spe__get_metadata_by_cpu(spe, cpu_nr);
+ metadata = arm_spe__get_metadata_by_cpu(spe, speq->cpu);
if (!metadata)
return false;
--
2.34.1
More information about the linux-arm-kernel
mailing list