On 17/08/2026 23:22, Amir Ayupov wrote:
CoreSight ETM can synthesize branch samples from an instruction trace, but context-sensitive PGO needs the branch history leading to an existing PMU sample together with that sample's event identity and callchain. This series implements that mode as --itrace=L, following the corresponding Intel PT behavior.
The series first separates timestamped queue setup and teardown from the ETM decode loop so decoding can stop at an existing sample's timestamp. It then reconstructs branch history in the thread stack and attaches it to eligible samples without replacing their IP, event, or callchain. The attached history is consumed after use so a later sample cannot reuse an earlier trace window.
This enables a context-sensitive PGO workflow where a cycles event supplies a frame-pointer callchain while duty-cycled ETM supplies the path leading to the sample. A dlfilter removes samples for which no ETM history was available, and the documentation describes the complete recording and decoding workflow.
Changes since v1:
- Rebased onto perf-tools-next at d17c5b770972.
- Dropped the HEADER_GROUP_DESC reader workaround. The issue is in the writer and should be fixed separately.
Doesn't it still need to be part of this patchset regardless of where the issue is? Running the new test is blocked on this. Also is this a regression? I noticed there was no fixes: tag on V1 for this commit.
- Dropped the branch-stack hw_idx patch after review established that zero is appropriate for age-ordered CoreSight branch stacks.
This doesn't seem to match what happened. The original patch initialized all branch stacks to hw_idx = -1, which I think was a good fix so shouldn't have been dropped.
Coresight still sets -1 which I said should be changed to 0, but there doesn't seem to be a change for that in V2. So now we're missing both changes.
- Dropped the local wrapped branch-stack copy fix in favor of upstream commit ab9c84d1cd59 ("perf thread-stack: Fix heap buffer overflow on branch stack wrap copy").
- Added James Clark's Reviewed-by tag to the dlfilter patch.
- Consume branch history after attaching it so samples with no newly decoded trace cannot reuse a window from before an untraced AUX pause interval.
- Flush all trace-ID frontend thread stacks when their physical ETM queue is exhausted, preventing stale history from surviving a trace gap.
- Check every matching CoreSight event when deciding whether kernel trace is enabled.
Were these changes due to my comment about the test not working? Might be worth some discussion about what the issue was on the V1 thread so it's easier to follow along with why these changes were made to V2.
- Reworked the shell test to use FIFO recording control, removed the invalid bare timestamp option, reduced the workload to 10000 iterations, and check proc1 and proc2 callchains independently with bounded failure diagnostics.
- Renamed decoded test outputs to script-L4 and script-L64.
Amir Ayupov (5): perf dlfilter: Add non-empty branch stack filter perf cs-etm: Split up cs_etm__process_timestamped_queues() perf cs-etm: Add branch history to existing samples perf test cs-etm: Test branch history on existing samples Documentation: coresight: Document context-sensitive PGO workflow
.../trace/coresight/coresight-perf.rst | 62 +++++ tools/perf/Makefile.perf | 1 + .../dlfilters/dlfilter-nonempty-brstack.c | 26 ++ .../tests/shell/coresight/add_last_branch.sh | 203 ++++++++++++++ tools/perf/util/cs-etm.c | 252 ++++++++++++++++-- tools/perf/util/thread-stack.c | 17 ++ tools/perf/util/thread-stack.h | 1 + 7 files changed, 546 insertions(+), 16 deletions(-) create mode 100644 tools/perf/dlfilters/dlfilter-nonempty-brstack.c create mode 100755 tools/perf/tests/shell/coresight/add_last_branch.sh
base-commit: d17c5b770972854a4fe4cf5cc22e17eb21cdc787