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

sashiko-bot
2026-04-25T18:04:52Z

Sashiko AI review found 1 potential issue(s):
- [Medium] Incorrect initialization of `min_wakeup_latency` artificially caps the minimum latency at 1 second and reports an incorrect value when no wakeups are processed.
--

commit 02a26dde701533f15dfaafd348b2b2126ca947be
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
utilizing the perf module. It implements a class-based architecture to
measure wakeup latency by tracking timestamps of sched:sched_wakeup and
sched:sched_switch events.

> diff --git a/tools/perf/python/wakeup-latency.py b/tools/perf/python/wakeup-latency.py
> new file mode 100755
> index 000000000000..1b0db115abcf
> --- /dev/null
> +++ b/tools/perf/python/wakeup-latency.py

[ ... ]

> +class WakeupLatency:
> + """Tracks and displays wakeup latency statistics."""
> + def __init__(self) -> None:
> + self.last_wakeup: Dict[int, int] = defaultdict(int)
> + self.max_wakeup_latency = 0
> + self.min_wakeup_latency = 1000000000

Is it possible for the true minimum wakeup latency to exceed 1 second
(1,000,000,000 ns)? By initializing the minimum latency to this hardcoded
value, any actual latency greater than 1 second will be ignored since the
min() calculation will prefer the initialized value, artificially capping
the results.

[ ... ]

> + def print_totals(self) -> None:
> + """Print summary statistics."""
> + print("wakeup_latency stats:\n")
> + print(f"total_wakeups: {self.total_wakeups}")
> + if self.total_wakeups:
> + avg = self.total_wakeup_latency // self.total_wakeups
> + print(f"avg_wakeup_latency (ns): {avg}")
> + else:
> + print("avg_wakeup_latency (ns): N/A")
> + print(f"min_wakeup_latency (ns): {self.min_wakeup_latency}")

Will this output an incorrect minimum latency if no wakeups are processed?
The average latency correctly handles the zero-wakeup case by printing N/A,
but the minimum latency will unconditionally print the hardcoded
initialization value.

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