Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Jan Bernloehr <jbernloehr@nvidia.com>
Cc: Leo Yan <leo.yan@linux.dev>, Will Deacon <will@kernel.org>,
	Mike Leach <mike.leach@arm.com>,
	John Garry <john.garry@linux.dev>,
	Namhyung Kim <namhyung@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Matt Ochs <mochs@nvidia.com>,
	Linux perf Profiling <linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH] perf arm-spe: Honor --time ranges when synthesizing samples
Date: Fri, 27 Nov 2026 13:07:38 +0000	[thread overview]
Message-ID: <f1cd9130-76d3-4828-9cd0-aebb43e51de2@linaro.org> (raw)
In-Reply-To: <20261127123855.78212-1-jbernloehr@nvidia.com>



On 27/11/2026 12:38, Jan Bernloehr wrote:
> perf script and perf report pass their --time ranges to the AUX trace
> decoders through itrace_synth_opts. Intel PT uses them to skip decoding
> outside the ranges, but Arm SPE ignores them: it synthesizes a sample
> for every record, only for the tool to drop the samples outside the
> ranges in its sample handler.
> 
> Check each record's timestamp against the ranges before synthesizing
> samples for it. The check runs after the --itrace period count and
> converts the record timestamp with tsc_to_perf_time(), as
> arm_spe_prep_sample() does for sample->time, so the tool receives the
> same samples as before. Without timestamps (timeless decoding) nothing
> changes.
> 
> Decoding still runs to the end of each queue rather than stopping at the
> first record past the last range: record timestamps do not always
> increase within a queue, and on Neoverse V2 traces such an early stop
> dropped samples that were inside the range.

Do you care that timestamps don't always increase? Seems like it would 
be acceptable to stop after the first timestamp that you see outside of 
the range, even if there are some edge cases where there may be an 
earlier one later.

Also can you elaborate why they don't always increase? I would have 
thought that they would always generally increase in SPE data, if not 
for some allowance for instruction re-ordering or something like that. 
But that would be tiny and not really relevant for this feature.

> 
> On 28 GB and 55 GB Neoverse V2 traces, perf script --itrace=i1i with
> --time=70%-95% goes from 212 s to 188 s and from 383 s to 339 s, and
> with --time=70%-70.01% from 101 s to 72 s and from 188 s to 131 s, with
> byte-identical output.
> 
> The code and this message were drafted with an AI coding assistant
> (Claude Opus 5.5).
> 
> Signed-off-by: Jan Bernloehr <jbernloehr@nvidia.com>
> ---
> Tested on GB200 (Neoverse V2) with two perf.data files (28 GB, 55 GB)
> recorded with
>    perf record -e 'arm_spe_0/branch_filter=1,event_filter=0x2,jitter=1,period=4096/u'
> and decoded with
>    perf script --itrace=i1i -F comm,tid,cpu,time,period,event,addr,ip,dso --no-demangle
> using perf-tools-next 29fd95dbd25 with and without this patch:
> 
>                            28 GB            55 GB
>    --time=70%-95%          212 s -> 188 s   383 s -> 339 s
>    --time=70%-70.01%       101 s ->  72 s   188 s -> 131 s
>    --itrace=i10i 70%-95%    84 s ->  81 s   150 s -> 147 s
> 
> Output was byte-identical to the unpatched perf in every case.
> 
> An earlier version also stopped decoding a queue at its first record past
> the last range. On the 55 GB trace that dropped 21% of the in-range
> samples, because some queues produced in-range records after a record
> stamped past the range, so this version decodes every queue to the end.
> 
>   tools/perf/util/arm-spe.c | 33 +++++++++++++++++++++++++++++++++
>   1 file changed, 33 insertions(+)
> 
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 8d95df23be6..bf1e824ea76 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -26,6 +26,7 @@
>   #include "symbol.h"
>   #include "thread.h"
>   #include "thread-stack.h"
> +#include "time-utils.h"
>   #include "tsc.h"
>   #include "tool.h"
>   #include "util/synthetic-events.h"
> @@ -93,6 +94,9 @@ struct arm_spe {
>   
>   	u64				kernel_start;
>   
> +	struct perf_time_interval	*ptime_range;
> +	int				range_num;
> +
>   	unsigned long			num_events;
>   	u8				use_ctx_pkt_for_pid;
>   
> @@ -1077,6 +1081,19 @@ arm_spe__synth_data_source(struct arm_spe_queue *speq,
>   	return data_src;
>   }
>   
> +/*
> + * Check a record against the --time ranges. Samples outside them would only
> + * be dropped by the tool, so do not synthesize them.
> + */
> +static bool arm_spe__skip_record(struct arm_spe *spe, u64 timestamp)
> +{
> +	if (!spe->range_num)
> +		return false;
> +
> +	return perf_time__ranges_skip_sample(spe->ptime_range, spe->range_num,
> +					     tsc_to_perf_time(timestamp, &spe->tc));
> +}
> +
>   static int arm_spe_sample(struct arm_spe_queue *speq)
>   {
>   	const struct arm_spe_record *record = &speq->decoder->record;
> @@ -1092,6 +1109,9 @@ static int arm_spe_sample(struct arm_spe_queue *speq)
>   		return 0;
>   	speq->sample_count = 0;
>   
> +	if (arm_spe__skip_record(spe, record->timestamp))
> +		return 0;
> +
>   	arm_spe__sample_flags(speq);
>   	data_src = arm_spe__synth_data_source(speq, record);
>   
> @@ -1255,6 +1275,17 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
>   	return 0;
>   }
>   
> +static void arm_spe__setup_time_ranges(struct arm_spe *spe,
> +				       struct itrace_synth_opts *opts)
> +{
> +	/* Without timestamps, samples cannot be filtered by time */
> +	if (!opts || !opts->range_num || spe->timeless_decoding)
> +		return;
> +
> +	spe->ptime_range = opts->ptime_range;
> +	spe->range_num = opts->range_num;
> +}
> +
>   static int arm_spe__setup_queue(struct arm_spe *spe,
>   			       struct auxtrace_queue *queue,
>   			       unsigned int queue_nr)
> @@ -2055,6 +2086,8 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
>   	 */
>   	spe->synth_opts.period = spe->synth_opts.period ?: 1;
>   
> +	arm_spe__setup_time_ranges(spe, session->itrace_synth_opts);
> +
>   	if (spe->synth_opts.period > 1)
>   		ui__warning("Arm SPE has a hardware-based sampling period.\n\n"
>   			    "--itrace periods > 1i downsample by an interval of n SPE samples rather than n instructions.\n");



      reply	other threads:[~2026-11-27 13:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:38 [PATCH] perf arm-spe: Honor --time ranges when synthesizing samples Jan Bernloehr
2026-11-27 13:07 ` James Clark [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1cd9130-76d3-4828-9cd0-aebb43e51de2@linaro.org \
    --to=james.clark@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jbernloehr@nvidia.com \
    --cc=john.garry@linux.dev \
    --cc=leo.yan@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mike.leach@arm.com \
    --cc=mochs@nvidia.com \
    --cc=namhyung@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox