Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf arm-spe: Honor --time ranges when synthesizing samples
@ 2026-11-27 12:38 Jan Bernloehr
  2026-11-27 12:47 ` sashiko-bot
  2026-11-27 13:07 ` James Clark
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Bernloehr @ 2026-11-27 12:38 UTC (permalink / raw)
  To: linux-perf-users
  Cc: Leo Yan, James Clark, Will Deacon, Mike Leach, John Garry,
	Namhyung Kim, Arnaldo Carvalho de Melo, Ian Rogers, Adrian Hunter,
	linux-arm-kernel, linux-kernel, Matt Ochs

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.

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");
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:38 [PATCH] perf arm-spe: Honor --time ranges when synthesizing samples Jan Bernloehr
2026-11-27 12:47 ` sashiko-bot
2026-11-27 13:07 ` James Clark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox