DEV Community

Discussion on: Running MacOS on Windows 10 with WSL2, KVM and QEMU

nicole profile image
Nicole Stevens Author

@pkostelnik yeah dbus is a great shout, same IPC etc, did you check the performance gain after the full kernel compile or with both together?

Thread Thread
pkostelnik profile image
Pawel Kostelnik

@nicole Not really because there is only a slightly speedup between this changes maybe 10-15%

Thread Thread
pkostelnik profile image
Pawel Kostelnik • Edited

@ciparis would you mind to share your configuration please.

Thread Thread
ciparis profile image
MichaelF • Edited

Here's the guide I followed:

github.com/kholia/OSX-KVM

I used the 2 networking lines from macOS-Simple-KVM rather than the method he listed, which did not work in WSL2. I've added a few more processor flags to my launch shell script (and changed the name for ease of typing) :

.wslconf borrowed and modified from yours (I'm pretty sure some of those AMD settings are non-functional) --note that the number of processors is inherited from the host and does not need listing here. When building my own kernel I had to use the 104 one -- the available 128 option failed to mount my C drive after building. I probably didn't need to go that route at all, since the current Insider dev build (20211.1005) has nested KVM support out of the box.

[wsl2]
nestedVirtualization=true
kernel=C:\\Users\\myUserPath\\bzImage
kernelCommandLine=amd_iommu=on iommu=pt vfio-pci.ids=1002:66af,1002:ab20 kvm.ignore_msrs=1 kvm-amd.nested=1 kvm-amd.ept=1 kvm-amd.emulate_invalid_guest_state=0 kvm-amd.enable_shadow_vmcs=1 kvm-amd.enable_apicv=1
memory=24GB
localhostForwarding=true

Launch script from this tutorial with my additions to the flags (I think svm is critical for AMD) and adjustments to RAM/Proc

############################################################################
# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems!
############################################################################

MY_OPTIONS="+svm,+hypervisor,+msr,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+avx2,+aes,+xsave,+xsaveopt,check"

# This script works for Big Sur, Catalina, Mojave, and High Sierra. Tested with
# macOS 10.15.6, macOS 10.14.6, and macOS 10.13.6

ALLOCATED_RAM="17166" # MiB
CPU_SOCKETS="1"
CPU_CORES="4"
CPU_THREADS="8"

REPO_PATH="./"
OVMF_DIR="."

It's possible (likely?) that I could trace my original installation-reboot issue by comparing the launch file with the one from macOS-simple-kvm.

That list of processor flags provide a big performance gain, but I'm not done yet. My next step is to place all of the AMD processor flags into the options line and then systematically remove the ones that cause errors -- this is similar to the process used for the huge long list of Intel flags at the bottom of the Accelerated KVM Guests post, and my performance with the graphical Ubuntu shell he walks through the installation of at the bottom is fantastic. Granted that's has a much lighter overhead then macOS.

Thread Thread
pkostelnik profile image
Pawel Kostelnik • Edited

@ciparis i'm sure there is also a huge difference with the vCPU which he uses for QEMU.
I also use the switch -deamonize to free the WSL console for htop and other monitoring.

Thread Thread
ciparis profile image
MichaelF • Edited

Here's the list of every AMD CPU flag (from /proc/cpuinfo) that is accepted without error by QEMU:

"+fpu,+vme,+de,+pse,+tsc,+msr,+pae,+mce,+cx8,+apic,+sep,+mtrr,+pge,+mca,+cmov,+pat,+pse36,+clflush,+mmx,+fxsr,+sse,+sse2,+ht,+syscall,+nx,+mmxext,+fxsr_opt,+pdpe1gb,+rdtscp,+lm,+pni,+pclmulqdq,+ssse3,+fma,+cx16,+sse4_1,+sse4_2,+movbe,+popcnt,+aes,+xsave,+avx,+f16c,+rdrand,+hypervisor,+lahf_lm,+cmp_legacy,+svm,+abm,+sse4a,+misalignsse,+3dnowprefetch,+osvw,+topoext,+ssbd,+ibpb,+stibp,+fsgsbase,+bmi1,+avx2,+smep,+bmi2,+rdseed,+adx,+smap,+clflushopt,+clwb,+xsaveopt,+xsavec,+xgetbv1,+xsaves,+clzero,+xsaveerptr,+arat,+npt,+nrip_save,+tsc_scale,+vmcb_clean,+flushbyasid,+decodeassists,+pfthreshold,+umip,+rdpid,check"

Performance remains good; I should probably benchmark between this list and the previous one.

Thread Thread
ciparis profile image
MichaelF • Edited

@pkostelnik What version of macOS are you using?

I just tried Mojave and it ran much slower than Catalina (the opposite of what I expected). For whatever reason, Catalina is faster on my Ryzen setup. Still laggy, but usable.

Thread Thread
pkostelnik profile image
Pawel Kostelnik

@ciparis trying actually both catalina (which started with clover) and also mojave, but trying now to change to opencore.