]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vmx: Support persistent CPU shares
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 3 Apr 2011 12:43:55 +0000 (14:43 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 5 Apr 2011 06:40:57 +0000 (08:40 +0200)
14 files changed:
src/vmx/vmx.c
tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx
tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml
tests/vmx2xmldata/vmx2xml-case-insensitive-2.xml
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-1.vmx
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-1.xml
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-4.xml
tests/vmx2xmldata/vmx2xml-esx-in-the-wild-5.xml
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.vmx
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-1.xml
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.vmx
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-4.xml
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-5.vmx
tests/xml2vmxdata/xml2vmx-esx-in-the-wild-5.xml

index 9f4d5fbbb1cb54a19f59ea4296081038de472d16..1d4abf0a46486ded0524b6f24b9ca70b78606d7c 100644 (file)
@@ -55,6 +55,8 @@ def->mem.cur_balloon = <value kilobyte>    <=>   sched.mem.max = "<value megabyt
 def->mem.min_guarantee = <value kilobyte>  <=>   sched.mem.minsize = "<value megabyte>"  # defaults to 0
 def->maxvcpus = <value>           <=>   numvcpus = "<value>"                    # must be 1 or a multiple of 2, defaults to 1
 def->cpumask = <uint list>        <=>   sched.cpu.affinity = "<uint list>"
+def->cputune.shares = <value>     <=>   sched.cpu.shares = "<value>"            # with handling for special values
+                                                                                # "high", "normal", "low"
 
 
 
@@ -1200,6 +1202,7 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx)
     long long sched_mem_minsize = 0;
     long long numvcpus = 0;
     char *sched_cpu_affinity = NULL;
+    char *sched_cpu_shares = NULL;
     char *guestOS = NULL;
     bool smbios_reflecthost = false;
     int controller;
@@ -1449,6 +1452,30 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx)
         }
     }
 
+    /* vmx:sched.cpu.shares -> def:cputune.shares */
+    if (virVMXGetConfigString(conf, "sched.cpu.shares", &sched_cpu_shares,
+                              true) < 0) {
+        goto cleanup;
+    }
+
+    if (sched_cpu_shares != NULL) {
+        /* See http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.SharesInfo.Level.html */
+        if (STRCASEEQ(sched_cpu_shares, "low")) {
+            def->cputune.shares = def->vcpus * 500;
+        } else if (STRCASEEQ(sched_cpu_shares, "normal")) {
+            def->cputune.shares = def->vcpus * 1000;
+        } else if (STRCASEEQ(sched_cpu_shares, "high")) {
+            def->cputune.shares = def->vcpus * 2000;
+        } else if (virStrToLong_ul(sched_cpu_shares, NULL, 10,
+                                   &def->cputune.shares) < 0) {
+            VMX_ERROR(VIR_ERR_INTERNAL_ERROR,
+                      _("Expecting VMX entry 'sched.cpu.shares' to be an "
+                        "unsigned integer or 'low', 'normal' or 'high' but "
+                        "found '%s'"), sched_cpu_shares);
+            goto cleanup;
+        }
+    }
+
     /* def:lifecycle */
     def->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART;
     def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY;
@@ -1715,6 +1742,7 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx)
     virConfFree(conf);
     VIR_FREE(encoding);
     VIR_FREE(sched_cpu_affinity);
+    VIR_FREE(sched_cpu_shares);
     VIR_FREE(guestOS);
 
     return def;
@@ -2998,6 +3026,21 @@ virVMXFormatConfig(virVMXContext *ctx, virCapsPtr caps, virDomainDefPtr def,
         virBufferAddLit(&buffer, "\"\n");
     }
 
