From: James Clark <james.clark@linaro•org>
To: Leo Yan <leo.yan@arm•com>
Cc: linux-arm-kernel@lists•infradead.org, coresight@lists•linaro.org,
linux-perf-users@vger•kernel.org,
Arnaldo Carvalho de Melo <acme@kernel•org>,
John Garry <john.g.garry@oracle•com>,
Will Deacon <will@kernel•org>, Mike Leach <mike.leach@arm•com>,
Suzuki K Poulose <suzuki.poulose@arm•com>,
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>,
Al Grant <al.grant@arm•com>,
Paschalis Mpeis <paschalis.mpeis@arm•com>,
Amir Ayupov <aaupov@fb•com>
Subject: Re: [PATCH v6 4/8] perf cs-etm: Flush thread stacks after decoder reset
Date: Thu, 4 Jun 2026 15:12:10 +0100 [thread overview]
Message-ID: <8bcb7a89-96db-4898-9d91-62360606602f@linaro.org> (raw)
In-Reply-To: <20260526-b4-arm_cs_callchain_support_v1-v6-4-f9f49f53c9dd@arm.com>
On 26/05/2026 5:59 pm, Leo Yan wrote:
> Perf resets the CoreSight decoder when moving to a new AUX trace buffer,
> this causes trace discontinunity globally.
>
> For callchain synthesis, keeping thread-stack state after decoder reset
> can leave stale call/return history attached to threads that are decoded
> later, producing incorrect synthesized callchains.
>
> Flush all host thread stacks after a decoder reset. When virtualization
> is present, flush the guest thread stacks as well.
>
> Signed-off-by: Leo Yan <leo.yan@arm•com>
> ---
> tools/perf/util/cs-etm.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 398ab3b7a429d402cc8e5f6cccb35c0b7c253732..ea2424175558ddc0a6f20a9de6c30f377facdc52 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1956,6 +1956,37 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
>
> return 0;
> }
> +
> +static int cs_etm__flush_stack_cb(struct thread *thread,
> + void *data __maybe_unused)
> +{
> + thread_stack__flush(thread);
> + return 0;
> +}
> +
> +static void cs_etm__flush_machine_stack(struct cs_etm_queue *etmq, pid_t pid)
> +{
> + struct machine *machine;
> +
> + machine = machines__find(&etmq->etm->session->machines, pid);
> + if (machine)
> + machine__for_each_thread(machine, cs_etm__flush_stack_cb, NULL);
> +}
> +
> +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;
> +
> + cs_etm__flush_machine_stack(etmq, HOST_KERNEL_ID);
> +
> + /* Clear the guest stack if virtualization is supported */
> + if (pid_fmt == CS_ETM_PIDFMT_CTXTID2)
> + cs_etm__flush_machine_stack(etmq, DEFAULT_GUEST_KERNEL_ID);
> +}
> +
> /*
> * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue
> * if need be.
> @@ -1978,6 +2009,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);
> }
>
> return etmq->buf_len;
>
Reviewed-by: James Clark <james.clark@linaro•org>
next prev parent reply other threads:[~2026-06-04 14:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 16:59 [PATCH v6 0/8] perf cs-etm: Support thread stack and callchain Leo Yan
2026-05-26 16:59 ` [PATCH v6 1/8] perf cs-etm: Decode ETE exception packets Leo Yan
2026-06-04 14:10 ` James Clark
2026-05-26 16:59 ` [PATCH v6 2/8] perf cs-etm: Refactor instruction size handling Leo Yan
2026-06-04 14:11 ` James Clark
2026-05-26 16:59 ` [PATCH v6 3/8] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-06-04 14:09 ` James Clark
2026-05-26 16:59 ` [PATCH v6 4/8] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-06-04 14:12 ` James Clark [this message]
2026-05-26 16:59 ` [PATCH v6 5/8] perf cs-etm: Support call indentation Leo Yan
2026-06-04 14:24 ` James Clark
2026-05-26 16:59 ` [PATCH v6 6/8] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-06-04 14:42 ` James Clark
2026-05-26 16:59 ` [PATCH v6 7/8] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-06-04 15:07 ` James Clark
2026-05-26 16:59 ` [PATCH v6 8/8] perf test: Add Arm CoreSight callchain test Leo Yan
2026-05-29 14:57 ` [PATCH v6 0/8] perf cs-etm: Support thread stack and callchain Arnaldo Carvalho de Melo
2026-06-01 11:03 ` 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=8bcb7a89-96db-4898-9d91-62360606602f@linaro.org \
--to=james.clark@linaro$(echo .)org \
--cc=aaupov@fb$(echo .)com \
--cc=acme@kernel$(echo .)org \
--cc=adrian.hunter@intel$(echo .)com \
--cc=al.grant@arm$(echo .)com \
--cc=alexander.shishkin@linux$(echo .)intel.com \
--cc=coresight@lists$(echo .)linaro.org \
--cc=irogers@google$(echo .)com \
--cc=john.g.garry@oracle$(echo .)com \
--cc=jolsa@kernel$(echo .)org \
--cc=leo.yan@arm$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-perf-users@vger$(echo .)kernel.org \
--cc=mark.rutland@arm$(echo .)com \
--cc=mike.leach@arm$(echo .)com \
--cc=namhyung@kernel$(echo .)org \
--cc=paschalis.mpeis@arm$(echo .)com \
--cc=suzuki.poulose@arm$(echo .)com \
--cc=will@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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