Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Leo Yan <leo.yan@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@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>,
	Adrian Hunter <adrian.hunter@intel.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>,
	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 07/14] perf arm-spe: Use generic snapshot search
Date: Fri, 9 Oct 2026 10:09:52 +0100	[thread overview]
Message-ID: <b174823d-2e5e-422d-a958-ee11c5bfc1a9@linaro.org> (raw)
In-Reply-To: <20260827161619.GN8904@e132581.arm.com>



On 27/08/2026 17:16, Leo Yan wrote:
> On Fri, Aug 21, 2026 at 10:49:05AM +0100, James Clark wrote:
> 
> [...]
> 
>> SPE also had a special fixup case for head pointers greater than the
>> buffer length, which is not needed because the SPE driver always wraps
>> them, and __auxtrace_mmap__read() handles that anyway. It also didn't
>> have the special case for old > head for when the wrap heuristic fails
>> but the pointers showed a wrap had happened.
> 
> Here mentioned the "special fixup case" is:
> 
>    if (head >= buffer_size)
>        return true
> 
> If the hardware pointer is exactly the end of buffer, it is a strong
> indication for wrapping. So it might be worth adding an explicit
> "head == buffer_size" check in the common code.
> 
> That said, if always checking the final 512 bytes, this case is very
> likely to be detected anyway, so I am not concerned about dropping the
> check.
> 

I can't visualise why head == buffer_size indicates wrapping any more 
than head equaling any other index in the buffer. The heuristic seems to 
be impossible to make perfect, so I'm inclined to leave it as is.

Couldn't you also say "head > buffer - 512" indicates a wrap? But that 
could also just be the first time around with no wrap if there is no 
data after that point. Same way that head == buffer_size could also not 
be a wrap on the first iteration. But then you end up saving the whole 
buffer anyway when *old is still 0 or any of it isn't padding, so it 
doesn't make a difference.

Really we should move to the duplicate detection algorithm like IntelPT, 
or update the driver to use a monotonic head if we think it won't break 
anything. It's so much more usable.

>> The other feature lost is that this search only looked from head to the
>> end of the buffer, rather than always at the last 512 bytes. This was
>> flawed because once head is close to the end, it's likely it could
>> contain zero padding from actual SPE data and a wrap would be missed.
> 
>> It's better to err on the side of caution and mark as a wrap, rather
>> than trying to optimize by limiting the search from head onwards.
> 
> Wouldn't this be a trade-off between missing a wrap and reporting a
> false positive wrap?

Yep, and false positives are basically harmless with this algorithm. It 
doesn't do anything do remove duplicate data, so you might as well mark 
it as wrapped as early as possible and save it all anyway.

> 
> Ignoring head makes the search overlap valid trace data when head is
> close to the end of the buffer but has not wrapped yet
> (e.g. mm->len - head < 512). That data can then be mistaken as evidence
> of a wrap.
> 
> For a false positive wrap, [head..mm->len] contains zero data. This
> should be fine, as zero data are treated as PAD packets and discarded
> during decoding.
> 
> I'd suggest adding this info into the commit log, in case later we need
> to understand these weird cases. With that:

The summaries are pretty good, will add to the commit message.

> 
> Reviewed-by: Leo Yan <leo.yan@arm.com>



  reply	other threads:[~2026-10-09  9:10 UTC|newest]

Thread overview: 29+ 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-10-08 10:16     ` James Clark
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-27 14:27   ` Leo Yan
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-27 16:16   ` Leo Yan
2026-10-09  9:09     ` James Clark [this message]
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-27 17:09   ` Leo Yan
2026-10-09  9:25     ` 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-27 17:15   ` Leo Yan
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
2026-08-24 14:32     ` James Clark
2026-08-27 18:21   ` Leo Yan
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=b174823d-2e5e-422d-a958-ee11c5bfc1a9@linaro.org \
    --to=james.clark@linaro.org \
    --cc=aaupov@fb.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=coresight@lists.linaro.org \
    --cc=irogers@google.com \
    --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