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

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

Sashiko AI review found 2 potential issue(s):
- [Medium] The ported powerpc-hcalls script incorrectly tracks hypercall state by `sample_pid` instead of CPU or thread ID, corrupting statistics for multi-threaded virtual machines.
- [Medium] The powerpc-hcalls script attempts to access a non-existent `sample.time` attribute, causing an AttributeError that aborts event processing.
--

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

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

This commit ports the powerpc-hcalls script to use the perf python module.
It refactors the script to use a class structure and tracks hypercall
entry/exit to calculate duration and aggregate statistics.

> diff --git a/tools/perf/python/powerpc-hcalls.py b/tools/perf/python/powerpc-hcalls.py
> new file mode 100755
> index 000000000000..c4fa539174c9
> --- /dev/null
> +++ b/tools/perf/python/powerpc-hcalls.py

[ ... ]

> +class HCallAnalyzer:
> + """Analyzes hypervisor calls and aggregates statistics."""

[ ... ]

> + def process_event(self, sample: perf.sample_event) -> None:
> + """Process a single sample event."""
> + name = str(sample.evsel)
> + pid = sample.sample_pid

Will using sample_pid (which corresponds to the Thread Group ID) cause
statistics to be corrupted for multi-threaded virtual machines?

Since QEMU uses multiple vCPU threads under a single process, concurrent
hypercalls from different vCPUs might share the same sample_pid and
overwrite each other's entry state in self.d_enter.

Should this use sample.sample_tid or CPU ID to track individual threads
instead?

> + time = sample.time

Does the perf Python API expose the timestamp as sample.time?

Looking at the perf Python extension, the timestamp is typically exposed as
sample.sample_time. If the time attribute doesn't exist, will it raise
an AttributeError and cause the script to fail on the first event?

> + opcode = getattr(sample, "opcode", -1)
> +
> + if opcode == -1:
> + return
> +
> + if name == "evsel(powerpc:hcall_entry)":
> + self.d_enter[pid] = (opcode, time)

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