From c4b621a418fe74a56e68140f1aa35c70562d7248 Mon Sep 17 00:00:00 2001 From: Simon Weller Date: Wed, 24 Oct 2018 20:24:13 -0500 Subject: [PATCH] kvm: HyperV Enlightment for Improved Windows Server 2008+ Performance (#2870) Windows has support for several paravirt features that it will use when running on Hyper-V, Microsoft's hypervisor. These features are called enlightenments. Many of the features are similar to paravirt functionality that exists with Linux on KVM (virtio, kvmclock, PV EOI, etc.) Nowadays QEMU/KVM can also enable support for several Hyper-V enlightenments. When enabled, Windows VMs running on KVM will use many of the same paravirt optimizations they would use when running on Hyper-V. A number of years ago, a PR was introduced that added a good portion of the code to enable this feature set, but it was never completed. This PR enables the existing features. The previous patch set detailed in #1013 also included the tests. By selecting Windows PV, the enlightenment additions will be applied to the libvirt configuration. This is support on Windows Server 2008 and beyond, so all currently supported versions of Windows Server. In our testing, we've seen benchmark improvements of around 20-25% running on Centos 7 hosts and it is also supported on Centos/RHEL 6.5 and later. Testing on Ubuntu would be appreciated. --- .../resource/LibvirtComputingResource.java | 27 ++++++++++++------- .../hypervisor/kvm/resource/LibvirtVMDef.java | 2 ++ .../kvm/resource/LibvirtVMDefTest.java | 7 +---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index ed87974cd51..f9dc1922e33 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2016,6 +2016,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } + protected void enlightenWindowsVm(VirtualMachineTO vmTO, FeaturesDef features) { + if (vmTO.getOs().contains("Windows PV")) { + // If OS is Windows PV, then enable the features. Features supported on Windows 2008 and later + LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv = new LibvirtVMDef.HyperVEnlightenmentFeatureDef(); + hyv.setFeature("relaxed", true); + hyv.setFeature("vapic", true); + hyv.setFeature("spinlocks", true); + hyv.setRetries(8096); + features.addHyperVFeature(hyv); + s_logger.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); + } + } + public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { final LibvirtVMDef vm = new LibvirtVMDef(); vm.setDomainName(vmTO.getName()); @@ -2101,14 +2114,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv features.addFeatures("pae"); features.addFeatures("apic"); features.addFeatures("acpi"); - //for rhel 6.5 and above, hyperv enlightment feature is added - /* - * if (vmTO.getOs().contains("Windows Server 2008") && hostOsVersion != null && ((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7))) { - * LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv = new LibvirtVMDef.HyperVEnlightenmentFeatureDef(); - * hyv.setRelaxed(true); - * features.addHyperVFeature(hyv); - * } - */ + + //KVM hyperv enlightenment features based on OS Type + enlightenWindowsVm(vmTO, features); + vm.addComp(features); final TermPolicy term = new TermPolicy(); @@ -2120,7 +2129,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final ClockDef clock = new ClockDef(); if (vmTO.getOs().startsWith("Windows")) { clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME); - clock.setTimer("rtc", "catchup", null); + clock.setTimer("hypervclock", null, null); } else if (vmTO.getType() != VirtualMachine.Type.User || isGuestPVEnabled(vmTO.getOs())) { if (_hypervisorLibvirtVersion >= 9 * 1000 + 10) { clock.setTimer("kvmclock", null, null, _noKvmClock); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 08ece9a104e..1e49cb58e78 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -370,6 +370,8 @@ public class LibvirtVMDef { if (_timerName.equals("kvmclock") && _noKvmClock) { clockBuilder.append("present='no' />"); + } else if (_timerName.equals("hypervclock")) { + clockBuilder.append("present='yes' />"); } else { if (_tickPolicy != null) { clockBuilder.append("tickpolicy='"); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java index b391b94e740..32effb474d8 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java @@ -26,7 +26,6 @@ import junit.framework.TestCase; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SCSIDef; -import com.cloud.utils.Pair; public class LibvirtVMDefTest extends TestCase { @@ -155,12 +154,8 @@ public class LibvirtVMDefTest extends TestCase { assertFalse(defs.contains("relaxed")); assertFalse(defs.contains("vapic")); assertFalse(defs.contains("spinlocks")); - assertTrue("Windows Server 2008 R2".contains("Windows Server 2008")); + assertTrue("Windows PV".contains("Windows PV")); - Pair hostOsVersion = new Pair(6,5); - assertTrue((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7)); - hostOsVersion = new Pair(7,1); - assertTrue((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7)); } public void testRngDef() {