[PATCH 00/34] perf cs-etm: JIT decoding support

James Clark james.clark at linaro.org
Wed Nov 18 08:33:21 PST 2026



On 18/11/2026 16:29, James Clark wrote:
> Restructure the Coresight decoder to decode trace in order with the Perf
> events. This improves decoding accuracy all workloads, but particularly
> with JIT code when instructions at the same addresses are re-written.
> 
> The resulting decode loop structure is simplified to
> cs_etm__insert_heap() and cs_etm__pop_heap(), which work in the same way
> for all of the timeless/per-thread/per-cpu etc modes.
> 
> For every Perf event, we pop from the heap while the packet's timestamps
> are before the current Perf event. When a packet is popped, the next
> packet is decoded and re-inserted.
> 
> The same path works for timeless mode because we can just assign the
> timestamp of the AUX record to all trace from that buffer. This also
> improves timeless decoding accuracy because now we don't use the
> timestamp from the very last AUX record for all samples.
> 
> In Coresight trace, timestamps come after their associated atoms and
> Perf uses a single decoder for both searching forwards for a timestamp
> and decoding. It does this by caching decoded packets into
> packet_buffer[] and replaying them once a timestamp is received.
> Unfortunately this does't work for strict ordering with Perf events
> because while searching for the timestamp the decoder will decode trace
> using previously seen mmap which is incorrect.
> 
> To fix this, add a "packet only" decoder for each queue. This is used
> for searching for the next timestamp after a discontinuity and not for
> decoding trace. Once it's found, the backend re-orders that timestamp
> and the previous packet before delivering them to the frontend so that
> we can be at the correct Perf event before processing context packets or
> ranges. Excluding the tests, this patchset results in similar total
> lines of code but if we updated OpenCSD to return timestamps and
> discontinuities in the correct order, then it would be a significant
> reduction in code and complexity.
> 
> This series depends on https://lore.kernel.org/linux-perf-users/20261105-james-cs-unformatted-per-thread-fix-v4-0-7759e0ce2449@linaro.org/
> 

Assisted by various Claude and Codex agents.