+    /* def:cputune.shares -> vmx:sched.cpu.shares */
+    if (def->cputune.shares > 0) {
+        /* See http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.SharesInfo.Level.html */
+        if (def->cputune.shares == def->vcpus * 500) {
+            virBufferAddLit(&buffer, "sched.cpu.shares = \"low\"\n");
+        } else if (def->cputune.shares == def->vcpus * 1000) {
+            virBufferAddLit(&buffer, "sched.cpu.shares = \"normal\"\n");
+        } else if (def->cputune.shares == def->vcpus * 2000) {
+            virBufferAddLit(&buffer, "sched.cpu.shares = \"high\"\n");
+        } else {
+            virBufferVSprintf(&buffer, "sched.cpu.shares = \"%lu\"\n",
+                              def->cputune.shares);
+        }
+    }
+
     /* def:graphics */
     for (i = 0; i < def->ngraphics; ++i) {
         switch (def->graphics[i]->type) {
index bd36cf86e5899c4ead603fa28b0b6fa8ade7ca16..8641c5c01bb10ecbc6ad78efe1d5269ca7f6c7b5 100644 (file)
@@ -35,7 +35,7 @@ UUID.BIOS = "50 11 5E 16 9B DC 49 D7-F1 71 53 C4 D7 F9 17 10"
 SNAPSHOT.ACTION = "KEEP"
 SCHED.CPU.MIN = "0"
 SCHED.CPU.UNITS = "MHZ"
-SCHED.CPU.SHARES = "NORMAL"
+SCHED.CPU.SHARES = "4223"
 SCHED.MEM.MINSIZE = "0"
 SCHED.MEM.SHARES = "NORMAL"
 TOOLSCRIPTS.AFTERPOWERON = "TRUE"
index 7a5ff5bc31748aec9fa93ef63539e7fc378bc3e2..ef6edd813536c1f1e7212d61991ead4dca835fee 100644 (file)
@@ -4,6 +4,9 @@
   <memory>1048576</memory>
   <currentMemory>1048576</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>4223</shares>
+  </cputune>
   <os>
     <type arch='i686'>hvm</type>
   </os>
index 18d64611fc1e994f6c9f6c0161b27c7c7e264920..02771b98cd36636f1a74745e4f5d3ecc042777d0 100644 (file)
@@ -4,6 +4,9 @@
   <memory>1048576</memory>
   <currentMemory>1048576</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>1000</shares>
+  </cputune>
   <os>
     <type arch='i686'>hvm</type>
   </os>
index 4392062fbc651dfdb88ba1aba8f6c253d5be8a7c..78741aed4f5c700fe5eba542ad56d26484f477fb 100644 (file)
@@ -36,7 +36,7 @@ uuid.bios = "50 11 5e 16 9b dc 49 d7-f1 71 53 c4 d7 f9 17 10"
 snapshot.action = "keep"
 sched.cpu.min = "0"
 sched.cpu.units = "mhz"
-sched.cpu.shares = "normal"
+sched.cpu.shares = "low"
 sched.mem.minsize = "0"
 sched.mem.shares = "normal"
 toolScripts.afterPowerOn = "true"
index 5e67e746fd89d5a40245f95526de55626c5bc213..e8f9307725416f194a55445647779fe1ad31494b 100644 (file)
@@ -4,6 +4,9 @@
   <memory>1048576</memory>
   <currentMemory>1048576</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>500</shares>
+  </cputune>
   <os>
     <type arch='i686'>hvm</type>
   </os>
index 419df518de2c607642c1a1a1e7eedf0008d0eb4f..2824d66028398c455f2588f5d608f04ef61a8d17 100644 (file)
@@ -4,6 +4,9 @@
   <memory>524288</memory>
   <currentMemory>524288</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>1000</shares>
+  </cputune>
   <os>
     <type arch='i686'>hvm</type>
   </os>
index 004016324ba5cf7695cb1755dc3ef85bfa56c203..6f0a9d1c445226a345d1c9c780c5141a62227e72 100644 (file)
@@ -8,6 +8,9 @@
     <min_guarantee>262144</min_guarantee>
   </memtune>
   <vcpu>2</vcpu>
+  <cputune>
+    <shares>2000</shares>
+  </cputune>
   <os>
     <type arch='x86_64'>hvm</type>
   </os>
index e72ca803f8ed09630b67cab7010da5e01a667208..9059197fb29c632ff95e5b1858c6edbb6381a96b 100644 (file)
@@ -6,6 +6,7 @@ uuid.bios = "50 11 5e 16 9b dc 49 d7-f1 71 53 c4 d7 f9 17 10"
 displayName = "Fedora11"
 memsize = "1024"
 numvcpus = "1"
+sched.cpu.shares = "low"
 scsi0.present = "true"
 scsi0.virtualDev = "lsilogic"
 scsi0:0.present = "true"
index 3f4ff8830d9a9540bb5529355e46db556816b23d..ea597785c3c76f7c2eb4a92139b8f7b51373f11f 100644 (file)
@@ -4,6 +4,9 @@
   <memory>1048576</memory>
   <currentMemory>1048576</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>500</shares>
+  </cputune>
   <os>
     <type>hvm</type>
   </os>
index 627fcfb949709a01c7086dd457cb59a9e709b832..504997f0f956eb2e4bc658b1f6ed685a2ceee2fd 100644 (file)
@@ -6,6 +6,7 @@ uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
 displayName = "virtMonServ1"
 memsize = "512"
 numvcpus = "1"
+sched.cpu.shares = "normal"
 scsi0.present = "true"
 scsi0.virtualDev = "lsilogic"
 scsi0:0.present = "true"
index 078753a94f85c21eeef66c1c761192657bc9e228..443aacd4ab021a43d6bcfcd76a00a6ef18552845 100644 (file)
@@ -4,6 +4,9 @@
   <memory>524288</memory>
   <currentMemory>524288</currentMemory>
   <vcpu>1</vcpu>
+  <cputune>
+    <shares>1000</shares>
+  </cputune>
   <os>
     <type>hvm</type>
   </os>
index cc2485f7c75d9274301ad57b06dce2d8dbba462a..2e3b85691d904493f3d623395a60149f69e26353 100644 (file)
@@ -8,6 +8,7 @@ annotation = "Centos 5.5 64bit Server"
 memsize = "2048"
 sched.mem.minsize = "256"
 numvcpus = "2"
+sched.cpu.shares = "normal"
 scsi0.present = "true"
 scsi0.virtualDev = "lsilogic"
 scsi0:0.present = "true"
index d55bf6be7e23bc43d1ccd439e364ea478252037e..f28c15e97976ebad8040f16a20a92b01f5ea043b 100644 (file)
@@ -8,6 +8,9 @@
     <min_guarantee>262144</min_guarantee>
   </memtune>
   <vcpu>2</vcpu>
+  <cputune>
+    <shares>2000</shares>
+  </cputune>
   <os>
     <type arch='x86_64'>hvm</type>
   </os>