[PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events

From: James Clark

Date: Wed Nov 18 2026 - 11:30:16 EST


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@xxxxxxxxxx>
---
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