From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795784862; b=CZjcghfAuhk0KpCm60vj8lrSCDAhGWT33A51XG7XZOWBaxZg4+57KbBSXxgb/9Q21K0x y6MTfSP4vqZVE+kvwk4bL0Kd7LhO2/M0uSd/aNUmdE9scztzzI8lTdxjt0dUUZQoOW2mI 6IQ/LW9edX1mQkbKDpbDtbH9t0EEYdW7E1am3QtTiEeGlmh0tifzt/XvmRZQmxzElJOXj hLiIYh6Nq/TEupC+8hrlBeAh4ZjznG1OlQciyuiTVTlj+pl6r3It/tbo1/qJ3i651JebJ NYXfd1wIS2lw9AbTkv8y12BRR0aPlf9m3wPQ7zN0Dj2uUJKuyDlUCLHh1XQl8k9x89g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795784862; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=kIn3Z40GB3Fv6RQJNleZ9bonkImRIY4BwaanX9JUugM=; b=zR0YlmvwxcQrqu9LyJk7gByDuRkoRtFrSzSljU8ulZ2EJhxvBubpYYEUKqc/bhu0aI6X G0Cbt4HYqwNjrFVvMcA8Anc2jjV2+sUsWbkEVHkWFtY1g5AHN09ymTGhWZbDH9qvq/2HF 6atJCuG4vLIHeHZTcteCOR/Rww6bezL+MMfZ4+AYmcq5ozPHhfHxQIP27LTePG8WemN+8 HK43inb2jZlnew7cJXLCZDXjJQvs+G91nv/Jui9lj2wl4Uo3O3PEMSryP4TKkZcNIp/ug DvSk1JTevUCSCRihd74cmMeybTOowlEsoZiERmg0UTOss3tRPKu0aTBGdZSnwlBxbTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=csHhW7oT; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B899A606A31E for ; Fri, 27 Nov 2026 13:07:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B899A606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=csHhW7oT Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so69534915e9.0 for ; Fri, 27 Nov 2026 05:07:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1795784860; x=1796389660; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kIn3Z40GB3Fv6RQJNleZ9bonkImRIY4BwaanX9JUugM=; b=csHhW7oTx/7IUXKBRYeC+C+z7IgdGVPU5zrgJhMaisMEotfSmxmYQzrUBUAj2EI2vj L44sPJZxi/FDJsBAJp18JKdXG/3Ih8ijYCzcHe5fGgtd58WF2GcPMdc0Fgj02DuXf3+t btRZYQXSlKdhUexvevGSlQDPveUZIwg8Vy7uY5cnLKuny9n2Z2yAZIpwDzO61CPWbU48 hiTSzeX1YkTfLpezfeofyAYaAU6I/GpqVI8kyXFUIYDN4WsAwV2XbhPFgDYtNHk4RJMO 37TgJsRfueLD6z2n8frUtpydcroGwBJWVLetLTc+bNH0Zkv1aH3uEGPwSiepLrR0YCkS G0Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795784860; x=1796389660; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kIn3Z40GB3Fv6RQJNleZ9bonkImRIY4BwaanX9JUugM=; b=cdHLn8uV3gwtfKdjlr1jU8DSqn8xT4L7W0WX6viqc/wRN4e1rLgknI/6zLzxbFForq 0wdYf40yoaT+BtIsu5J1VbPSxqERxNH0u1I3FmjHMx8D8wk8yyn9eUOg3c1yuFFM1nci OiNxsocozER2DqlupJC+/xc1hL5+FJee1ZXLXtuObPPMEjnijqhEMTxYAHb+CaM4I61b 33hPSceloq7ZkYashwSlEmV6Ccf/Jzb15Cr/5I9qeEa0D+8GBynjOKnQkqUpC8Jlw056 MVMO0ESuLI3EExnCtakJCc+jbMFxt9l7gximwQvdR6OWHD9G2uM1e1VjDrWacb2CdPhF 7kbQ== X-Forwarded-Encrypted: i=1; AL+hErFbpUfaTp/JKZQMz1/i5AOwEKH8wV+64lPBnZiuWezwNW00Kex6PZeL/0Dk2t6KJkQBLy8sZ8GnyKQa1gc=@vger.kernel.org X-Gm-Message-State: APuU4Z/rs/cM9tMG7GIvg41o9PUzMeW9zOR4wLIrpURo80DdwPYU+Ufu RFmZG1E6ar6b+GI0nUT+Mz3rYK5sTfmtIybGz5wlJshpSK9nw5DwZSQ9YihDB8LOTY8= X-Gm-Gg: AZFdTZeqFJTvWttaW99Ba2K7JP83Zm4Ixquzfv9vmoMgChnM8MBniKOedvr9VRG+hFP Ywm9glK4HZ0/LTPpkWezMEGPXYEcIO0UoKFwvN1RzNXDQCKw7MSWNO2Ectu4D/2xJRPGS99SD69 nDM9mR9IXpLRivNXidBJAMbbYM9TNtiE8/wiLn9/75U/H8ZbCjQdGV6xJ3B7J93SHe4QSLHtlGV m8k8io/qB+dZspuK+dV3RBc2oG86Bxb9Nnjt9+bWQSjZDuWdB+98xau2gifE2cry9ydvWUc3IMI 6moOqT4toBExUG4mEyNn8wxJDKfRwKgPlIVzscuoIrVNcomjl3QojAWeZdbbj5KuVr9RPuQKb5K NHbJEKiDfxyHmtFF3cNvdPrdm0a0ptoIcPvHlTvHxxXKFb339cVOkDizBbOpz60j0NZB6Hv7taY SWITMmq/7mTMPOTh1S517VRNFrudjoQNPIZynjNuw/364/rYRWsFtBhNi2Ecwnq/SbIzh5IfR56 J7920BusFBG1WkbphWH17WAE3HyxG8qx3nyPjxdC51GVR4CtlXvsERaH6qxmxq5TiTbZoyFw4KJ eqi3AGc9Yygonhb2APElqhAE4PWewdrVhQ== X-Received: by 2002:a05:600c:6749:b0:4a2:d99:3171 with SMTP id 5b1f17b1804b1-4bb8881b52dmr457902075e9.23.1795784859950; Fri, 27 Nov 2026 05:07:39 -0800 (PST) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88442995sm725641925e9.2.2026.11.27.05.07.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Nov 2026 05:07:39 -0800 (PST) Message-ID: Date: Fri, 27 Nov 2026 13:07:38 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf arm-spe: Honor --time ranges when synthesizing samples To: Jan Bernloehr Cc: Leo Yan , Will Deacon , Mike Leach , John Garry , Namhyung Kim , Arnaldo Carvalho de Melo , Ian Rogers , Adrian Hunter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Matt Ochs , Linux perf Profiling References: <20261127123855.78212-1-jbernloehr@nvidia.com> Content-Language: en-US From: James Clark In-Reply-To: <20261127123855.78212-1-jbernloehr@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > --- > 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");