utmapp / UTM

Virtual machines for iOS and macOS
https://getutm.app
Apache License 2.0
25.7k stars 1.3k forks source link

Expose usable PMU (perf counters) to guest #4200

Open cfallin opened 2 years ago

cfallin commented 2 years ago

I've been trying to get perf stat / perf record to work properly in a Linux aarch64 guest in UTM on my M1 hardware. My use-case is the need to profile software using common performance counters (cycles, instructions, cache misses, etc) while developing and optimizing in the guest.

This probably requires multiple moving parts: qemu support for PMU virtualization/passthrough, UTM setting the right options, guest Linux kernel knowledge of whatever PMU is exposed (is it Apple-specific?), and knowledge of the right counters in the perf userspace tool. This issue is an attempt to work out where each of these parts stands.

Has anyone gotten a perf stat /bin/ls (for exampe) in a Linux guest to report cycles and instructions? If so, are there instructions anywhere?

What I've worked out so far, using UTM 3.1.5 and a guest running a recent kernel (5.18), on macOS 12.4 / M1 as a host:

These lead me to suspect that more support may need to be added somewhere for Apple-specific performance counters, but that's just a guess. Any guidance would be welcome -- thanks!

chadbrewbaker commented 1 year ago

https://github.com/torvalds/linux/blob/master/drivers/perf/apple_m1_cpu_pmu.c

How to get them working without installing Linux natively is beyond me. No clue how QEMU does things, Linuxkit (Docker) is an older kernel, CoreOS (Podman) seems more recent based off Fedora.

Fedora 37 in UTMAPP didn't seem to like the PMUs. Kernel 6.0.7 by default. Maybe after SPICE tools install it gets better.