cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mlsoren...@apache.org
Subject git commit: updated refs/heads/master to 2f53295
Date Mon, 16 Dec 2013 23:13:40 GMT
Updated Branches:
  refs/heads/master 6ad0e4913 -> 2f5329515


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/2f532951
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2f532951
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2f532951

Branch: refs/heads/master
Commit: 2f53295151820c56c683ed280691ebd479d25ec2
Parents: 6ad0e49
Author: Marcus Sorensen <marcus@betterservers.com>
Authored: Mon Dec 16 16:12:43 2013 -0700
Committer: Marcus Sorensen <marcus@betterservers.com>
Committed: Mon Dec 16 16:12:43 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/2f532951/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 7a02f3b..a2c6682 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
@@ -3477,12 +3477,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         } 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/2f532951/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 3e44e94..9fd058f 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
@@ -949,6 +949,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;
@@ -958,17 +960,34 @@ public class LibvirtVMDef {
             _model = model;
         }
 
+        public void setTopology(int coresPerSocket, int sockets) {
+            _coresPerSocket = coresPerSocket;
+            _sockets = sockets;
+        }
+
         @Override
         public String toString() {
-            StringBuilder modeBuidler = new StringBuilder();
-            if ("custom".equalsIgnoreCase(_mode) && _model != null) {
-                modeBuidler.append("<cpu mode='custom' match='exact'><model fallback='allow'>"
+ _model + "</model></cpu>");
+            StringBuilder modeBuilder = new StringBuilder();
+
+            // start cpu def, adding mode, model
+            if ("custom".equalsIgnoreCase(_mode) && _model != null){
+                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/2f532951/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 7b1eade..c8af7f8 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
@@ -69,7 +69,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;
@@ -124,6 +124,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";
@@ -132,6 +133,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.
 
@@ -143,7 +284,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;
@@ -200,6 +341,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";


Mime
View raw message