From: sashiko-bot@kernel.org
To: "Leo Yan" <leo.yan@arm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v10 6/9] perf cs-etm: Flush thread stacks after decoder reset
Date: Wed, 17 Jun 2026 21:08:42 +0000 [thread overview]
Message-ID: <20260617210842.D0CCB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260617-b4-arm_cs_callchain_support_v1-v10-6-e8b6e5d63db5@arm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing thread stack flush for traces recorded without context IDs (`CS_ETM_PIDFMT_NONE`), leaving the stale callchain bug unfixed.
- [High] Global thread stack flush on a per-queue (per-CPU) trace discontinuity inappropriately wipes valid callchains for unaffected threads on other CPUs.
--
commit 50abc287497c8a3fa0588b51842fb028097af238
Author: Leo Yan <leo.yan@arm.com>
perf cs-etm: Flush thread stacks after decoder reset
Perf resets the CoreSight decoder when moving to a new AUX trace buffer,
which causes a trace discontinuity globally. For callchain synthesis, keeping
thread-stack state after a decoder reset can leave stale call/return history
attached to threads that are decoded later. This patch flushes all host thread
stacks, and guest thread stacks if virtualization is present, after a decoder
reset.
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 5ede0f0ff8c6e..e43f0c1dd0078 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> +static void cs_etm__flush_all_stack(struct cs_etm_queue *etmq)
> +{
> + enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq);
> +
> + if (!etmq->etm->synth_opts.last_branch)
> + return;
> +
> + switch (pid_fmt) {
> + case CS_ETM_PIDFMT_CTXTID2:
> + /* Clear the guest stack if virtualization is supported */
> + cs_etm__flush_machine_stack(etmq, DEFAULT_GUEST_KERNEL_ID);
> + fallthrough;
> + case CS_ETM_PIDFMT_CTXTID:
> + cs_etm__flush_machine_stack(etmq, HOST_KERNEL_ID);
> + break;
> + case CS_ETM_PIDFMT_NONE:
> + default:
> + break;
[Severity: High]
Does skipping the flush for CS_ETM_PIDFMT_NONE leave the stale callchain
bug unfixed for traces without context IDs?
Even when Context IDs are absent (e.g., in --per-thread mode or unprivileged
system-wide tracing), perf still maps execution to tidq->frontend_thread on
the host machine (HOST_KERNEL_ID), accumulating branch stack history on those
threads.
By bypassing the flush here, a decoder reset discontinuity would leave stale
call/return history on these thread stacks, producing the exact same incorrect
synthesized callchains this patch intends to fix.
> +
> + }
> +}
> +
> /*
> * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue
> * if need be.
> @@ -2034,6 +2073,12 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
> ret = cs_etm_decoder__reset(etmq->decoder);
> if (ret)
> return ret;
> +
> + /*
> + * Since the decoder is reset, this causes a global trace
> + * discontinuity. Flush all thread stacks.
> + */
> + cs_etm__flush_all_stack(etmq);
[Severity: High]
Does this code unnecessarily wipe active branch histories on unaffected CPUs?
When a trace buffer hits a discontinuity, cs_etm__get_data_block() resets the
decoder for that specific etmq. However, cs_etm__flush_all_stack() ends up
calling machine__for_each_thread() to indiscriminately flush the thread stacks
of every single traced thread system-wide.
In a per-CPU tracing scenario, a trace buffer wrap on CPU 0 is a local,
queue-specific discontinuity. By flushing the global machine, doesn't this
unnecessarily wipe the contiguous and valid branch histories of threads
currently executing on other CPUs, potentially corrupting their callchain
synthesis?
> }
>
> return etmq->buf_len;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260617-b4-arm_cs_callchain_support_v1-v10-0-e8b6e5d63db5@arm.com?part=6
next prev parent reply other threads:[~2026-06-17 21:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:08 [PATCH v10 0/9] perf cs-etm: Support thread stack and callchain Leo Yan
2026-06-17 15:08 ` [PATCH v10 1/9] perf cs-etm: Fix thread leaks on trace queue init failure Leo Yan
2026-06-17 20:25 ` sashiko-bot
2026-06-17 15:08 ` [PATCH v10 2/9] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-06-17 15:08 ` [PATCH v10 3/9] perf cs-etm: Decode ETE exception packets Leo Yan
2026-06-17 15:08 ` [PATCH v10 4/9] perf cs-etm: Refactor instruction size handling Leo Yan
2026-06-17 15:08 ` [PATCH v10 5/9] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-06-17 20:56 ` sashiko-bot
2026-06-17 15:08 ` [PATCH v10 6/9] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-06-17 21:08 ` sashiko-bot [this message]
2026-06-17 15:08 ` [PATCH v10 7/9] perf cs-etm: Support call indentation Leo Yan
2026-06-17 21:20 ` sashiko-bot
2026-06-17 15:08 ` [PATCH v10 8/9] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-06-17 21:35 ` sashiko-bot
2026-06-17 15:09 ` [PATCH v10 9/9] perf test: Add Arm CoreSight callchain test Leo Yan
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=20260617210842.D0CCB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=leo.yan@arm.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.