Skip to contentSkip to conversation

sched: Add trace_sched_waking() tracepoint to sched_ttwu_pending()

PATCH Superseded John Stultz 1 participant 1 message Mar 1, 2024 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched: Add trace_sched_waking() tracepoint to sched_ttwu_pending()

Zimuzo reported seeing occasional cases in perfetto traces where tasks went from sleeping directly to trace_sched_wakeup() without always seeing a trace_sched_waking().

Looking at the code, trace_sched_wakeup() is only called in ttwu_do_wakeup()

The call paths that get you to ttwu_do_wakeup() are:
try_to_wake_up() -> ttwu_do_wakeup()
try_to_wake_up() -> ttwu_runnable() -> ttwu_do_wakeup() try_to_wake_up() -> ttwu_queue() -> ttwu_do_activate() -> ttwu_do_wakeup() sched_ttwu_pending() -> ttwu_do_activate() -> ttwu_do_wakeup()

where trace_sched_waking() is currently called only in try_to_wake_up().

So add a trace_sched_waking() call to sched_ttwu_pending(), so we see the same state machine transitions.

With this change, the number of unexpected state transitions in perfetto was greatly reduced.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Daniel Bristot de Oliveira <[email protected]>
Cc Phil Auld <[email protected]>
Cc Valentin Schneider <[email protected]>

---
v2:
* Minor commit message fix suggested by Phil Auld

---
 kernel/sched/core.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/core.c +1 -0
index 9116bcc90346..233f06360d6a 100644
@@ -3894,6 +3894,7 @@ void sched_ttwu_pending(void *arg)
 		if (WARN_ON_ONCE(task_cpu(p) != cpu_of(rq)))
 			set_task_cpu(p, cpu_of(rq));
 
+		trace_sched_waking(p);
 		ttwu_do_activate(rq, p, p->sched_remote_wakeup ? WF_MIGRATED : 0, &rf);
 	}
 
Signature · 1 line
2.44.0.rc1.240.g4c46232300-goog