incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject git commit: kvm: Define CPU shares in domain XML
Date Tue, 07 Aug 2012 15:51:25 GMT
Updated Branches:
  refs/heads/master 64def0ef3 -> 5fa300cd9


kvm: Define CPU shares in domain XML

Since libvirt 0.9.0 this can be specified in the XML.

This used to be set by invoking virsh after starting the instance, but this is cleaner.


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

Branch: refs/heads/master
Commit: 5fa300cd9c64ec6bf3dbe5bf9f224e260e617329
Parents: 64def0e
Author: Wido den Hollander <wido@widodh.nl>
Authored: Tue Aug 7 17:48:12 2012 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Tue Aug 7 17:49:58 2012 +0200

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |    8 +++--
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |   23 +++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5fa300cd/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 73101a9..026b914 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
@@ -155,6 +155,7 @@ import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.api.to.VolumeTO;
 import com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool;
 import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef;
+import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef;
 import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef;
 import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
 import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.diskProtocol;
@@ -2475,6 +2476,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         grd.setVcpuNum(vmTO.getCpus());
         vm.addComp(grd);
 
+        CpuTuneDef ctd = new CpuTuneDef();
+        ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
+        vm.addComp(ctd);
+
         FeaturesDef features = new FeaturesDef();
         features.addFeatures("pae");
         features.addFeatures("apic");
@@ -2550,9 +2555,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements
 
             s_logger.debug("starting " + vmName + ": " + vm.toString());
             startDomain(conn, vmName, vm.toString());
-            Script.runSimpleBashScript("virsh schedinfo " + vmName
-                    + " --set cpu_shares=" + vmSpec.getCpus()
-                    * vmSpec.getSpeed());
 
             NicTO[] nics = vmSpec.getNics();
             for (NicTO nic : nics) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5fa300cd/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 56e3efa..ba6c715 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
@@ -752,6 +752,29 @@ public class LibvirtVMDef {
         }
     }
 
+    public static class CpuTuneDef {
+        private int _shares = 0;
+
+        public void setShares(int shares) {
+            _shares = shares;
+        }
+
+        public int getShares() {
+            return _shares;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder cpuTuneBuilder = new StringBuilder();
+            cpuTuneBuilder.append("<cputune>\n");
+            if (_shares > 0) {
+                cpuTuneBuilder.append("<shares>" + _shares + "</shares>\n");
+            }
+            cpuTuneBuilder.append("</cputune>\n");
+            return cpuTuneBuilder.toString();
+        }
+    }
+
     public static class SerialDef {
         private final String _type;
         private final String _source;


Mime
View raw message