Enable Hyper-V Enlightenments in KVM for Better Windows VM Performance

By | 2016/03/21

KVM for a few years now supports Hyper-V Enlightenments. This provides better Windows performance in a virtual machine under KVM. Check it out!


All credits due to this excellent post:

http://blog.wikichoon.com/2014/07/enabling-hyper-v-enlightenments-with-kvm.html


The following will enable Hyper-V Enlightenments with KVM

(virt-manager 1.0.1 or later)
A recent version of qemu and libvirt may also be required.

sudo virt-xml $VMNAME --edit --features hyperv_relaxed=on,hyperv_vapic=on,hyperv_spinlocks=on,hyperv_spinlocks_retries=8191

sudo virt-xml $VMNAME --edit --clock hypervclock_present=yes  
virtmanager

Example output:

$ sudo virt-xml win7 --edit --features hyperv_relaxed=on,hyperv_vapic=on,hyperv_spinlocks=on,hyperv_spinlocks_retries=8191
Domain 'win7' defined successfully.
Changes will take effect after the next domain shutdown.

To verify, check the output of ps axf after powering off/on the vm. There you should now see the various -cpu flags such as:

hv_relaxed,hv_vapic,hv_spinlocks=0x1fff

$ ps axf | grep qemu
 3087 pts/6    S+     0:00  |   \_ grep --color=auto qemu
 1650 ?        Sl     0:55 qemu-system-x86_64 -enable-kvm -name win7 -S -machine pc-i440fx-2.1,accel=kvm,usb=off -cpu Nehalem,+invtsc,+rdtscp,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff -m 4096 -realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid 638dc67e-b49a-4409-ad7f-a8797d71dcfd -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/win7.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x4.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x4.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x4.0x2 -drive file=/home/stmiller/Documents/kvm/windows7.qcow2,if=none,id=drive-ide0-0-0,format=qcow2 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -drive file=xxxxxxxxx,if=none,id=drive-ide0-0-1,readonly=on,format=raw -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 -netdev tap,fd=24,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:b1:30:29,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 127.0.0.1:0 -device VGA,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -msg timestamp=on
win7_kvm

Special thanks to Jeff!