Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 00/34] perf cs-etm: JIT decoding support
@ 2026-11-18 16:29 James Clark
  2026-11-18 16:29 ` [PATCH 01/34] perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64 James Clark
                   ` (34 more replies)
  0 siblings, 35 replies; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

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/

Signed-off-by: James Clark <james.clark@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@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@linaro.org>


^ permalink raw reply	[flat|nested] 70+ messages in thread

* [PATCH 01/34] perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
@ 2026-11-18 16:29 ` 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
                   ` (33 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

CLOCK_MONOTONIC can't be correlated with timestamps in trace, so to
allow the JVMTI agent to be used with SPE and Coresight, use CNTVCT_EL0
when JITDUMP_USE_ARCH_TIMESTAMP is set.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/jvmti/jvmti_agent.c       | 5 +++++
 tools/perf/tests/workloads/jitdump.c | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 526dcaf9f079..674eed455586 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -96,6 +96,11 @@ get_arch_timestamp(void)
 	asm volatile("rdtsc" : "=a" (low), "=d" (high));
 
 	return low | ((uint64_t)high) << 32;
+#elif defined(__aarch64__)
+	uint64_t val;
+
+	asm volatile("mrs %0, cntvct_el0" : "=r" (val));
+	return val;
 #else
 	return 0;
 #endif
diff --git a/tools/perf/tests/workloads/jitdump.c b/tools/perf/tests/workloads/jitdump.c
index 01cbbbd564e8..8422b66ee600 100644
--- a/tools/perf/tests/workloads/jitdump.c
+++ b/tools/perf/tests/workloads/jitdump.c
@@ -34,6 +34,11 @@ static inline uint64_t get_timestamp(void)
 	asm volatile("rdtsc" : "=a"(low), "=d"(high));
 
 	return low | ((uint64_t)high) << 32;
+#elif defined(__aarch64__)
+	uint64_t val;
+
+	asm volatile("mrs %0, cntvct_el0" : "=r" (val));
+	return val;
 #else
 	struct timespec ts;
 	int ret;
@@ -55,7 +60,7 @@ static FILE *open_jitdump(void)
 		.pid = getpid(),
 		.timestamp = get_timestamp(),
 		.flags =
-#if defined(__x86_64__) || defined(__i386__)
+#if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__)
 			JITDUMP_FLAGS_ARCH_TIMESTAMP,
 #else
 			0,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 02/34] perf jit: Add name of clock in error message
  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:29 ` 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
                   ` (32 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Use the full name in the error message. This is also a valid form of -k
argument and says exactly what clock is needed rather than having to
work out how these numbers map to clock names.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/jitdump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 45a05316b3ca..4c1a71702f62 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -220,7 +220,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 	 * validate event is using the correct clockid
 	 */
 	if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
-		pr_err("error, jitted code must be sampled with perf record -k 1\n");
+		pr_err("error, jitted code must be sampled with perf record -k CLOCK_MONOTONIC\n");
 		goto error;
 	}
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 03/34] perf jit: Add address ranges to DWARF compilation units
  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:29 ` [PATCH 02/34] perf jit: Add name of clock in error message James Clark
@ 2026-11-18 16:29 ` 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
                   ` (31 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

The JIT ELF writer emits a line table and a compilation unit containing
only DW_AT_stmt_list. LLVM locates the CU by address before looking up a
source line, but the CU address range isn't written into the DWARF.
Therefore it can't resolve these files even though GNU addr2line could
by reading the line table directly. This means that JIT src line lookups
when LLVM is used.

Pass the generated code size to the debug information writer and emit
DW_AT_low_pc and DW_AT_high_pc address ranges. Also mark the compilation
unit as childless to match its contents.

Add a test which writes JIT debug information at a nonzero runtime load
address and resolves an ELF-relative address through LLVM.

Fixes: c3f8644c21df ("perf report: Support LLVM for addr2line()")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/genelf.c      | 70 +++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/genelf.c       |  2 +-
 tools/perf/util/genelf.h       |  3 +-
 tools/perf/util/genelf_debug.c | 22 +++++++++----
 4 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
index 95f3be1b683a..4d23778c1979 100644
--- a/tools/perf/tests/genelf.c
+++ b/tools/perf/tests/genelf.c
@@ -5,6 +5,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <linux/compiler.h>
+#include <linux/kernel.h>
+#include <linux/unaligned.h>
 
 #include "debug.h"
 #include "tests.h"
@@ -12,6 +14,8 @@
 #ifdef HAVE_JITDUMP
 #include <libelf.h>
 #include "../util/genelf.h"
+#include "../util/jitdump.h"
+#include "../util/llvm.h"
 #endif
 
 #define TEMPL "/tmp/perf-test-XXXXXX"
@@ -50,4 +54,68 @@ static int test__jit_write_elf(struct test_suite *test __maybe_unused,
 #endif
 }
 
-DEFINE_SUITE("Test jit_write_elf", jit_write_elf);
+static int test__jit_write_elf_dwarf(struct test_suite *test __maybe_unused,
+				     int subtest __maybe_unused)
+{
+#if defined(HAVE_JITDUMP) && defined(HAVE_LIBDW_SUPPORT) && defined(HAVE_LIBLLVM_SUPPORT)
+	const uint64_t load_addr = 0x12340000;
+	static const char filename[] = "jit.c";
+	unsigned char code[16] = { 0 };
+	unsigned char debug[2 * (sizeof(struct debug_entry) + sizeof(filename))];
+	struct debug_entry *entry = (struct debug_entry *)debug;
+	char path[] = TEMPL;
+	char *file = NULL;
+	unsigned int line = 0;
+	int fd, ret = TEST_FAIL;
+
+	/* The second row terminates the first row's source-line range. */
+	for (int i = 0; i < 2; i++) {
+		put_unaligned(load_addr + i * 8, &entry->addr);
+		put_unaligned(42 + i, &entry->lineno);
+		put_unaligned(0, &entry->discrim);
+		memcpy(entry + 1, filename, sizeof(filename));
+		entry = debug_entry_next(entry);
+	}
+
+	fd = mkstemp(path);
+	if (fd < 0) {
+		perror("mkstemp failed");
+		return TEST_FAIL;
+	}
+
+	if (jit_write_elf(fd, load_addr, "main", code, sizeof(code),
+			  debug, 2, NULL, 0, 0))
+		goto out;
+
+	/* LLVM must find the CU from the ELF address before reading its lines. */
+	if (llvm__addr2line(path, GEN_ELF_TEXT_OFFSET + 4, &file, &line,
+			    NULL, false, NULL, NULL) <= 0) {
+		pr_debug("LLVM could not resolve the JIT source line\n");
+		goto out;
+	}
+	if (!file || strcmp(file, filename) || line != 42) {
+		pr_debug("Unexpected JIT source line: %s:%u\n", file ?: "??", line);
+		goto out;
+	}
+	ret = TEST_OK;
+out:
+	free(file);
+	close(fd);
+	unlink(path);
+	return ret;
+#else
+	return TEST_SKIP;
+#endif
+}
+
+static struct test_case tests__jit_write_elf[] = {
+	TEST_CASE("Write JIT ELF", jit_write_elf),
+	TEST_CASE_REASON("Resolve JIT ELF source line with LLVM", jit_write_elf_dwarf,
+			 "requires JIT dump, libdw and LLVM support"),
+	{ .name = NULL, }
+};
+
+struct test_suite suite__jit_write_elf = {
+	.desc = "Test jit_write_elf",
+	.test_cases = tests__jit_write_elf,
+};
diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
index 14882def9704..fc145f9401d2 100644
--- a/tools/perf/util/genelf.c
+++ b/tools/perf/util/genelf.c
@@ -449,7 +449,7 @@ jit_write_elf(int fd, uint64_t load_addr __maybe_unused, const char *sym,
 
 #ifdef HAVE_LIBDW_SUPPORT
 	if (debug && nr_debug_entries) {
-		retval = jit_add_debug_info(e, load_addr, debug, nr_debug_entries);
+		retval = jit_add_debug_info(e, load_addr, csize, debug, nr_debug_entries);
 		if (retval)
 			goto error;
 	} else
diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
index 9f0b875d6548..67309794239a 100644
--- a/tools/perf/util/genelf.h
+++ b/tools/perf/util/genelf.h
@@ -10,7 +10,8 @@ int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
 		  void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
 #ifdef HAVE_LIBDW_SUPPORT
 /* genelf_debug.c */
-int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
+int jit_add_debug_info(Elf *e, uint64_t code_addr, int code_size,
+		       void *debug, int nr_debug_entries);
 #endif
 
 #if   defined(__arm__)
diff --git a/tools/perf/util/genelf_debug.c b/tools/perf/util/genelf_debug.c
index 7d9ef43aa6ac..a124ab40f36b 100644
--- a/tools/perf/util/genelf_debug.c
+++ b/tools/perf/util/genelf_debug.c
@@ -449,9 +449,13 @@ add_debug_abbrev(struct buffer_ext *be)
 {
         emit_unsigned_LEB128(be, 1);
         emit_unsigned_LEB128(be, DW_TAG_compile_unit);
-        emit_unsigned_LEB128(be, DW_CHILDREN_yes);
+	emit_unsigned_LEB128(be, DW_CHILDREN_no);
         emit_unsigned_LEB128(be, DW_AT_stmt_list);
         emit_unsigned_LEB128(be, DW_FORM_data4);
+	emit_unsigned_LEB128(be, DW_AT_low_pc);
+	emit_unsigned_LEB128(be, DW_FORM_addr);
+	emit_unsigned_LEB128(be, DW_AT_high_pc);
+	emit_unsigned_LEB128(be, DW_FORM_addr);
         emit_unsigned_LEB128(be, 0);
         emit_unsigned_LEB128(be, 0);
         emit_unsigned_LEB128(be, 0);
@@ -459,9 +463,11 @@ add_debug_abbrev(struct buffer_ext *be)
 
 static void
 add_compilation_unit(struct buffer_ext *be,
-		     size_t offset_debug_line)
+		     size_t offset_debug_line, int code_size)
 {
 	struct compilation_unit_header *comp_unit_header;
+	uintptr_t low_pc = GEN_ELF_TEXT_OFFSET;
+	uintptr_t high_pc = low_pc + code_size;
 	size_t old_size = buffer_ext_size(be);
 
 	buffer_ext_add(be, &default_comp_unit_header,
@@ -469,6 +475,9 @@ add_compilation_unit(struct buffer_ext *be,
 
 	emit_unsigned_LEB128(be, 1);
 	emit_uword(be, offset_debug_line);
+	/* DW_FORM_addr uses the address size declared in the CU header. */
+	buffer_ext_add(be, &low_pc, sizeof(low_pc));
+	buffer_ext_add(be, &high_pc, sizeof(high_pc));
 
 	comp_unit_header = buffer_ext_addr(be) + old_size;
 	comp_unit_header->total_length = (buffer_ext_size(be) - old_size) -
@@ -476,7 +485,7 @@ add_compilation_unit(struct buffer_ext *be,
 }
 
 static int
-jit_process_debug_info(uint64_t code_addr,
+jit_process_debug_info(uint64_t code_addr, int code_size,
 		       void *debug, int nr_debug_entries,
 		       struct buffer_ext *dl,
 		       struct buffer_ext *da,
@@ -489,7 +498,7 @@ jit_process_debug_info(uint64_t code_addr,
 		put_unaligned(get_unaligned(&ent->addr) - code_addr, &ent->addr);
 		ent = debug_entry_next(ent);
 	}
-	add_compilation_unit(di, buffer_ext_size(dl));
+	add_compilation_unit(di, buffer_ext_size(dl), code_size);
 	add_debug_line(dl, debug, nr_debug_entries, GEN_ELF_TEXT_OFFSET);
 	add_debug_abbrev(da);
 	if (0) buffer_ext_dump(da, "abbrev");
@@ -498,7 +507,8 @@ jit_process_debug_info(uint64_t code_addr,
 }
 
 int
-jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries)
+jit_add_debug_info(Elf *e, uint64_t code_addr, int code_size,
+		   void *debug, int nr_debug_entries)
 {
 	Elf_Data *d;
 	Elf_Scn *scn;
@@ -510,7 +520,7 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries
 	buffer_ext_init(&di);
 	buffer_ext_init(&da);
 
-	if (jit_process_debug_info(code_addr, debug, nr_debug_entries, &dl, &da, &di))
+	if (jit_process_debug_info(code_addr, code_size, debug, nr_debug_entries, &dl, &da, &di))
 		goto out;
 
 	/*

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 04/34] perf libdw: Don't look up the module by ELF address
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (2 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 03/34] perf jit: Add address ranges to DWARF compilation units James Clark
@ 2026-11-18 16:29 ` 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
                   ` (30 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

libdw__addr2line() finds the module with dwfl_addrmodule() using the ELF
address. However, libdw reports modules loaded from disk at a fixed bias
of 0x10000, so any ELF address below that isn't considered to be in the
module. This means that source lines for very small binaries and JIT
files can't be found by libdw.

This used to be hidden by falling back to the next addr2line style, but
now missing information stops the fallback since commit (62d7cdc8d587
"perf libdw: Optimize fallback logic for missing DWARF"). So perf script
fails to show source line for these addresses.

Perf creates a separate Dwfl session for each DSO and only loads that
DSO's file into it, so take the session's only module instead of looking
it up by address to fix the issue.

Fixes: 88c51002d06f ("perf addr2line: Add a libdw implementation")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/libdw.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c
index 90767361f485..4f472ff9f1bf 100644
--- a/tools/perf/util/libdw.c
+++ b/tools/perf/util/libdw.c
@@ -164,6 +164,14 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args)
 	return DWARF_CB_ABORT;
 }
 
+static int libdw__get_module(Dwfl_Module *mod, void **userdata __maybe_unused,
+			     const char *name __maybe_unused,
+			     Dwarf_Addr base __maybe_unused, void *arg)
+{
+	*(Dwfl_Module **)arg = mod;
+	return DWARF_CB_ABORT;
+}
+
 int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
 		     struct dso *dso, bool unwind_inlines,
 		     struct inline_node *node, struct symbol *sym)
@@ -188,7 +196,13 @@ int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
 		goto out;
 	}
 
-	mod = dwfl_addrmodule(dwfl, addr);
+	/*
+	 * The session only contains this DSO, but libdw places offline modules
+	 * away from address 0. Take the module directly rather than looking it
+	 * up by an ELF address, which isn't a module address.
+	 */
+	mod = NULL;
+	dwfl_getmodules(dwfl, libdw__get_module, &mod, 0);
 	if (!mod) {
 		ret = 0;
 		goto out;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 05/34] perf cs-etm: Use the exception level to tell kernel from user
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (3 preceding siblings ...)
  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:29 ` 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
                   ` (29 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

cs_etm__cpu_mode() decides whether an address is in the kernel by
comparing it with the kernel start address. On arm64, modules are loaded
below that, so module code is looked up in the thread's user maps which
results in a decode failure.

The exception level of the trace is known for ETMv4 and ETE, so use that
instead and only fall back to the address when it's unknown. This
enables the ability to decode trace from kernel modules.

Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  6 ++++--
 tools/perf/util/cs-etm.c                        | 12 +++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

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 b9397151748b..f133e11ccc7b 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -462,7 +462,8 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 	packet->last_instr_type = elem->last_i_type;
 	packet->last_instr_subtype = elem->last_i_subtype;
 	packet->last_instr_cond = elem->last_instr_cond;
-	packet->el = elem->context.exception_level;
+	if (elem->context.el_valid)
+		packet->el = elem->context.exception_level;
 
 	if (elem->last_i_type == OCSD_INSTR_BR || elem->last_i_type == OCSD_INSTR_BR_INDIRECT)
 		packet->last_instr_taken_branch = elem->last_instr_exec;
@@ -607,7 +608,8 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 
 	packet = &packet_queue->packet_buffer[packet_queue->tail];
 	packet->tid = tid;
-	packet->el = elem->context.exception_level;
+	if (elem->context.el_valid)
+		packet->el = elem->context.exception_level;
 
 	/*
 	 * A timestamp is generated after a PE_CONTEXT element so make sure
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 51431a4d5db7..3fce3c357943 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1134,8 +1134,18 @@ static u8 cs_etm__cpu_mode(struct cs_etm_queue *etmq, u64 address,
 			   ocsd_ex_level el)
 {
 	struct machine *machine = cs_etm__get_machine(etmq, el);
+	bool kernel;
 
-	if (address >= machine__kernel_start(machine)) {
+	/*
+	 * Prefer the exception level when it's known, because arm64 modules are
+	 * below the kernel start address.
+	 */
+	if (el == ocsd_EL_unknown)
+		kernel = address >= machine__kernel_start(machine);
+	else
+		kernel = el != ocsd_EL0;
+
+	if (kernel) {
 		if (machine__is_host(machine))
 			return PERF_RECORD_MISC_KERNEL;
 		else

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 06/34] perf cs-etm: Don't read past the end of the map
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (4 preceding siblings ...)
  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:29 ` 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
                   ` (28 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

OpenCSD caches instruction memory one page size at a time. Perf reads
this requested size from the file on disk without limiting it to the end
of the map, so the page can contain ELF metadata from the file that
wasn't mapped. If a subsequent read for a different .so file falls into
this range, then it won't be decoded properly.

Fix it by clamping the read size to the end of the map. Now when OpenCSD
requests an address outside of that range, Perf will load the next .so
file rather than OpenCSD using the mis-cached data.

Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 3fce3c357943..fb4582dc378e 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1213,6 +1213,12 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
 
 	offset = map__map_ip(al.map, address);
 
+	/*
+	 * Clamp to the map size to avoid putting unmapped ELF file data from
+	 * the .so into OpenCSD's cache as map data.
+	 */
+	size = min_t(u64, size, map__end(al.map) - address);
+
 	map__load(al.map);
 
 	len = dso__data_read_offset(dso, maps__machine(thread__maps(thread)),

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 07/34] perf build-id: Cache the vDSO in build ID mmap mode
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (5 preceding siblings ...)
  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 16:29 ` 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
                   ` (27 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Since --buildid-mmap became the default, perf record doesn't add the
vDSO to the build ID cache. Caching a DSO requires its build ID, but the
vDSO doesn't have a file so the kernel can't add one to its mmap event.
Build IDs that are missing from mmap events were previously read when
writing the build ID table to the header, but the table isn't written
in build ID mmap mode.

This breaks decoding of hardware trace through the vDSO after perf
inject -b. Inject adds a build ID for the vDSO, so perf script looks it
up in the build ID cache and can't find it:

  CS ETM Trace: Debug data not found for address 0xffff95edb310 in [vdso]

Fix it by reading the vDSO's build ID from perf's copy of the vDSO
before caching it.

Fixes: 53b00ff358dc ("perf record: Make --buildid-mmap the default")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/build-id.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 02233ef0eaff..cc813f421c9b 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -886,6 +886,18 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
 	char *allocated_name = NULL;
 	int ret = 0;
 
+	/*
+	 * The kernel can't add the vDSO's build ID to mmap events because it
+	 * doesn't have a file, so read it from the copy that perf made. That
+	 * copy is of the host's vDSO, so it can't be used for guests.
+	 */
+	if (is_vdso && machine__is_host(machine) && !dso__has_build_id(dso)) {
+		struct build_id bid = { .size = 0, };
+
+		if (filename__read_build_id(name, &bid) > 0)
+			dso__set_build_id(dso, &bid);
+	}
+
 	if (!dso__has_build_id(dso) || !dso__hit(dso))
 		return 0;
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 08/34] perf cs-etm: arm-spe: Use arch timestamp in HW tracers
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (6 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 07/34] perf build-id: Cache the vDSO in build ID mmap mode James Clark
@ 2026-11-18 16:29 ` 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
                   ` (26 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

To allow the JIT dump records to be correlated with the HW timestamp in
trace, set JITDUMP_USE_ARCH_TIMESTAMP.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm/util/cs-etm.c    | 5 +++++
 tools/perf/arch/arm64/util/arm-spe.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 84a5d7392a5f..809da6f1a892 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -909,6 +909,11 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 		goto out;
 	}
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	ptr = zalloc(sizeof(struct cs_etm_recording));
 	if (!ptr) {
 		*err = -ENOMEM;
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 8d6a2bde2892..53899c7de846 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -521,6 +521,11 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
 		return NULL;
 	}
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	sper = zalloc(sizeof(struct arm_spe_recording));
 	if (!sper) {
 		*err = -ENOMEM;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 09/34] perf cs-etm: arm-spe: Report error if default clock isn't used
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (7 preceding siblings ...)
  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:29 ` 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
                   ` (25 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Coresight already reported an error if a different clock was used, but
this also applies to SPE so add the same error there.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm/util/cs-etm.c    | 2 +-
 tools/perf/arch/arm64/util/arm-spe.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 809da6f1a892..5a64c17cf254 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -365,7 +365,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 		return ret;
 
 	if (opts->use_clockid) {
-		pr_err("Cannot use clockid (-k option) with %s\n",
+		pr_err("Cannot use clockid (-k option) with %s, can only correlate samples with the default clock.\n",
 		       CORESIGHT_ETM_PMU_NAME);
 		return -EINVAL;
 	}
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 53899c7de846..834419f04617 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -416,6 +416,12 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 				       evsel->pmu->name);
 				return -EINVAL;
 			}
+
+			if (opts->use_clockid) {
+				pr_err("Cannot use clockid (-k option) with %s, can only correlate samples with the default clock.\n",
+				       evsel->pmu->name);
+				return -EINVAL;
+			}
 		}
 	}
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 10/34] perf cs-etm: Remove old pipe mode support
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (8 preceding siblings ...)
  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:29 ` 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
                   ` (24 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Pipe mode hasn't been supported since we added several peeks to
cs_etm__process_auxtrace_info_full() that require random access. Even if
it was supported, we would have to buffer the whole file anyway to make
fully ordered decoding work. You don't know if one core stopped tracing
for good or whether to wait till very end of the file for the next one.
IntelPT has the same issue, see 'perf-intel-pt.txt#Pipe mode'.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 38 +++-----------------------------------
 1 file changed, 3 insertions(+), 35 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index fb4582dc378e..11ebfdf1e933 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -66,7 +66,6 @@ struct cs_etm_auxtrace {
 	 */
 	bool per_thread_decoding;
 	bool snapshot_mode;
-	bool data_queued;
 	bool has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */
 	bool use_thread_stack;
 	bool use_callchain;
@@ -3126,33 +3125,7 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,
 	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
 						   struct cs_etm_auxtrace,
 						   auxtrace);
-	if (!etm->data_queued) {
-		struct auxtrace_buffer *buffer;
-		off_t  data_offset;
-		int fd = perf_data__fd(session->data);
-		bool is_pipe = perf_data__is_pipe(session->data);
-		int err;
-		int idx = event->auxtrace.idx;
-
-		if (is_pipe)
-			data_offset = 0;
-		else {
-			data_offset = lseek(fd, 0, SEEK_CUR);
-			if (data_offset == -1)
-				return -errno;
-		}
-
-		err = auxtrace_queues__add_event(&etm->queues, session,
-						 event, data_offset, &buffer);
-		if (err)
-			return err;
-
-		if (dump_trace)
-			if (auxtrace_buffer__get_data(buffer, fd)) {
-				cs_etm__dump_event(etm->queues.queue_array[idx].priv, buffer);
-				auxtrace_buffer__put_data(buffer);
-			}
-	} else if (dump_trace)
+	if (dump_trace)
 		dump_queued_data(etm, &event->auxtrace);
 
 	return 0;
@@ -3454,12 +3427,8 @@ static int cs_etm__queue_aux_records(struct perf_session *session)
 						 cs_etm__queue_aux_records_cb, NULL);
 
 	/*
-	 * We would get here if there are no entries in the index (either no auxtrace
-	 * buffers or no index at all). Fail silently as there is the possibility of
-	 * queueing them in cs_etm__process_auxtrace_event() if etm->data_queued is still
-	 * false.
-	 *
-	 * In that scenario, buffers will not be split by AUX records.
+	 * No entries in the index (either no auxtrace buffers or no index at
+	 * all).
 	 */
 	return 0;
 }
@@ -3867,7 +3836,6 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,
 	if (err)
 		goto err_free_queues;
 
-	etm->data_queued = etm->queues.populated;
 	return 0;
 
 err_free_queues:

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 11/34] perf cs-etm: Track threads in timeless mode
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (9 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 10/34] perf cs-etm: Remove old pipe mode support James Clark
@ 2026-11-18 16:29 ` 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
                   ` (23 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Associating TIDs with PIDs is useful with and without timestamps. This
is an old assumption from when timeless == per-thread mode so remove it.

Update the comment to say exactly why this needs to be done and move it
to a single function so it's not repeated.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 53 +++++++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 11ebfdf1e933..67e3e2becd0f 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2984,23 +2984,22 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 	return ret;
 }
 
-static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm,
-					union perf_event *event)
+static int cs_etm__associate_tid(struct cs_etm_auxtrace *etm, pid_t pid,
+				 pid_t tid)
 {
 	struct thread *th;
 
-	if (etm->timeless_decoding)
-		return 0;
-
 	/*
-	 * Add the tid/pid to the log so that we can get a match when we get a
-	 * contextID from the decoder. Only track for the host: only kernel
-	 * trace is supported for guests which wouldn't need pids so this should
-	 * be fine.
+	 * TIDs share their maps with their PID, but the association between the
+	 * two is only tracked by Perf on COMM, FORK and SAMPLE records.
+	 * Trace doesn't generate normal samples, and COMM and FORK may be
+	 * missed when attaching so pass the relationship using other record
+	 * types.
+	 *
+	 * Only track for the host: only kernel trace is supported for guests
+	 * which wouldn't need pids so this should be fine.
 	 */
-	th = machine__findnew_thread(&etm->session->machines.host,
-				     event->itrace_start.pid,
-				     event->itrace_start.tid);
+	th = machine__findnew_thread(&etm->session->machines.host, pid, tid);
 	if (!th)
 		return -ENOMEM;
 
@@ -3009,19 +3008,18 @@ static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm,
 	return 0;
 }
 
+static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm,
+					union perf_event *event)
+{
+	return cs_etm__associate_tid(etm, event->itrace_start.pid,
+				     event->itrace_start.tid);
+}
+
 static int cs_etm__process_switch_cpu_wide(struct cs_etm_auxtrace *etm,
 					   union perf_event *event)
 {
-	struct thread *th;
 	bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT;
 
-	/*
-	 * Context switch in per-thread mode are irrelevant since perf
-	 * will start/stop tracing as the process is scheduled.
-	 */
-	if (etm->timeless_decoding)
-		return 0;
-
 	/*
 	 * SWITCH_IN events carry the next process to be switched out while
 	 * SWITCH_OUT events carry the process to be switched in.  As such
@@ -3030,21 +3028,8 @@ static int cs_etm__process_switch_cpu_wide(struct cs_etm_auxtrace *etm,
 	if (!out)
 		return 0;
 
-	/*
-	 * Add the tid/pid to the log so that we can get a match when we get a
-	 * contextID from the decoder. Only track for the host: only kernel
-	 * trace is supported for guests which wouldn't need pids so this should
-	 * be fine.
-	 */
-	th = machine__findnew_thread(&etm->session->machines.host,
-				     event->context_switch.next_prev_pid,
+	return cs_etm__associate_tid(etm, event->context_switch.next_prev_pid,
 				     event->context_switch.next_prev_tid);
-	if (!th)
-		return -ENOMEM;
-
-	thread__put(th);
-
-	return 0;
 }
 
 static int cs_etm__process_event(struct perf_session *session,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 12/34] perf cs-etm: Track sched out events
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (10 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 11/34] perf cs-etm: Track threads in timeless mode James Clark
@ 2026-11-18 16:29 ` 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
                   ` (22 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

The sched in event might be dropped due to a full ringbuffer, so the
sched out event is still useful information if that thread is going to
be seen again. Call machine__findnew_thread() unconditionally as it's
harmless to do it twice for the same thread.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 67e3e2becd0f..1e1ff6cc8a5e 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -3018,16 +3018,6 @@ static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm,
 static int cs_etm__process_switch_cpu_wide(struct cs_etm_auxtrace *etm,
 					   union perf_event *event)
 {
-	bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT;
-
-	/*
-	 * SWITCH_IN events carry the next process to be switched out while
-	 * SWITCH_OUT events carry the process to be switched in.  As such
-	 * we don't care about IN events.
-	 */
-	if (!out)
-		return 0;
-
 	return cs_etm__associate_tid(etm, event->context_switch.next_prev_pid,
 				     event->context_switch.next_prev_tid);
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (11 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 12/34] perf cs-etm: Track sched out events James Clark
@ 2026-11-18 16:29 ` 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
                   ` (21 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Task bound events use PERF_RECORD_SWITCH events instead so handle these
too. Furthermore associate the current PID and TID on
PERF_RECORD_SWITCH_CPU_WIDE events as this is just as useful as the next
PID and TID.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 1e1ff6cc8a5e..4252d25c991d 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -3016,12 +3016,25 @@ static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm,
 }
 
 static int cs_etm__process_switch_cpu_wide(struct cs_etm_auxtrace *etm,
-					   union perf_event *event)
+					   union perf_event *event,
+					   struct perf_sample *sample)
 {
+	int ret;
+
+	ret = cs_etm__associate_tid(etm, sample->pid, sample->tid);
+	if (ret)
+		return ret;
+
 	return cs_etm__associate_tid(etm, event->context_switch.next_prev_pid,
 				     event->context_switch.next_prev_tid);
 }
 
+static int cs_etm__process_switch(struct cs_etm_auxtrace *etm,
+				  struct perf_sample *sample)
+{
+	return cs_etm__associate_tid(etm, sample->pid, sample->tid);
+}
+
 static int cs_etm__process_event(struct perf_session *session,
 				 union perf_event *event,
 				 struct perf_sample *sample,
@@ -3058,7 +3071,10 @@ static int cs_etm__process_event(struct perf_session *session,
 		return cs_etm__process_itrace_start(etm, event);
 
 	case PERF_RECORD_SWITCH_CPU_WIDE:
-		return cs_etm__process_switch_cpu_wide(etm, event);
+		return cs_etm__process_switch_cpu_wide(etm, event, sample);
+
+	case PERF_RECORD_SWITCH:
+		return cs_etm__process_switch(etm, sample);
 
 	case PERF_RECORD_AUX:
 		/*

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 14/34] perf cs-etm: Always enable Perf event timestamps
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (12 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events James Clark
@ 2026-11-18 16:29 ` 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
                   ` (20 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

We still need MMAP timestamps in per-thread mode for overlapping mmaps,
so always enable them. Also update the comment above to reflect the fact
that Coresight timestamps are on by default, -T just gives more frequent
ones.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm/util/cs-etm.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 5a64c17cf254..28aaaabf36bc 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -456,6 +456,9 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 	 */
 	evsel__set_sample_bit(cs_etm_evsel, CPU);
 
+	/* Need the time of AUX events */
+	evsel__set_sample_bit(cs_etm_evsel, TIME);
+
 	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
 		/*
 		 * Timestamps are required to interleave samples from different
@@ -479,9 +482,9 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 	}
 
 	/*
-	 * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME
-	 * bit is set for all events.  In this case, always enable Arm CoreSight
-	 * timestamp tracing.
+	 * When the Perf option '--timestamp' or '-T' is enabled, expect that
+	 * the user also wants more frequent Coresight timestamps than only
+	 * context packet ones.
 	 */
 	if (opts->sample_time_set)
 		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", DEFAULT_TS);
@@ -495,9 +498,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 	evsel->core.attr.freq = 0;
 	evsel->core.attr.sample_period = 1;
 
-	/* In per-cpu case, always need the time of mmap events etc */
-	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus))
-		evsel__set_sample_bit(evsel, TIME);
+	/* Need the time of mmap and sched events etc */
+	evsel__set_sample_bit(evsel, TIME);
 
 	err = cs_etm_validate_config(cs_etm_pmu, cs_etm_evsel);
 out:

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 15/34] perf cs-etm: Use time from Perf samples
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (13 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 14/34] perf cs-etm: Always enable Perf event timestamps James Clark
@ 2026-11-18 16:29 ` 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
                   ` (19 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

The time from the AUX record that's associated with a chunk of data can
be used as a time for the generated samples when there is no virtual
trace timestamp. This replaces 'latest_kernel_timestamp'.

Invert 'timeless_decoding' to 'has_timestamps' so that it's easier to
use and initialize it and 'has_virtual_ts' taking --itrace=Z into
account. That way the same codepaths can treat the trace as if it didn't
have timestamps, even if they exist in the trace.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/auxtrace.h                      |   2 +
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  15 +--
 tools/perf/util/cs-etm.c                        | 162 +++++++++++++-----------
 tools/perf/util/cs-etm.h                        |   2 +-
 4 files changed, 98 insertions(+), 83 deletions(-)

diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 980acb2dc687..c0f971b09b24 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -248,6 +248,7 @@ struct auxtrace {
  * @buffer_nr: used to number each buffer
  * @use_size: implementation actually only uses this number of bytes
  * @use_data: implementation actually only uses data starting at this address
+ * @time: PERF_SAMPLE_TIME associated with the trace
  */
 struct auxtrace_buffer {
 	struct list_head	list;
@@ -266,6 +267,7 @@ struct auxtrace_buffer {
 	u64			buffer_nr;
 	size_t			use_size;
 	void			*use_data;
+	u64			time;
 };
 
 /**
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 f133e11ccc7b..d260d89453ef 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -292,6 +292,10 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	u64 converted_timestamp;
 	u64 estimated_first_ts;
 
+	/* Ignore trace timestamps when unavailable or disabled by --itrace=Z. */
+	if (!cs_etm__has_timestamps(etmq))
+		return OCSD_RESP_CONT;
+
 	/* First get the packet queue for this traceID */
 	packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
 	if (!packet_queue)
@@ -326,10 +330,9 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 		 * underflow.
 		 */
 		packet_queue->cs_timestamp = 0;
-		if (!cs_etm__etmq_is_timeless(etmq))
-			pr_warning_once("Zero Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR
-					". Decoding may be improved by prepending 'Z' to your current --itrace arguments.\n",
-					indx);
+		pr_warning_once("Bad Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR
+				". Decode in order of trace collection by prepending 'Z' to your current --itrace arguments.\n",
+				indx);
 
 	} else if (packet_queue->instr_count / INSTR_PER_NS > converted_timestamp) {
 		/*
@@ -472,10 +475,6 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 
 	packet->last_instr_size = elem->last_instr_sz;
 
-	/* per-thread scenario, no need to generate a timestamp */
-	if (cs_etm__etmq_is_timeless(etmq))
-		goto out;
-
 	/*
 	 * The packet queue is full and we haven't seen a timestamp (had we
 	 * seen one the packet queue wouldn't be full).  Let the front end
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 4252d25c991d..ca3878a3b74e 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -49,14 +49,8 @@ struct cs_etm_auxtrace {
 	struct perf_session *session;
 	struct perf_tsc_conversion tc;
 
-	/*
-	 * Timeless has no timestamps in the trace so overlapping mmap lookups
-	 * are less accurate but produces smaller trace data. We use context IDs
-	 * in the trace instead of matching timestamps with fork records so
-	 * they're not really needed in the general case. Overlapping mmaps
-	 * happen in cases like between a fork and an exec.
-	 */
-	bool timeless_decoding;
+	/* Trace timestamps are available and not disabled by --itrace=Z. */
+	bool has_timestamps;
 
 	/*
 	 * Per-thread ignores the trace channel ID and instead assumes that
@@ -66,12 +60,11 @@ struct cs_etm_auxtrace {
 	 */
 	bool per_thread_decoding;
 	bool snapshot_mode;
-	bool has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */
+	bool has_virtual_ts; /* Trace timestamps can be used as kernel time. */
 	bool use_thread_stack;
 	bool use_callchain;
 
 	int num_cpu;
-	u64 latest_kernel_timestamp;
 	u32 auxtrace_type;
 	u32 branches_filter;
 	u64 branches_sample_type;
@@ -588,7 +581,19 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
 	etmq->pending_timestamp_chan_id = trace_chan_id;
 }
 
-static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq,
+/*
+ * Timestamp used to order sample generation between queues.
+ *
+ * This can either be a virtual or non-virtual CoreSight timestamp value, or the
+ * kernel time from the AUX record if there are no timestamps. The only
+ * requirement is that it's the same timebase between queues so comparisons
+ * work, the absolute value isn't important.
+ *
+ * This is not the same as the timestamp assigned to synthesized samples
+ * (cs_etm__resolve_sample_time()) and may be zero before a timestamp is
+ * received, at which point sample generation is still un-ordered.
+ */
+static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 				      u8 *trace_chan_id)
 {
 	struct cs_etm_packet_queue *packet_queue;
@@ -607,6 +612,13 @@ static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq,
 	/* Acknowledge pending status */
 	etmq->pending_timestamp_chan_id = 0;
 
+	/*
+	 * If there are no timestamps, use the TS from the AUX records to sort
+	 * in order of trace collection.
+	 */
+	if (!etmq->etm->has_timestamps)
+		return etmq->buffer->time;
+
 	/* See function cs_etm_decoder__do_{hard|soft}_timestamp() */
 	return packet_queue->cs_timestamp;
 }
@@ -961,7 +973,7 @@ static int cs_etm__flush_events(struct perf_session *session,
 	if (!tool->ordered_events)
 		return -EINVAL;
 
-	if (etm->timeless_decoding) {
+	if (!etm->has_timestamps) {
 		/*
 		 * Pass tid = -1 to process all queues. But likely they will have
 		 * already been processed on PERF_RECORD_EXIT anyway.
@@ -1355,7 +1367,7 @@ static int cs_etm__queue_first_cs_timestamp(struct cs_etm_auxtrace *etm,
 		 * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
 		 * the timestamp calculation for us.
 		 */
-		cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
+		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
 
 		/* We found a timestamp, no need to continue. */
 		if (cs_timestamp)
@@ -1572,9 +1584,9 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 	return 0;
 }
 
-bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq)
+bool cs_etm__has_timestamps(struct cs_etm_queue *etmq)
 {
-	return !!etmq->etm->timeless_decoding;
+	return etmq->etm->has_timestamps;
 }
 
 static void cs_etm__copy_insn(struct cs_etm_queue *etmq,
@@ -1625,10 +1637,14 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue;
 
-	if (!etm->timeless_decoding && etm->has_virtual_ts)
+	if (etm->has_virtual_ts)
 		return packet_queue->cs_timestamp;
-	else
-		return etm->latest_kernel_timestamp;
+
+	/*
+	 * Timestamps were disabled or no virtual TS. All samples are assigned
+	 * the kernel time from when the trace block was emitted.
+	 */
+	return etmq->buffer->time;
 }
 
 static bool cs_etm__packet_has_branch(struct cs_etm_packet *packet)
@@ -1897,10 +1913,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 	attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK;
 	attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID |
 			    PERF_SAMPLE_PERIOD;
-	if (etm->timeless_decoding)
-		attr.sample_type &= ~(u64)PERF_SAMPLE_TIME;
-	else
-		attr.sample_type |= PERF_SAMPLE_TIME;
+	attr.sample_type |= PERF_SAMPLE_TIME;
 
 	attr.exclude_user = evsel->core.attr.exclude_user;
 	attr.exclude_kernel = evsel->core.attr.exclude_kernel;
@@ -2935,7 +2948,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 		if (ret)
 			goto out;
 
-		cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
+		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
 
 		if (!cs_timestamp) {
 			/*
@@ -3062,7 +3075,7 @@ static int cs_etm__process_event(struct perf_session *session,
 		 * for flush so that events from different threads are interleaved
 		 * properly.
 		 */
-		if (etm->per_thread_decoding && etm->timeless_decoding)
+		if (etm->per_thread_decoding && !etm->has_timestamps)
 			return cs_etm__process_timeless_queues(etm,
 							       event->fork.tid);
 		break;
@@ -3076,15 +3089,6 @@ static int cs_etm__process_event(struct perf_session *session,
 	case PERF_RECORD_SWITCH:
 		return cs_etm__process_switch(etm, sample);
 
-	case PERF_RECORD_AUX:
-		/*
-		 * Record the latest kernel timestamp available in the header
-		 * for samples so that synthesised samples occur from this point
-		 * onwards.
-		 */
-		if (sample->time && (sample->time != (u64)-1))
-			etm->latest_kernel_timestamp = sample->time;
-		break;
 
 	default:
 		break;
@@ -3122,23 +3126,6 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,
 	return 0;
 }
 
-static void cs_etm__setup_timeless_decoding(struct cs_etm_auxtrace *etm)
-{
-	/* Take first ETM as all options will be the same for all ETMs */
-	u64 *metadata = etm->metadata[0];
-
-	/* Override timeless mode with user input from --itrace=Z */
-	if (etm->synth_opts.timeless_decoding) {
-		etm->timeless_decoding = true;
-		return;
-	}
-
-	if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic)
-		etm->timeless_decoding = !(metadata[CS_ETM_ETMCR] & ETMCR_TIMESTAMP_EN);
-	else
-		etm->timeless_decoding = !(metadata[CS_ETMV4_TRCCONFIGR] & TRCCONFIGR_TS);
-}
-
 /*
  * Read a single cpu parameter block from the auxtrace_info priv block.
  *
@@ -3287,6 +3274,7 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
 		/* Old per-thread files have no CPU (before v6.4) */
 		int queue_idx = sample->cpu == (u32)-1 ? 0 : sample->cpu;
 		struct cs_etm_queue *etmq = cs_etm__get_queue(etm, queue_idx);
+		struct auxtrace_buffer *buffer;
 
 		if (!etmq)
 			return -EINVAL;
@@ -3306,10 +3294,12 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
 		pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64
 			  " tid: %d cpu: %d\n", frag_size, frag_start, sample->tid, sample->cpu);
 		err = auxtrace_queues__add_event(&etm->queues, session, &auxtrace_fragment,
-						 file_offset, NULL);
+						 file_offset, &buffer);
 		if (err)
 			return err;
 
+		buffer->time = sample->time;
+
 		format = (aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW) ?
 				UNFORMATTED : FORMATTED;
 		if (etmq->format != UNSET && format != etmq->format) {
@@ -3568,6 +3558,51 @@ static int cs_etm__create_decoders(struct cs_etm_auxtrace *etm)
 	return 0;
 }
 
+static void cs_etm__timestamp_opts_init(struct cs_etm_auxtrace *etm)
+{
+	/*
+	 * Take first ETM for has_timestamps because record options are the same
+	 * for all ETMs.
+	 */
+	u64 *metadata = etm->metadata[0];
+
+	/* Leave both timestamp flags clear with --trace=Z */
+	if (etm->synth_opts.timeless_decoding)
+		return;
+
+	if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic)
+		etm->has_timestamps = metadata[CS_ETM_ETMCR] & ETMCR_TIMESTAMP_EN;
+	else
+		etm->has_timestamps = metadata[CS_ETMV4_TRCCONFIGR] & TRCCONFIGR_TS;
+
+	if (!etm->has_timestamps)
+		return;
+
+	if (etm->synth_opts.use_timestamp) {
+		/*
+		 * Prior to Armv8.4, Arm CPUs don't support FEAT_TRF feature,
+		 * therefore the decoder cannot know if the timestamp trace is
+		 * same with the kernel time.
+		 *
+		 * If a user has knowledge for the working platform they can
+		 * specify itrace option 'T' to force the decoder to use the
+		 * traced timestamp as the kernel time.
+		 */
+		etm->has_virtual_ts = true;
+	} else {
+		/* Use virtual timestamps if all ETMs report ts_source = 1 */
+		etm->has_virtual_ts = cs_etm__has_virtual_ts(etm->metadata, etm->num_cpu);
+		if (!etm->has_virtual_ts) {
+			ui__warning(
+				"Virtual timestamps are not enabled, or not supported by the traced system.\n"
+				"The time field of the samples will not be set accurately.\n"
+				"For Arm CPUs prior to Armv8.4 or without support FEAT_TRF,\n"
+				"you can specify the itrace option 'T' for timestamp decoding\n"
+				"if the Coresight timestamp on the platform is same with the kernel time.\n\n");
+		}
+	}
+}
+
 int cs_etm__process_auxtrace_info_full(union perf_event *event,
 				       struct perf_session *session)
 {
@@ -3733,29 +3768,8 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,
 	etm->metadata = metadata;
 	etm->auxtrace_type = auxtrace_info->type;
 
-	if (etm->synth_opts.use_timestamp)
-		/*
-		 * Prior to Armv8.4, Arm CPUs don't support FEAT_TRF feature,
-		 * therefore the decoder cannot know if the timestamp trace is
-		 * same with the kernel time.
-		 *
-		 * If a user has knowledge for the working platform and can
-		 * specify itrace option 'T' to tell decoder to forcely use the
-		 * traced timestamp as the kernel time.
-		 */
-		etm->has_virtual_ts = true;
-	else
-		/* Use virtual timestamps if all ETMs report ts_source = 1 */
-		etm->has_virtual_ts = cs_etm__has_virtual_ts(metadata, num_cpu);
-
-	if (!etm->has_virtual_ts)
-		ui__warning("Virtual timestamps are not enabled, or not supported by the traced system.\n"
-			    "The time field of the samples will not be set accurately.\n"
-			    "For Arm CPUs prior to Armv8.4 or without support FEAT_TRF,\n"
-			    "you can specify the itrace option 'T' for timestamp decoding\n"
-			    "if the Coresight timestamp on the platform is same with the kernel time.\n\n");
-
-	cs_etm__setup_timeless_decoding(etm);
+	/* Set etm->has_timestamps and etm->has_virtual_ts */
+	cs_etm__timestamp_opts_init(etm);
 
 	etm->tc.time_shift = tc->time_shift;
 	etm->tc.time_mult = tc->time_mult;
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index bf0e0f5a9711..9e842f1be9fc 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -269,7 +269,7 @@ enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_etm_queue *etmq);
 int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 				       u8 trace_chan_id, ocsd_ex_level el,
 				       pid_t tid);
-bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq);
+bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
 void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
 					      u8 trace_chan_id);
 struct cs_etm_packet_queue

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 16/34] perf cs-etm: Don't buffer non-timestamped packets
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (14 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 15/34] perf cs-etm: Use time from Perf samples James Clark
@ 2026-11-18 16:29 ` 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
                   ` (18 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

We're going to use the same decode path for timestamped and not
timestamped, but we don't want to buffer non-timestamped trace
unnecessarily. Buffering is only for searching for a timestamp and doing
it when there are no timestamps only results in not generating samples
in trace order.

Let the backend know if timestamps are expected or not so it can decide
to buffer or not.

Rename pending_timestamp_chan_id because now it just means that a packet
is pending, either due to a timestamp being found or the first packet
decoded.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 50 +++++++++++--------------
 tools/perf/util/cs-etm.c                        | 23 ++++--------
 tools/perf/util/cs-etm.h                        |  4 +-
 3 files changed, 31 insertions(+), 46 deletions(-)

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 d260d89453ef..895e85a1f54b 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -259,27 +259,16 @@ cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params,
 	return 0;
 }
 
-static ocsd_datapath_resp_t
-cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq,
-				  struct cs_etm_packet_queue *packet_queue,
-				  const uint8_t trace_chan_id)
+static void
+cs_etm_decoder__do_soft_timestamp(struct cs_etm_packet_queue *packet_queue)
 {
 	u64 estimated_ts;
 
-	/* No timestamp packet has been received, nothing to do */
-	if (!packet_queue->next_cs_timestamp)
-		return OCSD_RESP_CONT;
-
 	estimated_ts = packet_queue->cs_timestamp +
 			cs_etm_decoder__dec_instr_count_to_ns(&packet_queue->instr_count);
 
 	/* Estimated TS can never be higher than the next real one in the trace */
 	packet_queue->cs_timestamp = min(packet_queue->next_cs_timestamp, estimated_ts);
-
-	/* Tell the front end which traceid_queue needs attention */
-	cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
-
-	return OCSD_RESP_WAIT;
 }
 
 static ocsd_datapath_resp_t
@@ -358,7 +347,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	packet_queue->instr_count = 0;
 
 	/* Tell the front end which traceid_queue needs attention */
-	cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
+	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
 
 	/* Halt processing until we are being told to proceed */
 	return OCSD_RESP_WAIT;
@@ -437,10 +426,13 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	packet_queue->packet_buffer[et].el = ocsd_EL_unknown;
 	packet_queue->packet_buffer[et].tid = -1;
 
-	if (packet_queue->packet_count == CS_ETM_PACKET_MAX_BUFFER - 1)
-		return OCSD_RESP_WAIT;
+	/* Keep decoding until a timestamp is hit or queue fills up */
+	if (cs_etm__has_timestamps(etmq) &&
+	    packet_queue->packet_count < CS_ETM_PACKET_MAX_BUFFER - 1)
+		return OCSD_RESP_CONT;
 
-	return OCSD_RESP_CONT;
+	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
+	return OCSD_RESP_WAIT;
 }
 
 static ocsd_datapath_resp_t
@@ -475,19 +467,19 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 
 	packet->last_instr_size = elem->last_instr_sz;
 
-	/*
-	 * The packet queue is full and we haven't seen a timestamp (had we
-	 * seen one the packet queue wouldn't be full).  Let the front end
-	 * deal with it.
-	 */
-	if (ret == OCSD_RESP_WAIT)
-		goto out;
-
 	packet_queue->instr_count += elem->num_instr_range;
-	/* Tell the front end we have a new timestamp to process */
-	ret = cs_etm_decoder__do_soft_timestamp(etmq, packet_queue,
-						trace_chan_id);
-out:
+
+	if (packet_queue->next_cs_timestamp) {
+		/*
+		 * Once a real timestamp has been received, every range can be
+		 * handed to the frontend without queueing using an estimated
+		 * soft timestamp.
+		 */
+		cs_etm_decoder__do_soft_timestamp(packet_queue);
+		cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
+		return OCSD_RESP_WAIT;
+	}
+
 	return ret;
 }
 
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index ca3878a3b74e..b746d1215e0a 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -110,7 +110,7 @@ struct cs_etm_queue {
 	struct cs_etm_decoder *decoder;
 	struct auxtrace_buffer *buffer;
 	unsigned int queue_nr;
-	u8 pending_timestamp_chan_id;
+	u8 ready_chan_id;
 	enum cs_etm_format format;
 	u64 offset;
 	const unsigned char *buf;
@@ -568,17 +568,10 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session,
 	return err;
 }
 
-void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
-					      u8 trace_chan_id)
+void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
+					  u8 trace_chan_id)
 {
-	/*
-	 * When a timestamp packet is encountered the backend code
-	 * is stopped so that the front end has time to process packets
-	 * that were accumulated in the traceID queue.  Since there can
-	 * be more than one channel per cs_etm_queue, we need to specify
-	 * what traceID queue needs servicing.
-	 */
-	etmq->pending_timestamp_chan_id = trace_chan_id;
+	etmq->ready_chan_id = trace_chan_id;
 }
 
 /*
@@ -598,19 +591,19 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 {
 	struct cs_etm_packet_queue *packet_queue;
 
-	if (!etmq->pending_timestamp_chan_id)
+	if (!etmq->ready_chan_id)
 		return 0;
 
 	if (trace_chan_id)
-		*trace_chan_id = etmq->pending_timestamp_chan_id;
+		*trace_chan_id = etmq->ready_chan_id;
 
 	packet_queue = cs_etm__etmq_get_packet_queue(etmq,
-						     etmq->pending_timestamp_chan_id);
+						     etmq->ready_chan_id);
 	if (!packet_queue)
 		return 0;
 
 	/* Acknowledge pending status */
-	etmq->pending_timestamp_chan_id = 0;
+	etmq->ready_chan_id = 0;
 
 	/*
 	 * If there are no timestamps, use the TS from the AUX records to sort
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index 9e842f1be9fc..71b1ef321625 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -270,8 +270,8 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 				       u8 trace_chan_id, ocsd_ex_level el,
 				       pid_t tid);
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
-void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
-					      u8 trace_chan_id);
+void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
+					  u8 trace_chan_id);
 struct cs_etm_packet_queue
 *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
 int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 17/34] perf cs-etm: Decode in order of Perf samples
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (15 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 16/34] perf cs-etm: Don't buffer non-timestamped packets James Clark
@ 2026-11-18 16:29 ` 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
                   ` (17 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Replace all the special case paths for various combinations of
per-thread and timestamped/non-timestamped decode with a single ordered
decode path. By assigning the timestamp from the aux records to trace
without timestamps, the ordered decode produces the same results as if
decoding was done in file order. Non-virtual timestamps can't be
compared to Perf events but they can still order trace between queues,
so push all queues at AUX events.

There are now only two operations on the ordered decode heap, push and
pop. Pushing decodes up to the first timestamp, stops and adds to the
heap. If there are no timestamps, pushing adds the first packet to the
heap. When there are virtual timestamps in the trace we can push as soon
as we get the ITRACE_START event so that decoding can continue in order
with future JIT and MMAP events, without that we delay until the AUX
record for that chunk, at which point we know the MMAPs will have been
processed.

One downside of decoding the first couple of atoms to search for the
timestamp is we might mis-decode them because they are associate with
the wrong MMAP. This will be fixed in a later commit by using a separate
packet only decoder to search for the timestamp.

Update the per-thread test now that the output is correct for platforms
with virtual timestamps and slightly improved for ones without.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/coresight/per-thread.sh |  45 ++-
 tools/perf/util/cs-etm.c                       | 432 +++++++++----------------
 2 files changed, 188 insertions(+), 289 deletions(-)

diff --git a/tools/perf/tests/shell/coresight/per-thread.sh b/tools/perf/tests/shell/coresight/per-thread.sh
index 8a1ab9d8f1e7..bc17b6046c4c 100755
--- a/tools/perf/tests/shell/coresight/per-thread.sh
+++ b/tools/perf/tests/shell/coresight/per-thread.sh
@@ -27,22 +27,35 @@ perf record -o "$tmpdir/data" -e cs_etm//u --per-thread -- \
 echo "Decoding..."
 perf script -i "$tmpdir/data" --itrace=b -F comm,cpu 2> /dev/null | \
 	grep -Eo '(taskset|true).*(\[[0-9]+\])' | \
-	uniq | tail -n 3 > "$tmpdir/script" 2>/dev/null
-
-# Check that the decode says it ran on CPU 0, 1, 2, in that order. TODO: The
-# correct result should be "taskset [0,1,2], true 2" but we don't decode trace
-# in order of the Perf events yet, so everything is associated with the last
-# exec.
-cat > "$tmpdir/expected" << EOF
-true [000]
-true [001]
-true [002]
-EOF
-
-if ! diff -q "$tmpdir/script" "$tmpdir/expected"; then
-	echo "FAIL: per-thread output doesn't match expected:"
-	cat "$tmpdir/script"
-	exit 1
+	uniq > "$tmpdir/script" 2>/dev/null
+
+
+# Check that the decode says it ran on CPU 0, 1, 2, in that order. With
+# virtual timestamps the process name is also accurate.
+check_line()
+{
+	if ! sed -n "${1}p" "$tmpdir/procs" | grep -Eqx "$2"; then
+		echo "FAIL: per-thread output doesn't match expected on line $1:"
+		cat "$tmpdir/script"
+		exit 1
+	fi
+}
+
+if grep -qx '1' /sys/bus/coresight/devices/et*0/ts_source 2>/dev/null; then
+	tail -n 4 "$tmpdir/script" > "$tmpdir/procs"
+	check_line 1 'taskset \[000\]'
+	check_line 2 'taskset \[001\]'
+	check_line 3 'taskset \[002\]'
+	check_line 4 'true \[002\]'
+else
+	# No virtual timestamps means decoding is in order of AUX records, which
+	# are not guaranteed to be in order of COMM records. The last 'true'
+	# will be correct because tracing is always stopped after the last
+	# process was started.
+	tail -n 3 "$tmpdir/script" > "$tmpdir/procs"
+	check_line 1 '(true|taskset) \[000\]'
+	check_line 2 '(true|taskset) \[001\]'
+	check_line 3 'true \[002\]'
 fi
 
 exit 0
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index b746d1215e0a..5c98c7960f82 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -126,11 +126,12 @@ struct cs_etm_queue {
 	 */
 	struct intlist *own_traceid_list;
 	u32 sink_id;
+	/* Whether this queue currently occupies a slot in etm->heap */
+	bool on_heap;
 };
 
-static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm);
-static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm,
-					   pid_t tid);
+static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp);
+static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm);
 static int cs_etm__get_data_block(struct cs_etm_queue *etmq);
 static int cs_etm__decode_data_block(struct cs_etm_queue *etmq);
 static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metadata);
@@ -151,6 +152,7 @@ static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata);
 #define TO_QUEUE_NR(cs_queue_nr) (cs_queue_nr >> 16)
 #define TO_TRACE_CHAN_ID(cs_queue_nr) (cs_queue_nr & 0x0000ffff)
 #define SINK_UNSET ((u32) -1)
+#define MAX_TIMESTAMP (~0ULL)
 
 static u32 cs_etm__get_v7_protocol_version(u32 etmidr)
 {
@@ -288,6 +290,10 @@ static int cs_etm__map_trace_id(struct cs_etm_queue *etmq, u8 trace_chan_id,
 
 static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm, int cpu)
 {
+	/* Old per-thread files have no CPU on AUX events (before v6.4) */
+	if (cpu == -1)
+		cpu = 0;
+
 	if (cpu < 0 || cpu >= (int)etm->queues.nr_queues)
 		return NULL;
 
@@ -640,20 +646,6 @@ static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue)
 	}
 }
 
-static void cs_etm__clear_all_packet_queues(struct cs_etm_queue *etmq)
-{
-	int idx;
-	struct int_node *inode;
-	struct cs_etm_traceid_queue *tidq;
-	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
-
-	intlist__for_each_entry(inode, traceid_queues_list) {
-		idx = (int)(intptr_t)inode->priv;
-		tidq = etmq->traceid_queues[idx];
-		cs_etm__clear_packet_queue(&tidq->packet_queue);
-	}
-}
-
 static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
 				      struct cs_etm_traceid_queue *tidq,
 				      u8 trace_chan_id)
@@ -960,21 +952,19 @@ static int cs_etm__flush_events(struct perf_session *session,
 	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
 						   struct cs_etm_auxtrace,
 						   auxtrace);
+	int ret;
+
 	if (dump_trace || auxtrace__dont_decode(session))
 		return 0;
 
 	if (!tool->ordered_events)
 		return -EINVAL;
 
-	if (!etm->has_timestamps) {
-		/*
-		 * Pass tid = -1 to process all queues. But likely they will have
-		 * already been processed on PERF_RECORD_EXIT anyway.
-		 */
-		return cs_etm__process_timeless_queues(etm, -1);
-	}
+	ret = cs_etm__pop_heap(etm, MAX_TIMESTAMP);
+	if (ret)
+		return ret;
 
-	return cs_etm__process_timestamped_queues(etm);
+	return cs_etm__flush_queues(etm);
 }
 
 static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq)
@@ -1321,75 +1311,77 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
 	return 0;
 }
 
-static int cs_etm__queue_first_cs_timestamp(struct cs_etm_auxtrace *etm,
-					    struct cs_etm_queue *etmq,
-					    unsigned int queue_nr)
+static int cs_etm__add_to_heap(struct cs_etm_queue *etmq)
 {
-	int ret = 0;
+	struct cs_etm_auxtrace *etm = etmq->etm;
+	int ret;
 	unsigned int cs_queue_nr;
 	u8 trace_chan_id;
 	u64 cs_timestamp;
 
+	ret = cs_etm__decode_data_block(etmq);
+	if (ret || !etmq->ready_chan_id)
+		return ret;
+
+	cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
+
 	/*
-	 * We are under a CPU-wide trace scenario.  As such we need to know
-	 * when the code that generated the traces started to execute so that
-	 * it can be correlated with execution on other CPUs.  So we get a
-	 * handle on the beginning of traces and decode until we find a
-	 * timestamp.  The timestamp is then added to the auxtrace min heap
-	 * in order to know what nibble (of all the etmqs) to decode first.
+	 * We have a timestamp.  Add it to the min heap to reflect when
+	 * instructions conveyed by the range packets of this traceID queue
+	 * started to execute.
+	 *
+	 * Note that any packets decoded above are still in the traceID's packet
+	 * queue and will be processed later.
 	 */
-	while (1) {
-		/*
-		 * Fetch an aux_buffer from this etmq.  Bail if no more
-		 * blocks or an error has been encountered.
-		 */
+	cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, trace_chan_id);
+	ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
+	if (!ret)
+		etmq->on_heap = true;
+	return ret;
+}
+
+static int cs_etm__push_queue(struct cs_etm_queue *etmq, u64 time)
+{
+	int ret;
+
+	if (!etmq || etmq->on_heap)
+		return 0;
+
+	while (!etmq->on_heap) {
 		ret = cs_etm__get_data_block(etmq);
 		if (ret <= 0)
-			goto out;
+			return ret;
+		if (!etmq->etm->has_virtual_ts && etmq->buffer->time > time)
+			return 0;
 
-		/*
-		 * Run decoder on the trace block.  The decoder will stop when
-		 * encountering a CS timestamp, a full packet queue or the end of
-		 * trace for that block.
-		 */
-		ret = cs_etm__decode_data_block(etmq);
+		ret = cs_etm__add_to_heap(etmq);
 		if (ret)
-			goto out;
+			return ret;
+	}
 
-		/*
-		 * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
-		 * the timestamp calculation for us.
-		 */
-		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
+	return 0;
+}
 
-		/* We found a timestamp, no need to continue. */
-		if (cs_timestamp)
-			break;
+static int cs_etm__push_heap(struct cs_etm_auxtrace *etm,
+			     struct perf_sample *sample)
+{
+	return cs_etm__push_queue(cs_etm__get_queue(etm, sample->cpu),
+				  sample->time);
+}
 
-		/*
-		 * We didn't find a timestamp so empty all the traceid packet
-		 * queues before looking for another timestamp packet, either
-		 * in the current data block or a new one.  Packets that were
-		 * just decoded are useless since no timestamp has been
-		 * associated with them.  As such simply discard them.
-		 */
-		cs_etm__clear_all_packet_queues(etmq);
+static int cs_etm__push_heap_all(struct cs_etm_auxtrace *etm)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < etm->queues.nr_queues; i++) {
+		ret = cs_etm__push_queue(etm->queues.queue_array[i].priv,
+					 MAX_TIMESTAMP);
+		if (ret)
+			return ret;
 	}
 
-	/*
-	 * We have a timestamp.  Add it to the min heap to reflect when
-	 * instructions conveyed by the range packets of this traceID queue
-	 * started to execute.  Once the same has been done for all the traceID
-	 * queues of each etmq, redenring and decoding can start in
-	 * chronological order.
-	 *
-	 * Note that packets decoded above are still in the traceID's packet
-	 * queue and will be processed in cs_etm__process_timestamped_queues().
-	 */
-	cs_queue_nr = TO_CS_QUEUE_NR(queue_nr, trace_chan_id);
-	ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
-out:
-	return ret;
+	return 0;
 }
 
 static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
@@ -2731,159 +2723,15 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
 	return ret;
 }
 
-static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq)
-{
-	int idx;
-	struct int_node *inode;
-	struct cs_etm_traceid_queue *tidq;
-	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
-
-	intlist__for_each_entry(inode, traceid_queues_list) {
-		idx = (int)(intptr_t)inode->priv;
-		tidq = etmq->traceid_queues[idx];
-
-		/* Ignore return value */
-		cs_etm__process_traceid_queue(etmq, tidq);
-	}
-}
-
-static int cs_etm__run_per_thread_timeless_decoder(struct cs_etm_queue *etmq)
-{
-	int err = 0;
-	struct cs_etm_traceid_queue *tidq;
-
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, CS_ETM_PER_THREAD_TRACEID);
-	if (!tidq)
-		return -EINVAL;
-
-	/* Go through each buffer in the queue and decode them one by one */
-	while (1) {
-		err = cs_etm__get_data_block(etmq);
-		if (err <= 0)
-			return err;
-
-		/* Run trace decoder until buffer consumed or end of trace */
-		do {
-			err = cs_etm__decode_data_block(etmq);
-			if (err)
-				return err;
-
-			/*
-			 * Process each packet in this chunk, nothing to do if
-			 * an error occurs other than hoping the next one will
-			 * be better.
-			 */
-			err = cs_etm__process_traceid_queue(etmq, tidq);
-
-		} while (etmq->buf_len);
-
-		if (err == 0)
-			/* Flush any remaining branch stack entries */
-			err = cs_etm__end_block(etmq, tidq);
-	}
-
-	return err;
-}
-
-static int cs_etm__run_per_cpu_timeless_decoder(struct cs_etm_queue *etmq)
-{
-	int idx, err = 0;
-	struct cs_etm_traceid_queue *tidq;
-	struct int_node *inode;
-
-	/* Go through each buffer in the queue and decode them one by one */
-	while (1) {
-		err = cs_etm__get_data_block(etmq);
-		if (err <= 0)
-			return err;
-
-		/* Run trace decoder until buffer consumed or end of trace */
-		do {
-			err = cs_etm__decode_data_block(etmq);
-			if (err)
-				return err;
-
-			/*
-			 * cs_etm__run_per_thread_timeless_decoder() runs on a
-			 * single traceID queue because each TID has a separate
-			 * buffer. But here in per-cpu mode we need to iterate
-			 * over each channel instead.
-			 */
-			intlist__for_each_entry(inode,
-						etmq->traceid_queues_list) {
-				idx = (int)(intptr_t)inode->priv;
-				tidq = etmq->traceid_queues[idx];
-				cs_etm__process_traceid_queue(etmq, tidq);
-			}
-		} while (etmq->buf_len);
-
-		intlist__for_each_entry(inode, etmq->traceid_queues_list) {
-			idx = (int)(intptr_t)inode->priv;
-			tidq = etmq->traceid_queues[idx];
-			/* Flush any remaining branch stack entries */
-			err = cs_etm__end_block(etmq, tidq);
-			if (err)
-				return err;
-		}
-	}
-
-	return err;
-}
-
-static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm,
-					   pid_t tid)
-{
-	unsigned int i;
-	struct auxtrace_queues *queues = &etm->queues;
-
-	for (i = 0; i < queues->nr_queues; i++) {
-		struct auxtrace_queue *queue = &etm->queues.queue_array[i];
-		struct cs_etm_queue *etmq = queue->priv;
-		struct cs_etm_traceid_queue *tidq;
-
-		if (!etmq)
-			continue;
-
-		if (etm->per_thread_decoding) {
-			tidq = cs_etm__etmq_get_traceid_queue(
-				etmq, CS_ETM_PER_THREAD_TRACEID);
-
-			if (!tidq)
-				continue;
-
-			if (tid == -1 || thread__tid(tidq->frontend_thread) == tid)
-				cs_etm__run_per_thread_timeless_decoder(etmq);
-		} else
-			cs_etm__run_per_cpu_timeless_decoder(etmq);
-	}
-
-	return 0;
-}
-
-static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
+static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 {
 	int ret = 0;
-	unsigned int cs_queue_nr, queue_nr, i;
+	unsigned int cs_queue_nr, queue_nr;
 	u8 trace_chan_id;
-	u64 cs_timestamp;
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
 	struct cs_etm_traceid_queue *tidq;
 
-	/*
-	 * Pre-populate the heap with one entry from each queue so that we can
-	 * start processing in time order across all queues.
-	 */
-	for (i = 0; i < etm->queues.nr_queues; i++) {
-		etmq = etm->queues.queue_array[i].priv;
-		if (!etmq)
-			continue;
-
-		ret = cs_etm__queue_first_cs_timestamp(etm, etmq, i);
-		if (ret)
-			return ret;
-	}
-
 	while (1) {
 		if (!etm->heap.heap_cnt)
 			break;
@@ -2895,11 +2743,21 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 		queue = &etm->queues.queue_array[queue_nr];
 		etmq = queue->priv;
 
+		/* Don't go further than the trace timestamp or collection time */
+		if (etm->has_virtual_ts) {
+			if (etm->heap.heap_array[0].ordinal >= timestamp)
+				break;
+		} else {
+			if (etmq->buffer->time >= timestamp)
+				break;
+		}
+
 		/*
 		 * Remove the top entry from the heap since we are about
 		 * to process it.
 		 */
 		auxtrace_heap__pop(&etm->heap);
+		etmq->on_heap = false;
 
 		tidq  = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
 		if (!tidq) {
@@ -2913,7 +2771,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 		}
 
 		/*
-		 * Packets associated with this timestamp are already in
+		 * Packets associated with this timestamp, if any, are already in
 		 * the etmq's traceID queue, so process them.
 		 */
 		ret = cs_etm__process_traceid_queue(etmq, tidq);
@@ -2925,7 +2783,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 		 * move on to the next timestamp, fetching a new auxtrace_buffer
 		 * if need be.
 		 */
-refetch:
+get_data_block:
 		ret = cs_etm__get_data_block(etmq);
 		if (ret < 0)
 			goto out;
@@ -2937,37 +2795,28 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 		if (!ret)
 			continue;
 
-		ret = cs_etm__decode_data_block(etmq);
-		if (ret)
-			goto out;
-
-		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
-
-		if (!cs_timestamp) {
-			/*
-			 * Function cs_etm__decode_data_block() returns when
-			 * there is no more traces to decode in the current
-			 * auxtrace_buffer OR when a timestamp has been
-			 * encountered on any of the traceID queues.  Since we
-			 * did not get a timestamp, there is no more traces to
-			 * process in this auxtrace_buffer.  As such empty and
-			 * flush all traceID queues.
-			 */
-			cs_etm__clear_all_traceid_queues(etmq);
-
-			/* Fetch another auxtrace_buffer for this etmq */
-			goto refetch;
-		}
-
 		/*
-		 * Add to the min heap the timestamp for packets that have
-		 * just been decoded.  They will be processed and synthesized
-		 * during the next call to cs_etm__process_traceid_queue() for
-		 * this queue/traceID.
+		 * Add the next timestamp or decoded packets to the min heap.
+		 * Packets will be processed and synthesized during the next call
+		 * to cs_etm__process_traceid_queue() for this queue/traceID.
 		 */
-		cs_queue_nr = TO_CS_QUEUE_NR(queue_nr, trace_chan_id);
-		ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
+		ret = cs_etm__add_to_heap(etmq);
+		if (ret)
+			goto out;
+		if (!etmq->on_heap)
+			goto get_data_block;
 	}
+out:
+	return ret;
+}
+
+/* Flush any branch stack entries left over once all trace is decoded */
+static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm)
+{
+	int ret = 0;
+	unsigned int i;
+	struct cs_etm_queue *etmq;
+	struct cs_etm_traceid_queue *tidq;
 
 	for (i = 0; i < etm->queues.nr_queues; i++) {
 		struct int_node *inode;
@@ -2986,7 +2835,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
 				return ret;
 		}
 	}
-out:
+
 	return ret;
 }
 
@@ -3049,6 +2898,8 @@ static int cs_etm__process_event(struct perf_session *session,
 	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
 						   struct cs_etm_auxtrace,
 						   auxtrace);
+	bool has_sample_time = sample->time && sample->time != (u64)-1;
+	int ret = 0;
 
 	if (dump_trace || auxtrace__dont_decode(session))
 		return 0;
@@ -3059,34 +2910,71 @@ static int cs_etm__process_event(struct perf_session *session,
 	}
 
 	switch (event->header.type) {
-	case PERF_RECORD_EXIT:
+	case PERF_RECORD_ITRACE_START:
+		ret = cs_etm__process_itrace_start(etm, event);
+		if (ret)
+			return ret;
+
 		/*
-		 * Don't need to wait for cs_etm__flush_events() in per-thread mode to
-		 * start the decode because we know there will be no more trace from
-		 * this thread. All this does is emit samples earlier than waiting for
-		 * the flush in other modes, but with timestamps it makes sense to wait
-		 * for flush so that events from different threads are interleaved
-		 * properly.
+		 * Start decoding for this CPU on trace start. Timestamps in the
+		 * trace will prevent decoding from going further ahead than
+		 * Perf events.
 		 */
-		if (etm->per_thread_decoding && !etm->has_timestamps)
-			return cs_etm__process_timeless_queues(etm,
-							       event->fork.tid);
+		if (has_sample_time && etm->has_virtual_ts) {
+			ret = cs_etm__push_heap(etm, sample);
+			if (ret)
+				return ret;
+		}
 		break;
 
-	case PERF_RECORD_ITRACE_START:
-		return cs_etm__process_itrace_start(etm, event);
-
 	case PERF_RECORD_SWITCH_CPU_WIDE:
-		return cs_etm__process_switch_cpu_wide(etm, event, sample);
+		ret = cs_etm__process_switch_cpu_wide(etm, event, sample);
+		if (ret)
+			return ret;
+		break;
 
 	case PERF_RECORD_SWITCH:
-		return cs_etm__process_switch(etm, sample);
+		ret = cs_etm__process_switch(etm, sample);
+		if (ret)
+			return ret;
+		break;
+
+	case PERF_RECORD_AUX_OUTPUT_HW_ID:
+		/*
+		 * If ITRACE_START was dropped then use HW_ID as a backup start
+		 * point because it's emitted at the same time.
+		 */
+		if (has_sample_time && etm->has_virtual_ts) {
+			ret = cs_etm__push_heap(etm, sample);
+			if (ret)
+				return ret;
+		}
+		break;
 
+	case PERF_RECORD_AUX:
+		/*
+		 * Start decoding after AUX to support !etm->has_virtual_ts
+		 * because mmaps for that buffer must be available at this
+		 * point. Push all queues so that they are ordered between each
+		 * other, rather than waiting for their own AUX records which
+		 * would be too late.
+		 */
+		if (etm->has_timestamps && !etm->has_virtual_ts)
+			ret = cs_etm__push_heap_all(etm);
+		else if (has_sample_time)
+			ret = cs_etm__push_heap(etm, sample);
+
+		if (ret)
+			return ret;
+		break;
 
 	default:
 		break;
 	}
 
+	if (has_sample_time)
+		return cs_etm__pop_heap(etm, sample->time);
+
 	return 0;
 }
 
@@ -3264,9 +3152,7 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
 	frag_end = min(aux_end, auxtrace_end);
 
 	if (frag_start < frag_end) {
-		/* Old per-thread files have no CPU (before v6.4) */
-		int queue_idx = sample->cpu == (u32)-1 ? 0 : sample->cpu;
-		struct cs_etm_queue *etmq = cs_etm__get_queue(etm, queue_idx);
+		struct cs_etm_queue *etmq = cs_etm__get_queue(etm, sample->cpu);
 		struct auxtrace_buffer *buffer;
 
 		if (!etmq)

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 18/34] perf cs-etm: Don't special case per-thread mode
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (16 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 17/34] perf cs-etm: Decode in order of Perf samples James Clark
@ 2026-11-18 16:29 ` 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
                   ` (16 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

This was always an extra edge case to have to understand, and keeping it
would require another new special case in the following change to add a
timestamp decoder tree per trace ID. Removing it makes both cases
simpler and nothing is really lost anyway. The only change needed is to
seed every trace ID context with the TID from the AUX record, rather
than only updating the single special context.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm.c | 34 ++++++++++++++--------------------
 tools/perf/util/cs-etm.h | 10 ----------
 2 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 5c98c7960f82..accd4ffc19aa 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -51,13 +51,6 @@ struct cs_etm_auxtrace {
 
 	/* Trace timestamps are available and not disabled by --itrace=Z. */
 	bool has_timestamps;
-
-	/*
-	 * Per-thread ignores the trace channel ID and instead assumes that
-	 * everything in a buffer comes from the same process regardless of
-	 * which CPU it ran on. It also implies no context IDs so the TID is
-	 * taken from the auxtrace buffer.
-	 */
 	bool per_thread_decoding;
 	bool snapshot_mode;
 	bool has_virtual_ts; /* Trace timestamps can be used as kernel time. */
@@ -717,14 +710,8 @@ static struct cs_etm_traceid_queue
 {
 	int idx;
 	struct int_node *inode;
-	struct intlist *traceid_queues_list;
+	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
 	struct cs_etm_traceid_queue *tidq, **traceid_queues;
-	struct cs_etm_auxtrace *etm = etmq->etm;
-
-	if (etm->per_thread_decoding)
-		trace_chan_id = CS_ETM_PER_THREAD_TRACEID;
-
-	traceid_queues_list = etmq->traceid_queues_list;
 
 	/*
 	 * Check if the traceid_queue exist for this traceID by looking
@@ -2225,15 +2212,22 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 	/*
 	 * Per-thread mode still uses a queue for each CPU, but that CPU can run
 	 * different threads. When the TID from the AUX record on a CPU changes,
-	 * re-initialize the thread using the AUX record/buffer fragment TID so
-	 * we can start decoding even if the context ID packet was cropped or
-	 * they're disabled.
+	 * re-initialize the thread for each trace ID using the AUX record/buffer
+	 * fragment TID so we can start decoding even if the context ID packet
+	 * was cropped or they're disabled.
 	 */
 	if (etm->per_thread_decoding) {
-		struct cs_etm_traceid_queue *tidq = cs_etm__etmq_get_traceid_queue(etmq,
-							CS_ETM_PER_THREAD_TRACEID);
+		struct int_node *inode;
+
+		intlist__for_each_entry(inode, etmq->traceid_list) {
+			struct cs_etm_traceid_queue *tidq;
+
+			tidq = cs_etm__etmq_get_traceid_queue(etmq, inode->i);
+			if (!tidq)
+				return -ENOMEM;
+			if (thread__tid(tidq->decode_thread) == etmq->buffer->tid)
+				continue;
 
-		if (thread__tid(tidq->decode_thread) != etmq->buffer->tid) {
 			thread__zput(tidq->frontend_thread);
 			thread__zput(tidq->decode_thread);
 			tidq->frontend_thread = machine__findnew_thread(
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index 71b1ef321625..ffe3a33885a7 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -195,16 +195,6 @@ struct cs_etm_packet {
 
 #define CS_ETM_PACKET_MAX_BUFFER 1024
 
-/*
- * When working with per-thread scenarios the process under trace can
- * be scheduled on any CPU and as such, more than one traceID may be
- * associated with the same process.  Since a traceID of '0' is illegal
- * as per the CoreSight architecture, use that specific value to
- * identify the queue where all packets (with any traceID) are
- * aggregated.
- */
-#define CS_ETM_PER_THREAD_TRACEID 0
-
 struct cs_etm_packet_queue {
 	u32 packet_count;
 	u32 head;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 19/34] perf cs-etm: Decode one packet at a time and don't estimate timestamps
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (17 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 18/34] perf cs-etm: Don't special case per-thread mode James Clark
@ 2026-11-18 16:29 ` 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
                   ` (15 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Stop decoding after each packet instead of buffering packets until a
timestamp is reached. Give each range the last known timestamp instead
of estimating time using instruction counts. This makes the interleaving
of ranges between sinks less frequent, but that can be increased by
increasing the timestamp frequency. Timestamp estimation only added
complexity and was probably more misleading than useful.

Until the first trace timestamp is found, sort using zero. Only use the
AUX record time when trace timestamps are disabled.

packet_buffer[] now only ever has one packet in it, but keep it for a
later more mechanical removal in a later commit.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 124 +-----------------------
 tools/perf/util/cs-etm.c                        |  10 +-
 tools/perf/util/cs-etm.h                        |   4 +-
 3 files changed, 9 insertions(+), 129 deletions(-)

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 895e85a1f54b..d7b596aeaa41 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -33,15 +33,6 @@
 #define CS_PKT_MON	0
 #endif
 
-/*
- * Assume a maximum of 0.1ns elapsed per instruction. This would be the
- * case with a theoretical 10GHz core executing 1 instruction per cycle.
- * Used to estimate the sample time for synthesized instructions because
- * Coresight only emits a timestamp for a range of instructions rather
- * than per instruction.
- */
-const u32 INSTR_PER_NS = 10;
-
 struct cs_etm_decoder {
 	void *data;
 	void (*packet_printer)(const char *msg, void *data);
@@ -124,20 +115,6 @@ int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
 	return 1;
 }
 
-/*
- * Calculate the number of nanoseconds elapsed.
- *
- * instr_count is updated in place with the remainder of the instructions
- * which didn't make up a whole nanosecond.
- */
-static u32 cs_etm_decoder__dec_instr_count_to_ns(u32 *instr_count)
-{
-	const u32 instr_copy = *instr_count;
-
-	*instr_count %= INSTR_PER_NS;
-	return instr_copy / INSTR_PER_NS;
-}
-
 static int cs_etm_decoder__gen_etmv3_config(struct cs_etm_trace_params *params,
 					    ocsd_etmv3_cfg *config)
 {
@@ -259,18 +236,6 @@ cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params,
 	return 0;
 }
 
-static void
-cs_etm_decoder__do_soft_timestamp(struct cs_etm_packet_queue *packet_queue)
-{
-	u64 estimated_ts;
-
-	estimated_ts = packet_queue->cs_timestamp +
-			cs_etm_decoder__dec_instr_count_to_ns(&packet_queue->instr_count);
-
-	/* Estimated TS can never be higher than the next real one in the trace */
-	packet_queue->cs_timestamp = min(packet_queue->next_cs_timestamp, estimated_ts);
-}
-
 static ocsd_datapath_resp_t
 cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 				  const ocsd_generic_trace_elem *elem,
@@ -279,7 +244,6 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 {
 	struct cs_etm_packet_queue *packet_queue;
 	u64 converted_timestamp;
-	u64 estimated_first_ts;
 
 	/* Ignore trace timestamps when unavailable or disabled by --itrace=Z. */
 	if (!cs_etm__has_timestamps(etmq))
@@ -297,54 +261,14 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	converted_timestamp = elem->timestamp ?
 				cs_etm__convert_sample_time(etmq, elem->timestamp) : 0;
 
-	/*
-	 * We've seen a timestamp packet before - simply record the new value.
-	 * Function do_soft_timestamp() will report the value to the front end,
-	 * hence asking the decoder to keep decoding rather than stopping.
-	 */
-	if (packet_queue->next_cs_timestamp) {
-		/*
-		 * What was next is now where new ranges start from, overwriting
-		 * any previous estimate in cs_timestamp
-		 */
-		packet_queue->cs_timestamp = packet_queue->next_cs_timestamp;
-		packet_queue->next_cs_timestamp = converted_timestamp;
-		return OCSD_RESP_CONT;
-	}
-
 	if (!converted_timestamp) {
-		/*
-		 * Zero timestamps can be seen due to misconfiguration or hardware bugs.
-		 * Warn once, and don't try to subtract instr_count as it would result in an
-		 * underflow.
-		 */
-		packet_queue->cs_timestamp = 0;
 		pr_warning_once("Bad Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR
 				". Decode in order of trace collection by prepending 'Z' to your current --itrace arguments.\n",
 				indx);
-
-	} else if (packet_queue->instr_count / INSTR_PER_NS > converted_timestamp) {
-		/*
-		 * Sanity check that the elem->timestamp - packet_queue->instr_count would not
-		 * result in an underflow. Warn and clamp at 0 if it would.
-		 */
-		packet_queue->cs_timestamp = 0;
-		pr_err("Timestamp calculation underflow at Idx:%" OCSD_TRC_IDX_STR "\n", indx);
-	} else {
-		/*
-		 * This is the first timestamp we've seen since the beginning of traces
-		 * or a discontinuity.  Since timestamps packets are generated *after*
-		 * range packets have been generated, we need to estimate the time at
-		 * which instructions started by subtracting the number of instructions
-		 * executed to the timestamp. Don't estimate earlier than the last used
-		 * timestamp though.
-		 */
-		estimated_first_ts = converted_timestamp -
-					(packet_queue->instr_count / INSTR_PER_NS);
-		packet_queue->cs_timestamp = max(packet_queue->cs_timestamp, estimated_first_ts);
+		return OCSD_RESP_CONT;
 	}
-	packet_queue->next_cs_timestamp = converted_timestamp;
-	packet_queue->instr_count = 0;
+
+	packet_queue->cs_timestamp = max(packet_queue->cs_timestamp, converted_timestamp);
 
 	/* Tell the front end which traceid_queue needs attention */
 	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
@@ -353,13 +277,6 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	return OCSD_RESP_WAIT;
 }
 
-static void
-cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue)
-{
-	packet_queue->next_cs_timestamp = 0;
-	packet_queue->instr_count = 0;
-}
-
 static enum cs_etm_isa
 cs_etm_decoder__get_isa(const ocsd_generic_trace_elem *elem)
 {
@@ -426,11 +343,6 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	packet_queue->packet_buffer[et].el = ocsd_EL_unknown;
 	packet_queue->packet_buffer[et].tid = -1;
 
-	/* Keep decoding until a timestamp is hit or queue fills up */
-	if (cs_etm__has_timestamps(etmq) &&
-	    packet_queue->packet_count < CS_ETM_PACKET_MAX_BUFFER - 1)
-		return OCSD_RESP_CONT;
-
 	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
 	return OCSD_RESP_WAIT;
 }
@@ -467,19 +379,6 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 
 	packet->last_instr_size = elem->last_instr_sz;
 
-	packet_queue->instr_count += elem->num_instr_range;
-
-	if (packet_queue->next_cs_timestamp) {
-		/*
-		 * Once a real timestamp has been received, every range can be
-		 * handed to the frontend without queueing using an estimated
-		 * soft timestamp.
-		 */
-		cs_etm_decoder__do_soft_timestamp(packet_queue);
-		cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
-		return OCSD_RESP_WAIT;
-	}
-
 	return ret;
 }
 
@@ -489,11 +388,6 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq,
 				     const ocsd_generic_trace_elem *elem,
 				     const uint8_t trace_chan_id)
 {
-	/*
-	 * Something happened and who knows when we'll get new traces so
-	 * reset time statistics.
-	 */
-	cs_etm_decoder__reset_timestamp(queue);
 	return cs_etm_decoder__buffer_packet(etmq, queue, elem, trace_chan_id,
 					     CS_ETM_DISCONTINUITY);
 }
@@ -602,12 +496,6 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
 
-	/*
-	 * A timestamp is generated after a PE_CONTEXT element so make sure
-	 * to rely on that coming one.
-	 */
-	cs_etm_decoder__reset_timestamp(packet_queue);
-
 	return ret;
 }
 
@@ -815,11 +703,7 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 			break;
 		}
 
-		/*
-		 * Return to the input code if the packet buffer is full.
-		 * Flushing will get done once the packet buffer has been
-		 * processed.
-		 */
+		/* Return to the input code if processing was paused. */
 		if (OCSD_DATA_RESP_IS_WAIT(cur))
 			break;
 
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index accd4ffc19aa..f33e410e85bf 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -570,6 +570,7 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session,
 void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id)
 {
+	/* Tell the frontend which queue the last processed packet is in. */
 	etmq->ready_chan_id = trace_chan_id;
 }
 
@@ -596,8 +597,7 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	if (trace_chan_id)
 		*trace_chan_id = etmq->ready_chan_id;
 
-	packet_queue = cs_etm__etmq_get_packet_queue(etmq,
-						     etmq->ready_chan_id);
+	packet_queue = cs_etm__etmq_get_packet_queue(etmq, etmq->ready_chan_id);
 	if (!packet_queue)
 		return 0;
 
@@ -611,7 +611,7 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	if (!etmq->etm->has_timestamps)
 		return etmq->buffer->time;
 
-	/* See function cs_etm_decoder__do_{hard|soft}_timestamp() */
+	/* Use the last trace timestamp, or zero if none has been found yet. */
 	return packet_queue->cs_timestamp;
 }
 
@@ -2614,9 +2614,7 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
 	/*
 	 * Packets are decoded and added to the decoder's packet queue
 	 * until the decoder packet processing callback has requested that
-	 * processing stops or there is nothing left in the buffer.  Normal
-	 * operations that stop processing are a timestamp packet or a full
-	 * decoder buffer queue.
+	 * processing stops or there is nothing left in the buffer.
 	 */
 	ret = cs_etm_decoder__process_data_block(etmq->decoder,
 						 etmq->offset,
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index ffe3a33885a7..e404753820dc 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -199,9 +199,7 @@ struct cs_etm_packet_queue {
 	u32 packet_count;
 	u32 head;
 	u32 tail;
-	u32 instr_count;
-	u64 cs_timestamp; /* Timestamp from trace data, converted to ns if possible */
-	u64 next_cs_timestamp;
+	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
 	struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER];
 };
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 20/34] perf cs-etm: Remove the decoded packet ring buffer
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (18 preceding siblings ...)
  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:29 ` 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
                   ` (14 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Full decoding now stops after every output packet, so the frontend
drains the packet ring before the decoder can produce another packet.

Write directly into the frontend's current packet instead. Remove the
ring storage but retain the packet count as the pending-packet
indicator, which will be removed later.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 64 ++++++++++---------------
 tools/perf/util/cs-etm.c                        | 35 ++++----------
 tools/perf/util/cs-etm.h                        |  7 +--
 3 files changed, 36 insertions(+), 70 deletions(-)

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 d7b596aeaa41..e2eb606f2feb 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -96,22 +96,8 @@ int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
 	/* Nothing to do, might as well just return */
 	if (packet_queue->packet_count == 0)
 		return 0;
-	/*
-	 * The queueing process in function cs_etm_decoder__buffer_packet()
-	 * increments the tail *before* using it.  This is somewhat counter
-	 * intuitive but it has the advantage of centralizing tail management
-	 * at a single location.  Because of that we need to follow the same
-	 * heuristic with the head, i.e we increment it before using its
-	 * value.  Otherwise the first element of the packet queue is not
-	 * used.
-	 */
-	packet_queue->head = (packet_queue->head + 1) &
-			     (CS_ETM_PACKET_MAX_BUFFER - 1);
-
-	*packet = packet_queue->packet_buffer[packet_queue->head];
 
 	packet_queue->packet_count--;
-
 	return 1;
 }
 
@@ -312,36 +298,36 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 			      const u8 trace_chan_id,
 			      enum cs_etm_sample_type sample_type)
 {
-	u32 et = 0;
+	struct cs_etm_packet *packet;
 	int cpu;
 
-	if (packet_queue->packet_count >= CS_ETM_PACKET_MAX_BUFFER - 1)
+	if (packet_queue->packet_count)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
 	if (cs_etm__get_cpu(etmq, trace_chan_id, &cpu) < 0)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	et = packet_queue->tail;
-	et = (et + 1) & (CS_ETM_PACKET_MAX_BUFFER - 1);
-	packet_queue->tail = et;
-	packet_queue->packet_count++;
+	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
+	if (!packet)
+		return OCSD_RESP_FATAL_SYS_ERR;
 
-	packet_queue->packet_buffer[et].sample_type = sample_type;
-	packet_queue->packet_buffer[et].isa = cs_etm_decoder__get_isa(elem);
-	packet_queue->packet_buffer[et].cpu = cpu;
-	packet_queue->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR;
-	packet_queue->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR;
-	packet_queue->packet_buffer[et].instr_count = 0;
-	packet_queue->packet_buffer[et].last_instr_taken_branch = false;
-	packet_queue->packet_buffer[et].last_instr_size = 0;
-	packet_queue->packet_buffer[et].last_instr_type = 0;
-	packet_queue->packet_buffer[et].last_instr_subtype = 0;
-	packet_queue->packet_buffer[et].last_instr_cond = 0;
-	packet_queue->packet_buffer[et].flags = 0;
-	packet_queue->packet_buffer[et].exception_number = UINT32_MAX;
-	packet_queue->packet_buffer[et].trace_chan_id = trace_chan_id;
-	packet_queue->packet_buffer[et].el = ocsd_EL_unknown;
-	packet_queue->packet_buffer[et].tid = -1;
+	packet_queue->packet_count++;
+	packet->sample_type = sample_type;
+	packet->isa = cs_etm_decoder__get_isa(elem);
+	packet->cpu = cpu;
+	packet->start_addr = CS_ETM_INVAL_ADDR;
+	packet->end_addr = CS_ETM_INVAL_ADDR;
+	packet->instr_count = 0;
+	packet->last_instr_taken_branch = false;
+	packet->last_instr_size = 0;
+	packet->last_instr_type = 0;
+	packet->last_instr_subtype = 0;
+	packet->last_instr_cond = 0;
+	packet->flags = 0;
+	packet->exception_number = UINT32_MAX;
+	packet->trace_chan_id = trace_chan_id;
+	packet->el = ocsd_EL_unknown;
+	packet->tid = -1;
 
 	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
 	return OCSD_RESP_WAIT;
@@ -361,7 +347,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = &packet_queue->packet_buffer[packet_queue->tail];
+	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
 
 	packet->start_addr = elem->st_addr;
 	packet->end_addr = elem->en_addr;
@@ -407,7 +393,7 @@ cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = &queue->packet_buffer[queue->tail];
+	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
 	packet->exception_number = elem->exception_number;
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
@@ -491,7 +477,7 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = &packet_queue->packet_buffer[packet_queue->tail];
+	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
 	packet->tid = tid;
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index f33e410e85bf..0175b2facaac 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -615,30 +615,6 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	return packet_queue->cs_timestamp;
 }
 
-static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue)
-{
-	int i;
-
-	queue->head = 0;
-	queue->tail = 0;
-	queue->packet_count = 0;
-	for (i = 0; i < CS_ETM_PACKET_MAX_BUFFER; i++) {
-		queue->packet_buffer[i].isa = CS_ETM_ISA_UNKNOWN;
-		queue->packet_buffer[i].start_addr = CS_ETM_INVAL_ADDR;
-		queue->packet_buffer[i].end_addr = CS_ETM_INVAL_ADDR;
-		queue->packet_buffer[i].instr_count = 0;
-		queue->packet_buffer[i].last_instr_taken_branch = false;
-		queue->packet_buffer[i].last_instr_size = 0;
-		queue->packet_buffer[i].last_instr_type = 0;
-		queue->packet_buffer[i].last_instr_subtype = 0;
-		queue->packet_buffer[i].last_instr_cond = 0;
-		queue->packet_buffer[i].flags = 0;
-		queue->packet_buffer[i].exception_number = UINT32_MAX;
-		queue->packet_buffer[i].trace_chan_id = UINT8_MAX;
-		queue->packet_buffer[i].cpu = INT_MIN;
-	}
-}
-
 static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
 				      struct cs_etm_traceid_queue *tidq,
 				      u8 trace_chan_id)
@@ -647,8 +623,6 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
 	struct auxtrace_queue *queue;
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
-	cs_etm__clear_packet_queue(&tidq->packet_queue);
-
 	queue = &etmq->etm->queues.queue_array[etmq->queue_nr];
 	tidq->trace_chan_id = trace_chan_id;
 	tidq->decode_el = ocsd_EL_unknown;
@@ -772,6 +746,15 @@ static struct cs_etm_traceid_queue
 	return NULL;
 }
 
+struct cs_etm_packet *cs_etm__etmq_get_packet(struct cs_etm_queue *etmq,
+					      u8 trace_chan_id)
+{
+	struct cs_etm_traceid_queue *tidq;
+
+	tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+	return tidq ? tidq->packet : NULL;
+}
+
 struct cs_etm_packet_queue
 *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id)
 {
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index e404753820dc..c757a1fb465d 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -193,14 +193,9 @@ struct cs_etm_packet {
 	pid_t tid;
 };
 
-#define CS_ETM_PACKET_MAX_BUFFER 1024
-
 struct cs_etm_packet_queue {
 	u32 packet_count;
-	u32 head;
-	u32 tail;
 	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
-	struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER];
 };
 
 #define KiB(x) ((x) * 1024)
@@ -260,6 +255,8 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
 void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id);
+struct cs_etm_packet *cs_etm__etmq_get_packet(struct cs_etm_queue *etmq,
+					      u8 trace_chan_id);
 struct cs_etm_packet_queue
 *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
 int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 21/34] perf cs-etm: Fold packet state into the trace ID queue
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (19 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 20/34] perf cs-etm: Remove the decoded packet ring buffer James Clark
@ 2026-11-18 16:29 ` 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
                   ` (13 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

The packet queue no longer owns a packet buffer. The remaining timestamp
and packet_count state belongs to the surrounding trace ID queue.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 34 +++++-----
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |  4 +-
 tools/perf/util/cs-etm.c                        | 86 ++++++-------------------
 tools/perf/util/cs-etm.h                        | 39 ++++++++---
 4 files changed, 67 insertions(+), 96 deletions(-)

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 e2eb606f2feb..4c47bcf3e2e2 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -87,7 +87,7 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
 	return 0;
 }
 
-int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_queue *packet_queue,
 			       struct cs_etm_packet *packet)
 {
 	if (!packet_queue || !packet)
@@ -228,15 +228,15 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 				  const uint8_t trace_chan_id,
 				  const ocsd_trc_index_t indx)
 {
-	struct cs_etm_packet_queue *packet_queue;
+	struct cs_etm_traceid_queue *packet_queue;
 	u64 converted_timestamp;
 
 	/* Ignore trace timestamps when unavailable or disabled by --itrace=Z. */
 	if (!cs_etm__has_timestamps(etmq))
 		return OCSD_RESP_CONT;
 
-	/* First get the packet queue for this traceID */
-	packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
+	/* First get the decode context for this traceID */
+	packet_queue = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
 	if (!packet_queue)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
@@ -256,7 +256,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 
 	packet_queue->cs_timestamp = max(packet_queue->cs_timestamp, converted_timestamp);
 
-	/* Tell the front end which traceid_queue needs attention */
+	/* Tell the front end which decode context needs attention */
 	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
 
 	/* Halt processing until we are being told to proceed */
@@ -293,7 +293,7 @@ cs_etm_decoder__get_isa(const ocsd_generic_trace_elem *elem)
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
-			      struct cs_etm_packet_queue *packet_queue,
+			      struct cs_etm_traceid_queue *packet_queue,
 			      const ocsd_generic_trace_elem *elem,
 			      const u8 trace_chan_id,
 			      enum cs_etm_sample_type sample_type)
@@ -307,7 +307,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	if (cs_etm__get_cpu(etmq, trace_chan_id, &cpu) < 0)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
+	packet = packet_queue->packet;
 	if (!packet)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
@@ -335,7 +335,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
-			     struct cs_etm_packet_queue *packet_queue,
+			     struct cs_etm_traceid_queue *packet_queue,
 			     const ocsd_generic_trace_elem *elem,
 			     const uint8_t trace_chan_id)
 {
@@ -347,7 +347,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
+	packet = packet_queue->packet;
 
 	packet->start_addr = elem->st_addr;
 	packet->end_addr = elem->en_addr;
@@ -370,7 +370,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq,
-				     struct cs_etm_packet_queue *queue,
+				     struct cs_etm_traceid_queue *queue,
 				     const ocsd_generic_trace_elem *elem,
 				     const uint8_t trace_chan_id)
 {
@@ -380,7 +380,7 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
-				 struct cs_etm_packet_queue *queue,
+				 struct cs_etm_traceid_queue *queue,
 				 const ocsd_generic_trace_elem *elem,
 				 const uint8_t trace_chan_id)
 {
@@ -393,7 +393,7 @@ cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
+	packet = queue->packet;
 	packet->exception_number = elem->exception_number;
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
@@ -431,7 +431,7 @@ cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq,
-				     struct cs_etm_packet_queue *queue,
+				     struct cs_etm_traceid_queue *queue,
 				     const ocsd_generic_trace_elem *elem,
 				     const uint8_t trace_chan_id)
 {
@@ -441,7 +441,7 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
-			struct cs_etm_packet_queue *packet_queue,
+			struct cs_etm_traceid_queue *packet_queue,
 			const ocsd_generic_trace_elem *elem,
 			const uint8_t trace_chan_id)
 {
@@ -477,7 +477,7 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = cs_etm__etmq_get_packet(etmq, trace_chan_id);
+	packet = packet_queue->packet;
 	packet->tid = tid;
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
@@ -495,10 +495,10 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	ocsd_gen_trc_elem_t type;
 	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
 	struct cs_etm_queue *etmq = decoder->data;
-	struct cs_etm_packet_queue *packet_queue;
+	struct cs_etm_traceid_queue *packet_queue;
 
 	/* First get the packet queue for this traceID */
-	packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
+	packet_queue = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
 	if (!packet_queue)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 2a8214f17958..4420daaf159d 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -16,7 +16,7 @@
 
 struct cs_etm_decoder;
 struct cs_etm_packet;
-struct cs_etm_packet_queue;
+struct cs_etm_traceid_queue;
 
 struct cs_etm_queue;
 
@@ -102,7 +102,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
-int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_queue *packet_queue,
 			       struct cs_etm_packet *packet);
 
 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 0175b2facaac..3f5865ed2724 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -70,28 +70,6 @@ struct cs_etm_auxtrace {
 	enum cs_etm_pid_fmt pid_fmt;
 };
 
-struct cs_etm_traceid_queue {
-	u8 trace_chan_id;
-	u64 period_instructions;
-	u64 kernel_start;
-	union perf_event *event_buf;
-	unsigned int br_stack_sz;
-	struct branch_stack *last_branch;
-	struct ip_callchain *callchain;
-	struct cs_etm_packet *prev_packet;
-	struct cs_etm_packet *packet;
-	struct cs_etm_packet_queue packet_queue;
-
-	struct thread *decode_thread;
-	ocsd_ex_level decode_el;
-
-	/*
-	 * Samples use the EL saved in their source packet. A branch sample
-	 * cannot change thread, so the thread is kept in the frontend context.
-	 */
-	struct thread *frontend_thread;
-};
-
 enum cs_etm_format {
 	UNSET,
 	FORMATTED,
@@ -589,7 +567,7 @@ void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
 static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 				      u8 *trace_chan_id)
 {
-	struct cs_etm_packet_queue *packet_queue;
+	struct cs_etm_traceid_queue *tidq;
 
 	if (!etmq->ready_chan_id)
 		return 0;
@@ -597,8 +575,8 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	if (trace_chan_id)
 		*trace_chan_id = etmq->ready_chan_id;
 
-	packet_queue = cs_etm__etmq_get_packet_queue(etmq, etmq->ready_chan_id);
-	if (!packet_queue)
+	tidq = cs_etm__etmq_get_traceid_queue(etmq, etmq->ready_chan_id);
+	if (!tidq)
 		return 0;
 
 	/* Acknowledge pending status */
@@ -612,7 +590,7 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 		return etmq->buffer->time;
 
 	/* Use the last trace timestamp, or zero if none has been found yet. */
-	return packet_queue->cs_timestamp;
+	return tidq->cs_timestamp;
 }
 
 static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
@@ -679,7 +657,7 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
 	return rc;
 }
 
-static struct cs_etm_traceid_queue
+struct cs_etm_traceid_queue
 *cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id)
 {
 	int idx;
@@ -688,8 +666,8 @@ static struct cs_etm_traceid_queue
 	struct cs_etm_traceid_queue *tidq, **traceid_queues;
 
 	/*
-	 * Check if the traceid_queue exist for this traceID by looking
-	 * in the queue list.
+	 * Check if a decode context exists for this traceID by looking
+	 * in the context list.
 	 */
 	inode = intlist__find(traceid_queues_list, trace_chan_id);
 	if (inode) {
@@ -697,16 +675,16 @@ static struct cs_etm_traceid_queue
 		return etmq->traceid_queues[idx];
 	}
 
-	/* We couldn't find a traceid_queue for this traceID, allocate one */
+	/* We couldn't find a decode context for this traceID, allocate one */
 	tidq = malloc(sizeof(*tidq));
 	if (!tidq)
 		return NULL;
 
 	memset(tidq, 0, sizeof(*tidq));
 
-	/* Get a valid index for the new traceid_queue */
+	/* Get a valid index for the new decode context */
 	idx = intlist__nr_entries(traceid_queues_list);
-	/* Memory for the inode is free'ed in cs_etm_free_traceid_queues () */
+	/* Memory for the inode is freed in cs_etm__free_traceid_queues() */
 	inode = intlist__findnew(traceid_queues_list, trace_chan_id);
 	if (!inode)
 		goto out_free;
@@ -746,27 +724,6 @@ static struct cs_etm_traceid_queue
 	return NULL;
 }
 
-struct cs_etm_packet *cs_etm__etmq_get_packet(struct cs_etm_queue *etmq,
-					      u8 trace_chan_id)
-{
-	struct cs_etm_traceid_queue *tidq;
-
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
-	return tidq ? tidq->packet : NULL;
-}
-
-struct cs_etm_packet_queue
-*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id)
-{
-	struct cs_etm_traceid_queue *tidq;
-
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
-	if (tidq)
-		return &tidq->packet_queue;
-
-	return NULL;
-}
-
 static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
 				struct cs_etm_traceid_queue *tidq)
 {
@@ -949,7 +906,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq)
 		priv = (uintptr_t)inode->priv;
 		idx = priv;
 
-		/* Free this traceid_queue from the array */
+		/* Free this decode context from the array */
 		tidq = etmq->traceid_queues[idx];
 		thread__zput(tidq->frontend_thread);
 		thread__zput(tidq->decode_thread);
@@ -1590,10 +1547,9 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
 					       struct cs_etm_traceid_queue *tidq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
-	struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue;
 
 	if (etm->has_virtual_ts)
-		return packet_queue->cs_timestamp;
+		return tidq->cs_timestamp;
 
 	/*
 	 * Timestamps were disabled or no virtual TS. All samples are assigned
@@ -2619,14 +2575,10 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
 					 struct cs_etm_traceid_queue *tidq)
 {
 	int ret;
-	struct cs_etm_packet_queue *packet_queue;
-
-	packet_queue = &tidq->packet_queue;
 
 	/* Process each packet in this chunk */
 	while (1) {
-		ret = cs_etm_decoder__get_packet(packet_queue,
-						 tidq->packet);
+		ret = cs_etm_decoder__get_packet(tidq, tidq->packet);
 		if (ret <= 0)
 			/*
 			 * Stop processing this chunk on
@@ -2706,6 +2658,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
 	struct cs_etm_traceid_queue *tidq;
+	u64 queue_time;
 
 	while (1) {
 		if (!etm->heap.heap_cnt)
@@ -2719,13 +2672,10 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		etmq = queue->priv;
 
 		/* Don't go further than the trace timestamp or collection time */
-		if (etm->has_virtual_ts) {
-			if (etm->heap.heap_array[0].ordinal >= timestamp)
-				break;
-		} else {
-			if (etmq->buffer->time >= timestamp)
-				break;
-		}
+		queue_time = etm->has_virtual_ts ? etm->heap.heap_array[0].ordinal :
+						   etmq->buffer->time;
+		if (queue_time >= timestamp)
+			break;
 
 		/*
 		 * Remove the top entry from the heap since we are about
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index c757a1fb465d..1cbc8bc0aa06 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -193,11 +193,6 @@ struct cs_etm_packet {
 	pid_t tid;
 };
 
-struct cs_etm_packet_queue {
-	u32 packet_count;
-	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
-};
-
 #define KiB(x) ((x) * 1024)
 #define MiB(x) ((x) * 1024 * 1024)
 
@@ -247,6 +242,34 @@ enum cs_etm_pid_fmt {
 
 #ifdef HAVE_CSTRACE_SUPPORT
 #include <opencsd/ocsd_if_types.h>
+
+/*
+ * Decode context for a single trace ID stream. In a decode tree there is one
+ * of these for each stream.
+ */
+struct cs_etm_traceid_queue {
+	u8 trace_chan_id;
+	u64 period_instructions;
+	u64 kernel_start;
+	union perf_event *event_buf;
+	unsigned int br_stack_sz;
+	struct branch_stack *last_branch;
+	struct ip_callchain *callchain;
+	struct cs_etm_packet *prev_packet;
+	struct cs_etm_packet *packet;
+	u32 packet_count;
+	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
+
+	struct thread *decode_thread;
+	ocsd_ex_level decode_el;
+
+	/*
+	 * Samples use the EL saved in their source packet. A branch sample
+	 * cannot change thread, so the thread is kept in the frontend context.
+	 */
+	struct thread *frontend_thread;
+};
+
 int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu);
 enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_etm_queue *etmq);
 int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
@@ -255,10 +278,8 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
 void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id);
-struct cs_etm_packet *cs_etm__etmq_get_packet(struct cs_etm_queue *etmq,
-					      u8 trace_chan_id);
-struct cs_etm_packet_queue
-*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
+struct cs_etm_traceid_queue
+*cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
 int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused,
 				       struct perf_session *session __maybe_unused);
 u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 22/34] perf cs-etm: Rename trace ID queues to trace ID contexts
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (20 preceding siblings ...)
  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:29 ` 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
                   ` (12 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Now cs_etm_traceid_queue is a single decode context rather than a queue
of packets. Rename the struct and related functions to match. Keep tidq
variable names for a later cleanup.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  27 ++--
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |   4 +-
 tools/perf/util/cs-etm.c                        | 156 ++++++++++++------------
 tools/perf/util/cs-etm.h                        |   8 +-
 4 files changed, 97 insertions(+), 98 deletions(-)

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 4c47bcf3e2e2..3e3ec30bc7b3 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -87,7 +87,7 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
 	return 0;
 }
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_queue *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *packet_queue,
 			       struct cs_etm_packet *packet)
 {
 	if (!packet_queue || !packet)
@@ -228,7 +228,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 				  const uint8_t trace_chan_id,
 				  const ocsd_trc_index_t indx)
 {
-	struct cs_etm_traceid_queue *packet_queue;
+	struct cs_etm_traceid_ctxt *packet_queue;
 	u64 converted_timestamp;
 
 	/* Ignore trace timestamps when unavailable or disabled by --itrace=Z. */
@@ -236,7 +236,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 		return OCSD_RESP_CONT;
 
 	/* First get the decode context for this traceID */
-	packet_queue = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+	packet_queue = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
 	if (!packet_queue)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
@@ -257,7 +257,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	packet_queue->cs_timestamp = max(packet_queue->cs_timestamp, converted_timestamp);
 
 	/* Tell the front end which decode context needs attention */
-	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
+	cs_etm__etmq_set_traceid_ctxt_ready(etmq, trace_chan_id);
 
 	/* Halt processing until we are being told to proceed */
 	return OCSD_RESP_WAIT;
@@ -293,7 +293,7 @@ cs_etm_decoder__get_isa(const ocsd_generic_trace_elem *elem)
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
-			      struct cs_etm_traceid_queue *packet_queue,
+			      struct cs_etm_traceid_ctxt *packet_queue,
 			      const ocsd_generic_trace_elem *elem,
 			      const u8 trace_chan_id,
 			      enum cs_etm_sample_type sample_type)
@@ -329,13 +329,13 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	packet->el = ocsd_EL_unknown;
 	packet->tid = -1;
 
-	cs_etm__etmq_set_traceid_queue_ready(etmq, trace_chan_id);
+	cs_etm__etmq_set_traceid_ctxt_ready(etmq, trace_chan_id);
 	return OCSD_RESP_WAIT;
 }
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_queue *packet_queue,
+			     struct cs_etm_traceid_ctxt *packet_queue,
 			     const ocsd_generic_trace_elem *elem,
 			     const uint8_t trace_chan_id)
 {
@@ -370,7 +370,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_queue *queue,
+				     struct cs_etm_traceid_ctxt *queue,
 				     const ocsd_generic_trace_elem *elem,
 				     const uint8_t trace_chan_id)
 {
@@ -380,7 +380,7 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
-				 struct cs_etm_traceid_queue *queue,
+				 struct cs_etm_traceid_ctxt *queue,
 				 const ocsd_generic_trace_elem *elem,
 				 const uint8_t trace_chan_id)
 {
@@ -431,7 +431,7 @@ cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_queue *queue,
+				     struct cs_etm_traceid_ctxt *queue,
 				     const ocsd_generic_trace_elem *elem,
 				     const uint8_t trace_chan_id)
 {
@@ -441,7 +441,7 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
-			struct cs_etm_traceid_queue *packet_queue,
+			struct cs_etm_traceid_ctxt *packet_queue,
 			const ocsd_generic_trace_elem *elem,
 			const uint8_t trace_chan_id)
 {
@@ -495,10 +495,9 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	ocsd_gen_trc_elem_t type;
 	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
 	struct cs_etm_queue *etmq = decoder->data;
-	struct cs_etm_traceid_queue *packet_queue;
+	struct cs_etm_traceid_ctxt *packet_queue;
 
-	/* First get the packet queue for this traceID */
-	packet_queue = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+	packet_queue = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
 	if (!packet_queue)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 4420daaf159d..8624f48d696f 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -16,7 +16,7 @@
 
 struct cs_etm_decoder;
 struct cs_etm_packet;
-struct cs_etm_traceid_queue;
+struct cs_etm_traceid_ctxt;
 
 struct cs_etm_queue;
 
@@ -102,7 +102,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_queue *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *packet_queue,
 			       struct cs_etm_packet *packet);
 
 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 3f5865ed2724..b49bf606ffeb 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -86,9 +86,9 @@ struct cs_etm_queue {
 	u64 offset;
 	const unsigned char *buf;
 	size_t buf_len, buf_used;
-	/* Conversion between traceID and index in traceid_queues array */
-	struct intlist *traceid_queues_list;
-	struct cs_etm_traceid_queue **traceid_queues;
+	/* Conversion between traceID and index in traceid_ctxts array */
+	struct intlist *traceid_ctxts_list;
+	struct cs_etm_traceid_ctxt **traceid_ctxts;
 	/* Conversion between traceID and metadata pointers */
 	struct intlist *traceid_list;
 	/*
@@ -545,7 +545,7 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session,
 	return err;
 }
 
-void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
+void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id)
 {
 	/* Tell the frontend which queue the last processed packet is in. */
@@ -567,7 +567,7 @@ void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
 static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 				      u8 *trace_chan_id)
 {
-	struct cs_etm_traceid_queue *tidq;
+	struct cs_etm_traceid_ctxt *tidq;
 
 	if (!etmq->ready_chan_id)
 		return 0;
@@ -575,7 +575,7 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	if (trace_chan_id)
 		*trace_chan_id = etmq->ready_chan_id;
 
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, etmq->ready_chan_id);
+	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, etmq->ready_chan_id);
 	if (!tidq)
 		return 0;
 
@@ -593,8 +593,8 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	return tidq->cs_timestamp;
 }
 
-static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
-				      struct cs_etm_traceid_queue *tidq,
+static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
+				      struct cs_etm_traceid_ctxt *tidq,
 				      u8 trace_chan_id)
 {
 	int rc = -ENOMEM;
@@ -657,22 +657,22 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
 	return rc;
 }
 
-struct cs_etm_traceid_queue
-*cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id)
+struct cs_etm_traceid_ctxt
+*cs_etm__etmq_get_traceid_ctxt(struct cs_etm_queue *etmq, u8 trace_chan_id)
 {
 	int idx;
 	struct int_node *inode;
-	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
-	struct cs_etm_traceid_queue *tidq, **traceid_queues;
+	struct intlist *traceid_ctxts_list = etmq->traceid_ctxts_list;
+	struct cs_etm_traceid_ctxt *tidq, **traceid_ctxts;
 
 	/*
 	 * Check if a decode context exists for this traceID by looking
 	 * in the context list.
 	 */
-	inode = intlist__find(traceid_queues_list, trace_chan_id);
+	inode = intlist__find(traceid_ctxts_list, trace_chan_id);
 	if (inode) {
 		idx = (int)(intptr_t)inode->priv;
-		return etmq->traceid_queues[idx];
+		return etmq->traceid_ctxts[idx];
 	}
 
 	/* We couldn't find a decode context for this traceID, allocate one */
@@ -683,49 +683,49 @@ struct cs_etm_traceid_queue
 	memset(tidq, 0, sizeof(*tidq));
 
 	/* Get a valid index for the new decode context */
-	idx = intlist__nr_entries(traceid_queues_list);
-	/* Memory for the inode is freed in cs_etm__free_traceid_queues() */
-	inode = intlist__findnew(traceid_queues_list, trace_chan_id);
+	idx = intlist__nr_entries(traceid_ctxts_list);
+	/* Memory for the inode is freed in cs_etm__free_traceid_ctxts() */
+	inode = intlist__findnew(traceid_ctxts_list, trace_chan_id);
 	if (!inode)
 		goto out_free;
 
 	/* Associate this traceID with this index */
 	inode->priv = (void *)(intptr_t)idx;
 
-	if (cs_etm__init_traceid_queue(etmq, tidq, trace_chan_id))
+	if (cs_etm__init_traceid_ctxt(etmq, tidq, trace_chan_id))
 		goto out_free;
 
-	/* Grow the traceid_queues array by one unit */
-	traceid_queues = etmq->traceid_queues;
-	traceid_queues = reallocarray(traceid_queues,
+	/* Grow the traceid_ctxts array by one unit */
+	traceid_ctxts = etmq->traceid_ctxts;
+	traceid_ctxts = reallocarray(traceid_ctxts,
 				      idx + 1,
-				      sizeof(*traceid_queues));
+				      sizeof(*traceid_ctxts));
 
 	/*
 	 * On failure reallocarray() returns NULL and the original block of
 	 * memory is left untouched.
 	 */
-	if (!traceid_queues)
+	if (!traceid_ctxts)
 		goto out_free;
 
-	traceid_queues[idx] = tidq;
-	etmq->traceid_queues = traceid_queues;
+	traceid_ctxts[idx] = tidq;
+	etmq->traceid_ctxts = traceid_ctxts;
 
-	return etmq->traceid_queues[idx];
+	return etmq->traceid_ctxts[idx];
 
 out_free:
 	/*
 	 * Function intlist__remove() removes the inode from the list
 	 * and delete the memory associated to it.
 	 */
-	intlist__remove(traceid_queues_list, inode);
+	intlist__remove(traceid_ctxts_list, inode);
 	free(tidq);
 
 	return NULL;
 }
 
 static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
-				struct cs_etm_traceid_queue *tidq)
+				struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_packet *tmp;
 
@@ -894,20 +894,20 @@ static int cs_etm__flush_events(struct perf_session *session,
 	return cs_etm__flush_queues(etm);
 }
 
-static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq)
+static void cs_etm__free_traceid_ctxts(struct cs_etm_queue *etmq)
 {
 	int idx;
 	uintptr_t priv;
 	struct int_node *inode, *tmp;
-	struct cs_etm_traceid_queue *tidq;
-	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
+	struct cs_etm_traceid_ctxt *tidq;
+	struct intlist *traceid_ctxts_list = etmq->traceid_ctxts_list;
 
-	intlist__for_each_entry_safe(inode, tmp, traceid_queues_list) {
+	intlist__for_each_entry_safe(inode, tmp, traceid_ctxts_list) {
 		priv = (uintptr_t)inode->priv;
 		idx = priv;
 
 		/* Free this decode context from the array */
-		tidq = etmq->traceid_queues[idx];
+		tidq = etmq->traceid_ctxts[idx];
 		thread__zput(tidq->frontend_thread);
 		thread__zput(tidq->decode_thread);
 		zfree(&tidq->event_buf);
@@ -921,15 +921,15 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq)
 		 * Function intlist__remove() removes the inode from the list
 		 * and delete the memory associated to it.
 		 */
-		intlist__remove(traceid_queues_list, inode);
+		intlist__remove(traceid_ctxts_list, inode);
 	}
 
 	/* Then the RB tree itself */
-	intlist__delete(traceid_queues_list);
-	etmq->traceid_queues_list = NULL;
+	intlist__delete(traceid_ctxts_list);
+	etmq->traceid_ctxts_list = NULL;
 
-	/* finally free the traceid_queues array */
-	zfree(&etmq->traceid_queues);
+	/* finally free the traceid_ctxts array */
+	zfree(&etmq->traceid_ctxts);
 }
 
 static void cs_etm__free_queue(void *priv)
@@ -941,7 +941,7 @@ static void cs_etm__free_queue(void *priv)
 		return;
 
 	cs_etm_decoder__zfree(&etmq->decoder);
-	cs_etm__free_traceid_queues(etmq);
+	cs_etm__free_traceid_ctxts(etmq);
 
 	if (etmq->own_traceid_list) {
 		/* First remove all traceID/metadata nodes for the RB tree */
@@ -1163,7 +1163,7 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
 }
 
 static u32 cs_etm__frontend_mem_access(struct cs_etm_queue *etmq,
-				       struct cs_etm_traceid_queue *tidq,
+				       struct cs_etm_traceid_ctxt *tidq,
 				       struct cs_etm_packet *packet,
 				       u64 address, size_t size, u8 *buffer)
 {
@@ -1175,9 +1175,9 @@ static u32 cs_etm__decoder_mem_access(struct cs_etm_queue *etmq, u8 trace_chan_i
 				      u64 address, size_t size, u8 *buffer,
 				      const ocsd_mem_space_acc_t mem_space)
 {
-	struct cs_etm_traceid_queue *tidq;
+	struct cs_etm_traceid_ctxt *tidq;
 
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
 	if (!tidq)
 		return 0;
 
@@ -1192,8 +1192,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(void)
 	if (!etmq)
 		return NULL;
 
-	etmq->traceid_queues_list = intlist__new(NULL);
-	if (!etmq->traceid_queues_list)
+	etmq->traceid_ctxts_list = intlist__new(NULL);
+	if (!etmq->traceid_ctxts_list)
 		goto out_free;
 
 	/*
@@ -1208,7 +1208,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(void)
 	return etmq;
 
 out_free:
-	intlist__delete(etmq->traceid_queues_list);
+	intlist__delete(etmq->traceid_ctxts_list);
 	free(etmq);
 
 	return NULL;
@@ -1312,7 +1312,7 @@ static int cs_etm__push_heap_all(struct cs_etm_auxtrace *etm)
 }
 
 static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
-					 struct cs_etm_traceid_queue *tidq,
+					 struct cs_etm_traceid_ctxt *tidq,
 					 struct cs_etm_packet *packet, u64 addr)
 {
 	u8 instrBytes[2];
@@ -1328,7 +1328,7 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
 }
 
 static inline int cs_etm__instr_size(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_queue *tidq,
+				     struct cs_etm_traceid_ctxt *tidq,
 				     struct cs_etm_packet *packet,
 				     u64 addr)
 {
@@ -1364,7 +1364,7 @@ u64 cs_etm__last_executed_instr(const struct cs_etm_packet *packet)
 }
 
 static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_queue *tidq,
+				     struct cs_etm_traceid_ctxt *tidq,
 				     struct cs_etm_packet *packet,
 				     u64 offset)
 {
@@ -1480,10 +1480,10 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 				       u8 trace_chan_id,
 				       ocsd_ex_level el, pid_t tid)
 {
-	struct cs_etm_traceid_queue *tidq;
+	struct cs_etm_traceid_ctxt *tidq;
 	int ret;
 
-	tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
 	if (!tidq)
 		return -EINVAL;
 
@@ -1502,7 +1502,7 @@ bool cs_etm__has_timestamps(struct cs_etm_queue *etmq)
 }
 
 static void cs_etm__copy_insn(struct cs_etm_queue *etmq,
-			      struct cs_etm_traceid_queue *tidq,
+			      struct cs_etm_traceid_ctxt *tidq,
 			      struct cs_etm_packet *packet,
 			      struct perf_sample *sample)
 {
@@ -1544,7 +1544,7 @@ u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp)
 }
 
 static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
-					       struct cs_etm_traceid_queue *tidq)
+					       struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
@@ -1571,7 +1571,7 @@ static bool cs_etm__packet_has_branch(struct cs_etm_packet *packet)
 }
 
 static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
-				    struct cs_etm_traceid_queue *tidq)
+				    struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	u64 from, to;
@@ -1603,7 +1603,7 @@ static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
 }
 
 static void cs_etm__sample_branch_stack(struct cs_etm_auxtrace *etm,
-					struct cs_etm_traceid_queue *tidq,
+					struct cs_etm_traceid_ctxt *tidq,
 					struct perf_sample *sample)
 {
 	if (etm->synth_opts.last_branch) {
@@ -1634,7 +1634,7 @@ static void cs_etm__sample_branch_stack(struct cs_etm_auxtrace *etm,
 }
 
 static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
-					    struct cs_etm_traceid_queue *tidq,
+					    struct cs_etm_traceid_ctxt *tidq,
 					    struct cs_etm_packet *packet,
 					    u64 addr, u64 period)
 {
@@ -1683,7 +1683,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__synth_last_instruction_sample(struct cs_etm_queue *etmq,
-						 struct cs_etm_traceid_queue *tidq)
+						 struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_packet *packet = tidq->prev_packet;
 	int ret;
@@ -1710,7 +1710,7 @@ static int cs_etm__synth_last_instruction_sample(struct cs_etm_queue *etmq,
  * and the next taken branch. Generate sample accordingly.
  */
 static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
-				       struct cs_etm_traceid_queue *tidq)
+				       struct cs_etm_traceid_ctxt *tidq)
 {
 	int ret = 0;
 	struct cs_etm_auxtrace *etm = etmq->etm;
@@ -1879,7 +1879,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 }
 
 static int cs_etm__sample(struct cs_etm_queue *etmq,
-			  struct cs_etm_traceid_queue *tidq)
+			  struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	int ret;
@@ -1981,7 +1981,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__context(struct cs_etm_queue *etmq,
-			   struct cs_etm_traceid_queue *tidq)
+			   struct cs_etm_traceid_ctxt *tidq)
 {
 	ocsd_ex_level el = tidq->packet->el;
 	struct machine *machine;
@@ -2009,7 +2009,7 @@ static int cs_etm__context(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__exception(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_queue *tidq)
+			     struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_packet *packet = tidq->packet;
 
@@ -2030,7 +2030,7 @@ static int cs_etm__exception(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__flush(struct cs_etm_queue *etmq,
-			 struct cs_etm_traceid_queue *tidq)
+			 struct cs_etm_traceid_ctxt *tidq)
 {
 	int err = 0;
 	struct cs_etm_auxtrace *etm = etmq->etm;
@@ -2058,7 +2058,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__end_block(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_queue *tidq)
+			     struct cs_etm_traceid_ctxt *tidq)
 {
 	/*
 	 * It has no new packet coming and 'etmq->packet' contains the stale
@@ -2159,9 +2159,9 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 		struct int_node *inode;
 
 		intlist__for_each_entry(inode, etmq->traceid_list) {
-			struct cs_etm_traceid_queue *tidq;
+			struct cs_etm_traceid_ctxt *tidq;
 
-			tidq = cs_etm__etmq_get_traceid_queue(etmq, inode->i);
+			tidq = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
 			if (!tidq)
 				return -ENOMEM;
 			if (thread__tid(tidq->decode_thread) == etmq->buffer->tid)
@@ -2183,7 +2183,7 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 
 /* Check whether the instruction before ret_addr is an SVC. */
 static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
-				 struct cs_etm_traceid_queue *tidq,
+				 struct cs_etm_traceid_ctxt *tidq,
 				 struct cs_etm_packet *packet, u64 ret_addr)
 {
 	/* Initialise to keep compiler happy */
@@ -2254,7 +2254,7 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
 }
 
 static bool cs_etm__is_syscall(struct cs_etm_queue *etmq,
-			       struct cs_etm_traceid_queue *tidq, u64 magic)
+			       struct cs_etm_traceid_ctxt *tidq, u64 magic)
 {
 	struct cs_etm_packet *packet = tidq->packet;
 
@@ -2277,7 +2277,7 @@ static bool cs_etm__is_syscall(struct cs_etm_queue *etmq,
 	return false;
 }
 
-static bool cs_etm__is_async_exception(struct cs_etm_traceid_queue *tidq,
+static bool cs_etm__is_async_exception(struct cs_etm_traceid_ctxt *tidq,
 				       u64 magic)
 {
 	struct cs_etm_packet *packet = tidq->packet;
@@ -2304,7 +2304,7 @@ static bool cs_etm__is_async_exception(struct cs_etm_traceid_queue *tidq,
 }
 
 static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq,
-				      struct cs_etm_traceid_queue *tidq,
+				      struct cs_etm_traceid_ctxt *tidq,
 				      u64 magic)
 {
 	struct cs_etm_packet *packet = tidq->packet;
@@ -2351,7 +2351,7 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
-				    struct cs_etm_traceid_queue *tidq)
+				    struct cs_etm_traceid_ctxt *tidq)
 {
 	struct cs_etm_packet *packet = tidq->packet;
 	struct cs_etm_packet *prev_packet = tidq->prev_packet;
@@ -2571,8 +2571,8 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
 	return ret;
 }
 
-static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
-					 struct cs_etm_traceid_queue *tidq)
+static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
+					 struct cs_etm_traceid_ctxt *tidq)
 {
 	int ret;
 
@@ -2657,7 +2657,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 	u8 trace_chan_id;
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_queue *tidq;
+	struct cs_etm_traceid_ctxt *tidq;
 	u64 queue_time;
 
 	while (1) {
@@ -2684,7 +2684,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		auxtrace_heap__pop(&etm->heap);
 		etmq->on_heap = false;
 
-		tidq  = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
+		tidq  = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
 		if (!tidq) {
 			/*
 			 * No traceID queue has been allocated for this traceID,
@@ -2699,7 +2699,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		 * Packets associated with this timestamp, if any, are already in
 		 * the etmq's traceID queue, so process them.
 		 */
-		ret = cs_etm__process_traceid_queue(etmq, tidq);
+		ret = cs_etm__process_traceid_ctxt(etmq, tidq);
 		if (ret < 0)
 			goto out;
 
@@ -2723,7 +2723,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		/*
 		 * Add the next timestamp or decoded packets to the min heap.
 		 * Packets will be processed and synthesized during the next call
-		 * to cs_etm__process_traceid_queue() for this queue/traceID.
+		 * to cs_etm__process_traceid_ctxt() for this queue/traceID.
 		 */
 		ret = cs_etm__add_to_heap(etmq);
 		if (ret)
@@ -2741,7 +2741,7 @@ static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm)
 	int ret = 0;
 	unsigned int i;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_queue *tidq;
+	struct cs_etm_traceid_ctxt *tidq;
 
 	for (i = 0; i < etm->queues.nr_queues; i++) {
 		struct int_node *inode;
@@ -2750,11 +2750,11 @@ static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm)
 		if (!etmq)
 			continue;
 
-		intlist__for_each_entry(inode, etmq->traceid_queues_list) {
+		intlist__for_each_entry(inode, etmq->traceid_ctxts_list) {
 			int idx = (int)(intptr_t)inode->priv;
 
 			/* Flush any remaining branch stack entries */
-			tidq = etmq->traceid_queues[idx];
+			tidq = etmq->traceid_ctxts[idx];
 			ret = cs_etm__end_block(etmq, tidq);
 			if (ret)
 				return ret;
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index 1cbc8bc0aa06..115def9c6abb 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -247,7 +247,7 @@ enum cs_etm_pid_fmt {
  * Decode context for a single trace ID stream. In a decode tree there is one
  * of these for each stream.
  */
-struct cs_etm_traceid_queue {
+struct cs_etm_traceid_ctxt {
 	u8 trace_chan_id;
 	u64 period_instructions;
 	u64 kernel_start;
@@ -276,10 +276,10 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 				       u8 trace_chan_id, ocsd_ex_level el,
 				       pid_t tid);
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
-void cs_etm__etmq_set_traceid_queue_ready(struct cs_etm_queue *etmq,
+void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id);
-struct cs_etm_traceid_queue
-*cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
+struct cs_etm_traceid_ctxt
+*cs_etm__etmq_get_traceid_ctxt(struct cs_etm_queue *etmq, u8 trace_chan_id);
 int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused,
 				       struct perf_session *session __maybe_unused);
 u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 23/34] perf cs-etm: Rename tidq variables to tidc
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (21 preceding siblings ...)
  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:29 ` 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
                   ` (11 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Use tidc for variables that point at the new trace ID context struct.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  52 +--
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |   2 +-
 tools/perf/util/cs-etm.c                        | 402 ++++++++++++------------
 3 files changed, 228 insertions(+), 228 deletions(-)

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 3e3ec30bc7b3..7a1d50ca5949 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -87,17 +87,17 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
 	return 0;
 }
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *tidc,
 			       struct cs_etm_packet *packet)
 {
-	if (!packet_queue || !packet)
+	if (!tidc || !packet)
 		return -EINVAL;
 
 	/* Nothing to do, might as well just return */
-	if (packet_queue->packet_count == 0)
+	if (tidc->packet_count == 0)
 		return 0;
 
-	packet_queue->packet_count--;
+	tidc->packet_count--;
 	return 1;
 }
 
@@ -228,7 +228,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 				  const uint8_t trace_chan_id,
 				  const ocsd_trc_index_t indx)
 {
-	struct cs_etm_traceid_ctxt *packet_queue;
+	struct cs_etm_traceid_ctxt *tidc;
 	u64 converted_timestamp;
 
 	/* Ignore trace timestamps when unavailable or disabled by --itrace=Z. */
@@ -236,8 +236,8 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 		return OCSD_RESP_CONT;
 
 	/* First get the decode context for this traceID */
-	packet_queue = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-	if (!packet_queue)
+	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
+	if (!tidc)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
 	/*
@@ -254,7 +254,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 		return OCSD_RESP_CONT;
 	}
 
-	packet_queue->cs_timestamp = max(packet_queue->cs_timestamp, converted_timestamp);
+	tidc->cs_timestamp = max(tidc->cs_timestamp, converted_timestamp);
 
 	/* Tell the front end which decode context needs attention */
 	cs_etm__etmq_set_traceid_ctxt_ready(etmq, trace_chan_id);
@@ -293,7 +293,7 @@ cs_etm_decoder__get_isa(const ocsd_generic_trace_elem *elem)
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
-			      struct cs_etm_traceid_ctxt *packet_queue,
+			      struct cs_etm_traceid_ctxt *tidc,
 			      const ocsd_generic_trace_elem *elem,
 			      const u8 trace_chan_id,
 			      enum cs_etm_sample_type sample_type)
@@ -301,17 +301,17 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	struct cs_etm_packet *packet;
 	int cpu;
 
-	if (packet_queue->packet_count)
+	if (tidc->packet_count)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
 	if (cs_etm__get_cpu(etmq, trace_chan_id, &cpu) < 0)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	packet = packet_queue->packet;
+	packet = tidc->packet;
 	if (!packet)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	packet_queue->packet_count++;
+	tidc->packet_count++;
 	packet->sample_type = sample_type;
 	packet->isa = cs_etm_decoder__get_isa(elem);
 	packet->cpu = cpu;
@@ -335,19 +335,19 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_ctxt *packet_queue,
+			     struct cs_etm_traceid_ctxt *tidc,
 			     const ocsd_generic_trace_elem *elem,
 			     const uint8_t trace_chan_id)
 {
 	int ret = 0;
 	struct cs_etm_packet *packet;
 
-	ret = cs_etm_decoder__buffer_packet(etmq, packet_queue, elem,
+	ret = cs_etm_decoder__buffer_packet(etmq, tidc, elem,
 					    trace_chan_id, CS_ETM_RANGE);
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = packet_queue->packet;
+	packet = tidc->packet;
 
 	packet->start_addr = elem->st_addr;
 	packet->end_addr = elem->en_addr;
@@ -441,7 +441,7 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq,
 
 static ocsd_datapath_resp_t
 cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
-			struct cs_etm_traceid_ctxt *packet_queue,
+			struct cs_etm_traceid_ctxt *tidc,
 			const ocsd_generic_trace_elem *elem,
 			const uint8_t trace_chan_id)
 {
@@ -472,12 +472,12 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 				elem->context.exception_level, tid))
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	ret = cs_etm_decoder__buffer_packet(etmq, packet_queue, elem,
+	ret = cs_etm_decoder__buffer_packet(etmq, tidc, elem,
 					    trace_chan_id, CS_ETM_CONTEXT);
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
 		return ret;
 
-	packet = packet_queue->packet;
+	packet = tidc->packet;
 	packet->tid = tid;
 	if (elem->context.el_valid)
 		packet->el = elem->context.exception_level;
@@ -495,10 +495,10 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	ocsd_gen_trc_elem_t type;
 	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
 	struct cs_etm_queue *etmq = decoder->data;
-	struct cs_etm_traceid_ctxt *packet_queue;
+	struct cs_etm_traceid_ctxt *tidc;
 
-	packet_queue = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-	if (!packet_queue)
+	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
+	if (!tidc)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
 	type = elem->elem_type;
@@ -507,23 +507,23 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	    type == OCSD_GEN_TRC_ELEM_NO_SYNC ||
 	    type == OCSD_GEN_TRC_ELEM_TRACE_ON ||
 	    type == OCSD_GEN_TRC_ELEM_ADDR_NACC)
-		resp = cs_etm_decoder__buffer_discontinuity(etmq, packet_queue,
+		resp = cs_etm_decoder__buffer_discontinuity(etmq, tidc,
 							    elem, trace_chan_id);
 	else if (type == OCSD_GEN_TRC_ELEM_INSTR_RANGE)
-		resp = cs_etm_decoder__buffer_range(etmq, packet_queue, elem,
+		resp = cs_etm_decoder__buffer_range(etmq, tidc, elem,
 						    trace_chan_id);
 	else if (type == OCSD_GEN_TRC_ELEM_EXCEPTION)
-		resp = cs_etm_decoder__buffer_exception(etmq, packet_queue, elem,
+		resp = cs_etm_decoder__buffer_exception(etmq, tidc, elem,
 							trace_chan_id);
 	else if (type == OCSD_GEN_TRC_ELEM_EXCEPTION_RET)
-		resp = cs_etm_decoder__buffer_exception_ret(etmq, packet_queue,
+		resp = cs_etm_decoder__buffer_exception_ret(etmq, tidc,
 							    elem, trace_chan_id);
 	else if (type == OCSD_GEN_TRC_ELEM_TIMESTAMP)
 		resp = cs_etm_decoder__do_hard_timestamp(etmq, elem,
 							 trace_chan_id,
 							 indx);
 	else if (type == OCSD_GEN_TRC_ELEM_PE_CONTEXT)
-		resp = cs_etm_decoder__set_tid(etmq, packet_queue,
+		resp = cs_etm_decoder__set_tid(etmq, tidc,
 					       elem, trace_chan_id);
 
 	return resp;
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 8624f48d696f..f29f286f1d8b 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -102,7 +102,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *packet_queue,
+int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *tidc,
 			       struct cs_etm_packet *packet);
 
 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index b49bf606ffeb..e2e84561c0c9 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -567,7 +567,7 @@ void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
 static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 				      u8 *trace_chan_id)
 {
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 
 	if (!etmq->ready_chan_id)
 		return 0;
@@ -575,8 +575,8 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 	if (trace_chan_id)
 		*trace_chan_id = etmq->ready_chan_id;
 
-	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, etmq->ready_chan_id);
-	if (!tidq)
+	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, etmq->ready_chan_id);
+	if (!tidc)
 		return 0;
 
 	/* Acknowledge pending status */
@@ -590,11 +590,11 @@ static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
 		return etmq->buffer->time;
 
 	/* Use the last trace timestamp, or zero if none has been found yet. */
-	return tidq->cs_timestamp;
+	return tidc->cs_timestamp;
 }
 
 static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
-				      struct cs_etm_traceid_ctxt *tidq,
+				      struct cs_etm_traceid_ctxt *tidc,
 				      u8 trace_chan_id)
 {
 	int rc = -ENOMEM;
@@ -602,21 +602,21 @@ static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
 	queue = &etmq->etm->queues.queue_array[etmq->queue_nr];
-	tidq->trace_chan_id = trace_chan_id;
-	tidq->decode_el = ocsd_EL_unknown;
-	tidq->frontend_thread = machine__findnew_thread(&etm->session->machines.host, -1,
+	tidc->trace_chan_id = trace_chan_id;
+	tidc->decode_el = ocsd_EL_unknown;
+	tidc->frontend_thread = machine__findnew_thread(&etm->session->machines.host, -1,
 					       queue->tid);
-	tidq->decode_thread = machine__findnew_thread(&etm->session->machines.host, -1,
+	tidc->decode_thread = machine__findnew_thread(&etm->session->machines.host, -1,
 					       queue->tid);
-	if (!tidq->frontend_thread || !tidq->decode_thread)
+	if (!tidc->frontend_thread || !tidc->decode_thread)
 		goto out;
 
-	tidq->packet = zalloc(sizeof(struct cs_etm_packet));
-	if (!tidq->packet)
+	tidc->packet = zalloc(sizeof(struct cs_etm_packet));
+	if (!tidc->packet)
 		goto out;
 
-	tidq->prev_packet = zalloc(sizeof(struct cs_etm_packet));
-	if (!tidq->prev_packet)
+	tidc->prev_packet = zalloc(sizeof(struct cs_etm_packet));
+	if (!tidc->prev_packet)
 		goto out_free;
 
 	if (etm->use_thread_stack) {
@@ -624,36 +624,36 @@ static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
 
 		sz += etm->synth_opts.last_branch_sz *
 		      sizeof(struct branch_entry);
-		tidq->last_branch = zalloc(sz);
-		if (!tidq->last_branch)
+		tidc->last_branch = zalloc(sz);
+		if (!tidc->last_branch)
 			goto out_free;
 
-		tidq->br_stack_sz = etm->synth_opts.last_branch_sz;
+		tidc->br_stack_sz = etm->synth_opts.last_branch_sz;
 	}
 
 	if (etm->synth_opts.callchain) {
 		/* Add 1 to callchain_sz for callchain context */
-		tidq->callchain =
-			zalloc(struct_size(tidq->callchain, ips,
+		tidc->callchain =
+			zalloc(struct_size(tidc->callchain, ips,
 					   etm->synth_opts.callchain_sz + 1));
-		if (!tidq->callchain)
+		if (!tidc->callchain)
 			goto out_free;
 	}
 
-	tidq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);
-	if (!tidq->event_buf)
+	tidc->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);
+	if (!tidc->event_buf)
 		goto out_free;
 
 	return 0;
 
 out_free:
-	zfree(&tidq->callchain);
-	zfree(&tidq->last_branch);
-	zfree(&tidq->prev_packet);
-	zfree(&tidq->packet);
+	zfree(&tidc->callchain);
+	zfree(&tidc->last_branch);
+	zfree(&tidc->prev_packet);
+	zfree(&tidc->packet);
 out:
-	thread__zput(tidq->frontend_thread);
-	thread__zput(tidq->decode_thread);
+	thread__zput(tidc->frontend_thread);
+	thread__zput(tidc->decode_thread);
 	return rc;
 }
 
@@ -663,7 +663,7 @@ struct cs_etm_traceid_ctxt
 	int idx;
 	struct int_node *inode;
 	struct intlist *traceid_ctxts_list = etmq->traceid_ctxts_list;
-	struct cs_etm_traceid_ctxt *tidq, **traceid_ctxts;
+	struct cs_etm_traceid_ctxt *tidc, **traceid_ctxts;
 
 	/*
 	 * Check if a decode context exists for this traceID by looking
@@ -676,11 +676,11 @@ struct cs_etm_traceid_ctxt
 	}
 
 	/* We couldn't find a decode context for this traceID, allocate one */
-	tidq = malloc(sizeof(*tidq));
-	if (!tidq)
+	tidc = malloc(sizeof(*tidc));
+	if (!tidc)
 		return NULL;
 
-	memset(tidq, 0, sizeof(*tidq));
+	memset(tidc, 0, sizeof(*tidc));
 
 	/* Get a valid index for the new decode context */
 	idx = intlist__nr_entries(traceid_ctxts_list);
@@ -692,7 +692,7 @@ struct cs_etm_traceid_ctxt
 	/* Associate this traceID with this index */
 	inode->priv = (void *)(intptr_t)idx;
 
-	if (cs_etm__init_traceid_ctxt(etmq, tidq, trace_chan_id))
+	if (cs_etm__init_traceid_ctxt(etmq, tidc, trace_chan_id))
 		goto out_free;
 
 	/* Grow the traceid_ctxts array by one unit */
@@ -708,7 +708,7 @@ struct cs_etm_traceid_ctxt
 	if (!traceid_ctxts)
 		goto out_free;
 
-	traceid_ctxts[idx] = tidq;
+	traceid_ctxts[idx] = tidc;
 	etmq->traceid_ctxts = traceid_ctxts;
 
 	return etmq->traceid_ctxts[idx];
@@ -719,13 +719,13 @@ struct cs_etm_traceid_ctxt
 	 * and delete the memory associated to it.
 	 */
 	intlist__remove(traceid_ctxts_list, inode);
-	free(tidq);
+	free(tidc);
 
 	return NULL;
 }
 
 static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
-				struct cs_etm_traceid_ctxt *tidq)
+				struct cs_etm_traceid_ctxt *tidc)
 {
 	struct cs_etm_packet *tmp;
 
@@ -735,9 +735,9 @@ static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
 		 * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
 		 * the next incoming packet.
 		 */
-		tmp = tidq->packet;
-		tidq->packet = tidq->prev_packet;
-		tidq->prev_packet = tmp;
+		tmp = tidc->packet;
+		tidc->packet = tidc->prev_packet;
+		tidc->prev_packet = tmp;
 	}
 }
 
@@ -899,7 +899,7 @@ static void cs_etm__free_traceid_ctxts(struct cs_etm_queue *etmq)
 	int idx;
 	uintptr_t priv;
 	struct int_node *inode, *tmp;
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 	struct intlist *traceid_ctxts_list = etmq->traceid_ctxts_list;
 
 	intlist__for_each_entry_safe(inode, tmp, traceid_ctxts_list) {
@@ -907,15 +907,15 @@ static void cs_etm__free_traceid_ctxts(struct cs_etm_queue *etmq)
 		idx = priv;
 
 		/* Free this decode context from the array */
-		tidq = etmq->traceid_ctxts[idx];
-		thread__zput(tidq->frontend_thread);
-		thread__zput(tidq->decode_thread);
-		zfree(&tidq->event_buf);
-		zfree(&tidq->callchain);
-		zfree(&tidq->last_branch);
-		zfree(&tidq->prev_packet);
-		zfree(&tidq->packet);
-		zfree(&tidq);
+		tidc = etmq->traceid_ctxts[idx];
+		thread__zput(tidc->frontend_thread);
+		thread__zput(tidc->decode_thread);
+		zfree(&tidc->event_buf);
+		zfree(&tidc->callchain);
+		zfree(&tidc->last_branch);
+		zfree(&tidc->prev_packet);
+		zfree(&tidc->packet);
+		zfree(&tidc);
 
 		/*
 		 * Function intlist__remove() removes the inode from the list
@@ -1163,27 +1163,27 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
 }
 
 static u32 cs_etm__frontend_mem_access(struct cs_etm_queue *etmq,
-				       struct cs_etm_traceid_ctxt *tidq,
+				       struct cs_etm_traceid_ctxt *tidc,
 				       struct cs_etm_packet *packet,
 				       u64 address, size_t size, u8 *buffer)
 {
 	return __cs_etm__mem_access(etmq, address, size, buffer, 0, packet->el,
-				    tidq->frontend_thread);
+				    tidc->frontend_thread);
 }
 
 static u32 cs_etm__decoder_mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
 				      u64 address, size_t size, u8 *buffer,
 				      const ocsd_mem_space_acc_t mem_space)
 {
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 
-	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-	if (!tidq)
+	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
+	if (!tidc)
 		return 0;
 
 	return __cs_etm__mem_access(etmq, address, size, buffer,
-				    mem_space, tidq->decode_el,
-				    tidq->decode_thread);
+				    mem_space, tidc->decode_el,
+				    tidc->decode_thread);
 }
 
 static struct cs_etm_queue *cs_etm__alloc_queue(void)
@@ -1312,12 +1312,12 @@ static int cs_etm__push_heap_all(struct cs_etm_auxtrace *etm)
 }
 
 static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
-					 struct cs_etm_traceid_ctxt *tidq,
+					 struct cs_etm_traceid_ctxt *tidc,
 					 struct cs_etm_packet *packet, u64 addr)
 {
 	u8 instrBytes[2];
 
-	cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
+	cs_etm__frontend_mem_access(etmq, tidc, packet, addr,
 				    ARRAY_SIZE(instrBytes), instrBytes);
 	/*
 	 * T32 instruction size is indicated by bits[15:11] of the first
@@ -1328,12 +1328,12 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
 }
 
 static inline int cs_etm__instr_size(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_ctxt *tidq,
+				     struct cs_etm_traceid_ctxt *tidc,
 				     struct cs_etm_packet *packet,
 				     u64 addr)
 {
 	if (packet->isa == CS_ETM_ISA_T32)
-		return cs_etm__t32_instr_size(etmq, tidq, packet, addr);
+		return cs_etm__t32_instr_size(etmq, tidc, packet, addr);
 
 	return packet->last_instr_size;
 }
@@ -1364,7 +1364,7 @@ u64 cs_etm__last_executed_instr(const struct cs_etm_packet *packet)
 }
 
 static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_ctxt *tidq,
+				     struct cs_etm_traceid_ctxt *tidc,
 				     struct cs_etm_packet *packet,
 				     u64 offset)
 {
@@ -1375,7 +1375,7 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq,
 		return addr + offset * 4;
 
 	while (offset) {
-		addr += cs_etm__instr_size(etmq, tidq, packet, addr);
+		addr += cs_etm__instr_size(etmq, tidc, packet, addr);
 		offset--;
 	}
 	return addr;
@@ -1480,19 +1480,19 @@ int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
 				       u8 trace_chan_id,
 				       ocsd_ex_level el, pid_t tid)
 {
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 	int ret;
 
-	tidq = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-	if (!tidq)
+	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
+	if (!tidc)
 		return -EINVAL;
 
 	ret = cs_etm__etmq_update_thread(etmq, el, tid,
-					 &tidq->decode_thread);
+					 &tidc->decode_thread);
 	if (ret)
 		return ret;
 
-	tidq->decode_el = el;
+	tidc->decode_el = el;
 	return 0;
 }
 
@@ -1502,7 +1502,7 @@ bool cs_etm__has_timestamps(struct cs_etm_queue *etmq)
 }
 
 static void cs_etm__copy_insn(struct cs_etm_queue *etmq,
-			      struct cs_etm_traceid_ctxt *tidq,
+			      struct cs_etm_traceid_ctxt *tidc,
 			      struct cs_etm_packet *packet,
 			      struct perf_sample *sample)
 {
@@ -1515,7 +1515,7 @@ static void cs_etm__copy_insn(struct cs_etm_queue *etmq,
 		return;
 	}
 
-	sample->insn_len = cs_etm__instr_size(etmq, tidq, packet, sample->ip);
+	sample->insn_len = cs_etm__instr_size(etmq, tidc, packet, sample->ip);
 
 	/*
 	 * The instruction length should always fit within sample->insn,
@@ -1529,7 +1529,7 @@ static void cs_etm__copy_insn(struct cs_etm_queue *etmq,
 	if (packet->sample_type == CS_ETM_EXCEPTION && !sample->insn_len)
 		return;
 
-	cs_etm__frontend_mem_access(etmq, tidq, packet, sample->ip,
+	cs_etm__frontend_mem_access(etmq, tidc, packet, sample->ip,
 				    sample->insn_len, (void *)sample->insn);
 }
 
@@ -1544,12 +1544,12 @@ u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp)
 }
 
 static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
-					       struct cs_etm_traceid_ctxt *tidq)
+					       struct cs_etm_traceid_ctxt *tidc)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
 	if (etm->has_virtual_ts)
-		return tidq->cs_timestamp;
+		return tidc->cs_timestamp;
 
 	/*
 	 * Timestamps were disabled or no virtual TS. All samples are assigned
@@ -1571,7 +1571,7 @@ static bool cs_etm__packet_has_branch(struct cs_etm_packet *packet)
 }
 
 static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
-				    struct cs_etm_traceid_ctxt *tidq)
+				    struct cs_etm_traceid_ctxt *tidc)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	u64 from, to;
@@ -1580,67 +1580,67 @@ static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
 	if (!etm->synth_opts.branches && !etm->synth_opts.instructions)
 		return;
 
-	if (!cs_etm__packet_has_branch(tidq->prev_packet))
+	if (!cs_etm__packet_has_branch(tidc->prev_packet))
 		return;
 
 	if (etmq->etm->use_thread_stack) {
-		from = cs_etm__last_executed_instr(tidq->prev_packet);
-		to = cs_etm__first_executed_instr(tidq->packet);
+		from = cs_etm__last_executed_instr(tidc->prev_packet);
+		to = cs_etm__first_executed_instr(tidc->packet);
 
-		size = cs_etm__instr_size(etmq, tidq, tidq->prev_packet, from);
+		size = cs_etm__instr_size(etmq, tidc, tidc->prev_packet, from);
 
 		/* Enable callchain so thread stack entry can be allocated */
-		thread_stack__event(tidq->frontend_thread, tidq->prev_packet->cpu,
-				    tidq->prev_packet->flags, from, to, size,
+		thread_stack__event(tidc->frontend_thread, tidc->prev_packet->cpu,
+				    tidc->prev_packet->flags, from, to, size,
 				    etmq->buffer->buffer_nr + 1,
 				    etmq->etm->use_callchain,
-				    tidq->br_stack_sz, 0);
+				    tidc->br_stack_sz, 0);
 	} else {
-		thread_stack__set_trace_nr(tidq->frontend_thread,
-					   tidq->prev_packet->cpu,
+		thread_stack__set_trace_nr(tidc->frontend_thread,
+					   tidc->prev_packet->cpu,
 					   etmq->buffer->buffer_nr + 1);
 	}
 }
 
 static void cs_etm__sample_branch_stack(struct cs_etm_auxtrace *etm,
-					struct cs_etm_traceid_ctxt *tidq,
+					struct cs_etm_traceid_ctxt *tidc,
 					struct perf_sample *sample)
 {
 	if (etm->synth_opts.last_branch) {
-		thread_stack__br_sample(tidq->frontend_thread, tidq->packet->cpu,
-					tidq->last_branch, tidq->br_stack_sz);
-		sample->branch_stack = tidq->last_branch;
+		thread_stack__br_sample(tidc->frontend_thread, tidc->packet->cpu,
+					tidc->last_branch, tidc->br_stack_sz);
+		sample->branch_stack = tidc->last_branch;
 	}
 
 	if (etm->synth_opts.callchain) {
-		if (tidq->kernel_start)
-			thread_stack__sample(tidq->frontend_thread,
-					     tidq->packet->cpu,
-					     tidq->callchain,
+		if (tidc->kernel_start)
+			thread_stack__sample(tidc->frontend_thread,
+					     tidc->packet->cpu,
+					     tidc->callchain,
 					     etm->synth_opts.callchain_sz + 1,
-					     sample->ip, tidq->kernel_start);
+					     sample->ip, tidc->kernel_start);
 		else
 			/*
 			 * Clear the callchain when the kernel start address is
 			 * not available yet. The empty callchain can then be
 			 * consumed by cs_etm__inject_event().
 			 */
-			memset(tidq->callchain, 0,
-			       struct_size(tidq->callchain, ips,
+			memset(tidc->callchain, 0,
+			       struct_size(tidc->callchain, ips,
 					   etm->synth_opts.callchain_sz + 1));
 
-		sample->callchain = tidq->callchain;
+		sample->callchain = tidc->callchain;
 	}
 }
 
 static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
-					    struct cs_etm_traceid_ctxt *tidq,
+					    struct cs_etm_traceid_ctxt *tidc,
 					    struct cs_etm_packet *packet,
 					    u64 addr, u64 period)
 {
 	int ret = 0;
 	struct cs_etm_auxtrace *etm = etmq->etm;
-	union perf_event *event = tidq->event_buf;
+	union perf_event *event = tidc->event_buf;
 	struct perf_sample sample;
 
 	perf_sample__init(&sample, /*all=*/true);
@@ -1649,20 +1649,20 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 	event->sample.header.size = sizeof(struct perf_event_header);
 
 	/* Set time field based on etm auxtrace config. */
-	sample.time = cs_etm__resolve_sample_time(etmq, tidq);
+	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
 
 	sample.ip = addr;
-	sample.pid = thread__pid(tidq->frontend_thread);
-	sample.tid = thread__tid(tidq->frontend_thread);
+	sample.pid = thread__pid(tidc->frontend_thread);
+	sample.tid = thread__tid(tidc->frontend_thread);
 	sample.id = etmq->etm->instructions_id;
 	sample.stream_id = etmq->etm->instructions_id;
 	sample.period = period;
 	sample.cpu = packet->cpu;
-	sample.flags = tidq->prev_packet->flags;
+	sample.flags = tidc->prev_packet->flags;
 	sample.cpumode = event->sample.header.misc;
 
-	cs_etm__copy_insn(etmq, tidq, packet, &sample);
-	cs_etm__sample_branch_stack(etm, tidq, &sample);
+	cs_etm__copy_insn(etmq, tidc, packet, &sample);
+	cs_etm__sample_branch_stack(etm, tidc, &sample);
 
 	if (etm->synth_opts.inject) {
 		ret = cs_etm__inject_event(etm, event, &sample,
@@ -1683,9 +1683,9 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__synth_last_instruction_sample(struct cs_etm_queue *etmq,
-						 struct cs_etm_traceid_ctxt *tidq)
+						 struct cs_etm_traceid_ctxt *tidc)
 {
-	struct cs_etm_packet *packet = tidq->prev_packet;
+	struct cs_etm_packet *packet = tidc->prev_packet;
 	int ret;
 
 	if (!etmq->etm->synth_opts.last_branch ||
@@ -1696,11 +1696,11 @@ static int cs_etm__synth_last_instruction_sample(struct cs_etm_queue *etmq,
 	if (packet->sample_type != CS_ETM_RANGE || !packet->instr_count)
 		return 0;
 
-	ret = cs_etm__synth_instruction_sample(etmq, tidq, packet,
+	ret = cs_etm__synth_instruction_sample(etmq, tidc, packet,
 					       cs_etm__last_executed_instr(packet),
-					       tidq->period_instructions);
+					       tidc->period_instructions);
 	if (!ret)
-		tidq->period_instructions = 0;
+		tidc->period_instructions = 0;
 
 	return ret;
 }
@@ -1710,12 +1710,12 @@ static int cs_etm__synth_last_instruction_sample(struct cs_etm_queue *etmq,
  * and the next taken branch. Generate sample accordingly.
  */
 static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
-				       struct cs_etm_traceid_ctxt *tidq)
+				       struct cs_etm_traceid_ctxt *tidc)
 {
 	int ret = 0;
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	struct perf_sample sample;
-	union perf_event *event = tidq->event_buf;
+	union perf_event *event = tidc->event_buf;
 
 	struct dummy_branch_stack {
 		u64			nr;
@@ -1727,41 +1727,41 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
 	if (!etm->synth_opts.branches)
 		return 0;
 
-	if (!cs_etm__packet_has_branch(tidq->prev_packet) &&
-	    !(tidq->prev_packet->flags & (PERF_IP_FLAG_TRACE_BEGIN |
+	if (!cs_etm__packet_has_branch(tidc->prev_packet) &&
+	    !(tidc->prev_packet->flags & (PERF_IP_FLAG_TRACE_BEGIN |
 					  PERF_IP_FLAG_TRACE_END)))
 		return 0;
 
 	if (etm->branches_filter &&
-		!(etm->branches_filter & tidq->prev_packet->flags))
+		!(etm->branches_filter & tidc->prev_packet->flags))
 		return 0;
 
 	perf_sample__init(&sample, /*all=*/true);
-	ip = cs_etm__last_executed_instr(tidq->prev_packet);
+	ip = cs_etm__last_executed_instr(tidc->prev_packet);
 
 	event->sample.header.type = PERF_RECORD_SAMPLE;
 	event->sample.header.misc = cs_etm__cpu_mode(etmq, ip,
-						     tidq->prev_packet->el);
+						     tidc->prev_packet->el);
 	event->sample.header.size = sizeof(struct perf_event_header);
 
 	/* Set time field based on etm auxtrace config. */
-	sample.time = cs_etm__resolve_sample_time(etmq, tidq);
+	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
 
 	sample.ip = ip;
-	sample.pid = thread__pid(tidq->frontend_thread);
-	sample.tid = thread__tid(tidq->frontend_thread);
-	sample.addr = cs_etm__first_executed_instr(tidq->packet);
+	sample.pid = thread__pid(tidc->frontend_thread);
+	sample.tid = thread__tid(tidc->frontend_thread);
+	sample.addr = cs_etm__first_executed_instr(tidc->packet);
 	sample.id = etmq->etm->branches_id;
 	sample.stream_id = etmq->etm->branches_id;
 	sample.period = 1;
-	sample.cpu = tidq->packet->cpu;
-	sample.flags = tidq->prev_packet->flags;
+	sample.cpu = tidc->packet->cpu;
+	sample.flags = tidc->prev_packet->flags;
 	sample.cpumode = event->sample.header.misc;
 
-	if (tidq->prev_packet->sample_type == CS_ETM_EXCEPTION)
-		sample.ret_addr = tidq->prev_packet->pref_ret_addr;
+	if (tidc->prev_packet->sample_type == CS_ETM_EXCEPTION)
+		sample.ret_addr = tidc->prev_packet->pref_ret_addr;
 
-	cs_etm__copy_insn(etmq, tidq, tidq->prev_packet, &sample);
+	cs_etm__copy_insn(etmq, tidc, tidc->prev_packet, &sample);
 
 	/*
 	 * perf report cannot handle events without a branch stack
@@ -1879,21 +1879,21 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 }
 
 static int cs_etm__sample(struct cs_etm_queue *etmq,
-			  struct cs_etm_traceid_ctxt *tidq)
+			  struct cs_etm_traceid_ctxt *tidc)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 	int ret;
 	u64 instrs_prev;
 
 	/* Get instructions remainder from previous packet */
-	instrs_prev = tidq->period_instructions;
+	instrs_prev = tidc->period_instructions;
 
-	tidq->period_instructions += tidq->packet->instr_count;
+	tidc->period_instructions += tidc->packet->instr_count;
 
-	cs_etm__add_stack_event(etmq, tidq);
+	cs_etm__add_stack_event(etmq, tidc);
 
 	if (etm->synth_opts.instructions &&
-	    tidq->period_instructions >= etm->instructions_sample_period) {
+	    tidc->period_instructions >= etm->instructions_sample_period) {
 		/*
 		 * Emit instruction sample periodically
 		 * TODO: allow period to be defined in cycles and clock time
@@ -1916,7 +1916,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 		 *            |                                  |
 		 *            \---------------- -----------------/
 		 *                             V
-		 *                 tidq->packet->instr_count
+		 *                 tidc->packet->instr_count
 		 *
 		 * Instrs Sample(n...) are the synthesised samples occurring
 		 * every etm->instructions_sample_period instructions - as
@@ -1924,7 +1924,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 		 * last sample before the current etm packet, n+1 to n+3
 		 * samples are generated from the current etm packet.
 		 *
-		 * tidq->packet->instr_count represents the number of
+		 * tidc->packet->instr_count represents the number of
 		 * instructions in the current etm packet.
 		 *
 		 * Period instructions (Pi) contains the number of
@@ -1938,7 +1938,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 		 * sample(n+1); sample(n+2) and sample(n+3) consume the
 		 * instructions with sample period.  After sample(n+3), the rest
 		 * instructions will be used by later packet and it is assigned
-		 * to tidq->period_instructions for next round calculation.
+		 * to tidc->period_instructions for next round calculation.
 		 */
 
 		/*
@@ -1949,7 +1949,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 		u64 offset = etm->instructions_sample_period - instrs_prev;
 		u64 addr;
 
-		while (tidq->period_instructions >=
+		while (tidc->period_instructions >=
 				etm->instructions_sample_period) {
 			/*
 			 * Calculate the address of the sampled instruction (-1
@@ -1957,33 +1957,33 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
 			 * been executed, but PC has not advanced to next
 			 * instruction)
 			 */
-			addr = cs_etm__instr_addr(etmq, tidq, tidq->packet,
+			addr = cs_etm__instr_addr(etmq, tidc, tidc->packet,
 						  offset - 1);
 			ret = cs_etm__synth_instruction_sample(
-				etmq, tidq, tidq->packet, addr,
+				etmq, tidc, tidc->packet, addr,
 				etm->instructions_sample_period);
 			if (ret)
 				return ret;
 
 			offset += etm->instructions_sample_period;
-			tidq->period_instructions -=
+			tidc->period_instructions -=
 				etm->instructions_sample_period;
 		}
 	}
 
-	ret = cs_etm__synth_branch_sample(etmq, tidq);
+	ret = cs_etm__synth_branch_sample(etmq, tidc);
 	if (ret)
 		return ret;
 
-	cs_etm__packet_swap(etm, tidq);
+	cs_etm__packet_swap(etm, tidc);
 
 	return 0;
 }
 
 static int cs_etm__context(struct cs_etm_queue *etmq,
-			   struct cs_etm_traceid_ctxt *tidq)
+			   struct cs_etm_traceid_ctxt *tidc)
 {
-	ocsd_ex_level el = tidq->packet->el;
+	ocsd_ex_level el = tidc->packet->el;
 	struct machine *machine;
 	int ret;
 
@@ -1993,72 +1993,72 @@ static int cs_etm__context(struct cs_etm_queue *etmq,
 		goto err;
 	}
 
-	tidq->kernel_start = machine__kernel_start(machine);
+	tidc->kernel_start = machine__kernel_start(machine);
 
-	ret = cs_etm__etmq_update_thread(etmq, el, tidq->packet->tid,
-					 &tidq->frontend_thread);
+	ret = cs_etm__etmq_update_thread(etmq, el, tidc->packet->tid,
+					 &tidc->frontend_thread);
 	if (ret)
 		goto err;
 
 	return 0;
 
 err:
-	thread__zput(tidq->frontend_thread);
-	tidq->kernel_start = 0;
+	thread__zput(tidc->frontend_thread);
+	tidc->kernel_start = 0;
 	return ret;
 }
 
 static int cs_etm__exception(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_ctxt *tidq)
+			     struct cs_etm_traceid_ctxt *tidc)
 {
-	struct cs_etm_packet *packet = tidq->packet;
+	struct cs_etm_packet *packet = tidc->packet;
 
 	/*
 	 * Resolve the preceding branch without adding instructions, then keep
 	 * this exception as prev_packet until its destination is known.
 	 */
 	if (packet->start_addr != CS_ETM_INVAL_ADDR)
-		return cs_etm__sample(etmq, tidq);
+		return cs_etm__sample(etmq, tidc);
 
 	/* Fall back to attributing the exception to the preceding range. */
-	if (tidq->prev_packet->sample_type == CS_ETM_RANGE) {
-		tidq->prev_packet->flags = packet->flags;
-		tidq->prev_packet->last_instr_taken_branch = true;
+	if (tidc->prev_packet->sample_type == CS_ETM_RANGE) {
+		tidc->prev_packet->flags = packet->flags;
+		tidc->prev_packet->last_instr_taken_branch = true;
 	}
 
 	return 0;
 }
 
 static int cs_etm__flush(struct cs_etm_queue *etmq,
-			 struct cs_etm_traceid_ctxt *tidq)
+			 struct cs_etm_traceid_ctxt *tidc)
 {
 	int err = 0;
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
 	/* Handle start tracing packet */
-	if (tidq->prev_packet->sample_type == CS_ETM_EMPTY)
+	if (tidc->prev_packet->sample_type == CS_ETM_EMPTY)
 		goto swap_packet;
 
-	err = cs_etm__synth_last_instruction_sample(etmq, tidq);
+	err = cs_etm__synth_last_instruction_sample(etmq, tidc);
 	if (err)
 		return err;
 
-	err = cs_etm__synth_branch_sample(etmq, tidq);
+	err = cs_etm__synth_branch_sample(etmq, tidc);
 	if (err)
 		return err;
 
 swap_packet:
-	cs_etm__packet_swap(etm, tidq);
+	cs_etm__packet_swap(etm, tidc);
 
 	/* Reset last branches after flush the trace */
 	if (etm->use_thread_stack)
-		thread_stack__flush(tidq->frontend_thread);
+		thread_stack__flush(tidc->frontend_thread);
 
 	return err;
 }
 
 static int cs_etm__end_block(struct cs_etm_queue *etmq,
-			     struct cs_etm_traceid_ctxt *tidq)
+			     struct cs_etm_traceid_ctxt *tidc)
 {
 	/*
 	 * It has no new packet coming and 'etmq->packet' contains the stale
@@ -2069,7 +2069,7 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
 	 * event for the branches left in the circular buffer at the end of
 	 * the trace.
 	 */
-	return cs_etm__synth_last_instruction_sample(etmq, tidq);
+	return cs_etm__synth_last_instruction_sample(etmq, tidc);
 }
 
 static int cs_etm__flush_stack_cb(struct thread *thread,
@@ -2159,20 +2159,20 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 		struct int_node *inode;
 
 		intlist__for_each_entry(inode, etmq->traceid_list) {
-			struct cs_etm_traceid_ctxt *tidq;
+			struct cs_etm_traceid_ctxt *tidc;
 
-			tidq = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
-			if (!tidq)
+			tidc = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
+			if (!tidc)
 				return -ENOMEM;
-			if (thread__tid(tidq->decode_thread) == etmq->buffer->tid)
+			if (thread__tid(tidc->decode_thread) == etmq->buffer->tid)
 				continue;
 
-			thread__zput(tidq->frontend_thread);
-			thread__zput(tidq->decode_thread);
-			tidq->frontend_thread = machine__findnew_thread(
+			thread__zput(tidc->frontend_thread);
+			thread__zput(tidc->decode_thread);
+			tidc->frontend_thread = machine__findnew_thread(
 				&etm->session->machines.host, -1,
 				etmq->buffer->tid);
-			tidq->decode_thread = machine__findnew_thread(
+			tidc->decode_thread = machine__findnew_thread(
 				&etm->session->machines.host, -1,
 				etmq->buffer->tid);
 		}
@@ -2183,7 +2183,7 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 
 /* Check whether the instruction before ret_addr is an SVC. */
 static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
-				 struct cs_etm_traceid_ctxt *tidq,
+				 struct cs_etm_traceid_ctxt *tidc,
 				 struct cs_etm_packet *packet, u64 ret_addr)
 {
 	/* Initialise to keep compiler happy */
@@ -2206,7 +2206,7 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
 		 * so below only read 2 bytes as instruction size for T32.
 		 */
 		addr = ret_addr - 2;
-		cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
+		cs_etm__frontend_mem_access(etmq, tidc, packet, addr,
 					    sizeof(instr16), (u8 *)&instr16);
 		if ((instr16 & 0xFF00) == 0xDF00)
 			return true;
@@ -2222,7 +2222,7 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
 		 * +---------+---------+-------------------------+
 		 */
 		addr = ret_addr - 4;
-		cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
+		cs_etm__frontend_mem_access(etmq, tidc, packet, addr,
 					    sizeof(instr32), (u8 *)&instr32);
 		if ((instr32 & 0x0F000000) == 0x0F000000 &&
 		    (instr32 & 0xF0000000) != 0xF0000000)
@@ -2239,7 +2239,7 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
 		 * +-----------------------+---------+-----------+
 		 */
 		addr = ret_addr - 4;
-		cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
+		cs_etm__frontend_mem_access(etmq, tidc, packet, addr,
 					    sizeof(instr32), (u8 *)&instr32);
 		if ((instr32 & 0xFFE0001F) == 0xd4000001)
 			return true;
@@ -2254,9 +2254,9 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq,
 }
 
 static bool cs_etm__is_syscall(struct cs_etm_queue *etmq,
-			       struct cs_etm_traceid_ctxt *tidq, u64 magic)
+			       struct cs_etm_traceid_ctxt *tidc, u64 magic)
 {
-	struct cs_etm_packet *packet = tidq->packet;
+	struct cs_etm_packet *packet = tidc->packet;
 
 	if (magic == __perf_cs_etmv3_magic)
 		if (packet->exception_number == CS_ETMV3_EXC_SVC)
@@ -2269,7 +2269,7 @@ static bool cs_etm__is_syscall(struct cs_etm_queue *etmq,
 	 */
 	if (magic == __perf_cs_etmv4_magic || magic == __perf_cs_ete_magic) {
 		if (packet->exception_number == CS_ETMV4_EXC_CALL &&
-		    cs_etm__is_svc_instr(etmq, tidq, packet,
+		    cs_etm__is_svc_instr(etmq, tidc, packet,
 					 packet->pref_ret_addr))
 			return true;
 	}
@@ -2277,10 +2277,10 @@ static bool cs_etm__is_syscall(struct cs_etm_queue *etmq,
 	return false;
 }
 
-static bool cs_etm__is_async_exception(struct cs_etm_traceid_ctxt *tidq,
+static bool cs_etm__is_async_exception(struct cs_etm_traceid_ctxt *tidc,
 				       u64 magic)
 {
-	struct cs_etm_packet *packet = tidq->packet;
+	struct cs_etm_packet *packet = tidc->packet;
 
 	if (magic == __perf_cs_etmv3_magic)
 		if (packet->exception_number == CS_ETMV3_EXC_DEBUG_HALT ||
@@ -2304,10 +2304,10 @@ static bool cs_etm__is_async_exception(struct cs_etm_traceid_ctxt *tidq,
 }
 
 static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq,
-				      struct cs_etm_traceid_ctxt *tidq,
+				      struct cs_etm_traceid_ctxt *tidc,
 				      u64 magic)
 {
-	struct cs_etm_packet *packet = tidq->packet;
+	struct cs_etm_packet *packet = tidc->packet;
 
 	if (magic == __perf_cs_etmv3_magic)
 		if (packet->exception_number == CS_ETMV3_EXC_SMC ||
@@ -2331,7 +2331,7 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq,
 		 * (SMC, HVC) are taken as sync exceptions.
 		 */
 		if (packet->exception_number == CS_ETMV4_EXC_CALL &&
-		    !cs_etm__is_svc_instr(etmq, tidq, packet,
+		    !cs_etm__is_svc_instr(etmq, tidc, packet,
 					  packet->pref_ret_addr))
 			return true;
 
@@ -2351,10 +2351,10 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq,
 }
 
 static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
-				    struct cs_etm_traceid_ctxt *tidq)
+				    struct cs_etm_traceid_ctxt *tidc)
 {
-	struct cs_etm_packet *packet = tidq->packet;
-	struct cs_etm_packet *prev_packet = tidq->prev_packet;
+	struct cs_etm_packet *packet = tidc->packet;
+	struct cs_etm_packet *prev_packet = tidc->prev_packet;
 	u64 magic;
 	int ret;
 
@@ -2440,7 +2440,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 		if (prev_packet->flags == (PERF_IP_FLAG_BRANCH |
 					   PERF_IP_FLAG_RETURN |
 					   PERF_IP_FLAG_INTERRUPT) &&
-		    cs_etm__is_svc_instr(etmq, tidq, packet, packet->start_addr)) {
+		    cs_etm__is_svc_instr(etmq, tidc, packet, packet->start_addr)) {
 			prev_packet->flags = PERF_IP_FLAG_BRANCH |
 					     PERF_IP_FLAG_RETURN |
 					     PERF_IP_FLAG_SYSCALLRET;
@@ -2463,7 +2463,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 			return ret;
 
 		/* The exception is for system call. */
-		if (cs_etm__is_syscall(etmq, tidq, magic))
+		if (cs_etm__is_syscall(etmq, tidc, magic))
 			packet->flags = PERF_IP_FLAG_BRANCH |
 					PERF_IP_FLAG_CALL |
 					PERF_IP_FLAG_SYSCALLRET;
@@ -2471,7 +2471,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 		 * The exceptions are triggered by external signals from bus,
 		 * interrupt controller, debug module, PE reset or halt.
 		 */
-		else if (cs_etm__is_async_exception(tidq, magic))
+		else if (cs_etm__is_async_exception(tidc, magic))
 			packet->flags = PERF_IP_FLAG_BRANCH |
 					PERF_IP_FLAG_CALL |
 					PERF_IP_FLAG_ASYNC |
@@ -2480,7 +2480,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 		 * Otherwise, exception is caused by trap, instruction &
 		 * data fault, or alignment errors.
 		 */
-		else if (cs_etm__is_sync_exception(etmq, tidq, magic))
+		else if (cs_etm__is_sync_exception(etmq, tidc, magic))
 			packet->flags = PERF_IP_FLAG_BRANCH |
 					PERF_IP_FLAG_CALL |
 					PERF_IP_FLAG_INTERRUPT;
@@ -2496,7 +2496,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 		if (prev_packet->flags == (PERF_IP_FLAG_BRANCH |
 					   PERF_IP_FLAG_RETURN |
 					   PERF_IP_FLAG_INTERRUPT) &&
-		    cs_etm__is_svc_instr(etmq, tidq, packet,
+		    cs_etm__is_svc_instr(etmq, tidc, packet,
 					 packet->start_addr)) {
 			prev_packet->flags = PERF_IP_FLAG_BRANCH |
 					     PERF_IP_FLAG_RETURN |
@@ -2572,13 +2572,13 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
 }
 
 static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
-					 struct cs_etm_traceid_ctxt *tidq)
+					 struct cs_etm_traceid_ctxt *tidc)
 {
 	int ret;
 
 	/* Process each packet in this chunk */
 	while (1) {
-		ret = cs_etm_decoder__get_packet(tidq, tidq->packet);
+		ret = cs_etm_decoder__get_packet(tidc, tidc->packet);
 		if (ret <= 0)
 			/*
 			 * Stop processing this chunk on
@@ -2593,18 +2593,18 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
 		 * prior to switch() statement to use address
 		 * information before packets swapping.
 		 */
-		ret = cs_etm__set_sample_flags(etmq, tidq);
+		ret = cs_etm__set_sample_flags(etmq, tidc);
 		if (ret < 0)
 			break;
 
-		switch (tidq->packet->sample_type) {
+		switch (tidc->packet->sample_type) {
 		case CS_ETM_RANGE:
 			/*
 			 * If the packet contains an instruction
 			 * range, generate instruction sequence
 			 * events.
 			 */
-			ret = cs_etm__sample(etmq, tidq);
+			ret = cs_etm__sample(etmq, tidc);
 			if (ret)
 				goto out;
 			break;
@@ -2615,12 +2615,12 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
 			 * tracing the kernel the context packet will be emitted
 			 * between two ranges.
 			 */
-			ret = cs_etm__context(etmq, tidq);
+			ret = cs_etm__context(etmq, tidc);
 			if (ret)
 				goto out;
 			break;
 		case CS_ETM_EXCEPTION:
-			ret = cs_etm__exception(etmq, tidq);
+			ret = cs_etm__exception(etmq, tidc);
 			if (ret)
 				goto out;
 			break;
@@ -2632,7 +2632,7 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
 			 * Discontinuity in trace, flush
 			 * previous branch stack
 			 */
-			cs_etm__flush(etmq, tidq);
+			cs_etm__flush(etmq, tidc);
 			break;
 		case CS_ETM_EMPTY:
 			/*
@@ -2657,7 +2657,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 	u8 trace_chan_id;
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 	u64 queue_time;
 
 	while (1) {
@@ -2684,8 +2684,8 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		auxtrace_heap__pop(&etm->heap);
 		etmq->on_heap = false;
 
-		tidq  = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-		if (!tidq) {
+		tidc  = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
+		if (!tidc) {
 			/*
 			 * No traceID queue has been allocated for this traceID,
 			 * which means something somewhere went very wrong.  No
@@ -2699,7 +2699,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		 * Packets associated with this timestamp, if any, are already in
 		 * the etmq's traceID queue, so process them.
 		 */
-		ret = cs_etm__process_traceid_ctxt(etmq, tidq);
+		ret = cs_etm__process_traceid_ctxt(etmq, tidc);
 		if (ret < 0)
 			goto out;
 
@@ -2741,7 +2741,7 @@ static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm)
 	int ret = 0;
 	unsigned int i;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_ctxt *tidq;
+	struct cs_etm_traceid_ctxt *tidc;
 
 	for (i = 0; i < etm->queues.nr_queues; i++) {
 		struct int_node *inode;
@@ -2754,8 +2754,8 @@ static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm)
 			int idx = (int)(intptr_t)inode->priv;
 
 			/* Flush any remaining branch stack entries */
-			tidq = etmq->traceid_ctxts[idx];
-			ret = cs_etm__end_block(etmq, tidq);
+			tidc = etmq->traceid_ctxts[idx];
+			ret = cs_etm__end_block(etmq, tidc);
 			if (ret)
 				return ret;
 		}

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 24/34] perf cs-etm: Share the thread ctxt between frontend and backend
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (22 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 23/34] perf cs-etm: Rename tidq variables to tidc James Clark
@ 2026-11-18 16:29 ` 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
                   ` (10 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

The decoder stops at every context packet and resumes only after the
frontend has processed it, so now we only need to keep track of a single
thread context.

The thread gets updated when the frontend processes a context packet.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  4 --
 tools/perf/util/cs-etm.c                        | 73 +++++++------------------
 tools/perf/util/cs-etm.h                        | 10 +---
 3 files changed, 22 insertions(+), 65 deletions(-)

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 7a1d50ca5949..06c57326ac80 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -468,10 +468,6 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
 		break;
 	}
 
-	if (cs_etm__etmq_update_decode_context(etmq, trace_chan_id,
-				elem->context.exception_level, tid))
-		return OCSD_RESP_FATAL_SYS_ERR;
-
 	ret = cs_etm_decoder__buffer_packet(etmq, tidc, elem,
 					    trace_chan_id, CS_ETM_CONTEXT);
 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index e2e84561c0c9..97ed12d03555 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -604,11 +604,9 @@ static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
 	queue = &etmq->etm->queues.queue_array[etmq->queue_nr];
 	tidc->trace_chan_id = trace_chan_id;
 	tidc->decode_el = ocsd_EL_unknown;
-	tidc->frontend_thread = machine__findnew_thread(&etm->session->machines.host, -1,
+	tidc->thread = machine__findnew_thread(&etm->session->machines.host, -1,
 					       queue->tid);
-	tidc->decode_thread = machine__findnew_thread(&etm->session->machines.host, -1,
-					       queue->tid);
-	if (!tidc->frontend_thread || !tidc->decode_thread)
+	if (!tidc->thread)
 		goto out;
 
 	tidc->packet = zalloc(sizeof(struct cs_etm_packet));
@@ -652,8 +650,7 @@ static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
 	zfree(&tidc->prev_packet);
 	zfree(&tidc->packet);
 out:
-	thread__zput(tidc->frontend_thread);
-	thread__zput(tidc->decode_thread);
+	thread__zput(tidc->thread);
 	return rc;
 }
 
@@ -908,8 +905,7 @@ static void cs_etm__free_traceid_ctxts(struct cs_etm_queue *etmq)
 
 		/* Free this decode context from the array */
 		tidc = etmq->traceid_ctxts[idx];
-		thread__zput(tidc->frontend_thread);
-		thread__zput(tidc->decode_thread);
+		thread__zput(tidc->thread);
 		zfree(&tidc->event_buf);
 		zfree(&tidc->callchain);
 		zfree(&tidc->last_branch);
@@ -1168,7 +1164,7 @@ static u32 cs_etm__frontend_mem_access(struct cs_etm_queue *etmq,
 				       u64 address, size_t size, u8 *buffer)
 {
 	return __cs_etm__mem_access(etmq, address, size, buffer, 0, packet->el,
-				    tidc->frontend_thread);
+				    tidc->thread);
 }
 
 static u32 cs_etm__decoder_mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
@@ -1183,7 +1179,7 @@ static u32 cs_etm__decoder_mem_access(struct cs_etm_queue *etmq, u8 trace_chan_i
 
 	return __cs_etm__mem_access(etmq, address, size, buffer,
 				    mem_space, tidc->decode_el,
-				    tidc->decode_thread);
+				    tidc->thread);
 }
 
 static struct cs_etm_queue *cs_etm__alloc_queue(void)
@@ -1472,30 +1468,6 @@ static int cs_etm__etmq_update_thread(struct cs_etm_queue *etmq,
 	return 0;
 }
 
-/*
- * Set the thread and EL of the decode context which is ahead in time of the
- * frontend context.
- */
-int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
-				       u8 trace_chan_id,
-				       ocsd_ex_level el, pid_t tid)
-{
-	struct cs_etm_traceid_ctxt *tidc;
-	int ret;
-
-	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-	if (!tidc)
-		return -EINVAL;
-
-	ret = cs_etm__etmq_update_thread(etmq, el, tid,
-					 &tidc->decode_thread);
-	if (ret)
-		return ret;
-
-	tidc->decode_el = el;
-	return 0;
-}
-
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq)
 {
 	return etmq->etm->has_timestamps;
@@ -1590,13 +1562,13 @@ static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
 		size = cs_etm__instr_size(etmq, tidc, tidc->prev_packet, from);
 
 		/* Enable callchain so thread stack entry can be allocated */
-		thread_stack__event(tidc->frontend_thread, tidc->prev_packet->cpu,
+		thread_stack__event(tidc->thread, tidc->prev_packet->cpu,
 				    tidc->prev_packet->flags, from, to, size,
 				    etmq->buffer->buffer_nr + 1,
 				    etmq->etm->use_callchain,
 				    tidc->br_stack_sz, 0);
 	} else {
-		thread_stack__set_trace_nr(tidc->frontend_thread,
+		thread_stack__set_trace_nr(tidc->thread,
 					   tidc->prev_packet->cpu,
 					   etmq->buffer->buffer_nr + 1);
 	}
@@ -1607,14 +1579,14 @@ static void cs_etm__sample_branch_stack(struct cs_etm_auxtrace *etm,
 					struct perf_sample *sample)
 {
 	if (etm->synth_opts.last_branch) {
-		thread_stack__br_sample(tidc->frontend_thread, tidc->packet->cpu,
+		thread_stack__br_sample(tidc->thread, tidc->packet->cpu,
 					tidc->last_branch, tidc->br_stack_sz);
 		sample->branch_stack = tidc->last_branch;
 	}
 
 	if (etm->synth_opts.callchain) {
 		if (tidc->kernel_start)
-			thread_stack__sample(tidc->frontend_thread,
+			thread_stack__sample(tidc->thread,
 					     tidc->packet->cpu,
 					     tidc->callchain,
 					     etm->synth_opts.callchain_sz + 1,
@@ -1652,8 +1624,8 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
 
 	sample.ip = addr;
-	sample.pid = thread__pid(tidc->frontend_thread);
-	sample.tid = thread__tid(tidc->frontend_thread);
+	sample.pid = thread__pid(tidc->thread);
+	sample.tid = thread__tid(tidc->thread);
 	sample.id = etmq->etm->instructions_id;
 	sample.stream_id = etmq->etm->instructions_id;
 	sample.period = period;
@@ -1748,8 +1720,8 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
 	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
 
 	sample.ip = ip;
-	sample.pid = thread__pid(tidc->frontend_thread);
-	sample.tid = thread__tid(tidc->frontend_thread);
+	sample.pid = thread__pid(tidc->thread);
+	sample.tid = thread__tid(tidc->thread);
 	sample.addr = cs_etm__first_executed_instr(tidc->packet);
 	sample.id = etmq->etm->branches_id;
 	sample.stream_id = etmq->etm->branches_id;
@@ -1994,16 +1966,17 @@ static int cs_etm__context(struct cs_etm_queue *etmq,
 	}
 
 	tidc->kernel_start = machine__kernel_start(machine);
+	tidc->decode_el = el;
 
 	ret = cs_etm__etmq_update_thread(etmq, el, tidc->packet->tid,
-					 &tidc->frontend_thread);
+					 &tidc->thread);
 	if (ret)
 		goto err;
 
 	return 0;
 
 err:
-	thread__zput(tidc->frontend_thread);
+	thread__zput(tidc->thread);
 	tidc->kernel_start = 0;
 	return ret;
 }
@@ -2052,7 +2025,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
 
 	/* Reset last branches after flush the trace */
 	if (etm->use_thread_stack)
-		thread_stack__flush(tidc->frontend_thread);
+		thread_stack__flush(tidc->thread);
 
 	return err;
 }
@@ -2164,15 +2137,11 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 			tidc = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
 			if (!tidc)
 				return -ENOMEM;
-			if (thread__tid(tidc->decode_thread) == etmq->buffer->tid)
+			if (thread__tid(tidc->thread) == etmq->buffer->tid)
 				continue;
 
-			thread__zput(tidc->frontend_thread);
-			thread__zput(tidc->decode_thread);
-			tidc->frontend_thread = machine__findnew_thread(
-				&etm->session->machines.host, -1,
-				etmq->buffer->tid);
-			tidc->decode_thread = machine__findnew_thread(
+			thread__zput(tidc->thread);
+			tidc->thread = machine__findnew_thread(
 				&etm->session->machines.host, -1,
 				etmq->buffer->tid);
 		}
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index 115def9c6abb..c41a7b5dd62f 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -260,21 +260,13 @@ struct cs_etm_traceid_ctxt {
 	u32 packet_count;
 	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
 
-	struct thread *decode_thread;
 	ocsd_ex_level decode_el;
 
-	/*
-	 * Samples use the EL saved in their source packet. A branch sample
-	 * cannot change thread, so the thread is kept in the frontend context.
-	 */
-	struct thread *frontend_thread;
+	struct thread *thread;
 };
 
 int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu);
 enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_etm_queue *etmq);
-int cs_etm__etmq_update_decode_context(struct cs_etm_queue *etmq,
-				       u8 trace_chan_id, ocsd_ex_level el,
-				       pid_t tid);
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
 void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
 					  u8 trace_chan_id);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 25/34] perf cs-etm: Consume each OpenCSD packet immediately
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (23 preceding siblings ...)
  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:29 ` 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
                   ` (9 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Decode and consume one packet during each heap iteration. Return the
context directly from the backend so that the packet can be processed.
If the packet was a timestamp, then there is no action other than
inserting that queue back into the heap at the new time.

Drain the decoder on the last trace byte of each buffer because it gets
reset across each buffer and that would drop the last bit of unprocessed
trace.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c |  39 ++--
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |   5 +-
 tools/perf/util/cs-etm.c                        | 225 +++++++++---------------
 tools/perf/util/cs-etm.h                        |   4 +-
 4 files changed, 105 insertions(+), 168 deletions(-)

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 06c57326ac80..dc17a2fd6c00 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -41,6 +41,7 @@ struct cs_etm_decoder {
 	cs_etm_mem_cb_type mem_access;
 	ocsd_datapath_resp_t prev_return;
 	const char *decoder_name;
+	struct cs_etm_traceid_ctxt *traceid_ctxt;
 };
 
 static u32
@@ -87,20 +88,6 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
 	return 0;
 }
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *tidc,
-			       struct cs_etm_packet *packet)
-{
-	if (!tidc || !packet)
-		return -EINVAL;
-
-	/* Nothing to do, might as well just return */
-	if (tidc->packet_count == 0)
-		return 0;
-
-	tidc->packet_count--;
-	return 1;
-}
-
 static int cs_etm_decoder__gen_etmv3_config(struct cs_etm_trace_params *params,
 					    ocsd_etmv3_cfg *config)
 {
@@ -255,9 +242,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	}
 
 	tidc->cs_timestamp = max(tidc->cs_timestamp, converted_timestamp);
-
-	/* Tell the front end which decode context needs attention */
-	cs_etm__etmq_set_traceid_ctxt_ready(etmq, trace_chan_id);
+	tidc->packet->sample_type = CS_ETM_TIMESTAMP;
 
 	/* Halt processing until we are being told to proceed */
 	return OCSD_RESP_WAIT;
@@ -301,9 +286,6 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	struct cs_etm_packet *packet;
 	int cpu;
 
-	if (tidc->packet_count)
-		return OCSD_RESP_FATAL_SYS_ERR;
-
 	if (cs_etm__get_cpu(etmq, trace_chan_id, &cpu) < 0)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
@@ -311,7 +293,6 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	if (!packet)
 		return OCSD_RESP_FATAL_SYS_ERR;
 
-	tidc->packet_count++;
 	packet->sample_type = sample_type;
 	packet->isa = cs_etm_decoder__get_isa(elem);
 	packet->cpu = cpu;
@@ -329,7 +310,6 @@ cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq,
 	packet->el = ocsd_EL_unknown;
 	packet->tid = -1;
 
-	cs_etm__etmq_set_traceid_ctxt_ready(etmq, trace_chan_id);
 	return OCSD_RESP_WAIT;
 }
 
@@ -522,6 +502,9 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 		resp = cs_etm_decoder__set_tid(etmq, tidc,
 					       elem, trace_chan_id);
 
+	if (OCSD_DATA_RESP_IS_WAIT(resp))
+		decoder->traceid_ctxt = tidc;
+
 	return resp;
 }
 
@@ -655,7 +638,8 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 
 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 				       u64 indx, const u8 *buf,
-				       size_t len, size_t *consumed)
+				       size_t len, size_t *consumed,
+				       struct cs_etm_traceid_ctxt **tidc)
 {
 	int ret = 0;
 	ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
@@ -663,7 +647,10 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 	size_t processed = 0;
 	u32 count;
 
-	while (processed < len) {
+	decoder->traceid_ctxt = NULL;
+
+	/* Drain buffered output even if the last input byte was consumed. */
+	while (processed < len || OCSD_DATA_RESP_IS_WAIT(prev_return)) {
 		if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
 			cur = ocsd_dt_process_data(decoder->dcd_tree,
 						   OCSD_OP_FLUSH,
@@ -693,6 +680,10 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 
 	decoder->prev_return = cur;
 	*consumed = processed;
+	if (tidc)
+		*tidc = decoder->traceid_ctxt;
+	if (OCSD_DATA_RESP_IS_FATAL(cur))
+		return -EINVAL;
 
 	return ret;
 }
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index f29f286f1d8b..afe9a466986a 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -89,7 +89,8 @@ enum cs_etm_decoder_operation {
 
 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 				       u64 indx, const u8 *buf,
-				       size_t len, size_t *consumed);
+				       size_t len, size_t *consumed,
+				       struct cs_etm_traceid_ctxt **tidc);
 
 struct cs_etm_decoder *
 cs_etm_decoder__new(int num_cpu,
@@ -102,8 +103,6 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
-int cs_etm_decoder__get_packet(struct cs_etm_traceid_ctxt *tidc,
-			       struct cs_etm_packet *packet);
 
 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
 const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 97ed12d03555..97c1dde1579b 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -81,7 +81,6 @@ struct cs_etm_queue {
 	struct cs_etm_decoder *decoder;
 	struct auxtrace_buffer *buffer;
 	unsigned int queue_nr;
-	u8 ready_chan_id;
 	enum cs_etm_format format;
 	u64 offset;
 	const unsigned char *buf;
@@ -104,7 +103,8 @@ struct cs_etm_queue {
 static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp);
 static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm);
 static int cs_etm__get_data_block(struct cs_etm_queue *etmq);
-static int cs_etm__decode_data_block(struct cs_etm_queue *etmq);
+static int cs_etm__decode_data_block(struct cs_etm_queue *etmq,
+				     struct cs_etm_traceid_ctxt **tidc);
 static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metadata);
 static u64 *get_cpu_data(struct cs_etm_auxtrace *etm, int cpu);
 static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata);
@@ -545,13 +545,6 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session,
 	return err;
 }
 
-void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
-					  u8 trace_chan_id)
-{
-	/* Tell the frontend which queue the last processed packet is in. */
-	etmq->ready_chan_id = trace_chan_id;
-}
-
 /*
  * Timestamp used to order sample generation between queues.
  *
@@ -565,23 +558,8 @@ void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
  * received, at which point sample generation is still un-ordered.
  */
 static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
-				      u8 *trace_chan_id)
+					struct cs_etm_traceid_ctxt *tidc)
 {
-	struct cs_etm_traceid_ctxt *tidc;
-
-	if (!etmq->ready_chan_id)
-		return 0;
-
-	if (trace_chan_id)
-		*trace_chan_id = etmq->ready_chan_id;
-
-	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, etmq->ready_chan_id);
-	if (!tidc)
-		return 0;
-
-	/* Acknowledge pending status */
-	etmq->ready_chan_id = 0;
-
 	/*
 	 * If there are no timestamps, use the TS from the AUX records to sort
 	 * in order of trace collection.
@@ -860,7 +838,7 @@ static void cs_etm__dump_event(struct cs_etm_queue *etmq,
 		ret = cs_etm_decoder__process_data_block(
 				etmq->decoder, buffer->offset,
 				&((u8 *)buffer->data)[buffer_used],
-				buffer->size - buffer_used, &consumed);
+				buffer->size - buffer_used, &consumed, NULL);
 		if (ret)
 			break;
 
@@ -1234,30 +1212,26 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
 	return 0;
 }
 
-static int cs_etm__add_to_heap(struct cs_etm_queue *etmq)
+static int cs_etm__add_to_heap(struct cs_etm_queue *etmq,
+			       struct cs_etm_traceid_ctxt *tidc)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
-	int ret;
 	unsigned int cs_queue_nr;
-	u8 trace_chan_id;
-	u64 cs_timestamp;
+	int ret;
 
-	ret = cs_etm__decode_data_block(etmq);
-	if (ret || !etmq->ready_chan_id)
-		return ret;
+	if (!tidc) {
+		struct int_node *inode = intlist__first(etmq->traceid_list);
 
-	cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
+		if (!inode)
+			return -EINVAL;
+		tidc = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
+	}
+	if (!tidc)
+		return -ENOMEM;
 
-	/*
-	 * We have a timestamp.  Add it to the min heap to reflect when
-	 * instructions conveyed by the range packets of this traceID queue
-	 * started to execute.
-	 *
-	 * Note that any packets decoded above are still in the traceID's packet
-	 * queue and will be processed later.
-	 */
-	cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, trace_chan_id);
-	ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
+	cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, tidc->trace_chan_id);
+	ret = auxtrace_heap__add(&etm->heap, cs_queue_nr,
+				 cs_etm__etmq_get_sort_timestamp(etmq, tidc));
 	if (!ret)
 		etmq->on_heap = true;
 	return ret;
@@ -1277,7 +1251,7 @@ static int cs_etm__push_queue(struct cs_etm_queue *etmq, u64 time)
 		if (!etmq->etm->has_virtual_ts && etmq->buffer->time > time)
 			return 0;
 
-		ret = cs_etm__add_to_heap(etmq);
+		ret = cs_etm__add_to_heap(etmq, NULL);
 		if (ret)
 			return ret;
 	}
@@ -2506,6 +2480,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 		}
 		break;
 	case CS_ETM_CONTEXT:
+	case CS_ETM_TIMESTAMP:
 	case CS_ETM_EMPTY:
 	default:
 		break;
@@ -2514,22 +2489,19 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 	return 0;
 }
 
-static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
+static int cs_etm__decode_data_block(struct cs_etm_queue *etmq,
+				     struct cs_etm_traceid_ctxt **tidc)
 {
 	int ret = 0;
 	size_t processed = 0;
 
-	/*
-	 * Packets are decoded and added to the decoder's packet queue
-	 * until the decoder packet processing callback has requested that
-	 * processing stops or there is nothing left in the buffer.
-	 */
+	/* Stop at a packet, a timestamp update, or the end of the buffer. */
 	ret = cs_etm_decoder__process_data_block(etmq->decoder,
 						 etmq->offset,
 						 &etmq->buf[etmq->buf_used],
 						 etmq->buf_len,
-						 &processed);
-	if (ret)
+						 &processed, tidc);
+	if (ret < 0)
 		goto out;
 
 	etmq->offset += processed;
@@ -2541,81 +2513,64 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
 }
 
 static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
-					 struct cs_etm_traceid_ctxt *tidc)
+				 struct cs_etm_traceid_ctxt *tidc)
 {
 	int ret;
 
-	/* Process each packet in this chunk */
-	while (1) {
-		ret = cs_etm_decoder__get_packet(tidc, tidc->packet);
-		if (ret <= 0)
-			/*
-			 * Stop processing this chunk on
-			 * end of data or error
-			 */
-			break;
+	/*
+	 * Since packet addresses are swapped in packet
+	 * handling within below switch() statements,
+	 * thus setting sample flags must be called
+	 * prior to switch() statement to use address
+	 * information before packets swapping.
+	 */
+	ret = cs_etm__set_sample_flags(etmq, tidc);
+	if (ret < 0)
+		return ret;
 
+	switch (tidc->packet->sample_type) {
+	case CS_ETM_RANGE:
 		/*
-		 * Since packet addresses are swapped in packet
-		 * handling within below switch() statements,
-		 * thus setting sample flags must be called
-		 * prior to switch() statement to use address
-		 * information before packets swapping.
+		 * If the packet contains an instruction
+		 * range, generate instruction sequence
+		 * events.
 		 */
-		ret = cs_etm__set_sample_flags(etmq, tidc);
-		if (ret < 0)
-			break;
-
-		switch (tidc->packet->sample_type) {
-		case CS_ETM_RANGE:
-			/*
-			 * If the packet contains an instruction
-			 * range, generate instruction sequence
-			 * events.
-			 */
-			ret = cs_etm__sample(etmq, tidc);
-			if (ret)
-				goto out;
-			break;
-		case CS_ETM_CONTEXT:
-			/*
-			 * Update context but don't swap packet. Keep the
-			 * previous one for branch source address info, if
-			 * tracing the kernel the context packet will be emitted
-			 * between two ranges.
-			 */
-			ret = cs_etm__context(etmq, tidc);
-			if (ret)
-				goto out;
-			break;
-		case CS_ETM_EXCEPTION:
-			ret = cs_etm__exception(etmq, tidc);
-			if (ret)
-				goto out;
-			break;
-		case CS_ETM_EXCEPTION_RET:
-			/* The return annotates the preceding instruction range. */
-			break;
-		case CS_ETM_DISCONTINUITY:
-			/*
-			 * Discontinuity in trace, flush
-			 * previous branch stack
-			 */
-			cs_etm__flush(etmq, tidc);
-			break;
-		case CS_ETM_EMPTY:
-			/*
-			 * Should not receive empty packet,
-			 * report error.
-			 */
-			pr_err("CS ETM Trace: empty packet\n");
-			return -EINVAL;
-		default:
-			break;
-		}
+		ret = cs_etm__sample(etmq, tidc);
+		break;
+	case CS_ETM_CONTEXT:
+		/*
+		 * Update context but don't swap packet. Keep the
+		 * previous one for branch source address info, if
+		 * tracing the kernel the context packet will be emitted
+		 * between two ranges.
+		 */
+		ret = cs_etm__context(etmq, tidc);
+		break;
+	case CS_ETM_EXCEPTION:
+		ret = cs_etm__exception(etmq, tidc);
+		break;
+	case CS_ETM_EXCEPTION_RET:
+		/* The return annotates the preceding instruction range. */
+		break;
+	case CS_ETM_DISCONTINUITY:
+		/*
+		 * Discontinuity in trace, flush
+		 * previous branch stack
+		 */
+		cs_etm__flush(etmq, tidc);
+		break;
+	case CS_ETM_EMPTY:
+		/*
+		 * Should not receive empty packet,
+		 * report error.
+		 */
+		pr_err("CS ETM Trace: empty packet\n");
+		return -EINVAL;
+	case CS_ETM_TIMESTAMP:
+	default:
+		break;
 	}
 
-out:
 	return ret;
 }
 
@@ -2626,7 +2581,7 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 	u8 trace_chan_id;
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_ctxt *tidc;
+	struct cs_etm_traceid_ctxt *tidc, *decoded;
 	u64 queue_time;
 
 	while (1) {
@@ -2664,19 +2619,16 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 			goto out;
 		}
 
-		/*
-		 * Packets associated with this timestamp, if any, are already in
-		 * the etmq's traceID queue, so process them.
-		 */
-		ret = cs_etm__process_traceid_ctxt(etmq, tidc);
+		ret = cs_etm__decode_data_block(etmq, &decoded);
 		if (ret < 0)
 			goto out;
-
-		/*
-		 * Packets for this timestamp have been processed, time to
-		 * move on to the next timestamp, fetching a new auxtrace_buffer
-		 * if need be.
-		 */
+		if (decoded) {
+			tidc = decoded;
+			ret = cs_etm__process_traceid_ctxt(etmq, tidc);
+			if (ret)
+				goto out;
+			goto add_to_heap;
+		}
 get_data_block:
 		ret = cs_etm__get_data_block(etmq);
 		if (ret < 0)
@@ -2689,12 +2641,9 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		if (!ret)
 			continue;
 
-		/*
-		 * Add the next timestamp or decoded packets to the min heap.
-		 * Packets will be processed and synthesized during the next call
-		 * to cs_etm__process_traceid_ctxt() for this queue/traceID.
-		 */
-		ret = cs_etm__add_to_heap(etmq);
+add_to_heap:
+		/* Schedule the next decode step after consuming the current packet. */
+		ret = cs_etm__add_to_heap(etmq, tidc);
 		if (ret)
 			goto out;
 		if (!etmq->on_heap)
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index c41a7b5dd62f..5d9cc31b08d0 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -159,6 +159,7 @@ enum cs_etm_sample_type {
 	CS_ETM_EXCEPTION,
 	CS_ETM_EXCEPTION_RET,
 	CS_ETM_CONTEXT,
+	CS_ETM_TIMESTAMP,
 };
 
 enum cs_etm_isa {
@@ -257,7 +258,6 @@ struct cs_etm_traceid_ctxt {
 	struct ip_callchain *callchain;
 	struct cs_etm_packet *prev_packet;
 	struct cs_etm_packet *packet;
-	u32 packet_count;
 	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
 
 	ocsd_ex_level decode_el;
@@ -268,8 +268,6 @@ struct cs_etm_traceid_ctxt {
 int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu);
 enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_etm_queue *etmq);
 bool cs_etm__has_timestamps(struct cs_etm_queue *etmq);
-void cs_etm__etmq_set_traceid_ctxt_ready(struct cs_etm_queue *etmq,
-					  u8 trace_chan_id);
 struct cs_etm_traceid_ctxt
 *cs_etm__etmq_get_traceid_ctxt(struct cs_etm_queue *etmq, u8 trace_chan_id);
 int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 26/34] perf cs-etm: Split base and packet decoder state
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (24 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 25/34] perf cs-etm: Consume each OpenCSD packet immediately James Clark
@ 2026-11-18 16:29 ` 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
                   ` (8 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Separate decoder struct into members that will be common with the
timestamp decoder and members that are specific to the packet decoder.
Then the timestamp decoder can use the shared base struct.

No functional changes intended.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 80 +++++++++++++------------
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 14 ++---
 tools/perf/util/cs-etm.c                        |  2 +-
 3 files changed, 50 insertions(+), 46 deletions(-)

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 dc17a2fd6c00..4f8da538d645 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -38,9 +38,13 @@ struct cs_etm_decoder {
 	void (*packet_printer)(const char *msg, void *data);
 	bool suppress_printing;
 	dcd_tree_handle_t dcd_tree;
-	cs_etm_mem_cb_type mem_access;
 	ocsd_datapath_resp_t prev_return;
 	const char *decoder_name;
+};
+
+struct cs_etm_packet_decoder {
+	struct cs_etm_decoder base;
+	cs_etm_mem_cb_type mem_access;
 	struct cs_etm_traceid_ctxt *traceid_ctxt;
 };
 
@@ -52,19 +56,19 @@ cs_etm_decoder__mem_access(const void *context,
 			   const u32 req_size,
 			   u8 *buffer)
 {
-	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
+	struct cs_etm_packet_decoder *decoder = (struct cs_etm_packet_decoder *) context;
 
-	return decoder->mem_access(decoder->data, trace_chan_id, address,
+	return decoder->mem_access(decoder->base.data, trace_chan_id, address,
 				   req_size, buffer, mem_space);
 }
 
-int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
+int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func)
 {
 	decoder->mem_access = cb_func;
 
-	if (ocsd_dt_add_callback_trcid_mem_acc(decoder->dcd_tree, start, end,
+	if (ocsd_dt_add_callback_trcid_mem_acc(decoder->base.dcd_tree, start, end,
 					       OCSD_MEM_SPACE_ANY,
 					       cs_etm_decoder__mem_access,
 					       decoder))
@@ -73,15 +77,15 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
 	return 0;
 }
 
-int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
+int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder)
 {
 	ocsd_datapath_resp_t dp_ret;
 
-	decoder->prev_return = OCSD_RESP_CONT;
-	decoder->suppress_printing = true;
-	dp_ret = ocsd_dt_process_data(decoder->dcd_tree, OCSD_OP_RESET,
+	decoder->base.prev_return = OCSD_RESP_CONT;
+	decoder->base.suppress_printing = true;
+	dp_ret = ocsd_dt_process_data(decoder->base.dcd_tree, OCSD_OP_RESET,
 				      0, 0, NULL, NULL);
-	decoder->suppress_printing = false;
+	decoder->base.suppress_printing = false;
 	if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
 		return -1;
 
@@ -469,8 +473,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 {
 	ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
 	ocsd_gen_trc_elem_t type;
-	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
-	struct cs_etm_queue *etmq = decoder->data;
+	struct cs_etm_packet_decoder *decoder = (struct cs_etm_packet_decoder *) context;
+	struct cs_etm_queue *etmq = decoder->base.data;
 	struct cs_etm_traceid_ctxt *tidc;
 
 	tidc = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
@@ -511,7 +515,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 static int
 cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 				   struct cs_etm_trace_params *t_params,
-				   struct cs_etm_decoder *decoder)
+				   struct cs_etm_packet_decoder *decoder)
 {
 	ocsd_etmv3_cfg config_etmv3;
 	ocsd_etmv4_cfg trace_config_etmv4;
@@ -524,7 +528,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 	case CS_ETM_PROTO_PTM:
 		csid = (t_params->etmv3.reg_idr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3);
-		decoder->decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
+		decoder->base.decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
 							OCSD_BUILTIN_DCD_ETMV3 :
 							OCSD_BUILTIN_DCD_PTM;
 		trace_config = &config_etmv3;
@@ -532,13 +536,13 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 	case CS_ETM_PROTO_ETMV4i:
 		csid = (t_params->etmv4.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4);
-		decoder->decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
+		decoder->base.decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
 		trace_config = &trace_config_etmv4;
 		break;
 	case CS_ETM_PROTO_ETE:
 		csid = (t_params->ete.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_ete_config(t_params, &trace_config_ete);
-		decoder->decoder_name = OCSD_BUILTIN_DCD_ETE;
+		decoder->base.decoder_name = OCSD_BUILTIN_DCD_ETE;
 		trace_config = &trace_config_ete;
 		break;
 	default:
@@ -551,25 +555,25 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 		decode_flags |= OCSD_OPFLG_N_UNCOND_DIR_BR_CHK | OCSD_OPFLG_CHK_RANGE_CONTINUE |
 				ETM4_OPFLG_PKTDEC_AA64_OPCODE_CHK;
 #endif
-		if (ocsd_dt_create_decoder(decoder->dcd_tree,
-					   decoder->decoder_name,
+		if (ocsd_dt_create_decoder(decoder->base.dcd_tree,
+					   decoder->base.decoder_name,
 					   decode_flags,
 					   trace_config, &csid))
 			return -1;
 
-		if (ocsd_dt_set_gen_elem_outfn(decoder->dcd_tree,
+		if (ocsd_dt_set_gen_elem_outfn(decoder->base.dcd_tree,
 					       cs_etm_decoder__gen_trace_elem_printer,
 					       decoder))
 			return -1;
 
 		return 0;
 	} else if (d_params->operation == CS_ETM_OPERATION_PRINT) {
-		if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name,
+		if (ocsd_dt_create_decoder(decoder->base.dcd_tree, decoder->base.decoder_name,
 					   OCSD_CREATE_FLG_PACKET_PROC,
 					   trace_config, &csid))
 			return -1;
 
-		if (ocsd_dt_set_pkt_protocol_printer(decoder->dcd_tree, csid, CS_PKT_MON))
+		if (ocsd_dt_set_pkt_protocol_printer(decoder->base.dcd_tree, csid, CS_PKT_MON))
 			return -1;
 
 		return 0;
@@ -578,11 +582,11 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 	return -1;
 }
 
-struct cs_etm_decoder *
+struct cs_etm_packet_decoder *
 cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 		    struct cs_etm_trace_params t_params[])
 {
-	struct cs_etm_decoder *decoder;
+	struct cs_etm_packet_decoder *decoder;
 	ocsd_dcd_tree_src_t format;
 	u32 flags;
 	int i, ret;
@@ -595,8 +599,8 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 	if (!decoder)
 		return NULL;
 
-	decoder->data = d_params->data;
-	decoder->prev_return = OCSD_RESP_CONT;
+	decoder->base.data = d_params->data;
+	decoder->base.prev_return = OCSD_RESP_CONT;
 	format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
 					 OCSD_TRC_SRC_SINGLE);
 	flags = 0;
@@ -611,13 +615,13 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 	flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
 
 	/* Create decode tree for the data source */
-	decoder->dcd_tree = ocsd_create_dcd_tree(format, flags);
+	decoder->base.dcd_tree = ocsd_create_dcd_tree(format, flags);
 
-	if (decoder->dcd_tree == 0)
+	if (decoder->base.dcd_tree == 0)
 		goto err_free_decoder;
 
 	/* init library print logging support */
-	ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder);
+	ret = cs_etm_decoder__init_def_logger_printing(d_params, &decoder->base);
 	if (ret != 0)
 		goto err_free_decoder;
 
@@ -636,14 +640,14 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 	return NULL;
 }
 
-int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
+int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
 				       u64 indx, const u8 *buf,
 				       size_t len, size_t *consumed,
 				       struct cs_etm_traceid_ctxt **tidc)
 {
 	int ret = 0;
 	ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
-	ocsd_datapath_resp_t prev_return = decoder->prev_return;
+	ocsd_datapath_resp_t prev_return = decoder->base.prev_return;
 	size_t processed = 0;
 	u32 count;
 
@@ -652,14 +656,14 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 	/* Drain buffered output even if the last input byte was consumed. */
 	while (processed < len || OCSD_DATA_RESP_IS_WAIT(prev_return)) {
 		if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
-			cur = ocsd_dt_process_data(decoder->dcd_tree,
+			cur = ocsd_dt_process_data(decoder->base.dcd_tree,
 						   OCSD_OP_FLUSH,
 						   0,
 						   0,
 						   NULL,
 						   NULL);
 		} else if (OCSD_DATA_RESP_IS_CONT(prev_return)) {
-			cur = ocsd_dt_process_data(decoder->dcd_tree,
+			cur = ocsd_dt_process_data(decoder->base.dcd_tree,
 						   OCSD_OP_DATA,
 						   indx + processed,
 						   len - processed,
@@ -678,7 +682,7 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 		prev_return = cur;
 	}
 
-	decoder->prev_return = cur;
+	decoder->base.prev_return = cur;
 	*consumed = processed;
 	if (tidc)
 		*tidc = decoder->traceid_ctxt;
@@ -688,17 +692,17 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
 	return ret;
 }
 
-void cs_etm_decoder__zfree(struct cs_etm_decoder **decoder)
+void cs_etm_decoder__zfree(struct cs_etm_packet_decoder **decoder)
 {
 	if (!(*decoder))
 		return;
 
-	ocsd_destroy_dcd_tree((*decoder)->dcd_tree);
-	(*decoder)->dcd_tree = NULL;
+	ocsd_destroy_dcd_tree((*decoder)->base.dcd_tree);
+	(*decoder)->base.dcd_tree = NULL;
 	zfree(decoder);
 }
 
-const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder)
+const char *cs_etm_decoder__get_name(struct cs_etm_packet_decoder *decoder)
 {
-	return decoder->decoder_name;
+	return decoder->base.decoder_name;
 }
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index afe9a466986a..376feffd6558 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -14,7 +14,7 @@
 #include <opencsd/ocsd_if_types.h>
 #include <stdio.h>
 
-struct cs_etm_decoder;
+struct cs_etm_packet_decoder;
 struct cs_etm_packet;
 struct cs_etm_traceid_ctxt;
 
@@ -87,24 +87,24 @@ enum cs_etm_decoder_operation {
 	CS_ETM_OPERATION_MAX,
 };
 
-int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
+int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
 				       u64 indx, const u8 *buf,
 				       size_t len, size_t *consumed,
 				       struct cs_etm_traceid_ctxt **tidc);
 
-struct cs_etm_decoder *
+struct cs_etm_packet_decoder *
 cs_etm_decoder__new(int num_cpu,
 		    struct cs_etm_decoder_params *d_params,
 		    struct cs_etm_trace_params t_params[]);
 
-void cs_etm_decoder__zfree(struct cs_etm_decoder **decoder);
+void cs_etm_decoder__zfree(struct cs_etm_packet_decoder **decoder);
 
-int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
+int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
 
-int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
-const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder);
+int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder);
+const char *cs_etm_decoder__get_name(struct cs_etm_packet_decoder *decoder);
 
 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 97c1dde1579b..6bd833d9ed81 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -78,7 +78,7 @@ enum cs_etm_format {
 
 struct cs_etm_queue {
 	struct cs_etm_auxtrace *etm;
-	struct cs_etm_decoder *decoder;
+	struct cs_etm_packet_decoder *decoder;
 	struct auxtrace_buffer *buffer;
 	unsigned int queue_nr;
 	enum cs_etm_format format;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 27/34] perf cs-etm: Add packet-only timestamp decoder ops
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (25 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 26/34] perf cs-etm: Split base and packet decoder state James Clark
@ 2026-11-18 16:29 ` 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
                   ` (7 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Add OpenCSD packet-processing callbacks that find the next timestamp
without fetching instructions or producing instruction ranges. Bound the
search with CS_ETM_TIMESTAMP_SEARCH_MAX packets.

Keep the timestamp search state in cs_etm_timestamp_decoder, separate
from the full packet decoder. Each source's callback context identifies
its protocol. The frontend continues to use the existing full decoder.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 79 +++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

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 4f8da538d645..685d8d75912f 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -33,6 +33,14 @@
 #define CS_PKT_MON	0
 #endif
 
+/*
+ * Limit when searching forwards for a timestamp.
+ *
+ * Timestamps follow context packets (which appear on trace on) after only
+ * 1 or 2 atoms. Allow up to 1024 packets across all interleaved trace IDs.
+ */
+#define CS_ETM_TIMESTAMP_SEARCH_MAX 1024
+
 struct cs_etm_decoder {
 	void *data;
 	void (*packet_printer)(const char *msg, void *data);
@@ -48,6 +56,19 @@ struct cs_etm_packet_decoder {
 	struct cs_etm_traceid_ctxt *traceid_ctxt;
 };
 
+struct cs_etm_timestamp_source {
+	struct cs_etm_timestamp_decoder *decoder;
+	int protocol;
+};
+
+struct cs_etm_timestamp_decoder {
+	struct cs_etm_decoder base;
+	u64 timestamp; /* Raw trace timestamp. */
+	u64 timestamp_search_index;
+	u32 timestamp_packet_count;
+	struct cs_etm_timestamp_source sources[];
+};
+
 static u32
 cs_etm_decoder__mem_access(const void *context,
 			   const ocsd_vaddr_t address,
@@ -512,6 +533,64 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	return resp;
 }
 
+static ocsd_datapath_resp_t __maybe_unused
+cs_etm_decoder__timestamp(const void *context, const ocsd_datapath_op_t op,
+			  const ocsd_trc_index_t indx, const void *packet)
+{
+	const struct cs_etm_timestamp_source *source = context;
+	struct cs_etm_timestamp_decoder *decoder = source->decoder;
+	bool timestamp = false;
+
+	if (op != OCSD_OP_DATA)
+		return OCSD_RESP_CONT;
+	if (indx < decoder->timestamp_search_index)
+		return OCSD_RESP_CONT;
+
+	decoder->timestamp_packet_count++;
+	switch (source->protocol) {
+	case CS_ETM_PROTO_ETMV3: {
+		const ocsd_etmv3_pkt *pkt = packet;
+
+		if (pkt->type == ETM3_PKT_TIMESTAMP) {
+			decoder->timestamp = pkt->timestamp;
+			timestamp = true;
+		}
+		break;
+	}
+	case CS_ETM_PROTO_PTM: {
+		const ocsd_ptm_pkt *pkt = packet;
+
+		if (pkt->type == PTM_PKT_TIMESTAMP) {
+			decoder->timestamp = pkt->timestamp;
+			timestamp = true;
+		}
+		break;
+	}
+	case CS_ETM_PROTO_ETMV4i:
+	case CS_ETM_PROTO_ETE: {
+		const ocsd_etmv4_i_pkt *pkt = packet;
+
+		if (pkt->type == ETM4_PKT_I_TIMESTAMP) {
+			decoder->timestamp = pkt->ts.timestamp;
+			timestamp = true;
+		}
+		break;
+	}
+	default:
+		return OCSD_RESP_FATAL_INVALID_PARAM;
+	}
+
+	/* Report where the timestamp was found */
+	if (timestamp)
+		decoder->timestamp_search_index = indx;
+
+	if (timestamp ||
+	    decoder->timestamp_packet_count >= CS_ETM_TIMESTAMP_SEARCH_MAX)
+		return OCSD_RESP_WAIT;
+
+	return OCSD_RESP_CONT;
+}
+
 static int
 cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
 				   struct cs_etm_trace_params *t_params,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 28/34] perf cs-etm: Create timestamp decoders
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (26 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 27/34] perf cs-etm: Add packet-only timestamp decoder ops James Clark
@ 2026-11-18 16:29 ` 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
                   ` (6 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Create a packet-only decode tree for each queue when ordered timestamp
decoding is enabled.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 253 +++++++++++++++++-------
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |   2 +-
 tools/perf/util/cs-etm.c                        |   8 +-
 3 files changed, 188 insertions(+), 75 deletions(-)

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 685d8d75912f..56de6c76de68 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -10,6 +10,7 @@
 #include <linux/coresight-pmu.h>
 #include <linux/err.h>
 #include <linux/list.h>
+#include <linux/overflow.h>
 #include <linux/zalloc.h>
 #include <stdlib.h>
 #include <opencsd/c_api/opencsd_c_api.h>
@@ -54,6 +55,7 @@ struct cs_etm_packet_decoder {
 	struct cs_etm_decoder base;
 	cs_etm_mem_cb_type mem_access;
 	struct cs_etm_traceid_ctxt *traceid_ctxt;
+	struct cs_etm_timestamp_decoder *timestamp_decoder;
 };
 
 struct cs_etm_timestamp_source {
@@ -65,6 +67,7 @@ struct cs_etm_timestamp_decoder {
 	struct cs_etm_decoder base;
 	u64 timestamp; /* Raw trace timestamp. */
 	u64 timestamp_search_index;
+	u64 timestamp_decode_index;
 	u32 timestamp_packet_count;
 	struct cs_etm_timestamp_source sources[];
 };
@@ -98,17 +101,37 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 	return 0;
 }
 
-int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder)
+static int cs_etm_decoder__reset_core(struct cs_etm_decoder *core)
 {
 	ocsd_datapath_resp_t dp_ret;
 
-	decoder->base.prev_return = OCSD_RESP_CONT;
-	decoder->base.suppress_printing = true;
-	dp_ret = ocsd_dt_process_data(decoder->base.dcd_tree, OCSD_OP_RESET,
+	core->prev_return = OCSD_RESP_CONT;
+	core->suppress_printing = true;
+	dp_ret = ocsd_dt_process_data(core->dcd_tree, OCSD_OP_RESET,
 				      0, 0, NULL, NULL);
-	decoder->base.suppress_printing = false;
-	if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
-		return -1;
+	core->suppress_printing = false;
+	return OCSD_DATA_RESP_IS_FATAL(dp_ret) ? -1 : 0;
+}
+
+static int cs_etm_timestamp_decoder__reset(struct cs_etm_timestamp_decoder *decoder,
+					   u64 index)
+{
+	decoder->timestamp_search_index = 0;
+	decoder->timestamp_decode_index = index;
+	decoder->timestamp_packet_count = 0;
+	return cs_etm_decoder__reset_core(&decoder->base);
+}
+
+int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder, u64 index)
+{
+	int ret;
+
+	ret = cs_etm_decoder__reset_core(&decoder->base);
+	if (ret)
+		return ret;
+
+	if (decoder->timestamp_decoder)
+		return cs_etm_timestamp_decoder__reset(decoder->timestamp_decoder, index);
 
 	return 0;
 }
@@ -234,6 +257,42 @@ cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params,
 	return 0;
 }
 
+static int cs_etm_decoder__init_core(struct cs_etm_decoder *decoder,
+				     struct cs_etm_decoder_params *d_params)
+{
+	ocsd_dcd_tree_src_t format;
+	u32 flags;
+	int ret;
+
+	decoder->data = d_params->data;
+	decoder->prev_return = OCSD_RESP_CONT;
+	format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
+					 OCSD_TRC_SRC_SINGLE);
+	flags = 0;
+	flags |= (d_params->fsyncs ? OCSD_DFRMTR_HAS_FSYNCS : 0);
+	flags |= (d_params->hsyncs ? OCSD_DFRMTR_HAS_HSYNCS : 0);
+	flags |= (d_params->frame_aligned ? OCSD_DFRMTR_FRAME_MEM_ALIGN : 0);
+
+	/*
+	 * Drivers may add barrier frames when used with perf, set up to
+	 * handle this. Barriers const of FSYNC packet repeated 4 times.
+	 */
+	flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
+
+	/* Create decode tree for the data source */
+	decoder->dcd_tree = ocsd_create_dcd_tree(format, flags);
+
+	if (decoder->dcd_tree == 0)
+		return -1;
+
+	/* init library print logging support */
+	ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder);
+	if (ret != 0)
+		return ret;
+
+	return 0;
+}
+
 static ocsd_datapath_resp_t
 cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 				  const ocsd_generic_trace_elem *elem,
@@ -533,7 +592,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 	return resp;
 }
 
-static ocsd_datapath_resp_t __maybe_unused
+static ocsd_datapath_resp_t
 cs_etm_decoder__timestamp(const void *context, const ocsd_datapath_op_t op,
 			  const ocsd_trc_index_t indx, const void *packet)
 {
@@ -592,73 +651,149 @@ cs_etm_decoder__timestamp(const void *context, const ocsd_datapath_op_t op,
 }
 
 static int
-cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
+cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder *decoder,
 				   struct cs_etm_trace_params *t_params,
-				   struct cs_etm_packet_decoder *decoder)
+				   int flags, u8 *csid)
 {
 	ocsd_etmv3_cfg config_etmv3;
 	ocsd_etmv4_cfg trace_config_etmv4;
 	ocsd_ete_cfg trace_config_ete;
 	void *trace_config;
-	u8 csid;
 
 	switch (t_params->protocol) {
 	case CS_ETM_PROTO_ETMV3:
 	case CS_ETM_PROTO_PTM:
-		csid = (t_params->etmv3.reg_idr & CORESIGHT_TRACE_ID_VAL_MASK);
+		*csid = (t_params->etmv3.reg_idr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3);
-		decoder->base.decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
+		decoder->decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
 							OCSD_BUILTIN_DCD_ETMV3 :
 							OCSD_BUILTIN_DCD_PTM;
 		trace_config = &config_etmv3;
 		break;
 	case CS_ETM_PROTO_ETMV4i:
-		csid = (t_params->etmv4.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
+		*csid = (t_params->etmv4.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4);
-		decoder->base.decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
+		decoder->decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
 		trace_config = &trace_config_etmv4;
 		break;
 	case CS_ETM_PROTO_ETE:
-		csid = (t_params->ete.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
+		*csid = (t_params->ete.reg_traceidr & CORESIGHT_TRACE_ID_VAL_MASK);
 		cs_etm_decoder__gen_ete_config(t_params, &trace_config_ete);
-		decoder->base.decoder_name = OCSD_BUILTIN_DCD_ETE;
+		decoder->decoder_name = OCSD_BUILTIN_DCD_ETE;
 		trace_config = &trace_config_ete;
 		break;
 	default:
 		return -1;
 	}
 
+	return ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name,
+				      flags, trace_config, csid);
+}
+
+static void cs_etm_decoder__free_core(struct cs_etm_decoder *core)
+{
+	ocsd_destroy_dcd_tree(core->dcd_tree);
+	core->dcd_tree = NULL;
+}
+
+static void cs_etm_timestamp_decoder__zfree(struct cs_etm_timestamp_decoder **decoder)
+{
+	if (!*decoder)
+		return;
+
+	cs_etm_decoder__free_core(&(*decoder)->base);
+	zfree(decoder);
+}
+
+static int
+cs_etm_decoder__create_timestamp_decoders(int decoders, struct cs_etm_decoder_params *d_params,
+					  struct cs_etm_trace_params t_params[],
+					  struct cs_etm_timestamp_decoder *decoder)
+{
+	int i;
+
+	if (cs_etm_decoder__init_core(&decoder->base, d_params))
+		return -1;
+
+	for (i = 0; i < decoders; i++) {
+		struct cs_etm_timestamp_source *source = &decoder->sources[i];
+		u8 csid;
+
+		source->decoder = decoder;
+		source->protocol = t_params[i].protocol;
+		if (cs_etm_decoder__create_etm_decoder(&decoder->base, &t_params[i],
+						       OCSD_CREATE_FLG_PACKET_PROC,
+						       &csid))
+			return -1;
+		if (ocsd_dt_attach_packet_callback(decoder->base.dcd_tree, csid,
+						   OCSD_C_API_CB_PKT_SINK,
+						   (void *)cs_etm_decoder__timestamp,
+						   source))
+			return -1;
+	}
+
+	return 0;
+}
+
+static int
+cs_etm_decoder__create_packet_decoders(int decoders, struct cs_etm_decoder_params *d_params,
+				       struct cs_etm_trace_params t_params[],
+				       struct cs_etm_packet_decoder *decoder)
+{
+	int decode_flags = OCSD_CREATE_FLG_PACKET_PROC;
+	int i;
+
+	if (cs_etm_decoder__init_core(&decoder->base, d_params))
+		return -1;
+
 	if (d_params->operation == CS_ETM_OPERATION_DECODE) {
-		int decode_flags = OCSD_CREATE_FLG_FULL_DECODER;
+		decode_flags = OCSD_CREATE_FLG_FULL_DECODER;
 #ifdef OCSD_OPFLG_N_UNCOND_DIR_BR_CHK
 		decode_flags |= OCSD_OPFLG_N_UNCOND_DIR_BR_CHK | OCSD_OPFLG_CHK_RANGE_CONTINUE |
 				ETM4_OPFLG_PKTDEC_AA64_OPCODE_CHK;
 #endif
-		if (ocsd_dt_create_decoder(decoder->base.dcd_tree,
-					   decoder->base.decoder_name,
-					   decode_flags,
-					   trace_config, &csid))
-			return -1;
+	} else if (d_params->operation != CS_ETM_OPERATION_PRINT) {
+		return -1;
+	}
 
-		if (ocsd_dt_set_gen_elem_outfn(decoder->base.dcd_tree,
-					       cs_etm_decoder__gen_trace_elem_printer,
-					       decoder))
-			return -1;
+	for (i = 0; i < decoders; i++) {
+		u8 csid;
 
-		return 0;
-	} else if (d_params->operation == CS_ETM_OPERATION_PRINT) {
-		if (ocsd_dt_create_decoder(decoder->base.dcd_tree, decoder->base.decoder_name,
-					   OCSD_CREATE_FLG_PACKET_PROC,
-					   trace_config, &csid))
+		if (cs_etm_decoder__create_etm_decoder(&decoder->base, &t_params[i],
+						       decode_flags, &csid))
 			return -1;
-
-		if (ocsd_dt_set_pkt_protocol_printer(decoder->base.dcd_tree, csid, CS_PKT_MON))
+		if (d_params->operation == CS_ETM_OPERATION_PRINT &&
+		    ocsd_dt_set_pkt_protocol_printer(decoder->base.dcd_tree, csid, CS_PKT_MON))
 			return -1;
-
-		return 0;
 	}
 
-	return -1;
+	if (d_params->operation == CS_ETM_OPERATION_DECODE &&
+	    ocsd_dt_set_gen_elem_outfn(decoder->base.dcd_tree,
+				       cs_etm_decoder__gen_trace_elem_printer,
+				       decoder))
+		return -1;
+
+	return 0;
+}
+
+static struct cs_etm_timestamp_decoder *
+cs_etm_timestamp_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
+			      struct cs_etm_trace_params t_params[])
+{
+	struct cs_etm_timestamp_decoder *decoder;
+
+	decoder = zalloc(struct_size(decoder, sources, decoders));
+	if (!decoder)
+		return NULL;
+
+	if (cs_etm_decoder__create_timestamp_decoders(decoders, d_params, t_params, decoder))
+		goto err_free_decoder;
+
+	return decoder;
+
+err_free_decoder:
+	cs_etm_timestamp_decoder__zfree(&decoder);
+	return NULL;
 }
 
 struct cs_etm_packet_decoder *
@@ -666,49 +801,22 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 		    struct cs_etm_trace_params t_params[])
 {
 	struct cs_etm_packet_decoder *decoder;
-	ocsd_dcd_tree_src_t format;
-	u32 flags;
-	int i, ret;
 
 	if ((!t_params) || (!d_params))
 		return NULL;
 
 	decoder = zalloc(sizeof(*decoder));
-
 	if (!decoder)
 		return NULL;
 
-	decoder->base.data = d_params->data;
-	decoder->base.prev_return = OCSD_RESP_CONT;
-	format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
-					 OCSD_TRC_SRC_SINGLE);
-	flags = 0;
-	flags |= (d_params->fsyncs ? OCSD_DFRMTR_HAS_FSYNCS : 0);
-	flags |= (d_params->hsyncs ? OCSD_DFRMTR_HAS_HSYNCS : 0);
-	flags |= (d_params->frame_aligned ? OCSD_DFRMTR_FRAME_MEM_ALIGN : 0);
-
-	/*
-	 * Drivers may add barrier frames when used with perf, set up to
-	 * handle this. Barriers const of FSYNC packet repeated 4 times.
-	 */
-	flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
-
-	/* Create decode tree for the data source */
-	decoder->base.dcd_tree = ocsd_create_dcd_tree(format, flags);
-
-	if (decoder->base.dcd_tree == 0)
+	if (cs_etm_decoder__create_packet_decoders(decoders, d_params, t_params, decoder))
 		goto err_free_decoder;
 
-	/* init library print logging support */
-	ret = cs_etm_decoder__init_def_logger_printing(d_params, &decoder->base);
-	if (ret != 0)
-		goto err_free_decoder;
-
-	for (i = 0; i < decoders; i++) {
-		ret = cs_etm_decoder__create_etm_decoder(d_params,
-							 &t_params[i],
-							 decoder);
-		if (ret != 0)
+	if (d_params->operation == CS_ETM_OPERATION_DECODE &&
+	    cs_etm__has_timestamps(decoder->base.data)) {
+		decoder->timestamp_decoder = cs_etm_timestamp_decoder__new(decoders, d_params,
+									   t_params);
+		if (!decoder->timestamp_decoder)
 			goto err_free_decoder;
 	}
 
@@ -776,8 +884,9 @@ void cs_etm_decoder__zfree(struct cs_etm_packet_decoder **decoder)
 	if (!(*decoder))
 		return;
 
-	ocsd_destroy_dcd_tree((*decoder)->base.dcd_tree);
-	(*decoder)->base.dcd_tree = NULL;
+	cs_etm_timestamp_decoder__zfree(&(*decoder)->timestamp_decoder);
+
+	cs_etm_decoder__free_core(&(*decoder)->base);
 	zfree(decoder);
 }
 
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 376feffd6558..125696520625 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -104,7 +104,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 				      cs_etm_mem_cb_type cb_func);
 
 
-int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder);
+int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder, u64 index);
 const char *cs_etm_decoder__get_name(struct cs_etm_packet_decoder *decoder);
 
 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 6bd833d9ed81..d275d3701165 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -845,7 +845,7 @@ static void cs_etm__dump_event(struct cs_etm_queue *etmq,
 		buffer_used += consumed;
 	} while (buffer_used < buffer->size);
 
-	cs_etm_decoder__reset(etmq->decoder);
+	cs_etm_decoder__reset(etmq->decoder, etmq->offset);
 }
 
 static int cs_etm__flush_events(struct perf_session *session,
@@ -877,6 +877,9 @@ static void cs_etm__free_traceid_ctxts(struct cs_etm_queue *etmq)
 	struct cs_etm_traceid_ctxt *tidc;
 	struct intlist *traceid_ctxts_list = etmq->traceid_ctxts_list;
 
+	if (!traceid_ctxts_list)
+		return;
+
 	intlist__for_each_entry_safe(inode, tmp, traceid_ctxts_list) {
 		priv = (uintptr_t)inode->priv;
 		idx = priv;
@@ -2085,7 +2088,7 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 	 * We cannot assume consecutive blocks in the data file
 	 * are contiguous, reset the decoder to force re-sync.
 	 */
-	ret = cs_etm_decoder__reset(etmq->decoder);
+	ret = cs_etm_decoder__reset(etmq->decoder, etmq->offset);
 	if (ret)
 		return ret;
 
@@ -3251,6 +3254,7 @@ static int cs_etm__create_queue_decoders(struct cs_etm_queue *etmq)
 
 out_free_decoder:
 	cs_etm_decoder__zfree(&etmq->decoder);
+	cs_etm__free_traceid_ctxts(etmq);
 out_free:
 	zfree(&t_params);
 	return -EINVAL;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (27 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 28/34] perf cs-etm: Create timestamp decoders James Clark
@ 2026-11-18 16:29 ` James Clark
  2026-11-18 17:01   ` sashiko-bot
  2026-11-18 16:29 ` [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs James Clark
                   ` (5 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Use the packet-only timestamp decoder to search ahead for the next
timestamp on discontinuities, so the time is known before the full
decoder needs instruction mappings.

Use the next timestamp from any trace ID rather than searching only
within one stream which would be significantly more complicated.
Searching and re-ordering is most useful with TRBE and virtual
timestamps where there is only one trace ID stream anyway. Timestamps are
also unlikely to be significantly out of order between streams.

Reorder the packets in the backend so timestamps precede context packets
and discontinuities. The frontend can then flush samples using the old
timestamp before processing the next packet, and not attempt to look up
the thread from the context packet before the Perf event for it was
reached.

Drop the trace ID from the heap and only store the queue number. We
never used the heap to re-order between individual trace ID streams
anyway, and now that the decoder returns last decoded context directly,
storing the ID in the heap does nothing.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 163 +++++++++++++++++--
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |   9 +-
 tools/perf/util/cs-etm.c                        | 200 +++++++++---------------
 tools/perf/util/cs-etm.h                        |   2 +-
 4 files changed, 227 insertions(+), 147 deletions(-)

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 56de6c76de68..b7ed7847f209 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -13,12 +13,12 @@
 #include <linux/overflow.h>
 #include <linux/zalloc.h>
 #include <stdlib.h>
+#include <string.h>
 #include <opencsd/c_api/opencsd_c_api.h>
 
 #include "cs-etm.h"
 #include "cs-etm-decoder.h"
 #include "debug.h"
-#include "intlist.h"
 
 /* use raw logging */
 #ifdef CS_DEBUG_RAW
@@ -42,6 +42,12 @@
  */
 #define CS_ETM_TIMESTAMP_SEARCH_MAX 1024
 
+struct cs_etm_buffer {
+	u64 index;
+	const u8 *data;
+	size_t len;
+};
+
 struct cs_etm_decoder {
 	void *data;
 	void (*packet_printer)(const char *msg, void *data);
@@ -55,7 +61,12 @@ struct cs_etm_packet_decoder {
 	struct cs_etm_decoder base;
 	cs_etm_mem_cb_type mem_access;
 	struct cs_etm_traceid_ctxt *traceid_ctxt;
+	u64 packet_index;
+	/* Next output packet, returned before resuming OpenCSD. */
+	struct cs_etm_traceid_ctxt *pending;
+	struct cs_etm_packet pending_packet;
 	struct cs_etm_timestamp_decoder *timestamp_decoder;
+	u64 timestamp; /* Last delivered queue timestamp. */
 };
 
 struct cs_etm_timestamp_source {
@@ -126,6 +137,10 @@ int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder, u64 index)
 {
 	int ret;
 
+	decoder->traceid_ctxt = NULL;
+	decoder->packet_index = 0;
+	decoder->pending = NULL;
+	memset(&decoder->pending_packet, 0, sizeof(decoder->pending_packet));
 	ret = cs_etm_decoder__reset_core(&decoder->base);
 	if (ret)
 		return ret;
@@ -294,11 +309,12 @@ static int cs_etm_decoder__init_core(struct cs_etm_decoder *decoder,
 }
 
 static ocsd_datapath_resp_t
-cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
+cs_etm_decoder__do_hard_timestamp(struct cs_etm_packet_decoder *decoder,
 				  const ocsd_generic_trace_elem *elem,
 				  const uint8_t trace_chan_id,
 				  const ocsd_trc_index_t indx)
 {
+	struct cs_etm_queue *etmq = decoder->base.data;
 	struct cs_etm_traceid_ctxt *tidc;
 	u64 converted_timestamp;
 
@@ -325,7 +341,7 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 		return OCSD_RESP_CONT;
 	}
 
-	tidc->cs_timestamp = max(tidc->cs_timestamp, converted_timestamp);
+	decoder->timestamp = max(decoder->timestamp, converted_timestamp);
 	tidc->packet->sample_type = CS_ETM_TIMESTAMP;
 
 	/* Halt processing until we are being told to proceed */
@@ -579,15 +595,17 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
 		resp = cs_etm_decoder__buffer_exception_ret(etmq, tidc,
 							    elem, trace_chan_id);
 	else if (type == OCSD_GEN_TRC_ELEM_TIMESTAMP)
-		resp = cs_etm_decoder__do_hard_timestamp(etmq, elem,
+		resp = cs_etm_decoder__do_hard_timestamp(decoder, elem,
 							 trace_chan_id,
 							 indx);
 	else if (type == OCSD_GEN_TRC_ELEM_PE_CONTEXT)
 		resp = cs_etm_decoder__set_tid(etmq, tidc,
 					       elem, trace_chan_id);
 
-	if (OCSD_DATA_RESP_IS_WAIT(resp))
+	if (OCSD_DATA_RESP_IS_WAIT(resp)) {
 		decoder->traceid_ctxt = tidc;
+		decoder->packet_index = indx;
+	}
 
 	return resp;
 }
@@ -827,30 +845,27 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
 	return NULL;
 }
 
-int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
-				       u64 indx, const u8 *buf,
-				       size_t len, size_t *consumed,
-				       struct cs_etm_traceid_ctxt **tidc)
+static int cs_etm_decoder__process_data(struct cs_etm_decoder *decoder,
+					u64 indx, const u8 *buf,
+					size_t len, size_t *consumed)
 {
 	int ret = 0;
 	ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
-	ocsd_datapath_resp_t prev_return = decoder->base.prev_return;
+	ocsd_datapath_resp_t prev_return = decoder->prev_return;
 	size_t processed = 0;
 	u32 count;
 
-	decoder->traceid_ctxt = NULL;
-
 	/* Drain buffered output even if the last input byte was consumed. */
 	while (processed < len || OCSD_DATA_RESP_IS_WAIT(prev_return)) {
 		if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
-			cur = ocsd_dt_process_data(decoder->base.dcd_tree,
+			cur = ocsd_dt_process_data(decoder->dcd_tree,
 						   OCSD_OP_FLUSH,
 						   0,
 						   0,
 						   NULL,
 						   NULL);
 		} else if (OCSD_DATA_RESP_IS_CONT(prev_return)) {
-			cur = ocsd_dt_process_data(decoder->base.dcd_tree,
+			cur = ocsd_dt_process_data(decoder->dcd_tree,
 						   OCSD_OP_DATA,
 						   indx + processed,
 						   len - processed,
@@ -869,16 +884,130 @@ int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
 		prev_return = cur;
 	}
 
-	decoder->base.prev_return = cur;
+	decoder->prev_return = cur;
 	*consumed = processed;
-	if (tidc)
-		*tidc = decoder->traceid_ctxt;
 	if (OCSD_DATA_RESP_IS_FATAL(cur))
 		return -EINVAL;
 
 	return ret;
 }
 
+static int cs_etm_decoder__process_timestamp(struct cs_etm_timestamp_decoder *timestamp_decoder,
+					     const struct cs_etm_buffer *buffer,
+					     u64 index)
+{
+	u64 decode_index = timestamp_decoder->timestamp_decode_index;
+	size_t offset, processed;
+	int ret;
+
+	if (decode_index < buffer->index ||
+	    decode_index - buffer->index > buffer->len)
+		return -EINVAL;
+
+	offset = decode_index - buffer->index;
+	timestamp_decoder->timestamp_search_index = index;
+	timestamp_decoder->timestamp_packet_count = 0;
+	timestamp_decoder->timestamp = 0;
+	ret = cs_etm_decoder__process_data(&timestamp_decoder->base, decode_index,
+					   &buffer->data[offset], buffer->len - offset,
+					   &processed);
+	timestamp_decoder->timestamp_decode_index += processed;
+	return ret;
+}
+
+static int cs_etm_decoder__search_timestamp(struct cs_etm_packet_decoder *decoder,
+					    const struct cs_etm_buffer *buffer,
+					    u64 index, u64 *timestamp)
+{
+	struct cs_etm_timestamp_decoder *timestamp_decoder = decoder->timestamp_decoder;
+	int ret;
+
+	*timestamp = 0;
+	if (index < buffer->index || index - buffer->index >= buffer->len)
+		return 0;
+
+	/* Reuse a timestamp still ahead of this packet instead of skipping it. */
+	if (!timestamp_decoder->timestamp ||
+	    timestamp_decoder->timestamp_search_index <= index) {
+		ret = cs_etm_decoder__process_timestamp(timestamp_decoder, buffer, index);
+		if (ret)
+			return ret;
+	}
+
+	if (timestamp_decoder->timestamp)
+		*timestamp = cs_etm__convert_sample_time(decoder->base.data,
+							 timestamp_decoder->timestamp);
+	return 0;
+}
+
+/*
+ * Re-order timestamps and context and discontinuity packets so that the
+ * frontend can process them at the correct time.
+ */
+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;
+}
+
+int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
+				       u64 indx, const u8 *buf,
+				       size_t len, size_t offset, size_t *consumed,
+				       struct cs_etm_traceid_ctxt **tidc)
+{
+	const struct cs_etm_buffer buffer = { .index = indx, .data = buf, .len = len };
+	int ret;
+
+	*consumed = 0;
+	if (decoder->pending) {
+		*tidc = decoder->pending;
+		*(*tidc)->packet = decoder->pending_packet;
+		decoder->timestamp = decoder->pending_packet.timestamp;
+		decoder->pending = NULL;
+		ret = 0;
+		goto out;
+	}
+
+	decoder->traceid_ctxt = NULL;
+	ret = cs_etm_decoder__process_data(&decoder->base, indx + offset, buf + offset,
+					   len - offset, consumed);
+	if (tidc)
+		*tidc = decoder->traceid_ctxt;
+	if (!ret && decoder->timestamp_decoder && tidc && *tidc)
+		ret = cs_etm_decoder__reorder_packet(decoder, &buffer, *tidc);
+out:
+	if (!ret && tidc && *tidc)
+		(*tidc)->packet->timestamp = decoder->timestamp;
+	return ret;
+}
+
 void cs_etm_decoder__zfree(struct cs_etm_packet_decoder **decoder)
 {
 	if (!(*decoder))
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 125696520625..67592b93778e 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -87,9 +87,14 @@ enum cs_etm_decoder_operation {
 	CS_ETM_OPERATION_MAX,
 };
 
+/*
+ * Feed the complete AUX buffer, starting full decoding at offset. The timestamp
+ * decoder maintains its own position in the same buffer. Output may be
+ * returned without consuming input, including at the buffer end.
+ */
 int cs_etm_decoder__process_data_block(struct cs_etm_packet_decoder *decoder,
 				       u64 indx, const u8 *buf,
-				       size_t len, size_t *consumed,
+				       size_t len, size_t offset, size_t *consumed,
 				       struct cs_etm_traceid_ctxt **tidc);
 
 struct cs_etm_packet_decoder *
@@ -103,7 +108,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
-
+/* Reset all decoders to the start index of a new AUX buffer. */
 int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder, u64 index);
 const char *cs_etm_decoder__get_name(struct cs_etm_packet_decoder *decoder);
 
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index d275d3701165..5a704dfeebd3 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -79,6 +79,8 @@ enum cs_etm_format {
 struct cs_etm_queue {
 	struct cs_etm_auxtrace *etm;
 	struct cs_etm_packet_decoder *decoder;
+	/* current packet/context */
+	struct cs_etm_traceid_ctxt *tidc;
 	struct auxtrace_buffer *buffer;
 	unsigned int queue_nr;
 	enum cs_etm_format format;
@@ -103,8 +105,8 @@ struct cs_etm_queue {
 static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp);
 static int cs_etm__flush_queues(struct cs_etm_auxtrace *etm);
 static int cs_etm__get_data_block(struct cs_etm_queue *etmq);
-static int cs_etm__decode_data_block(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_ctxt **tidc);
+static int cs_etm__decode_packet(struct cs_etm_queue *etmq,
+				 struct cs_etm_traceid_ctxt **tidc);
 static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metadata);
 static u64 *get_cpu_data(struct cs_etm_auxtrace *etm, int cpu);
 static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata);
@@ -112,16 +114,6 @@ static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata);
 /* PTMs ETMIDR [11:8] set to b0011 */
 #define ETMIDR_PTM_VERSION 0x00000300
 
-/*
- * A struct auxtrace_heap_item only has a queue_nr and a timestamp to
- * work with.  One option is to modify to auxtrace_heap_XYZ() API or simply
- * encode the etm queue number as the upper 16 bit and the channel as
- * the lower 16 bit.
- */
-#define TO_CS_QUEUE_NR(queue_nr, trace_chan_id)	\
-		      (queue_nr << 16 | trace_chan_id)
-#define TO_QUEUE_NR(cs_queue_nr) (cs_queue_nr >> 16)
-#define TO_TRACE_CHAN_ID(cs_queue_nr) (cs_queue_nr & 0x0000ffff)
 #define SINK_UNSET ((u32) -1)
 #define MAX_TIMESTAMP (~0ULL)
 
@@ -545,32 +537,6 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session,
 	return err;
 }
 
-/*
- * Timestamp used to order sample generation between queues.
- *
- * This can either be a virtual or non-virtual CoreSight timestamp value, or the
- * kernel time from the AUX record if there are no timestamps. The only
- * requirement is that it's the same timebase between queues so comparisons
- * work, the absolute value isn't important.
- *
- * This is not the same as the timestamp assigned to synthesized samples
- * (cs_etm__resolve_sample_time()) and may be zero before a timestamp is
- * received, at which point sample generation is still un-ordered.
- */
-static u64 cs_etm__etmq_get_sort_timestamp(struct cs_etm_queue *etmq,
-					struct cs_etm_traceid_ctxt *tidc)
-{
-	/*
-	 * If there are no timestamps, use the TS from the AUX records to sort
-	 * in order of trace collection.
-	 */
-	if (!etmq->etm->has_timestamps)
-		return etmq->buffer->time;
-
-	/* Use the last trace timestamp, or zero if none has been found yet. */
-	return tidc->cs_timestamp;
-}
-
 static int cs_etm__init_traceid_ctxt(struct cs_etm_queue *etmq,
 				      struct cs_etm_traceid_ctxt *tidc,
 				      u8 trace_chan_id)
@@ -836,9 +802,8 @@ static void cs_etm__dump_event(struct cs_etm_queue *etmq,
 		size_t consumed;
 
 		ret = cs_etm_decoder__process_data_block(
-				etmq->decoder, buffer->offset,
-				&((u8 *)buffer->data)[buffer_used],
-				buffer->size - buffer_used, &consumed, NULL);
+				etmq->decoder, buffer->offset, buffer->data,
+				buffer->size, buffer_used, &consumed, NULL);
 		if (ret)
 			break;
 
@@ -1215,68 +1180,74 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
 	return 0;
 }
 
-static int cs_etm__add_to_heap(struct cs_etm_queue *etmq,
-			       struct cs_etm_traceid_ctxt *tidc)
+static int cs_etm__add_to_heap(struct cs_etm_queue *etmq, u64 timestamp)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
-	unsigned int cs_queue_nr;
 	int ret;
 
-	if (!tidc) {
-		struct int_node *inode = intlist__first(etmq->traceid_list);
-
-		if (!inode)
-			return -EINVAL;
-		tidc = cs_etm__etmq_get_traceid_ctxt(etmq, inode->i);
-	}
-	if (!tidc)
-		return -ENOMEM;
+	/*
+	 * Use collection time only when trace timestamps are unavailable or
+	 * disabled. Otherwise keep the last trace timestamp, or zero until
+	 * one is found.
+	 */
+	if (!etm->has_timestamps)
+		timestamp = etmq->buffer->time;
 
-	cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, tidc->trace_chan_id);
-	ret = auxtrace_heap__add(&etm->heap, cs_queue_nr,
-				 cs_etm__etmq_get_sort_timestamp(etmq, tidc));
+	ret = auxtrace_heap__add(&etm->heap, etmq->queue_nr, timestamp);
 	if (!ret)
 		etmq->on_heap = true;
 	return ret;
 }
 
-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;
 }
 
-static int cs_etm__push_heap(struct cs_etm_auxtrace *etm,
-			     struct perf_sample *sample)
+static int cs_etm__insert_heap(struct cs_etm_auxtrace *etm,
+			       struct perf_sample *sample)
 {
-	return cs_etm__push_queue(cs_etm__get_queue(etm, sample->cpu),
-				  sample->time);
+	return cs_etm__insert_heap_queue(cs_etm__get_queue(etm, sample->cpu),
+					 sample->time);
 }
 
-static int cs_etm__push_heap_all(struct cs_etm_auxtrace *etm)
+static int cs_etm__insert_heap_all(struct cs_etm_auxtrace *etm)
 {
 	unsigned int i;
 	int ret;
 
 	for (i = 0; i < etm->queues.nr_queues; i++) {
-		ret = cs_etm__push_queue(etm->queues.queue_array[i].priv,
-					 MAX_TIMESTAMP);
+		ret = cs_etm__insert_heap_queue(etm->queues.queue_array[i].priv,
+						MAX_TIMESTAMP);
 		if (ret)
 			return ret;
 	}
@@ -1493,12 +1464,12 @@ u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp)
 }
 
 static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
-					       struct cs_etm_traceid_ctxt *tidc)
+					       struct cs_etm_packet *packet)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
 
 	if (etm->has_virtual_ts)
-		return tidc->cs_timestamp;
+		return packet->timestamp;
 
 	/*
 	 * Timestamps were disabled or no virtual TS. All samples are assigned
@@ -1598,7 +1569,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 	event->sample.header.size = sizeof(struct perf_event_header);
 
 	/* Set time field based on etm auxtrace config. */
-	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
+	sample.time = cs_etm__resolve_sample_time(etmq, packet);
 
 	sample.ip = addr;
 	sample.pid = thread__pid(tidc->thread);
@@ -1694,7 +1665,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
 	event->sample.header.size = sizeof(struct perf_event_header);
 
 	/* Set time field based on etm auxtrace config. */
-	sample.time = cs_etm__resolve_sample_time(etmq, tidc);
+	sample.time = cs_etm__resolve_sample_time(etmq, tidc->packet);
 
 	sample.ip = ip;
 	sample.pid = thread__pid(tidc->thread);
@@ -2086,7 +2057,7 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
 
 	/*
 	 * We cannot assume consecutive blocks in the data file
-	 * are contiguous, reset the decoder to force re-sync.
+	 * are contiguous, reset the decoders to force re-sync.
 	 */
 	ret = cs_etm_decoder__reset(etmq->decoder, etmq->offset);
 	if (ret)
@@ -2492,17 +2463,20 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq,
 	return 0;
 }
 
-static int cs_etm__decode_data_block(struct cs_etm_queue *etmq,
-				     struct cs_etm_traceid_ctxt **tidc)
+/*
+ * Decode the next packet and put its context in tidc.
+ */
+static int cs_etm__decode_packet(struct cs_etm_queue *etmq,
+				 struct cs_etm_traceid_ctxt **tidc)
 {
 	int ret = 0;
 	size_t processed = 0;
+	size_t len = etmq->buf_used + etmq->buf_len;
+	u64 buffer_index = etmq->offset - etmq->buf_used;
 
-	/* Stop at a packet, a timestamp update, or the end of the buffer. */
 	ret = cs_etm_decoder__process_data_block(etmq->decoder,
-						 etmq->offset,
-						 &etmq->buf[etmq->buf_used],
-						 etmq->buf_len,
+						 buffer_index, etmq->buf, len,
+						 etmq->buf_used,
 						 &processed, tidc);
 	if (ret < 0)
 		goto out;
@@ -2520,6 +2494,10 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
 {
 	int ret;
 
+	/* A timestamp update only reschedules decoding; it consumes no trace. */
+	if (tidc->packet->sample_type == CS_ETM_TIMESTAMP)
+		return 0;
+
 	/*
 	 * Since packet addresses are swapped in packet
 	 * handling within below switch() statements,
@@ -2560,7 +2538,7 @@ static int cs_etm__process_traceid_ctxt(struct cs_etm_queue *etmq,
 		 * Discontinuity in trace, flush
 		 * previous branch stack
 		 */
-		cs_etm__flush(etmq, tidc);
+		ret = cs_etm__flush(etmq, tidc);
 		break;
 	case CS_ETM_EMPTY:
 		/*
@@ -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)
 {
 	int ret = 0;
-	unsigned int cs_queue_nr, queue_nr;
-	u8 trace_chan_id;
+	unsigned int queue_nr;
+	u64 cs_timestamp;
 	struct auxtrace_queue *queue;
 	struct cs_etm_queue *etmq;
-	struct cs_etm_traceid_ctxt *tidc, *decoded;
+	struct cs_etm_traceid_ctxt *tidc;
 	u64 queue_time;
 
 	while (1) {
@@ -2592,14 +2570,13 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 			break;
 
 		/* 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;
@@ -2611,46 +2588,15 @@ static int cs_etm__pop_heap(struct cs_etm_auxtrace *etm, u64 timestamp)
 		auxtrace_heap__pop(&etm->heap);
 		etmq->on_heap = false;
 
-		tidc  = cs_etm__etmq_get_traceid_ctxt(etmq, trace_chan_id);
-		if (!tidc) {
-			/*
-			 * No traceID queue has been allocated for this traceID,
-			 * which means something somewhere went very wrong.  No
-			 * other choice than simply exit.
-			 */
-			ret = -EINVAL;
-			goto out;
-		}
-
-		ret = cs_etm__decode_data_block(etmq, &decoded);
-		if (ret < 0)
-			goto out;
-		if (decoded) {
-			tidc = decoded;
-			ret = cs_etm__process_traceid_ctxt(etmq, tidc);
-			if (ret)
-				goto out;
-			goto add_to_heap;
-		}
-get_data_block:
-		ret = cs_etm__get_data_block(etmq);
-		if (ret < 0)
+		tidc = etmq->tidc;
+		etmq->tidc = NULL;
+		ret = cs_etm__process_traceid_ctxt(etmq, tidc);
+		if (ret)
 			goto out;
 
-		/*
-		 * No more auxtrace_buffers to process in this etmq, simply
-		 * move on to another entry in the auxtrace_heap.
-		 */
-		if (!ret)
-			continue;
-
-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;
@@ -2767,7 +2713,7 @@ static int cs_etm__process_event(struct perf_session *session,
 		 * Perf events.
 		 */
 		if (has_sample_time && etm->has_virtual_ts) {
-			ret = cs_etm__push_heap(etm, sample);
+			ret = cs_etm__insert_heap(etm, sample);
 			if (ret)
 				return ret;
 		}
@@ -2791,7 +2737,7 @@ static int cs_etm__process_event(struct perf_session *session,
 		 * point because it's emitted at the same time.
 		 */
 		if (has_sample_time && etm->has_virtual_ts) {
-			ret = cs_etm__push_heap(etm, sample);
+			ret = cs_etm__insert_heap(etm, sample);
 			if (ret)
 				return ret;
 		}
@@ -2806,9 +2752,9 @@ static int cs_etm__process_event(struct perf_session *session,
 		 * would be too late.
 		 */
 		if (etm->has_timestamps && !etm->has_virtual_ts)
-			ret = cs_etm__push_heap_all(etm);
+			ret = cs_etm__insert_heap_all(etm);
 		else if (has_sample_time)
-			ret = cs_etm__push_heap(etm, sample);
+			ret = cs_etm__insert_heap(etm, sample);
 
 		if (ret)
 			return ret;
diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h
index 5d9cc31b08d0..ff947bb847df 100644
--- a/tools/perf/util/cs-etm.h
+++ b/tools/perf/util/cs-etm.h
@@ -172,6 +172,7 @@ enum cs_etm_isa {
 struct cs_etm_queue;
 
 struct cs_etm_packet {
+	u64 timestamp; /* Timestamp, in ns when has_virtual_ts == true */
 	enum cs_etm_sample_type sample_type;
 	enum cs_etm_isa isa;
 	/* For exceptions: source PC, or CS_ETM_INVAL_ADDR. */
@@ -258,7 +259,6 @@ struct cs_etm_traceid_ctxt {
 	struct ip_callchain *callchain;
 	struct cs_etm_packet *prev_packet;
 	struct cs_etm_packet *packet;
-	u64 cs_timestamp; /* Timestamp, in ns when has_virtual_ts == true */
 
 	ocsd_ex_level decode_el;
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (28 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead James Clark
@ 2026-11-18 16:29 ` 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
                   ` (4 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

OpenCSD caches instruction bytes, but with a JIT runtime a new jitdump
mmap can replace code at a cached address without changing the context,
so subsequent decoding can use stale instructions.

Invalidate the packet decoder's caches on MMAPs when virtual timestamps
are enabled. Without virtual timestamps there's no proper ordering so
this wouldn't increase accuracy. This is unlikely to cause any
significant increase in overhead because MMAPs should be relatively rare
and OpenCSD invalidates the cache on context switches anyway.

The API has no explicit cache invalidation operation, so disable and
re-enable caching to discard its contents.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 42 +++++++++++++++++++++++++
 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h |  2 ++
 tools/perf/util/cs-etm.c                        | 36 +++++++++++++++++++--
 3 files changed, 78 insertions(+), 2 deletions(-)

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 b7ed7847f209..d6c2ae0b6a04 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -9,6 +9,7 @@
 #include <asm/bug.h>
 #include <linux/coresight-pmu.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/overflow.h>
 #include <linux/zalloc.h>
@@ -112,6 +113,47 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 	return 0;
 }
 
+#if OCSD_VER_NUM >= 0x010503
+static int cs_etm_decoder__cache_param(const char *name, int default_value,
+				       long min_value, long max_value)
+{
+	const char *env = getenv(name);
+	long value = env ? strtol(env, NULL, 0) : 0;
+
+	if (value <= 0)
+		return default_value;
+
+	return clamp(value, min_value, max_value);
+}
+
+int cs_etm_decoder__invalidate_cache(struct cs_etm_packet_decoder *decoder)
+{
+	int page_size, nr_pages;
+
+	if (getenv("OPENCSD_MEMACC_CACHE_OFF"))
+		return 0;
+
+	/* Match OpenCSD's defaults and environment overrides. */
+	page_size = cs_etm_decoder__cache_param("OPENCSD_MEMACC_CACHE_PAGE_SIZE",
+						2048, 64, 16384);
+	nr_pages = cs_etm_decoder__cache_param("OPENCSD_MEMACC_CACHE_PAGE_NUM",
+					       16, 4, 256);
+
+	/* The C API has no invalidate operation; disabling destroys the cache. */
+	if (ocsd_dt_set_mem_acc_cacheing(decoder->base.dcd_tree, 0, 0, 0) ||
+	    ocsd_dt_set_mem_acc_cacheing(decoder->base.dcd_tree, 1, page_size, nr_pages))
+		return -1;
+
+	return 0;
+}
+
+#else
+int cs_etm_decoder__invalidate_cache(struct cs_etm_packet_decoder *decoder __maybe_unused)
+{
+	return 0;
+}
+#endif
+
 static int cs_etm_decoder__reset_core(struct cs_etm_decoder *core)
 {
 	ocsd_datapath_resp_t dp_ret;
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index 67592b93778e..6e56ac57b311 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
@@ -108,6 +108,8 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_packet_decoder *decoder,
 				      u64 start, u64 end,
 				      cs_etm_mem_cb_type cb_func);
 
+int cs_etm_decoder__invalidate_cache(struct cs_etm_packet_decoder *decoder);
+
 /* Reset all decoders to the start index of a new AUX buffer. */
 int cs_etm_decoder__reset(struct cs_etm_packet_decoder *decoder, u64 index);
 const char *cs_etm_decoder__get_name(struct cs_etm_packet_decoder *decoder);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 5a704dfeebd3..a747c5873bc8 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2682,6 +2682,25 @@ static int cs_etm__process_switch(struct cs_etm_auxtrace *etm,
 	return cs_etm__associate_tid(etm, sample->pid, sample->tid);
 }
 
+static int cs_etm__invalidate_cache(struct cs_etm_auxtrace *etm)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < etm->queues.nr_queues; i++) {
+		struct cs_etm_queue *etmq = etm->queues.queue_array[i].priv;
+
+		if (!etmq || !etmq->decoder)
+			continue;
+
+		ret = cs_etm_decoder__invalidate_cache(etmq->decoder);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int cs_etm__process_event(struct perf_session *session,
 				 union perf_event *event,
 				 struct perf_sample *sample,
@@ -2764,8 +2783,21 @@ static int cs_etm__process_event(struct perf_session *session,
 		break;
 	}
 
-	if (has_sample_time)
-		return cs_etm__pop_heap(etm, sample->time);
+	if (has_sample_time) {
+		ret = cs_etm__pop_heap(etm, sample->time);
+		if (ret)
+			return ret;
+	}
+
+	/*
+	 * Invalidate after popping and decoding because Perf only updates the
+	 * map after returning from this function. That way decoding doesn't
+	 * pull the old map back into the cache again.
+	 */
+	if (etm->has_virtual_ts &&
+	    (event->header.type == PERF_RECORD_MMAP ||
+	     event->header.type == PERF_RECORD_MMAP2))
+		return cs_etm__invalidate_cache(etm);
 
 	return 0;
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 31/34] perf test cs-etm: Add a Java JIT source-line test
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (29 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs James Clark
@ 2026-11-18 16:29 ` 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
                   ` (3 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Record a deterministic Java workload using the JVMTI agent and check
that the decoded source lines match the expected sequence.

Alternate fresh class loaders and request garbage collection to
encourage address re-use so that we can test if trace timestamps match
up to jitdump events.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/Makefile.perf                          |  4 +-
 tools/perf/tests/shell/coresight/java-jit.sh      | 65 ++++++++++++++++++
 tools/perf/tests/shell/coresight/lib/PerfJit.java | 82 +++++++++++++++++++++++
 3 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index b74b534e1153..53c10e8e4556 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -992,7 +992,9 @@ install-tests: all install-gtk
 		$(INSTALL) tests/shell/base_report/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
 		$(INSTALL) tests/shell/base_report/*.txt '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight' ; \
-		$(INSTALL) tests/shell/coresight/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight'
+		$(INSTALL) tests/shell/coresight/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight'; \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight/lib'; \
+		$(INSTALL) tests/shell/coresight/lib/*.java -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight/lib'
 
 install-bin: install-tools install-tests
 
diff --git a/tools/perf/tests/shell/coresight/java-jit.sh b/tools/perf/tests/shell/coresight/java-jit.sh
new file mode 100755
index 000000000000..cb6099efa899
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/java-jit.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# CoreSight Java JIT source lines and code address reuse (exclusive)
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+set -o pipefail
+
+script_dir=$(dirname "$0")
+
+# Requires a HotSpot JDK (11+) and libperf-jvmti with line number support.
+perf list pmu | grep cs_etm > /dev/null || exit 2
+# Require TRBE so that the trace always has virtual timestamps.
+if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then
+	echo "No TRBE sinks, skipping"
+	exit 2
+fi
+command -v java > /dev/null || exit 2
+command -v javac > /dev/null || exit 2
+command -v timeout > /dev/null || exit 2
+for lib in "${LIBJVMTI:-}" \
+	"$(dirname "$(readlink -f "$(type -P perf)")")/libperf-jvmti.so" \
+	"${PREFIX:-/usr}/lib64/libperf-jvmti.so" "${PREFIX:-/usr}/lib/libperf-jvmti.so"; do
+	if [ -f "$lib" ]; then
+		LIBJVMTI=$(readlink -f "$lib")
+		break
+	fi
+done
+[ -f "${LIBJVMTI:-}" ] || { echo "SKIP: missing libperf-jvmti.so"; exit 2; }
+
+tmpdir=$(mktemp -d /tmp/__perf_test.coresight_java_jit.XXXXX)
+trap '[ "$?" -eq 0 ] && rm -rf "$tmpdir" || echo "Java JIT test files retained in $tmpdir"' EXIT
+trap 'exit 1' TERM INT
+
+javac -g --release 11 -d "$tmpdir" "$script_dir/lib/PerfJit.java"
+mkfifo "$tmpdir/ctl" "$tmpdir/ack"
+export JITDUMPDIR="$tmpdir" JITDUMP_USE_ARCH_TIMESTAMP=1
+
+# Compile only run(), and collect trace only while it executes.
+# A small code cache and class unloading encourage address reuse.
+timeout 60s perf record \
+	-o "$tmpdir/data" -e cs_etm//u -D -1 -m ,8M \
+	--control "fifo:$tmpdir/ctl,$tmpdir/ack" -- \
+	java -Xbatch -XX:-TieredCompilation -XX:CompileThreshold=100 \
+	-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints \
+	'-XX:CompileCommand=compileonly,PerfJit$*::run' \
+	-XX:ReservedCodeCacheSize=4m -XX:+UseSerialGC \
+	-agentpath:"$LIBJVMTI" -cp "$tmpdir" PerfJit "$tmpdir/ctl" "$tmpdir/ack"
+
+perf inject --jit -b \
+	-i "$tmpdir/data" -o "$tmpdir/injected.data"
+
+perf script \
+	-i "$tmpdir/injected.data" --itrace=i1i -F ip,srcline \
+	--symbols 'PerfJit$First.run(),PerfJit$Second.run()' > "$tmpdir/script"
+
+# The workload runs eight pairs of First.run() and Second.run().
+awk '/\/\/ TRACE$/ { lines = lines "PerfJit.java:" NR "\n" }
+     END { for (i = 0; i < 8; i++) printf "%s", lines }' \
+	"$script_dir/lib/PerfJit.java" > "$tmpdir/expected"
+
+# Ignore entry/return lines and retain the order of the marked Java lines.
+sed -n 's/^.*PerfJit\.java:/PerfJit.java:/p' "$tmpdir/script" | uniq > "$tmpdir/lines"
+grep -Fxf "$tmpdir/expected" "$tmpdir/lines" > "$tmpdir/actual" || true
+diff -u "$tmpdir/expected" "$tmpdir/actual"
+echo "Java JIT source lines match the expected sequence"
diff --git a/tools/perf/tests/shell/coresight/lib/PerfJit.java b/tools/perf/tests/shell/coresight/lib/PerfJit.java
new file mode 100644
index 000000000000..30b22e952bd4
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/lib/PerfJit.java
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.util.Arrays;
+
+public class PerfJit {
+    public static class First implements Runnable {
+        public static volatile int value;
+        public void run() {
+            value += 1; // TRACE
+            value += 2; // TRACE
+            value += 3; // TRACE
+            value += 0; // Give the last checked line a DWARF end address.
+        }
+    }
+
+    public static class Second implements Runnable {
+        public static volatile int value;
+        public void run() {
+            value += 4; // TRACE
+            value += 5; // TRACE
+            value += 6; // TRACE
+            value += 0; // Give the last checked line a DWARF end address.
+        }
+    }
+
+    static FileWriter control;
+    static FileInputStream ack;
+
+    static void command(String command) throws Exception {
+        if (control != null) {
+            control.write(command + "\n");
+            control.flush();
+            // perf writes sizeof("ack\n"), including the trailing NUL.
+            byte[] reply = new byte[5];
+            if (ack.readNBytes(reply, 0, reply.length) != reply.length ||
+                !Arrays.equals(reply, new byte[] {'a', 'c', 'k', '\n', 0}))
+                throw new Exception("Missing perf control ack");
+        }
+    }
+
+    static void phase(String name, int repeats) throws Exception {
+        byte[] code;
+        try (InputStream in = PerfJit.class.getResourceAsStream("PerfJit$" + name + ".class")) {
+            code = in.readAllBytes();
+        }
+        // A fresh loader allows this class and its compiled code to be reclaimed.
+        Class<?> block = new ClassLoader(null) {
+            Class<?> load() { return defineClass(null, code, 0, code.length); }
+        }.load();
+        Runnable work = (Runnable) block.getConstructor().newInstance();
+        for (int i = 0; i < 20000; i++)
+            work.run();
+        command("enable");
+        for (int i = 0; i < repeats; i++)
+            work.run();
+        command("disable");
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (args.length >= 2) {
+            control = new FileWriter(args[0]);
+            ack = new FileInputStream(args[1]);
+        }
+        int rounds = args.length >= 3 ? Integer.parseInt(args[2]) : 8;
+        int repeats = args.length >= 4 ? Integer.parseInt(args[3]) : 1;
+        // Warm up the FIFO path before enabling trace for the first method.
+        command("disable");
+        for (int i = 0; i < rounds * 2; i++) {
+            phase(i % 2 == 0 ? "First" : "Second", repeats);
+            for (int gc = 0; gc < 3; gc++) {
+                System.gc();
+                Thread.sleep(20);
+            }
+        }
+        if (control != null) {
+            control.close();
+            ack.close();
+        }
+    }
+}

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 32/34] perf test cs-etm: Test trace is ordered with context switch records
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (30 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 31/34] perf test cs-etm: Add a Java JIT source-line test James Clark
@ 2026-11-18 16:29 ` 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
                   ` (2 subsequent siblings)
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Enable timestamps in the context switch attribution test and add an
additional check that decoded samples are output in order with context
switch events.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 .../tests/shell/coresight/context_switch_thread.sh   | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/shell/coresight/context_switch_thread.sh b/tools/perf/tests/shell/coresight/context_switch_thread.sh
index 2b9c44b86c59..584661cf47b0 100755
--- a/tools/perf/tests/shell/coresight/context_switch_thread.sh
+++ b/tools/perf/tests/shell/coresight/context_switch_thread.sh
@@ -55,7 +55,7 @@ mkfifo "$cf" "$af"
 # Pin to one CPU so the two threads alternate running but record into the same
 # trace buffer. Start disabled and use the control FIFO to only record the
 # workload and not startup.
-perf record -o "$tmpdir/data" -e cs_etm/timestamp=0/u -C 0 -D -1 --control fifo:"$cf","$af" -- \
+perf record -o "$tmpdir/data" -e cs_etm//u -C 0 -D -1 --control fifo:"$cf","$af" -- \
 	taskset --cpu-list 0 perf test --record-ctl fifo:"$cf","$af" \
 	-w context_switch_loop > /dev/null 2>&1
 
@@ -65,5 +65,23 @@ check_samples
 perf script -i "$tmpdir/data" --itrace=b -F comm,pid,tid,ip,sym > "$tmpdir/script" 2>/dev/null
 check_samples
 
+# Decoded trace should be output in time order with the context switch records.
+# Allow 1ms for estimated trace timestamps.
+perf script -i "$tmpdir/data" --itrace=b --show-switch-events -F time,event > \
+	"$tmpdir/script" 2>/dev/null
+if ! awk 'match($0, /[0-9]+\.[0-9]+:/) {
+		t = substr($0, RSTART, RLENGTH - 1) + 0
+		if (t < last - 0.001) {
+			printf "Time went back %.6fs: %s\n", last - t, $0
+			exit 1
+		}
+		if (t > last)
+			last = t
+	}' "$tmpdir/script"; then
+	echo "Trace was output out of order with context switches"
+	cleanup
+	exit 1
+fi
+
 cleanup
 exit 0

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 33/34] perf test cs-etm: Test decoding of kernel modules
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (31 preceding siblings ...)
  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:29 ` 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 16:33 ` [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

If kernel symbols are available, test that recording the kernel results
in etm4_enable* and etm4_disable* symbols. Use these symbols because
they will always be present when using trace.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/coresight/kernel_module.sh | 54 +++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/tools/perf/tests/shell/coresight/kernel_module.sh b/tools/perf/tests/shell/coresight/kernel_module.sh
new file mode 100755
index 000000000000..96bacb02b1fb
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/kernel_module.sh
@@ -0,0 +1,54 @@
+#!/bin/bash -e
+# CoreSight kernel module decode (exclusive)
+
+# SPDX-License-Identifier: GPL-2.0
+
+# If CoreSight is not available, skip the test
+perf list pmu | grep -q cs_etm || exit 2
+
+if [ "$(id -u)" != 0 ]; then
+	# Requires root for kernel trace and symbols
+	echo "[Skip] No root permission"
+	exit 2
+fi
+
+if ! perf probe --dry-run --module coresight_etm4x \
+	--add etm4_enable_trace_unit > /dev/null 2>&1 &&
+   ! perf probe --dry-run --add etm4_enable_trace_unit > /dev/null 2>&1; then
+	echo "[Skip] Kernel debug symbols for Coresight aren't available"
+	exit 2
+fi
+
+tmpdir=$(mktemp -d /tmp/__perf_test.coresight_kernel_module.XXXXX)
+
+cleanup() {
+	rm -rf "${tmpdir}"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+if ! perf record -o "$tmpdir/data" -e cs_etm//k -- true > /dev/null 2>&1; then
+	echo "[Fail] Failed to record kernel ETM trace"
+	cleanup
+	exit 1
+fi
+
+perf script -i "$tmpdir/data" --itrace=b -F ip,sym \
+	> "$tmpdir/script" 2>/dev/null
+
+# enable_* and disable_* functions always run so check they were decoded
+for symbol in etm4_enable etm4_disable; do
+	if ! grep -q "$symbol" "$tmpdir/script"; then
+		echo "No branches decoded in $symbol"
+		cleanup
+		exit 1
+	fi
+done
+
+cleanup
+exit 0

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* [PATCH 34/34] perf test cs-etm: Add an HHVM JIT call stack test
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (32 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 33/34] perf test cs-etm: Test decoding of kernel modules James Clark
@ 2026-11-18 16:29 ` 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
  34 siblings, 1 reply; 70+ messages in thread
From: James Clark @ 2026-11-18 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar
  Cc: linux-perf-users, linux-kernel, coresight, linux-arm-kernel,
	James Clark

Record a Hack workload with HHVM's jitdump enabled and compare the
decode matches the expected order of execution.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/coresight/hhvm-jit.sh | 89 ++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/tools/perf/tests/shell/coresight/hhvm-jit.sh b/tools/perf/tests/shell/coresight/hhvm-jit.sh
new file mode 100755
index 000000000000..cde8725519e6
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/hhvm-jit.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+# CoreSight HHVM JIT call stacks (exclusive)
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+set -o pipefail
+
+perf list pmu | grep cs_etm > /dev/null || exit 2
+# Require TRBE so that the trace always has virtual timestamps.
+if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then
+	echo "No TRBE sinks, skipping"
+	exit 2
+fi
+command -v hhvm > /dev/null || { echo "SKIP: missing hhvm"; exit 2; }
+
+tmpdir=$(mktemp -d /tmp/__perf_test.coresight_hhvm_jit.XXXXX)
+trap '[ "$?" -eq 0 ] && rm -rf "$tmpdir" || echo "HHVM JIT test files retained in $tmpdir"' EXIT
+trap 'exit 1' TERM INT
+
+# Use the control pipe to only trace the two call stacks rather than all of HHVM's startup.
+# Run stacks() twice to test hot and cold versions.
+cat > "$tmpdir/hello.hack" << 'EOF'
+function command(resource $ctl, resource $ack, string $cmd): void {
+  \fwrite($ctl, $cmd."\n");
+  \fflush($ctl);
+  // perf writes sizeof("ack\n"), including the trailing NUL.
+  invariant(\fread($ack, 5) === "ack\n\0", "Missing perf control ack");
+}
+
+<<__NEVER_INLINE>>
+function leaf(string $s): void {
+  echo $s;
+}
+
+<<__NEVER_INLINE>>
+function a2(string $s): void {
+  leaf($s);
+}
+
+<<__NEVER_INLINE>>
+function a1(string $s): void {
+  a2($s);
+}
+
+<<__NEVER_INLINE>>
+function b1(string $s): void {
+  leaf($s);
+}
+
+<<__NEVER_INLINE>>
+function stacks(string $hello, string $world): void {
+  a1($hello);
+  b1($world);
+}
+
+<<__EntryPoint>>
+function main(): void {
+  $ctl = \fopen(\getenv("PERF_CTL_FIFO") as string, "w");
+  $ack = \fopen(\getenv("PERF_ACK_FIFO") as string, "r");
+  command($ctl, $ack, "enable");
+  stacks("Hello, ", "world\n");
+  stacks("Hello, ", "world\n");
+  command($ctl, $ack, "disable");
+}
+EOF
+mkfifo "$tmpdir/ctl" "$tmpdir/ack"
+export PERF_CTL_FIFO="$tmpdir/ctl" PERF_ACK_FIFO="$tmpdir/ack"
+export JITDUMP_USE_ARCH_TIMESTAMP=1
+
+# HHVM deletes the jitdump on exit unless KeepPerfPidMap is set.
+perf record \
+	-o "$tmpdir/data" -e cs_etm//u -D -1 -m ,8M \
+	--control "fifo:$tmpdir/ctl,$tmpdir/ack" -- \
+	hhvm -vEval.PerfJitDump=1 -vEval.PerfJitDumpDir="$tmpdir" \
+	-vEval.KeepPerfPidMap=1 "$tmpdir/hello.hack" > "$tmpdir/out"
+[ "$(cat "$tmpdir/out")" = "$(printf 'Hello, world\nHello, world')" ]
+
+perf inject --jit -b \
+	-i "$tmpdir/data" -o "$tmpdir/injected.data"
+
+perf script -i "$tmpdir/injected.data" \
+	--itrace=b -F ip,sym > "$tmpdir/script"
+
+stacks="stacks a1 a2 leaf a2 a1 stacks b1 leaf b1 stacks"
+printf '%s\n' main $stacks main $stacks main > "$tmpdir/expected"
+sed -nE 's/^.*hello\.hack::(main|stacks|a1|a2|b1|leaf)$/\1/p' "$tmpdir/script" |
+	uniq > "$tmpdir/actual"
+diff -u "$tmpdir/expected" "$tmpdir/actual"
+echo "HHVM JIT call stacks match the expected sequence"

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 70+ messages in thread

* Re: [PATCH 02/34] perf jit: Add name of clock in error message
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:32 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Use the full name in the error message. This is also a valid form of -k
> argument and says exactly what clock is needed rather than having to
> work out how these numbers map to clock names.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 00/34] perf cs-etm: JIT decoding support
  2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
                   ` (33 preceding siblings ...)
  2026-11-18 16:29 ` [PATCH 34/34] perf test cs-etm: Add an HHVM JIT call stack test James Clark
@ 2026-11-18 16:33 ` James Clark
  34 siblings, 0 replies; 70+ messages in thread
From: James Clark @ 2026-11-18 16:33 UTC (permalink / raw)
  To: Linux perf Profiling
  Cc: linux-kernel, coresight, linux-arm-kernel,
	Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Suzuki K Poulose, Mike Leach, Leo Yan, Amir Ayupov,
	Suyash Mahar



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@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@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@linaro.org>
> 


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 03/34] perf jit: Add address ranges to DWARF compilation units
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:34 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> The JIT ELF writer emits a line table and a compilation unit containing
> only DW_AT_stmt_list. LLVM locates the CU by address before looking up a
> source line, but the CU address range isn't written into the DWARF.
> Therefore it can't resolve these files even though GNU addr2line could
> by reading the line table directly. This means that JIT src line lookups
> when LLVM is used.
> 
> Pass the generated code size to the debug information writer and emit
> DW_AT_low_pc and DW_AT_high_pc address ranges. Also mark the compilation
> unit as childless to match its contents.
> 
> Add a test which writes JIT debug information at a nonzero runtime load
> address and resolves an ELF-relative address through LLVM.
> 
> Fixes: c3f8644c21df ("perf report: Support LLVM for addr2line()")
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 11/34] perf cs-etm: Track threads in timeless mode
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:35 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Associating TIDs with PIDs is useful with and without timestamps. This
> is an old assumption from when timeless == per-thread mode so remove it.
> 
> Update the comment to say exactly why this needs to be done and move it
> to a single function so it's not repeated.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 09/34] perf cs-etm: arm-spe: Report error if default clock isn't used
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:35 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Coresight already reported an error if a different clock was used, but
> this also applies to SPE so add the same error there.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 04/34] perf libdw: Don't look up the module by ELF address
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:36 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> libdw__addr2line() finds the module with dwfl_addrmodule() using the ELF
> address. However, libdw reports modules loaded from disk at a fixed bias
> of 0x10000, so any ELF address below that isn't considered to be in the
> module. This means that source lines for very small binaries and JIT
> files can't be found by libdw.
> 
> This used to be hidden by falling back to the next addr2line style, but
> now missing information stops the fallback since commit (62d7cdc8d587
> "perf libdw: Optimize fallback logic for missing DWARF"). So perf script
> fails to show source line for these addresses.
> 
> Perf creates a separate Dwfl session for each DSO and only loads that
> DSO's file into it, so take the session's only module instead of looking
> it up by address to fix the issue.
> 
> Fixes: 88c51002d06f ("perf addr2line: Add a libdw implementation")
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:36 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Task bound events use PERF_RECORD_SWITCH events instead so handle these
> too. Furthermore associate the current PID and TID on
> PERF_RECORD_SWITCH_CPU_WIDE events as this is just as useful as the next
> PID and TID.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 19/34] perf cs-etm: Decode one packet at a time and don't estimate timestamps
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:39 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Stop decoding after each packet instead of buffering packets until a
> timestamp is reached. Give each range the last known timestamp instead
> of estimating time using instruction counts. This makes the interleaving
> of ranges between sinks less frequent, but that can be increased by
> increasing the timestamp frequency. Timestamp estimation only added
> complexity and was probably more misleading than useful.
> 
> Until the first trace timestamp is found, sort using zero. Only use the
> AUX record time when trace timestamps are disabled.
> 
> packet_buffer[] now only ever has one packet in it, but keep it for a
> later more mechanical removal in a later commit.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 14/34] perf cs-etm: Always enable Perf event timestamps
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> We still need MMAP timestamps in per-thread mode for overlapping mmaps,
> so always enable them. Also update the comment above to reflect the fact
> that Coresight timestamps are on by default, -T just gives more frequent
> ones.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 12/34] perf cs-etm: Track sched out events
  2026-11-18 16:29 ` [PATCH 12/34] perf cs-etm: Track sched out events James Clark
@ 2026-11-18 16:40   ` sashiko-bot
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> The sched in event might be dropped due to a full ringbuffer, so the
> sched out event is still useful information if that thread is going to
> be seen again. Call machine__findnew_thread() unconditionally as it's
> harmless to do it twice for the same thread.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 22/34] perf cs-etm: Rename trace ID queues to trace ID contexts
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Now cs_etm_traceid_queue is a single decode context rather than a queue
> of packets. Rename the struct and related functions to match. Keep tidq
> variable names for a later cleanup.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 21/34] perf cs-etm: Fold packet state into the trace ID queue
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> The packet queue no longer owns a packet buffer. The remaining timestamp
> and packet_count state belongs to the surrounding trace ID queue.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 01/34] perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> CLOCK_MONOTONIC can't be correlated with timestamps in trace, so to
> allow the JVMTI agent to be used with SPE and Coresight, use CNTVCT_EL0
> when JITDUMP_USE_ARCH_TIMESTAMP is set.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 18/34] perf cs-etm: Don't special case per-thread mode
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> This was always an extra edge case to have to understand, and keeping it
> would require another new special case in the following change to add a
> timestamp decoder tree per trace ID. Removing it makes both cases
> simpler and nothing is really lost anyway. The only change needed is to
> seed every trace ID context with the TID from the AUX record, rather
> than only updating the single special context.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 27/34] perf cs-etm: Add packet-only timestamp decoder ops
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:42 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Add OpenCSD packet-processing callbacks that find the next timestamp
> without fetching instructions or producing instruction ranges. Bound the
> search with CS_ETM_TIMESTAMP_SEARCH_MAX packets.
> 
> Keep the timestamp search state in cs_etm_timestamp_decoder, separate
> from the full packet decoder. Each source's callback context identifies
> its protocol. The frontend continues to use the existing full decoder.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 08/34] perf cs-etm: arm-spe: Use arch timestamp in HW tracers
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:42 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> To allow the JIT dump records to be correlated with the HW timestamp in
> trace, set JITDUMP_USE_ARCH_TIMESTAMP.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 26/34] perf cs-etm: Split base and packet decoder state
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:42 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Separate decoder struct into members that will be common with the
> timestamp decoder and members that are specific to the packet decoder.
> Then the timestamp decoder can use the shared base struct.
> 
> No functional changes intended.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 16/34] perf cs-etm: Don't buffer non-timestamped packets
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:43 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> We're going to use the same decode path for timestamped and not
> timestamped, but we don't want to buffer non-timestamped trace
> unnecessarily. Buffering is only for searching for a timestamp and doing
> it when there are no timestamps only results in not generating samples
> in trace order.
> 
> Let the backend know if timestamps are expected or not so it can decide
> to buffer or not.
> 
> Rename pending_timestamp_chan_id because now it just means that a packet
> is pending, either due to a timestamp being found or the first packet
> decoded.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 10/34] perf cs-etm: Remove old pipe mode support
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:44 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Pipe mode hasn't been supported since we added several peeks to
> cs_etm__process_auxtrace_info_full() that require random access. Even if
> it was supported, we would have to buffer the whole file anyway to make
> fully ordered decoding work. You don't know if one core stopped tracing
> for good or whether to wait till very end of the file for the next one.
> IntelPT has the same issue, see 'perf-intel-pt.txt#Pipe mode'.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 25/34] perf cs-etm: Consume each OpenCSD packet immediately
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:44 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Decode and consume one packet during each heap iteration. Return the
> context directly from the backend so that the packet can be processed.
> If the packet was a timestamp, then there is no action other than
> inserting that queue back into the heap at the new time.
> 
> Drain the decoder on the last trace byte of each buffer because it gets
> reset across each buffer and that would drop the last bit of unprocessed
> trace.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:45 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> OpenCSD caches instruction bytes, but with a JIT runtime a new jitdump
> mmap can replace code at a cached address without changing the context,
> so subsequent decoding can use stale instructions.
> 
> Invalidate the packet decoder's caches on MMAPs when virtual timestamps
> are enabled. Without virtual timestamps there's no proper ordering so
> this wouldn't increase accuracy. This is unlikely to cause any
> significant increase in overhead because MMAPs should be relatively rare
> and OpenCSD invalidates the cache on context switches anyway.
> 
> The API has no explicit cache invalidation operation, so disable and
> re-enable caching to discard its contents.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 20/34] perf cs-etm: Remove the decoded packet ring buffer
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:46 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Full decoding now stops after every output packet, so the frontend
> drains the packet ring before the decoder can produce another packet.
> 
> Write directly into the frontend's current packet instead. Remove the
> ring storage but retain the packet count as the pending-packet
> indicator, which will be removed later.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 05/34] perf cs-etm: Use the exception level to tell kernel from user
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:47 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> cs_etm__cpu_mode() decides whether an address is in the kernel by
> comparing it with the kernel start address. On arm64, modules are loaded
> below that, so module code is looked up in the thread's user maps which
> results in a decode failure.
> 
> The exception level of the trace is known for ETMv4 and ETE, so use that
> instead and only fall back to the address when it's unknown. This
> enables the ability to decode trace from kernel modules.
> 
> Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data")
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 24/34] perf cs-etm: Share the thread ctxt between frontend and backend
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:47 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> The decoder stops at every context packet and resumes only after the
> frontend has processed it, so now we only need to keep track of a single
> thread context.
> 
> The thread gets updated when the frontend processes a context packet.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 28/34] perf cs-etm: Create timestamp decoders
  2026-11-18 16:29 ` [PATCH 28/34] perf cs-etm: Create timestamp decoders James Clark
@ 2026-11-18 16:48   ` sashiko-bot
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:48 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Create a packet-only decode tree for each queue when ordered timestamp
> decoding is enabled.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 23/34] perf cs-etm: Rename tidq variables to tidc
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:49 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Use tidc for variables that point at the new trace ID context struct.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 32/34] perf test cs-etm: Test trace is ordered with context switch records
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:49 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> Enable timestamps in the context switch attribution test and add an
> additional check that decoded samples are output in order with context
> switch events.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 15/34] perf cs-etm: Use time from Perf samples
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:51 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf cs-etm: uninitialized pointer deref in
  cs_etm__queue_aux_fragment()
- [Medium] perf cs-etm: unvalidated (u64)-1 sample time in
  cs_etm__queue_aux_fragment()
--

commit 3c88e19ea9cd0c9b777217d6c7decbf883a6a671
Author: James Clark <james.clark@linaro.org>

perf cs-etm: Use time from Perf samples

This commit records the sample timestamp from each PERF_RECORD_AUX event on
its auxtrace_buffer and uses it in place of latest_kernel_timestamp when
virtual trace timestamps are unavailable or disabled.  It also replaces
timeless_decoding with has_timestamps.

> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 4252d25c991d8..ca3878a3b74e0 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c

[ ... ]

> @@ -1625,10 +1637,14 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
>  	struct cs_etm_auxtrace *etm = etmq->etm;
>  	struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue;
>  
> -	if (!etm->timeless_decoding && etm->has_virtual_ts)
> +	if (etm->has_virtual_ts)
>  		return packet_queue->cs_timestamp;
> -	else
> -		return etm->latest_kernel_timestamp;
> +
> +	/*
> +	 * Timestamps were disabled or no virtual TS. All samples are assigned
> +	 * the kernel time from when the trace block was emitted.
> +	 */
> +	return etmq->buffer->time;
>  }

[ ... ]

> @@ -1897,10 +1913,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
>  	attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK;
>  	attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID |
>  			    PERF_SAMPLE_PERIOD;
> -	if (etm->timeless_decoding)
> -		attr.sample_type &= ~(u64)PERF_SAMPLE_TIME;
> -	else
> -		attr.sample_type |= PERF_SAMPLE_TIME;
> +	attr.sample_type |= PERF_SAMPLE_TIME;
>  
>  	attr.exclude_user = evsel->core.attr.exclude_user;
>  	attr.exclude_kernel = evsel->core.attr.exclude_kernel;

[ ... ]

> @@ -3076,15 +3089,6 @@ static int cs_etm__process_event(struct perf_session *session,
>  	case PERF_RECORD_SWITCH:
>  		return cs_etm__process_switch(etm, sample);
>  
> -	case PERF_RECORD_AUX:
> -		/*
> -		 * Record the latest kernel timestamp available in the header
> -		 * for samples so that synthesised samples occur from this point
> -		 * onwards.
> -		 */
> -		if (sample->time && (sample->time != (u64)-1))
> -			etm->latest_kernel_timestamp = sample->time;
> -		break;
>  
>  	default:
>  		break;

[Severity: Medium]
Does dropping the sample->time != (u64)-1 check propagate (u64)-1 into
synthesized samples when PERF_SAMPLE_TIME is not set on the cs_etm evsel?

__evsel__parse_sample() initializes sample->time to (u64)-1 and only
updates it when PERF_SAMPLE_TIME is present in sample_type.  For
recordings without PERF_SAMPLE_TIME (such as perf record --no-timestamp)
decoded without virtual timestamps, cs_etm__queue_aux_fragment() now
stores (u64)-1 in buffer->time and cs_etm__resolve_sample_time() assigns
it to every synthesized sample, which produces bogus timestamps in perf
script and causes ordered_events__queue() to reject perf inject --itrace
output with -ETIME.

[ ... ]

> @@ -3287,6 +3274,7 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
>  		/* Old per-thread files have no CPU (before v6.4) */
>  		int queue_idx = sample->cpu == (u32)-1 ? 0 : sample->cpu;
>  		struct cs_etm_queue *etmq = cs_etm__get_queue(etm, queue_idx);
> +		struct auxtrace_buffer *buffer;
>  
>  		if (!etmq)
>  			return -EINVAL;
> @@ -3306,10 +3294,12 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
>  		pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64
>  			  " tid: %d cpu: %d\n", frag_size, frag_start, sample->tid, sample->cpu);
>  		err = auxtrace_queues__add_event(&etm->queues, session, &auxtrace_fragment,
> -						 file_offset, NULL);
> +						 file_offset, &buffer);
>  		if (err)
>  			return err;
>  
> +		buffer->time = sample->time;

[Severity: Medium]
Can buffer->time = sample->time dereference an uninitialized pointer when
CPU filtering (-C / --cpu) is active?

auxtrace_queues__add_event() -> auxtrace_queues__add_buffer() returns 0
without writing to *buffer_ptr when the AUX record's CPU is excluded by
filter_cpu():

tools/perf/util/auxtrace.c:auxtrace_queues__add_buffer() {
	if (filter_cpu(session, buffer->cpu))
		return 0;
    ...
}

Because buffer is not initialized to NULL and checked before writing
buffer->time, any PERF_RECORD_AUX event for a filtered-out CPU
dereferences the uninitialized stack pointer.

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 33/34] perf test cs-etm: Test decoding of kernel modules
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 16:57 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

> If kernel symbols are available, test that recording the kernel results
> in etm4_enable* and etm4_disable* symbols. Use these symbols because
> they will always be present when using trace.
> 
> Signed-off-by: James Clark <james.clark@linaro.org>

Sashiko has reviewed this patch and found no issues.

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


^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 34/34] perf test cs-etm: Add an HHVM JIT call stack test
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:01 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf test cs-etm: missing -vEval.PerfPidMap=0 in hhvm-jit.sh
  leaks pid map
--

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

perf test cs-etm: Add an HHVM JIT call stack test

This commit adds a CoreSight shell test that records a Hack workload
with HHVM jitdump enabled and checks the decoded call stack sequence.

> diff --git a/tools/perf/tests/shell/coresight/hhvm-jit.sh b/tools/perf/tests/shell/coresight/hhvm-jit.sh
> new file mode 100755
> index 0000000000000..cde8725519e6e
> --- /dev/null
> +++ b/tools/perf/tests/shell/coresight/hhvm-jit.sh
> @@ -0,0 +1,89 @@

[ ... ]

> +# HHVM deletes the jitdump on exit unless KeepPerfPidMap is set.
> +perf record \
> +	-o "$tmpdir/data" -e cs_etm//u -D -1 -m ,8M \
> +	--control "fifo:$tmpdir/ctl,$tmpdir/ack" -- \
> +	hhvm -vEval.PerfJitDump=1 -vEval.PerfJitDumpDir="$tmpdir" \
> +	-vEval.KeepPerfPidMap=1 "$tmpdir/hello.hack" > "$tmpdir/out"

[Severity: Low]
Does this leave /tmp/perf-<pid>.map behind in /tmp after the test exits?
HHVM enables Eval.PerfPidMap by default and writes /tmp/perf-<pid>.map
outside Eval.PerfJitDumpDir, while Eval.KeepPerfPidMap=1 prevents HHVM
from unlinking it on exit and the EXIT trap only removes $tmpdir.
Passing -vEval.PerfPidMap=0 would avoid creating the file.

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:01 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 07/34] perf build-id: Cache the vDSO in build ID mmap mode
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:03 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf build-id: dso__cache_build_id() fails to cache vDSO for
  synthesized mmaps
--

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

perf build-id: Cache the vDSO in build ID mmap mode

This commit reads the host vDSO build ID from perf's temporary copy of the
vDSO in dso__cache_build_id() when the DSO lacks a build ID, so that the
vDSO can be added to the build ID cache in --buildid-mmap mode.

> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 02233ef0eafff..cc813f421c9b2 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -886,6 +886,18 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
>  	char *allocated_name = NULL;
>  	int ret = 0;
>  
> +	/*
> +	 * The kernel can't add the vDSO's build ID to mmap events because it
> +	 * doesn't have a file, so read it from the copy that perf made. That
> +	 * copy is of the host's vDSO, so it can't be used for guests.
> +	 */
> +	if (is_vdso && machine__is_host(machine) && !dso__has_build_id(dso)) {
> +		struct build_id bid = { .size = 0, };
> +
> +		if (filename__read_build_id(name, &bid) > 0)
> +			dso__set_build_id(dso, &bid);
> +	}
> +
>  	if (!dso__has_build_id(dso) || !dso__hit(dso))
>  		return 0;

[Severity: Medium]
Does filename__read_build_id(name, &bid) still fail when perf record
synthesizes mmap2 events from /proc (for example with -a or -p)?

In --buildid-mmap mode, perf_event__synthesize_mmap_events() calls
perf_record_mmap2__read_build_id() for the "[vdso]" mapping, which inserts
a DSO with short_name and long_name set to "[vdso]" and no build ID:

tools/perf/util/synthetic-events.c:perf_record_mmap2__read_build_id() {
	...
	dso = dsos__findnew_id(&machine->dsos, event->filename, &dso_id);
	...
	rc = filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1;
	...
}

When process_buildids() later processes the mmap2 event, map__new() calls
machine__findnew_vdso(), which finds that existing "[vdso]" DSO in
machine->dsos via machine__find_vdso() and returns early before calling
get_file(&vdso_info->vdso) to create the temporary vDSO file:

tools/perf/util/vdso.c:machine__findnew_vdso() {
	...
	dso = machine__find_vdso(machine, thread);
	if (dso)
		return dso;
	...
	file = get_file(&vdso_info->vdso);
	if (!file)
		return NULL;

	return __machine__addnew_vdso(machine, DSO__NAME_VDSO, file);
}

As a result, name (dso__long_name(dso)) is still "[vdso]" when
dso__cache_build_id() runs, so filename__read_build_id() fails and the
vDSO remains uncached.

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 17/34] perf cs-etm: Decode in order of Perf samples
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:10 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf cs-etm: trace decoding fails when PERF_SAMPLE_TIME is
  absent
- [Medium] perf cs-etm: premature next-buffer load in cs_etm__pop_heap()
  before flush
--

commit 11ab0fc2c585444dee0fab0f3ef2be954d8f75a6
Author: James Clark <james.clark@linaro.org>

perf cs-etm: Decode in order of Perf samples

This commit replaces the separate timestamped, timeless, and per-thread
CoreSight ETM decode paths with a unified heap-ordered decode driven by
Perf event timestamps.

> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index b746d1215e0a0..5c98c7960f823 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -960,21 +952,19 @@ static int cs_etm__flush_events(struct perf_session *session,
>  	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
>  						   struct cs_etm_auxtrace,
>  						   auxtrace);
> +	int ret;
> +
>  	if (dump_trace || auxtrace__dont_decode(session))
>  		return 0;
>  
>  	if (!tool->ordered_events)
>  		return -EINVAL;
>  
> -	if (!etm->has_timestamps) {
> -		/*
> -		 * Pass tid = -1 to process all queues. But likely they will have
> -		 * already been processed on PERF_RECORD_EXIT anyway.
> -		 */
> -		return cs_etm__process_timeless_queues(etm, -1);
> -	}
> +	ret = cs_etm__pop_heap(etm, MAX_TIMESTAMP);
> +	if (ret)
> +		return ret;
>  
> -	return cs_etm__process_timestamped_queues(etm);
> +	return cs_etm__flush_queues(etm);
>  }
[ ... ]
> @@ -1321,75 +1311,77 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
[ ... ]
> +static int cs_etm__push_queue(struct cs_etm_queue *etmq, u64 time)
> +{
> +	int ret;
> +
> +	if (!etmq || etmq->on_heap)
> +		return 0;
> +
> +	while (!etmq->on_heap) {
>  		ret = cs_etm__get_data_block(etmq);
>  		if (ret <= 0)
> -			goto out;
> +			return ret;
> +		if (!etmq->etm->has_virtual_ts && etmq->buffer->time > time)
> +			return 0;
>  
> -		/*
> -		 * Run decoder on the trace block.  The decoder will stop when
> -		 * encountering a CS timestamp, a full packet queue or the end of
> -		 * trace for that block.
> -		 */
> -		ret = cs_etm__decode_data_block(etmq);
> +		ret = cs_etm__add_to_heap(etmq);
>  		if (ret)
> -			goto out;
> +			return ret;
> +	}
>  
> -		/*
> -		 * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
> -		 * the timestamp calculation for us.
> -		 */
> -		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
> +	return 0;
> +}
[ ... ]
> @@ -2895,11 +2743,21 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
>  		queue = &etm->queues.queue_array[queue_nr];
>  		etmq = queue->priv;
>  
> +		/* Don't go further than the trace timestamp or collection time */
> +		if (etm->has_virtual_ts) {
> +			if (etm->heap.heap_array[0].ordinal >= timestamp)
> +				break;
> +		} else {
> +			if (etmq->buffer->time >= timestamp)
> +				break;
> +		}
> +
>  		/*
>  		 * Remove the top entry from the heap since we are about
>  		 * to process it.
>  		 */
>  		auxtrace_heap__pop(&etm->heap);
> +		etmq->on_heap = false;
>  
>  		tidq  = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id);
>  		if (!tidq) {
> @@ -2913,7 +2771,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
>  		}
>  
>  		/*
> -		 * Packets associated with this timestamp are already in
> +		 * Packets associated with this timestamp, if any, are already in
>  		 * the etmq's traceID queue, so process them.
>  		 */
>  		ret = cs_etm__process_traceid_queue(etmq, tidq);
> @@ -2925,7 +2783,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
>  		 * move on to the next timestamp, fetching a new auxtrace_buffer
>  		 * if need be.
>  		 */
> -refetch:
> +get_data_block:
>  		ret = cs_etm__get_data_block(etmq);
>  		if (ret < 0)
>  			goto out;
> @@ -2937,37 +2795,28 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm)
>  		if (!ret)
>  			continue;
>  
> -		ret = cs_etm__decode_data_block(etmq);
> -		if (ret)
> -			goto out;
> -
> -		cs_timestamp = cs_etm__etmq_get_sort_timestamp(etmq, &trace_chan_id);
> -
> -		if (!cs_timestamp) {
> -			/*
> -			 * Function cs_etm__decode_data_block() returns when
> -			 * there is no more traces to decode in the current
> -			 * auxtrace_buffer OR when a timestamp has been
> -			 * encountered on any of the traceID queues.  Since we
> -			 * did not get a timestamp, there is no more traces to
> -			 * process in this auxtrace_buffer.  As such empty and
> -			 * flush all traceID queues.
> -			 */
> -			cs_etm__clear_all_traceid_queues(etmq);
> -
> -			/* Fetch another auxtrace_buffer for this etmq */
> -			goto refetch;
> -		}
> -
>  		/*
> -		 * Add to the min heap the timestamp for packets that have
> -		 * just been decoded.  They will be processed and synthesized
> -		 * during the next call to cs_etm__process_traceid_queue() for
> -		 * this queue/traceID.
> +		 * Add the next timestamp or decoded packets to the min heap.
> +		 * Packets will be processed and synthesized during the next call
> +		 * to cs_etm__process_traceid_queue() for this queue/traceID.
>  		 */
> -		cs_queue_nr = TO_CS_QUEUE_NR(queue_nr, trace_chan_id);
> -		ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
> +		ret = cs_etm__add_to_heap(etmq);
> +		if (ret)
> +			goto out;
> +		if (!etmq->on_heap)
> +			goto get_data_block;
>  	}

[Severity: Medium]
Does loading the next auxtrace_buffer via cs_etm__get_data_block() here
corrupt the state needed to flush the previous buffer's final packet and
cause premature decoding of future AUX buffers?

When the last CS_ETM_RANGE packet of an auxtrace_buffer is processed,
cs_etm__sample() swaps it into tidq->prev_packet with any unsampled
period_instructions remaining.  Unlike the removed timeless decoder loops,
which called cs_etm__end_block() at the end of each buffer before fetching
the next one, cs_etm__pop_heap() immediately calls cs_etm__get_data_block()
when etmq->buf_len reaches 0.  When the next buffer is loaded,
cs_etm__get_trace() replaces etmq->buffer, wipes all thread branch stacks
via cs_etm__flush_all_stack(), and in per-thread mode overwrites
tidq->frontend_thread and tidq->decode_thread with the new buffer's TID.
When the new buffer's initial CS_ETM_DISCONTINUITY packet later calls
cs_etm__flush(), the previous buffer's final instruction and branch samples
are synthesized with the new buffer's timestamp, thread, and cleared call
stack.

In addition, when !etm->has_virtual_ts, both cs_etm__push_queue() and this
loop call cs_etm__get_data_block() before checking whether the next buffer's
time is beyond the current Perf event timestamp, and cs_etm__pop_heap() does
not check etmq->buffer->time > timestamp at all before calling
cs_etm__add_to_heap(), decoding the start of the next AUX buffer before
intervening MMAP and COMM records have been processed (a later patch in this
series, commit "perf cs-etm: Find timestamps by searching ahead", adds the
timestamp check via cs_etm__insert_heap_queue(), but still calls
cs_etm__get_data_block() before that check and before flushing the previous
buffer).

[ ... ]
> @@ -3049,6 +2898,8 @@ static int cs_etm__process_event(struct perf_session *session,
>  	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
>  						   struct cs_etm_auxtrace,
>  						   auxtrace);
> +	bool has_sample_time = sample->time && sample->time != (u64)-1;
> +	int ret = 0;
>  
>  	if (dump_trace || auxtrace__dont_decode(session))
>  		return 0;
> @@ -3059,34 +2910,71 @@ static int cs_etm__process_event(struct perf_session *session,
>  	}
>  
>  	switch (event->header.type) {
> -	case PERF_RECORD_EXIT:
> +	case PERF_RECORD_ITRACE_START:
> +		ret = cs_etm__process_itrace_start(etm, event);
> +		if (ret)
> +			return ret;
> +
>  		/*
> -		 * Don't need to wait for cs_etm__flush_events() in per-thread mode to
> -		 * start the decode because we know there will be no more trace from
> -		 * this thread. All this does is emit samples earlier than waiting for
> -		 * the flush in other modes, but with timestamps it makes sense to wait
> -		 * for flush so that events from different threads are interleaved
> -		 * properly.
> +		 * Start decoding for this CPU on trace start. Timestamps in the
> +		 * trace will prevent decoding from going further ahead than
> +		 * Perf events.
>  		 */
> -		if (etm->per_thread_decoding && !etm->has_timestamps)
> -			return cs_etm__process_timeless_queues(etm,
> -							       event->fork.tid);
> +		if (has_sample_time && etm->has_virtual_ts) {
> +			ret = cs_etm__push_heap(etm, sample);
> +			if (ret)
> +				return ret;
> +		}
>  		break;
[ ... ]
> +	case PERF_RECORD_AUX:
> +		/*
> +		 * Start decoding after AUX to support !etm->has_virtual_ts
> +		 * because mmaps for that buffer must be available at this
> +		 * point. Push all queues so that they are ordered between each
> +		 * other, rather than waiting for their own AUX records which
> +		 * would be too late.
> +		 */
> +		if (etm->has_timestamps && !etm->has_virtual_ts)
> +			ret = cs_etm__push_heap_all(etm);
> +		else if (has_sample_time)
> +			ret = cs_etm__push_heap(etm, sample);
> +
> +		if (ret)
> +			return ret;
> +		break;
>  
>  	default:
>  		break;
>  	}
>  
> +	if (has_sample_time)
> +		return cs_etm__pop_heap(etm, sample->time);
> +
>  	return 0;
>  }

[Severity: Medium]
Does this skip all trace decoding when analyzing a perf.data file recorded
without PERF_SAMPLE_TIME (such as per-thread recordings created by older
perf binaries without -T)?

When PERF_SAMPLE_TIME is not set, __evsel__parse_sample() sets sample->time
to (u64)-1 (which equals MAX_TIMESTAMP), so has_sample_time is false for
every event and cs_etm__queue_aux_fragment() sets buffer->time to (u64)-1.
As a result, queues are never pushed during cs_etm__process_event() when
etm->has_virtual_ts or !etm->has_timestamps, and cs_etm__flush_events()
calls cs_etm__pop_heap(etm, MAX_TIMESTAMP) without pushing them first.
Even when etm->has_timestamps && !etm->has_virtual_ts pushes the queues on
PERF_RECORD_AUX, cs_etm__pop_heap(etm, MAX_TIMESTAMP) immediately hits
etmq->buffer->time >= timestamp (~0ULL >= ~0ULL) and breaks out without
decoding any trace data.

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 31/34] perf test cs-etm: Add a Java JIT source-line test
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:11 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf test cs-etm: java-jit.sh fails with EPERM for
  unprivileged users due to -m ,8M
- [Low] perf test cs-etm: missing libopencsd and dwarf checks in
  java-jit.sh
--

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

perf test cs-etm: Add a Java JIT source-line test

This commit adds a CoreSight shell test that records a Java workload with
the JVMTI agent, injects JIT symbols, and verifies the decoded source line
sequence across address reuse.

> diff --git a/tools/perf/tests/shell/coresight/java-jit.sh b/tools/perf/tests/shell/coresight/java-jit.sh
> new file mode 100755
> index 0000000000000..cb6099efa8991
> --- /dev/null
> +++ b/tools/perf/tests/shell/coresight/java-jit.sh
> @@ -0,0 +1,65 @@
> +#!/bin/bash
> +# CoreSight Java JIT source lines and code address reuse (exclusive)
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +set -o pipefail
> +
> +script_dir=$(dirname "$0")
> +
> +# Requires a HotSpot JDK (11+) and libperf-jvmti with line number support.
> +perf list pmu | grep cs_etm > /dev/null || exit 2

[Severity: Low]
Should the prerequisite checks also verify "perf check feature -q
libopencsd" and "perf check feature -q dwarf" before running the test?

The cs_etm PMU is exposed by the kernel and tools/perf/arch/arm/util/cs-etm.c
is compiled unconditionally on arm64, so perf list pmu and perf record
succeed even when perf is built without CORESIGHT=1, causing perf inject
and perf script to fail in cs_etm__process_auxtrace_info_full() instead of
skipping.  Likewise, jit_write_elf() only emits DWARF line tables via
jit_add_debug_info() when built with HAVE_LIBDW_SUPPORT, so builds without
libdw produce no source lines and fail the diff check.

[ ... ]

> +# Compile only run(), and collect trace only while it executes.
> +# A small code cache and class unloading encourage address reuse.
> +timeout 60s perf record \
> +	-o "$tmpdir/data" -e cs_etm//u -D -1 -m ,8M \
> +	--control "fifo:$tmpdir/ctl,$tmpdir/ack" -- \
> +	java -Xbatch -XX:-TieredCompilation -XX:CompileThreshold=100 \

[Severity: Medium]
Does "-m ,8M" cause perf record to fail with EPERM when running perf test
as an unprivileged user?

Passing "-m ,8M" sets opts->auxtrace_mmap_pages to 8 MiB while leaving
opts->mmap_pages at UINT_MAX, bypassing the unprivileged 128 KiB AUX /
256 KiB data fallback in cs_etm_recording_options():

tools/perf/arch/arm/util/cs-etm.c:cs_etm_recording_options() {
    ...
	if (!opts->auxtrace_mmap_pages) {
		if (privileged) {
			opts->auxtrace_mmap_pages = MiB(4) / page_size;
		} else {
			opts->auxtrace_mmap_pages = KiB(128) / page_size;
			if (opts->mmap_pages == UINT_MAX)
				opts->mmap_pages = KiB(256) / page_size;
		}
	}
    ...
}

Because --per-thread is not used, perf record mmaps a 516 KiB data buffer
and an 8 MiB AUX buffer on every online CPU.  In perf_mmap_calc_limits(),
the per-CPU data buffers consume the entire user_lock_limit and the 8 MiB
per-CPU AUX buffers exceed the default 8 MiB RLIMIT_MEMLOCK, aborting the
test with exit status 1.  Since tracing is only enabled for a single
work.run() call per phase, can this use the default buffer sizing from
cs_etm_recording_options() or skip when unprivileged?

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

* Re: [PATCH 06/34] perf cs-etm: Don't read past the end of the map
  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
  0 siblings, 0 replies; 70+ messages in thread
From: sashiko-bot @ 2026-11-18 17:11 UTC (permalink / raw)
  To: James Clark; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf cs-etm: __cs_etm__mem_access() uses map bounds before
  map__load()
- [Low] perf cs-etm: Fixes trailer cites c9a01a11dfe6 instead of
  20d9c478b01a
--

commit 12640a74a59159fbba9b39a02acb1bd86e89bf8a
Author: James Clark <james.clark@linaro.org>

> perf cs-etm: Don't read past the end of the map
>
> OpenCSD caches instruction memory one page size at a time. Perf reads
> this requested size from the file on disk without limiting it to the end
> of the map, so the page can contain ELF metadata from the file that
> wasn't mapped. If a subsequent read for a different .so file falls into
> this range, then it won't be decoded properly.
>
> Fix it by clamping the read size to the end of the map. Now when OpenCSD
> requests an address outside of that range, Perf will load the next .so
> file rather than OpenCSD using the mis-cached data.
>
> Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data")
> Signed-off-by: James Clark <james.clark@linaro.org>

[Severity: Low]
Commit c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace
data") only added packet buffering and trace element printing in
cs-etm-decoder.c.  The unclamped dso__data_read_offset() call in
cs_etm__mem_access() was introduced in commit 20d9c478b01a ("pert tools:
Add queue management functionality"), so should the Fixes tag reference
that commit instead?

> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 3fce3c3579438..fb4582dc378e1 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1213,6 +1213,12 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
>  
>  	offset = map__map_ip(al.map, address);
>  
> +	/*
> +	 * Clamp to the map size to avoid putting unmapped ELF file data from
> +	 * the .so into OpenCSD's cache as map data.
> +	 */
> +	size = min_t(u64, size, map__end(al.map) - address);
> +
>  	map__load(al.map);
>  
>  	len = dso__data_read_offset(dso, maps__machine(thread__maps(thread)),

[Severity: Medium]
Can map__end(al.map) - address underflow or evaluate against stale map
bounds when decoding kernel or module traces?

When symbol_conf.lazy_load_kernel_maps is false (the default in perf
script and perf report), thread__find_map() calls map__load(al->map) after
maps__find(), which shrinks vmlinux_map in place to the .text section
(e.g., via remap_kernel_cb()) and splits other executable sections into
separate maps without re-looking up al->map.  If address was in one of
those split sections above the new map__end(al.map), map__end(al.map) -
address underflows u64 (or evaluates to 0 at the boundary, causing
dso__data_read_offset() to return 0 and fail decoding).

Conversely, when symbol_conf.lazy_load_kernel_maps is true (such as in
perf inject --itrace), thread__find_map() skips map__load(), so offset and
map__end(al.map) here are computed from the unloaded map before
map__load(al.map) updates map bounds, pgoff, and mapping_type.

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

^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2026-11-18 17:11 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox