Re: [PATCH v2 42/58] perf powerpc-hcalls: Port powerpc-hcalls to use python module

sashiko-bot
2026-04-23T04:15:36Z

Sashiko AI review found 2 potential issue(s):
- [Medium] The script attempts to access the event timestamp via `sample.time`, which does not exist and will raise an `AttributeError`.
- [Medium] The script uses `sample_pid` (process ID) to track hypercalls, causing state collisions and data corruption for multi-threaded applications.
--

commit 513528145437ce5fa89bb95f8f8f46b59f1f4d00
Author: Ian Rogers <irogers@google.com>

perf powerpc-hcalls: Port powerpc-hcalls to use python module

This commit refactors the powerpc-hcalls script to use the perf.session
module instead of legacy tracepoint handlers. It introduces the
HCallAnalyzer class to encapsulate state and tracks hypervisor call entry
and exit to calculate durations and aggregate statistics.

> diff --git a/tools/perf/python/powerpc-hcalls.py b/tools/perf/python/powerpc-hcalls.py
> new file mode 100755
> index 0000000000000..c4fa539174c9d
> --- /dev/null
> +++ b/tools/perf/python/powerpc-hcalls.py
[ ... ]
> + def process_event(self, sample: perf.sample_event) -> None:
> + """Process a single sample event."""
> + name = str(sample.evsel)
> + pid = sample.sample_pid

Does using sample_pid cause state collisions for multi-threaded
applications?

Since sample_pid maps to the process ID (TGID) in perf tools, concurrent
hypercalls from different threads in the same process would share the same
sample_pid. This could cause threads to overwrite each other's entry
records in the d_enter dictionary, leading to unmatched exits and incorrect
duration calculations.

Would it be safer to use sample_tid or sample_cpu (as the legacy script did
with common_cpu) to prevent these collisions?

> + time = sample.time

Will accessing sample.time raise an AttributeError on the first event?

Looking at the perf Python C extension, the timestamp field for a
sample_event is explicitly exposed to Python as sample_time rather than
time. Since the tracepoint does not have a dynamic field named time, the
script might crash when attempting to read it.

> + opcode = getattr(sample, "opcode", -1)
[ ... ]

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