[PATCH 11/34] perf cs-etm: Track threads in timeless mode

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


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 at 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




More information about the linux-arm-kernel mailing list