You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ml...@apache.org on 2013/12/17 00:28:39 UTC

git commit: updated refs/heads/4.3 to 6ae1c26

Updated Branches:
  refs/heads/4.3 a6792c57b -> 6ae1c26b9


CLOUDSTACK-5521: Create multi-core topology when deploying KVM virtual machines with many cores


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6ae1c26b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6ae1c26b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6ae1c26b

Branch: refs/heads/4.3
Commit: 6ae1c26b9a7964ce96202719368fe0830534c51e
Parents: a6792c5
Author: Marcus Sorensen <ma...@betterservers.com>
Authored: Mon Dec 16 16:28:00 2013 -0700
Committer: Marcus Sorensen <ma...@betterservers.com>
Committed: Mon Dec 16 16:28:00 2013 -0700

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java  |  11 +-
 .../hypervisor/kvm/resource/LibvirtVMDef.java   |  31 +++-
 .../resource/LibvirtComputingResourceTest.java  | 146 ++++++++++++++++++-
 3 files changed, 179 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ae1c26b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 013a7b8..3f51d5e 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -3478,12 +3478,21 @@ ServerResource {
         else{
             grd.setMemorySize(vmTO.getMaxRam() / 1024);
         }
-        grd.setVcpuNum(vmTO.getCpus());
+        int vcpus = vmTO.getCpus();
+        grd.setVcpuNum(vcpus);
         vm.addComp(grd);
 
         CpuModeDef cmd = new CpuModeDef();
         cmd.setMode(_guestCpuMode);
         cmd.setModel(_guestCpuModel);
+        // multi cores per socket, for larger core configs
+        if (vcpus % 6 == 0) {
+            int sockets = vcpus / 6;
+            cmd.setTopology(6, sockets);
+        } else if (vcpus % 4 == 0) {
+            int sockets = vcpus / 4;
+            cmd.setTopology(4, sockets);
+        }
         vm.addComp(cmd);
 
         if (_hypervisorLibvirtVersion >= 9000) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ae1c26b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index 6aaabc5..0ceea24 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -941,6 +941,8 @@ public class LibvirtVMDef {
     public static class CpuModeDef {
         private String _mode;
         private String _model;
+        private int _coresPerSocket = -1;
+        private int _sockets = -1;
 
         public void setMode(String mode) {
             _mode = mode;
@@ -950,18 +952,35 @@ public class LibvirtVMDef {
             _model = model;
         }
 
+        public void setTopology(int coresPerSocket, int sockets) {
+            _coresPerSocket = coresPerSocket;
+            _sockets = sockets;
+        }
+
         @Override
         public String toString() {
-            StringBuilder modeBuidler = new StringBuilder();
+            StringBuilder modeBuilder = new StringBuilder();
+
+            // start cpu def, adding mode, model
             if ("custom".equalsIgnoreCase(_mode) && _model != null) {
-                modeBuidler.append("<cpu mode='custom' match='exact'><model fallback='allow'>"
-                            + _model + "</model></cpu>");
+                modeBuilder.append("<cpu mode='custom' match='exact'><model fallback='allow'>"
+                            + _model + "</model>");
             } else if ("host-model".equals(_mode)) {
-                modeBuidler.append("<cpu mode='host-model'><model fallback='allow'></model></cpu>");
+                modeBuilder.append("<cpu mode='host-model'><model fallback='allow'></model>");
             } else if ("host-passthrough".equals(_mode)) {
-                modeBuidler.append("<cpu mode='host-passthrough'></cpu>");
+                modeBuilder.append("<cpu mode='host-passthrough'>");
+            } else {
+                modeBuilder.append("<cpu>");
             }
-            return modeBuidler.toString();
+
+            // add topology
+            if (_sockets > 0 && _coresPerSocket > 0) {
+                modeBuilder.append("<topology sockets='" + _sockets + "' cores='" + _coresPerSocket + "' threads='1' />");
+            }
+
+            // close cpu def
+            modeBuilder.append("</cpu>");
+            return modeBuilder.toString();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6ae1c26b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index 803ac32..8773067 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -67,7 +67,7 @@ public class LibvirtComputingResourceTest {
         int id = _random.nextInt(65534);
         String name = "test-instance-1";
 
-        int cpus = _random.nextInt(7) + 1;
+        int cpus = _random.nextInt(2) + 1;
         int speed = 1024;
         int minRam = 256 * 1024;
         int maxRam = 512 * 1024;
@@ -122,6 +122,7 @@ public class LibvirtComputingResourceTest {
         //vmStr += "<cputune>\n";
         //vmStr += "<shares>" + (cpus * speed) + "</shares>\n";
         //vmStr += "</cputune>\n";
+        vmStr += "<cpu></cpu>";
         vmStr += "<on_reboot>restart</on_reboot>\n";
         vmStr += "<on_poweroff>destroy</on_poweroff>\n";
         vmStr += "<on_crash>destroy</on_crash>\n";
@@ -130,6 +131,146 @@ public class LibvirtComputingResourceTest {
     }
 
     /**
+        This test verifies that CPU topology is properly set for hex-core
+    */
+    @Test
+    public void testCreateVMFromSpecWithTopology6() {
+        int id = _random.nextInt(65534);
+        String name = "test-instance-1";
+
+        int cpus = 12;
+        int minSpeed = 1024;
+        int maxSpeed = 2048;
+        int minRam = 256 * 1024;
+        int maxRam = 512 * 1024;
+
+        String os = "Ubuntu";
+        boolean haEnabled = false;
+        boolean limitCpuUse = false;
+
+        String vncAddr = "";
+        String vncPassword = "mySuperSecretPassword";
+
+        LibvirtComputingResource lcr = new LibvirtComputingResource();
+        VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, minSpeed, maxSpeed, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
+        to.setVncAddr(vncAddr);
+        to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
+
+        LibvirtVMDef vm = lcr.createVMFromSpec(to);
+        vm.setHvsType(_hyperVisorType);
+
+        String vmStr = "<domain type='" + _hyperVisorType + "'>\n";
+        vmStr += "<name>" + name + "</name>\n";
+        vmStr += "<uuid>b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9</uuid>\n";
+        vmStr += "<description>" + os + "</description>\n";
+        vmStr += "<clock offset='utc'>\n";
+        vmStr += "</clock>\n";
+        vmStr += "<features>\n";
+        vmStr += "<pae/>\n";
+        vmStr += "<apic/>\n";
+        vmStr += "<acpi/>\n";
+        vmStr += "</features>\n";
+        vmStr += "<devices>\n";
+        vmStr += "<serial type='pty'>\n";
+        vmStr += "<target port='0'/>\n";
+        vmStr += "</serial>\n";
+        vmStr += "<graphics type='vnc' autoport='yes' listen='" + vncAddr + "' passwd='" + vncPassword + "'/>\n";
+        vmStr += "<console type='pty'>\n";
+        vmStr += "<target port='0'/>\n";
+        vmStr += "</console>\n";
+        vmStr += "<input type='tablet' bus='usb'/>\n";
+        vmStr += "</devices>\n";
+        vmStr += "<memory>" + maxRam / 1024 + "</memory>\n";
+        vmStr += "<currentMemory>" + minRam / 1024 + "</currentMemory>\n";
+        vmStr += "<devices>\n";
+        vmStr += "<memballoon model='virtio'/>\n";
+        vmStr += "</devices>\n";
+        vmStr += "<vcpu>" + cpus + "</vcpu>\n";
+        vmStr += "<os>\n";
+        vmStr += "<type  machine='pc'>hvm</type>\n";
+        vmStr += "<boot dev='cdrom'/>\n";
+        vmStr += "<boot dev='hd'/>\n";
+        vmStr += "</os>\n";
+        vmStr += "<cpu><topology sockets='2' cores='6' threads='1' /></cpu>";
+        vmStr += "<on_reboot>restart</on_reboot>\n";
+        vmStr += "<on_poweroff>destroy</on_poweroff>\n";
+        vmStr += "<on_crash>destroy</on_crash>\n";
+        vmStr += "</domain>\n";
+
+        assertEquals(vmStr, vm.toString());
+    }
+
+    /**
+        This test verifies that CPU topology is properly set for quad-core
+    */
+    @Test
+    public void testCreateVMFromSpecWithTopology4() {
+        int id = _random.nextInt(65534);
+        String name = "test-instance-1";
+
+        int cpus = 8;
+        int minSpeed = 1024;
+        int maxSpeed = 2048;
+        int minRam = 256 * 1024;
+        int maxRam = 512 * 1024;
+
+        String os = "Ubuntu";
+        boolean haEnabled = false;
+        boolean limitCpuUse = false;
+
+        String vncAddr = "";
+        String vncPassword = "mySuperSecretPassword";
+
+        LibvirtComputingResource lcr = new LibvirtComputingResource();
+        VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, minSpeed, maxSpeed, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
+        to.setVncAddr(vncAddr);
+        to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
+
+        LibvirtVMDef vm = lcr.createVMFromSpec(to);
+        vm.setHvsType(_hyperVisorType);
+
+        String vmStr = "<domain type='" + _hyperVisorType + "'>\n";
+        vmStr += "<name>" + name + "</name>\n";
+        vmStr += "<uuid>b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9</uuid>\n";
+        vmStr += "<description>" + os + "</description>\n";
+        vmStr += "<clock offset='utc'>\n";
+        vmStr += "</clock>\n";
+        vmStr += "<features>\n";
+        vmStr += "<pae/>\n";
+        vmStr += "<apic/>\n";
+        vmStr += "<acpi/>\n";
+        vmStr += "</features>\n";
+        vmStr += "<devices>\n";
+        vmStr += "<serial type='pty'>\n";
+        vmStr += "<target port='0'/>\n";
+        vmStr += "</serial>\n";
+        vmStr += "<graphics type='vnc' autoport='yes' listen='" + vncAddr + "' passwd='" + vncPassword + "'/>\n";
+        vmStr += "<console type='pty'>\n";
+        vmStr += "<target port='0'/>\n";
+        vmStr += "</console>\n";
+        vmStr += "<input type='tablet' bus='usb'/>\n";
+        vmStr += "</devices>\n";
+        vmStr += "<memory>" + maxRam / 1024 + "</memory>\n";
+        vmStr += "<currentMemory>" + minRam / 1024 + "</currentMemory>\n";
+        vmStr += "<devices>\n";
+        vmStr += "<memballoon model='virtio'/>\n";
+        vmStr += "</devices>\n";
+        vmStr += "<vcpu>" + cpus + "</vcpu>\n";
+        vmStr += "<os>\n";
+        vmStr += "<type  machine='pc'>hvm</type>\n";
+        vmStr += "<boot dev='cdrom'/>\n";
+        vmStr += "<boot dev='hd'/>\n";
+        vmStr += "</os>\n";
+        vmStr += "<cpu><topology sockets='2' cores='4' threads='1' /></cpu>";
+        vmStr += "<on_reboot>restart</on_reboot>\n";
+        vmStr += "<on_poweroff>destroy</on_poweroff>\n";
+        vmStr += "<on_crash>destroy</on_crash>\n";
+        vmStr += "</domain>\n";
+
+        assertEquals(vmStr, vm.toString());
+    }
+
+    /**
         This test tests if the Agent can handle a vmSpec coming
         from a >4.1 management server.
 
@@ -141,7 +282,7 @@ public class LibvirtComputingResourceTest {
         int id = _random.nextInt(65534);
         String name = "test-instance-1";
 
-        int cpus = _random.nextInt(7) + 1;
+        int cpus = _random.nextInt(2) + 1;
         int minSpeed = 1024;
         int maxSpeed = 2048;
         int minRam = 256 * 1024;
@@ -197,6 +338,7 @@ public class LibvirtComputingResourceTest {
         //vmStr += "<cputune>\n";
         //vmStr += "<shares>" + (cpus * minSpeed) + "</shares>\n";
         //vmStr += "</cputune>\n";
+        vmStr += "<cpu></cpu>";
         vmStr += "<on_reboot>restart</on_reboot>\n";
         vmStr += "<on_poweroff>destroy</on_poweroff>\n";
         vmStr += "<on_crash>destroy</on_crash>\n";