[PATCH v4 12/15] perf arm_spe: Improve CPU number retrieving in per-thread mode

James Clark james.clark at linaro.org
Thu Sep 11 09:08:31 PDT 2025



On 31/07/2025 2:25 pm, Leo Yan wrote:
> In per-thread mode on a homogeneous system, the current code simply
> picks the first metadata entry for data source parsing.
> 
> This change improves that by using the PMU type to find the matching PMU
> event. From there, it reads the CPU map and uses the first CPU ID to
> fetch the metadata.
> 
> Although this makes no difference when there's only one Arm SPE PMU, it
> helps for future support of multiple SPE events.
> 
> Signed-off-by: Leo Yan <leo.yan at arm.com>
> ---
>   tools/perf/util/arm-spe.c | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index db681dd2aed205655e77f3dfcd7eb3c33f20277a..2ac10b8008527a066c9b2f67a22eb8511af9239a 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -914,6 +914,9 @@ 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;
> @@ -935,13 +938,21 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
>   			if (!spe->is_homogeneous)
>   				return false;
>   
> -			/* In homogeneous system, simply use CPU0's metadata */
> -			if (spe->metadata)
> -				metadata = spe->metadata[0];
> +			cpus = perf_pmus__find_by_type(spe->pmu_type)->cpus;

You can't run perf_pmus__find_by_type() at this point because we're 
decoding and might not even be running on the same system or even 
architecture.

If we've already determined that it's homogeneous I don't think this is 
much of an improvement anwyay. Looks like handling multiple SPE 
instances needs a lot more work than this. We should skip doing it in 
this patchset and do it properly on its own later.

> +			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 {
> -			metadata = arm_spe__get_metadata_by_cpu(spe, speq->cpu);
> +			cpu_nr = speq->cpu;
>   		}
>   
> +		metadata = arm_spe__get_metadata_by_cpu(spe, cpu_nr);
>   		if (!metadata)
>   			return false;
>   
> 




More information about the linux-arm-kernel mailing list