Linux Documentation
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: James Clark <james.clark@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@arm.com>, Leo Yan <leo.yan@arm.com>,
	John Garry <john.g.garry@oracle.com>,
	Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Suyash Mahar <smahar@meta.com>, Amir Ayupov <aaupov@fb.com>
Cc: Leo Yan <leo.yan@linux.dev>,
	<linux-arm-kernel@lists.infradead.org>,
	<coresight@lists.linaro.org>, <linux-perf-users@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	<linux-doc@vger.kernel.org>
Subject: Re: [PATCH v2 11/14] perf auxtrace: cs-etm: Capture wrapped snapshots
Date: Mon, 24 Aug 2026 15:21:54 +0300	[thread overview]
Message-ID: <568a14ed-161d-4f67-842a-c671e7f4c409@intel.com> (raw)
In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-11-00c4fd0701b4@linaro.org>

On 21/08/2026 12:49, James Clark wrote:
> snapshot_has_wrapped() isn't implemented for Coresight, so when a wrap
> occurs we only save from offset 0 to current head, modulo buffer size,
> rather than capturing the whole buffer. Coresight drivers currently use
> a monotonic head pointer even in snapshot mode, which gives a lot more
> information for taking snapshots than a wrapped pointer. It means we
> don't need to search for data at the end of the buffer to guess if a
> wrap has occurred, and we can go back to saving partial buffers after a
> wrap by checking if the next size to take is less than the buffer
> size.
> 
> The drivers will always be able to generate a monotonic head because
> TRBE has a bytes written counter, so even if we stop generating an AUX
> record on every overflow, we can check if the counter indicated an
> overwrite and offset head by a whole buffer size if it wrapped. This
> forces userspace to read the whole buffer rather than between last and
> current head. ETR and other sinks use software double buffering, so can
> continue as they are.
> 
> Add a much simpler 'monotonic_snapshot_head' path for tracers to use,
> and use it for Coresight.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
>  tools/perf/arch/arm/util/cs-etm.c                  |  1 +
>  .../perf/tests/shell/coresight/raw_dump_stress.sh  |  5 -----
>  tools/perf/util/auxtrace.c                         | 22 ++++++++++++++++------
>  tools/perf/util/auxtrace.h                         |  2 ++
>  4 files changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index d36b7e41399b..dbf76dd3349e 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -918,6 +918,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	ptr->itr.info_fill		= cs_etm_info_fill;
>  	ptr->itr.snapshot_start		= cs_etm_snapshot_start;
>  	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
> +	ptr->itr.monotonic_snapshot_head = true;
>  	ptr->itr.reference		= cs_etm_reference;
>  	ptr->itr.free			= cs_etm_recording_free;
>  	ptr->itr.read_finish		= auxtrace_record__read_finish;
> diff --git a/tools/perf/tests/shell/coresight/raw_dump_stress.sh b/tools/perf/tests/shell/coresight/raw_dump_stress.sh
> index bea70d825596..c9459ded4cbe 100755
> --- a/tools/perf/tests/shell/coresight/raw_dump_stress.sh
> +++ b/tools/perf/tests/shell/coresight/raw_dump_stress.sh
> @@ -48,11 +48,6 @@ read -r size offset last_idx <<< "$(awk '
>  # everything was dumped. Allow 48 bytes difference to cover 3 frames: current
>  # frame length, a partial frame and a final empty one, all of which aren't
>  # dumped.
> -#
> -# TODO: for a single snapshot, offset should always be zero. However, we
> -# currently output AUX records in snapshot mode when we shouldn't, which
> -# increments the offset. Allow for that until it's fixed so we can test raw
> -# dumping.
>  decode_size=$((1 + last_idx - offset))
>  if [ "$decode_size" -gt "$((size - 48))" ] && [ "$decode_size" -le "$((size))" ]; then
>  	echo "PASS: AUXTRACE buffer length matches dumped packet index"
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index 8ca872e6d465..e3c770b46e94 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -2051,9 +2051,9 @@ static int __auxtrace_mmap__read(struct mmap *map,
>  				 bool snapshot, size_t snapshot_size)
>  {
>  	struct auxtrace_mmap *mm = &map->auxtrace_mmap;
> -	u64 head, old = mm->prev, offset, ref;
> +	u64 head, old = mm->prev, offset, ref, size;
>  	unsigned char *data = mm->base;
> -	size_t size, head_off, old_off, len1, len2, padding;
> +	size_t head_off, old_off, len1, len2, padding;
>  	union perf_event ev;
>  	void *data1, *data2;
>  	int kernel_is_64_bit = perf_env__kernel_is_64_bit(env);
> @@ -2061,10 +2061,20 @@ static int __auxtrace_mmap__read(struct mmap *map,
>  
>  	head = auxtrace_mmap__read_head(mm, kernel_is_64_bit);
>  
> -	if (snapshot && itr->snapshot_has_wrapped) {
> -		err = auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old);
> -		if (err)
> -			return err;
> +	if (snapshot) {
> +		if (itr->snapshot_has_wrapped) {
> +			err = auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old);
> +			if (err)
> +				return err;
> +		} else if (itr->monotonic_snapshot_head) {
> +			size = head - old;
> +			/* Force a full buffer read if a wrap has occurred */
> +			if (size > mm->len) {
> +				pr_debug3("%s: wrap detected, adjusting old from 0x%"PRIx64" to 0x%"PRIx64"\n",
> +					  __func__, old, head - mm->len);
> +				old = head - mm->len;
> +			}
> +		}

I feel like this is asking to keep the ->find_snapshot() callback.
i.e. basically the same thing, but add a helper that BTS and SPE
can call directly, like auxtrace_record__default_find_snapshot().
For PT, add/use auxtrace_record__snapshot_fixup() that does the
common old/head adjustment.

Then ->monotonic_snapshot_head is not needed.

>  	}
>  
>  	if (old == head)
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index a9d0c84184c5..971b817d3396 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -385,6 +385,7 @@ struct auxtrace_mmap_params {
>   * @evlist: selected events list
>   * @snapshot_wrapped_len: number of bits in @snapshot_wrapped
>   * @snapshot_wrapped: bitmap indicating if each aux buffer has wrapped
> + * @monotonic_snapshot_head: driver doesn't wrap head pointer on overflow
>   */
>  struct auxtrace_record {
>  	int (*recording_options)(struct auxtrace_record *itr,
> @@ -412,6 +413,7 @@ struct auxtrace_record {
>  	int snapshot_wrapped_len;
>  	unsigned long *snapshot_wrapped;
>  	int snapshot_search_bytes;
> +	bool monotonic_snapshot_head;
>  };
>  
>  /**
> 


  reply	other threads:[~2026-08-24 12:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  9:48 [PATCH v2 00/14] perf cs-etm: Per-thread mode fixes and snapshot wrap support James Clark
2026-08-21  9:48 ` [PATCH v2 01/14] perf cs-etm: Fix nVHE per-thread decoding James Clark
2026-08-26 15:01   ` Leo Yan
2026-08-21  9:49 ` [PATCH v2 02/14] perf cs-etm: Warn for invalid timestamp option James Clark
2026-08-26 15:04   ` Leo Yan
2026-08-21  9:49 ` [PATCH v2 03/14] perf cs-etm: Turn on context packet timestamps in per-thread mode James Clark
2026-08-26 15:36   ` Leo Yan
2026-08-21  9:49 ` [PATCH v2 04/14] perf cs-etm: Use per-CPU queues for " James Clark
2026-08-26 19:06   ` Leo Yan
2026-08-21  9:49 ` [PATCH v2 05/14] perf cs-etm: Increase default timestamp generation period James Clark
2026-08-21  9:49 ` [PATCH v2 06/14] perf auxtrace: Turn Intel BTS snapshot search into a generic one James Clark
2026-08-21  9:49 ` [PATCH v2 07/14] perf arm-spe: Use generic snapshot search James Clark
2026-08-21  9:49 ` [PATCH v2 08/14] perf auxtrace: intel-pt: Use new snapshot_has_wrapped callback James Clark
2026-08-21  9:49 ` [PATCH v2 09/14] perf cs-etm: Queue partial AUX records James Clark
2026-08-21  9:49 ` [PATCH v2 10/14] perf cs-etm: Don't print missing buffers in snapshot mode James Clark
2026-08-21  9:49 ` [PATCH v2 11/14] perf auxtrace: cs-etm: Capture wrapped snapshots James Clark
2026-08-24 12:21   ` Adrian Hunter [this message]
2026-08-24 14:32     ` James Clark
2026-08-21  9:49 ` [PATCH v2 12/14] perf test: Allow infinite named_thread loops James Clark
2026-08-21  9:49 ` [PATCH v2 13/14] perf test: Add test for per-thread mode James Clark
2026-08-21  9:49 ` [PATCH v2 14/14] perf cs-etm: Test multiple per-thread threads James Clark

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=568a14ed-161d-4f67-842a-c671e7f4c409@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=aaupov@fb.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=coresight@lists.linaro.org \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=leo.yan@arm.com \
    --cc=leo.yan@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=smahar@meta.com \
    --cc=suzuki.poulose@arm.com \
    --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