[libvirt] [PATCH v2 09/17] Support simulatorpin xml parse.

Hu Tao hutao at cn.fujitsu.com
Tue Aug 21 06:43:59 UTC 2012


From: Tang Chen <tangchen at cn.fujitsu.com>

This patch adds a new xml element <simulatorpin>, which is a sibling
to the existing <vcpupin> element under the <cputune>, to pin simulator
threads to specified physical CPUs.

Signed-off-by: Tang Chen <tangchen at cn.fujitsu.com>
Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 docs/formatdomain.html.in                       |    9 ++++
 docs/schemas/domaincommon.rng                   |    7 ++++
 src/conf/domain_conf.c                          |   50 ++++++++++++++++++++++-
 src/conf/domain_conf.h                          |    1 +
 tests/qemuxml2argvdata/qemuxml2argv-cputune.xml |    1 +
 5 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 2c5c456..6f7f62a 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -384,6 +384,7 @@
     <vcpupin vcpu="1" cpuset="0,1"/>
     <vcpupin vcpu="2" cpuset="2,3"/>
     <vcpupin vcpu="3" cpuset="0,4"/>
+    <emulatorpin cpuset="1-3"/%gt;
     <shares>2048</shares>
     <period>1000000</period>
     <quota>-1</quota>
@@ -410,6 +411,14 @@
         of element <code>vcpu</code>. (NB: Only qemu driver support)
         <span class="since">Since 0.9.0</span>
        </dd>
+       <dt><code>emulatorpin</code></dt>
+       <dd>
+         The optional <code>emulatorpin</code> element specifies which of host
+         physical CPUs the "emulator", a subset of a domain not including vcpu,
+         will be pinned to. If this is ommitted, "emulator" is pinned to all
+         the physical CPUs by default. It contains one required attribute
+         <code>cpuset</code> specifying which physical CPUs to pin to.
+       </dd>
       <dt><code>shares</code></dt>
       <dd>
         The optional <code>shares</code> element specifies the proportional
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 35e9f82..23bef1a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -577,6 +577,13 @@
               </attribute>
             </element>
           </zeroOrMore>
+          <optional>
+            <element name="emulatorpin">
+              <attribute name="cpuset">
+                <ref name="cpuset"/>
+              </attribute>
+            </element>
+          </optional>
         </element>
       </optional>
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9abf675..1319362 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8229,6 +8229,34 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
     VIR_FREE(nodes);
 
+    if ((n = virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("cannot extract emulatorpin nodes"));
+        goto error;
+    }
+
+    if (n) {
+        if (n > 1) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("only one emulatorpin is supported"));
+            VIR_FREE(nodes);
+            goto error;
+        }
+
+        if (VIR_ALLOC(def->cputune.emulatorpin) < 0) {
+            goto no_memory;
+        }
+
+        virDomainVcpuPinDefPtr emulatorpin = NULL;
+        emulatorpin = virDomainVcpuPinDefParseXML(nodes[0], ctxt, 0);
+
+        if (!emulatorpin)
+            goto error;
+
+        def->cputune.emulatorpin = emulatorpin;
+    }
+    VIR_FREE(nodes);
+
     /* Extract numatune if exists. */
     if ((n = virXPathNodeSet("./numatune", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -12824,7 +12852,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
 
     if (def->cputune.shares || def->cputune.vcpupin ||
-        def->cputune.period || def->cputune.quota)
+        def->cputune.period || def->cputune.quota ||
+        def->cputune.emulatorpin)
         virBufferAddLit(buf, "  <cputune>\n");
 
     if (def->cputune.shares)
@@ -12856,8 +12885,25 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         }
     }
 
+    if (def->cputune.emulatorpin) {
+        virBufferAsprintf(buf, "    <emulatorpin ");
+
+        char *cpumask = NULL;
+        cpumask = virDomainCpuSetFormat(def->cputune.emulatorpin->cpumask,
+                                        VIR_DOMAIN_CPUMASK_LEN);
+        if (cpumask == NULL) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "%s", _("failed to format cpuset for hypervisor"));
+                goto cleanup;
+        }
+
+        virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask);
+        VIR_FREE(cpumask);
+    }
+
     if (def->cputune.shares || def->cputune.vcpupin ||
-        def->cputune.period || def->cputune.quota)
+        def->cputune.period || def->cputune.quota ||
+        def->cputune.emulatorpin)
         virBufferAddLit(buf, "  </cputune>\n");
 
     if (def->numatune.memory.nodemask ||
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a18408e..ac10323 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1597,6 +1597,7 @@ struct _virDomainDef {
         long long quota;
         int nvcpupin;
         virDomainVcpuPinDefPtr *vcpupin;
+        virDomainVcpuPinDefPtr emulatorpin;
     } cputune;
 
     virDomainNumatuneDef numatune;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
index df3101d..593e650 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
@@ -10,6 +10,7 @@
     <quota>-1</quota>
     <vcpupin vcpu='0' cpuset='0'/>
     <vcpupin vcpu='1' cpuset='1'/>
+    <emulatorpin cpuset='1'/>
   </cputune>
   <os>
     <type arch='i686' machine='pc'>hvm</type>
-- 
1.7.10.2




More information about the libvir-list mailing list