Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead
Date: Wed, 18 Nov 2026 17:01:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-221574@kernel.org> (raw)
In-Reply-To: <20261118-james-coresight-jit-v1-29-dad4d90747f6@linaro.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf cs-etm: heap stall and dropped queues in non-virtual
  timestamp mode
--

commit 95d787db531b56fc0f9104f4d25589c7638920b3
Author: James Clark <james.clark@linaro.org>

perf cs-etm: Find timestamps by searching ahead

This commit uses the packet-only timestamp decoder to search ahead for
the next timestamp on context packets and trace discontinuities, and
reorders packets so timestamps are delivered before context changes or
after discontinuities flush earlier samples.

> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
> index 56de6c76de68b..b7ed7847f209b 100644
> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
[ ... ]
> @@ -869,16 +884,130 @@ int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
[ ... ]
> +static int cs_etm_decoder__reorder_packet(struct cs_etm_packet_decoder *decoder,
> +					  const struct cs_etm_buffer *buffer,
> +					  struct cs_etm_traceid_ctxt *tidc)
> +{
> +	u64 timestamp;
> +	int ret;
> +
> +	if (tidc->packet->sample_type != CS_ETM_CONTEXT &&
> +	    tidc->packet->sample_type != CS_ETM_DISCONTINUITY)
> +		return 0;
> +
> +	/*
> +	 * ETM always emits a timestamp after a context or trace discontinuity
> +	 * so search for it and give it to the frontend first.
> +	 */
> +	ret = cs_etm_decoder__search_timestamp(decoder, buffer, decoder->packet_index, &timestamp);
> +	if (ret)
> +		return ret;
> +
> +	decoder->pending = tidc;
> +	decoder->pending_packet = *tidc->packet;
> +	decoder->pending_packet.timestamp = max(decoder->timestamp, timestamp);
> +	if (tidc->packet->sample_type == CS_ETM_CONTEXT) {
> +		/* Publish the timestamp before allowing the context to be applied. */
> +		decoder->timestamp = decoder->pending_packet.timestamp;
> +		tidc->packet->sample_type = CS_ETM_TIMESTAMP;
> +	} else {
> +		/* Let the discontinuity flush preceding samples at the old time. */
> +		decoder->pending_packet.sample_type = CS_ETM_TIMESTAMP;
> +	}
> +	return 0;
> +}
[ ... ]
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index d275d37011659..5a704dfeebd34 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -1215,68 +1180,74 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
[ ... ]
> -static int cs_etm__push_queue(struct cs_etm_queue *etmq, u64 time)
> +static int cs_etm__insert_heap_queue(struct cs_etm_queue *etmq, u64 time)
>  {
>  	int ret;
>  
>  	if (!etmq || etmq->on_heap)
>  		return 0;
>  
> -	while (!etmq->on_heap) {
> +	if (!etmq->buf) {
>  		ret = cs_etm__get_data_block(etmq);
>  		if (ret <= 0)
>  			return ret;
> +	}
> +
> +	while (1) {
>  		if (!etmq->etm->has_virtual_ts && etmq->buffer->time > time)
>  			return 0;
>  
> -		ret = cs_etm__add_to_heap(etmq, NULL);
> -		if (ret)
> +		ret = cs_etm__decode_packet(etmq, &etmq->tidc);
> +		if (ret < 0)
>  			return ret;
> +		if (etmq->tidc)
> +			return cs_etm__add_to_heap(etmq, etmq->tidc->packet->timestamp);
> +
> +		/* Drain buffered decoder output before fetching another AUX buffer. */
> +		ret = cs_etm__get_data_block(etmq);
> +		if (ret <= 0)
> +			break;
>  	}
>  
> -	return 0;
> +	if (!ret)
> +		etmq->buf = NULL;
> +	return ret;
>  }
[ ... ]
> @@ -2580,11 +2558,11 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
>  static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
>  {
[ ... ]
>  		/* Take the entry at the top of the min heap */
> -		cs_queue_nr = etm->heap.heap_array[0].queue_nr;
> -		queue_nr = TO_QUEUE_NR(cs_queue_nr);
> -		trace_chan_id = TO_TRACE_CHAN_ID(cs_queue_nr);
> +		queue_nr = etm->heap.heap_array[0].queue_nr;
> +		cs_timestamp = etm->heap.heap_array[0].ordinal;
>  		queue = &etm->queues.queue_array[queue_nr];
>  		etmq = queue->priv;
>  
>  		/* Don't go further than the trace timestamp or collection time */
> -		queue_time = etm->has_virtual_ts ? etm->heap.heap_array[0].ordinal :
> +		queue_time = etm->has_virtual_ts ? cs_timestamp :
>  						   etmq->buffer->time;
>  		if (queue_time >= timestamp)
>  			break;
[ ... ]
> -add_to_heap:
> -		/* Schedule the next decode step after consuming the current packet. */
> -		ret = cs_etm__add_to_heap(etmq, tidc);
> +		ret = cs_etm__insert_heap_queue(etmq, timestamp);
>  		if (ret)
>  			goto out;
> -		if (!etmq->on_heap)
> -			goto get_data_block;
>  	}
>  out:
>  	return ret;

[Severity: Medium]
Does this stall earlier queues and drop queues from the min-heap when
decoding with non-virtual hardware timestamps (etm->has_timestamps &&
!etm->has_virtual_ts)?

On PERF_RECORD_AUX, cs_etm__insert_heap_all() decodes each queue's initial
CS_ETM_DISCONTINUITY packet.  In cs_etm_decoder__reorder_packet(), the
discontinuity branch leaves decoder->timestamp at 0 and defers the
searched-ahead timestamp to decoder->pending_packet, so every queue enters
etm->heap with ordinal 0.  Once a queue with an earlier AUX collection time
pops its discontinuity packet and re-enters the heap with a non-zero
CoreSight timestamp, any unpopped queue whose etmq->buffer->time >=
timestamp remains at the top of the min-heap at ordinal 0 and causes
cs_etm__pop_heap() to break out of the loop, blocking the earlier queue
until timestamp reaches the later queue's buffer->time.

Also, cs_etm__pop_heap() passes timestamp rather than MAX_TIMESTAMP to
cs_etm__insert_heap_queue().  When a queue advances to its next AUX buffer
with etmq->buffer->time > timestamp in non-virtual timestamp mode,
cs_etm__insert_heap_queue() returns 0 without re-inserting the queue into
etm->heap, dropping it from cross-queue timestamp ordering until the next
PERF_RECORD_AUX event.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-james-coresight-jit-v1-0-dad4d90747f6@linaro.org?part=29

  reply	other threads:[~2026-11-18 17:01 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
2026-11-18 16:29 ` [PATCH 01/34] perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64 James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 02/34] perf jit: Add name of clock in error message James Clark
2026-11-18 16:32   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 03/34] perf jit: Add address ranges to DWARF compilation units James Clark
2026-11-18 16:34   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 04/34] perf libdw: Don't look up the module by ELF address James Clark
2026-11-18 16:36   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 05/34] perf cs-etm: Use the exception level to tell kernel from user James Clark
2026-11-18 16:47   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 06/34] perf cs-etm: Don't read past the end of the map James Clark
2026-11-18 17:11   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 07/34] perf build-id: Cache the vDSO in build ID mmap mode James Clark
2026-11-18 17:03   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 08/34] perf cs-etm: arm-spe: Use arch timestamp in HW tracers James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 09/34] perf cs-etm: arm-spe: Report error if default clock isn't used James Clark
2026-11-18 16:35   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 10/34] perf cs-etm: Remove old pipe mode support James Clark
2026-11-18 16:44   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 11/34] perf cs-etm: Track threads in timeless mode James Clark
2026-11-18 16:35   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 12/34] perf cs-etm: Track sched out events James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events James Clark
2026-11-18 16:36   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 14/34] perf cs-etm: Always enable Perf event timestamps James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 15/34] perf cs-etm: Use time from Perf samples James Clark
2026-11-18 16:51   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 16/34] perf cs-etm: Don't buffer non-timestamped packets James Clark
2026-11-18 16:43   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 17/34] perf cs-etm: Decode in order of Perf samples James Clark
2026-11-18 17:10   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 18/34] perf cs-etm: Don't special case per-thread mode James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 19/34] perf cs-etm: Decode one packet at a time and don't estimate timestamps James Clark
2026-11-18 16:39   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 20/34] perf cs-etm: Remove the decoded packet ring buffer James Clark
2026-11-18 16:46   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 21/34] perf cs-etm: Fold packet state into the trace ID queue James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 22/34] perf cs-etm: Rename trace ID queues to trace ID contexts James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 23/34] perf cs-etm: Rename tidq variables to tidc James Clark
2026-11-18 16:49   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 24/34] perf cs-etm: Share the thread ctxt between frontend and backend James Clark
2026-11-18 16:47   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 25/34] perf cs-etm: Consume each OpenCSD packet immediately James Clark
2026-11-18 16:44   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 26/34] perf cs-etm: Split base and packet decoder state James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 27/34] perf cs-etm: Add packet-only timestamp decoder ops James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 28/34] perf cs-etm: Create timestamp decoders James Clark
2026-11-18 16:48   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead James Clark
2026-11-18 17:01   ` sashiko-bot [this message]
2026-11-18 16:29 ` [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs James Clark
2026-11-18 16:45   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 31/34] perf test cs-etm: Add a Java JIT source-line test James Clark
2026-11-18 17:11   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 32/34] perf test cs-etm: Test trace is ordered with context switch records James Clark
2026-11-18 16:49   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 33/34] perf test cs-etm: Test decoding of kernel modules James Clark
2026-11-18 16:57   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 34/34] perf test cs-etm: Add an HHVM JIT call stack test James Clark
2026-11-18 17:01   ` sashiko-bot
2026-11-18 16:33 ` [PATCH 00/34] perf cs-etm: JIT decoding support 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=sashiko-outbox-221574@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.clark@linaro.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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