[PATCH v2 11/13] perf arm_spe: Refactor arm_spe__get_metadata_by_cpu()

Ian Rogers irogers at google.com
Mon Jun 30 09:53:18 PDT 2025


On Mon, Jun 30, 2025 at 8:24 AM Leo Yan <leo.yan at arm.com> 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.
>
> Reviewed-by: James Clark <james.clark at linaro.org>
> Signed-off-by: Leo Yan <leo.yan at arm.com>
> ---
>  tools/perf/util/arm-spe.c | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 3715afbe1e4713b5eebb00afbcb3eaa56ff1c49c..5b6699f192e5e58bab6b0d8e2e8df80fdf404a36 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -324,6 +324,19 @@ static u64 *arm_spe__get_metadata_by_cpu(struct arm_spe *spe, u64 cpu)
>         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 meta data.
> +                */
> +               if (!spe->is_homogeneous)
> +                       return NULL;
> +
> +               /* In homogeneous system, simply use CPU0's metadata */

Could this be derived from the spe's pmu_type? Something like
perf_pmus__find_by_type(spe->pmu_type)->cpus ?

Thanks,
Ian

> +               return spe->metadata[0];
> +       }
> +
>         for (i = 0; i < spe->metadata_nr_cpu; i++)
>                 if (spe->metadata[i][ARM_SPE_CPU] == cpu)
>                         return spe->metadata[i];
> @@ -926,22 +939,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;
> -
> -                       /* In homogeneous system, simply use CPU0's metadata */
> -                       if (spe->metadata)
> -                               metadata = spe->metadata[0];
> -               } else {
> -                       metadata = arm_spe__get_metadata_by_cpu(spe, speq->cpu);
> -               }
> -
> +               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