This is a series of semi-related patches for the x86 macOS Hypervisor.framework (hvf) accelerator backend. The intention is to make VMs run slightly more efficiently on macOS host machines. They have been subject to some months of CI workloads with macOS guest VMs without issues and they seem to give a few percent performance improvement. (Though this varies greatly with the type of workload.)
Patch 1 enables the INVTSC CPUID bit when running with hvf. This can enable some optimisations in the guest OS, and I've not found any reason it shouldn't be allowed for hvf based hosts. Patch 2 fixes hvf_kick_vcpu_thread so it actually forces a VM exit instead of doing nothing. I guess this previously didn't cause any huge issues because hvf's hv_vcpu_run() would exit so extremely frequently on its own accord. The temp variable is needed because the pointer expected by the hv_vcpu_interrupt() call doesn't match the fd field's type in the hvf accel's struct AccelCPUState. I'm unsure if it would be better to change that struct field to the relevant architecture's handle types, hv_vcpuid_t (x86, unsigned int) and hv_vcpu_t (aarch64, uint64_t), perhaps via an intermediate typedef? Patch 3, which replaces the call to hv_vcpu_run() with the more modern hv_vcpu_run_until() for running the guest vCPU. The newer API is available from macOS 10.15 host systems onwards. This call causes significantly fewer VM exits, which also means we really need that exit-forcing interrupt from patch 2. The reduction in VM exits means less overhead from exits and less contention on the BQL. Using hv_vcpu_run_until() is also a prerequisite for using certain newer hvf features, though this patchset doesn't use any. Patches 2 & 3 must therefore be applied in that order, patch 1 is independent. This work has been sponsored by Sauce Labs Inc. Phil Dennis-Jordan (3): i386: hvf: Adds support for INVTSC cpuid bit i386: hvf: In kick_vcpu use hv_vcpu_interrupt to force exit i386: hvf: Updates API usage to use modern vCPU run function target/i386/hvf/hvf.c | 26 +++++++++++++++++++++++++- target/i386/hvf/x86_cpuid.c | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) -- 2.36.1