Re: [PATCH v1 51/58] perf wakeup-latency: Port wakeup-latency to use python module

sashiko-bot
2026-04-20T00:47:51Z

Sashiko AI review found 1 potential issue(s):
- [High] Wakeup latency is calculated based on the target CPU rather than the task being woken up, leading to invalid and meaningless statistics.
--

commit 6b0cef4a823ca1458fe5c3eb39e24c043a11d86f
Author: Ian Rogers <irogers@google.com>

perf wakeup-latency: Port wakeup-latency to use python module

This commit ports the legacy Perl script wakeup-latency.pl to a python script
using the perf module in tools/perf/python. It tracks timestamps of
sched:sched_wakeup and sched:sched_switch events to measure latency.

> diff --git a/tools/perf/python/wakeup-latency.py b/tools/perf/python/wakeup-latency.py
> new file mode 100755
> index 0000000000000..109b751aefb30
> --- /dev/null
> +++ b/tools/perf/python/wakeup-latency.py

[ ... ]

> + def process_event(self, sample: perf.sample_event) -> None:
> + """Process events."""
> + event_name = str(sample.evsel)
> + sample_time = sample.sample_time
> + cpu = sample.sample_cpu
> +
> + if "sched:sched_wakeup" in event_name:
> + try:
> + target_cpu = sample.target_cpu
> + self.last_wakeup[target_cpu] = sample_time
> + except AttributeError:
> + pass
> + elif "sched:sched_switch" in event_name:
> + wakeup_ts = self.last_wakeup[cpu]
> + if wakeup_ts:
> + latency = sample_time - wakeup_ts
> + self.max_wakeup_latency = max(self.max_wakeup_latency, latency)
> + self.min_wakeup_latency = min(self.min_wakeup_latency, latency)
> + self.total_wakeup_latency += latency
> + self.total_wakeups += 1
> + self.last_wakeup[cpu] = 0

Does this logic accurately measure wakeup latency? It appears to be keyed by
the target CPU rather than the task being woken up.

If multiple tasks are woken up on the same CPU before a context switch
occurs, wouldn't the earlier wakeup timestamps get overwritten? When
sched_switch fires, the script pairs the last recorded wakeup timestamp with
whichever task is being switched in, even if the incoming task is completely
unrelated.

Additionally, if a task is load-balanced to a different CPU after wakeup,
would the latency calculation use the wrong CPU's last wakeup time or fail to
find one?

Tracking the wakeup timestamps per-task using the woken task's PID instead of
the CPU might be necessary to accurately measure wakeup latency, though I see
this behavior was ported directly from the legacy Perl script.

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260419235911.2186050-1-irogers@google.com?part=51