[PATCH v4 13/15] perf arm_spe: Refactor arm_spe__get_metadata_by_cpu()
James Clark
james.clark at linaro.org
Thu Sep 11 09:09:21 PDT 2025
On 31/07/2025 2:25 pm, Leo Yan wrote:
> 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 2ac10b8008527a066c9b2f67a22eb8511af9239a..3c32b9bc9c983370e37d871adeaa610bf5905c1d 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(perf_session__env(spe->session));
> 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;
>
>
Reviewed-by: James Clark <james.clark at linaro.org>
More information about the linux-arm-kernel
mailing list