> Signed-off-by: James Clark <james.clark at linaro.org>
> ---
> James Clark (34):
>        perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64
>        perf jit: Add name of clock in error message
>        perf jit: Add address ranges to DWARF compilation units
>        perf libdw: Don't look up the module by ELF address
>        perf cs-etm: Use the exception level to tell kernel from user
>        perf cs-etm: Don't read past the end of the map
>        perf build-id: Cache the vDSO in build ID mmap mode
>        perf cs-etm: arm-spe: Use arch timestamp in HW tracers
>        perf cs-etm: arm-spe: Report error if default clock isn't used
>        perf cs-etm: Remove old pipe mode support
>        perf cs-etm: Track threads in timeless mode
>        perf cs-etm: Track sched out events
>        perf cs-etm: Handle PERF_RECORD_SWITCH events
>        perf cs-etm: Always enable Perf event timestamps
>        perf cs-etm: Use time from Perf samples
>        perf cs-etm: Don't buffer non-timestamped packets
>        perf cs-etm: Decode in order of Perf samples
>        perf cs-etm: Don't special case per-thread mode
>        perf cs-etm: Decode one packet at a time and don't estimate timestamps
>        perf cs-etm: Remove the decoded packet ring buffer
>        perf cs-etm: Fold packet state into the trace ID queue
>        perf cs-etm: Rename trace ID queues to trace ID contexts
>        perf cs-etm: Rename tidq variables to tidc
>        perf cs-etm: Share the thread ctxt between frontend and backend
>        perf cs-etm: Consume each OpenCSD packet immediately
>        perf cs-etm: Split base and packet decoder state
>        perf cs-etm: Add packet-only timestamp decoder ops
>        perf cs-etm: Create timestamp decoders
>        perf cs-etm: Find timestamps by searching ahead
>        perf cs-etm: Invalidate OpenCSD's cache on MMAPs
>        perf test cs-etm: Add a Java JIT source-line test
>        perf test cs-etm: Test trace is ordered with context switch records
>        perf test cs-etm: Test decoding of kernel modules
>        perf test cs-etm: Add an HHVM JIT call stack test
> 
>   tools/perf/Makefile.perf                           |    4 +-
>   tools/perf/arch/arm/util/cs-etm.c                  |   21 +-
>   tools/perf/arch/arm64/util/arm-spe.c               |   11 +
>   tools/perf/jvmti/jvmti_agent.c                     |    5 +
>   tools/perf/tests/genelf.c                          |   70 +-
>   .../tests/shell/coresight/context_switch_thread.sh |   20 +-
>   tools/perf/tests/shell/coresight/hhvm-jit.sh       |   89 ++
>   tools/perf/tests/shell/coresight/java-jit.sh       |   65 +
>   tools/perf/tests/shell/coresight/kernel_module.sh  |   54 +
>   tools/perf/tests/shell/coresight/lib/PerfJit.java  |   82 ++
>   tools/perf/tests/shell/coresight/per-thread.sh     |   45 +-
>   tools/perf/tests/workloads/jitdump.c               |    7 +-
>   tools/perf/util/auxtrace.h                         |    2 +
>   tools/perf/util/build-id.c                         |   12 +
>   tools/perf/util/cs-etm-decoder/cs-etm-decoder.c    |  790 ++++++----
>   tools/perf/util/cs-etm-decoder/cs-etm-decoder.h    |   28 +-
>   tools/perf/util/cs-etm.c                           | 1515 ++++++++------------
>   tools/perf/util/cs-etm.h                           |   56 +-
>   tools/perf/util/genelf.c                           |    2 +-
>   tools/perf/util/genelf.h                           |    3 +-
>   tools/perf/util/genelf_debug.c                     |   22 +-
>   tools/perf/util/jitdump.c                          |    2 +-
>   tools/perf/util/libdw.c                            |   16 +-
>   23 files changed, 1643 insertions(+), 1278 deletions(-)
> ---
> base-commit: b7ff10b9ddec8da75304c40fe4abf1ee4f9f0a43
> change-id: 20260824-james-coresight-jit-250f19309e35
> prerequisite-message-id: <20261105-james-cs-unformatted-per-thread-fix-v4-0-7759e0ce2449 at linaro.org>
> prerequisite-patch-id: 9c49b9ffb75309e9187eb2e3ef84026118fcfdb5
> prerequisite-patch-id: 4ce0ba0ab1302c9043f0d0734d9cf6a35298bc47
> prerequisite-patch-id: 5e69770fbaf94296da5c474ce09539a1993bc61e
> prerequisite-patch-id: 41d797af2aba7e97ff4435ae2659629e026d36ec
> prerequisite-patch-id: d5f67b3b704f4f4b3d9e39c4299d13a086b29363
> prerequisite-patch-id: a99348cc2065af31840f652286f840f23395892f
> prerequisite-patch-id: aa90408e69dedf9e68d7158f2499bd9fbc7b0b40
> prerequisite-patch-id: cd31a650f8dd3e7a9795fa641eee2415b126ad29
> prerequisite-patch-id: 922a7fe2937a575beb8d0e7777fd869a11023eb2
> prerequisite-patch-id: b0436630e22fd92803e277cd08d782c50f135be6
> prerequisite-patch-id: e136ff402ddf5121c63c1393b7fc00a826f60a69
> prerequisite-patch-id: 8a2674fa45e40848742e8b8472003e2b9706211d
> prerequisite-patch-id: df905386a100ac4b8b047328de08da86b3adf241
> prerequisite-patch-id: 44ee88eeafd54c0148ed2332dc5e33f1ba6dfce4
> prerequisite-patch-id: b9622164f99682ca6b813b9d38ced3e95170653e
> prerequisite-patch-id: 2f22df1738caf5af3a631851d8a57fc3bfea7742
> prerequisite-patch-id: afe679ea285ddc6cd281f697ce504b7a18888999
> prerequisite-patch-id: f507254858995051e8e1b96fb9fd95506228c5e6
> prerequisite-patch-id: 6fe822580ea330633f8a23260aa7b2c7de834ab3
> 
> Best regards,
> --
> James Clark <james.clark at linaro.org>
> 




More information about the linux-arm-kernel mailing list