[PATCH v3 04/13] conf: Don't copy def->cpumask into cpu pinning info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This step can be omitted, so that drivers can decide what to do when the
user requests to use default vcpu pinning.
---

Notes:
    v2: use correct variable
    v3: already ACKed, but depends on previous patches

 src/conf/domain_conf.c   | 32 --------------------------------
 src/libxl/libxl_domain.c | 15 ++++++++++++---
 src/libxl/libxl_driver.c |  2 ++
 src/qemu/qemu_driver.c   | 34 ++--------------------------------
 src/qemu/qemu_process.c  | 12 ++++++++----
 src/test/test_driver.c   |  2 ++
 src/vz/vz_sdk.c          |  4 ++--
 7 files changed, 28 insertions(+), 73 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2d7a4c7..6914466 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15198,34 +15198,6 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
     VIR_FREE(nodes);

-    /* Initialize the pinning policy for vcpus which doesn't has
-     * the policy specified explicitly as def->cpuset.
-     */
-    if (def->cpumask) {
-        if (VIR_REALLOC_N(def->cputune.vcpupin, virDomainDefGetVcpus(def)) < 0)
-            goto error;
-
-        for (i = 0; i < virDomainDefGetVcpus(def); i++) {
-            if (virDomainPinIsDuplicate(def->cputune.vcpupin,
-                                        def->cputune.nvcpupin,
-                                        i))
-                continue;
-
-            virDomainPinDefPtr vcpupin = NULL;
-
-            if (VIR_ALLOC(vcpupin) < 0)
-                goto error;
-
-            if (!(vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN))) {
-                VIR_FREE(vcpupin);
-                goto error;
-            }
-            virBitmapCopy(vcpupin->cpumask, def->cpumask);
-            vcpupin->id = i;
-            def->cputune.vcpupin[def->cputune.nvcpupin++] = vcpupin;
-        }
-    }
-
     if ((n = virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract emulatorpin nodes"));
@@ -21900,10 +21872,6 @@ virDomainDefFormatInternal(virDomainDefPtr def,

     for (i = 0; i < def->cputune.nvcpupin; i++) {
         char *cpumask;
-        /* Ignore the vcpupin which inherit from "cpuset of "<vcpu>." */
-        if (virBitmapEqual(def->cpumask, def->cputune.vcpupin[i]->cpumask))
-            continue;
-
         virBufferAsprintf(&childrenBuf, "<vcpupin vcpu='%u' ",
                           def->cputune.vcpupin[i]->id);

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 1133c8b..67b230a 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -829,9 +829,18 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)

     libxl_bitmap_init(&map);

-    for (i = 0; i < vm->def->cputune.nvcpupin; ++i) {
-        pin = vm->def->cputune.vcpupin[i];
-        cpumask = pin->cpumask;
+    for (i = 0; i < virDomainDefGetVcpus(vm->def); ++i) {
+        pin = virDomainPinFind(vm->def->cputune.vcpupin,
+                               vm->def->cputune.nvcpupin,
+                               i);
+
+        if (pin && pin->cpumask)
+            cpumask = pin->cpumask;
+        else
+            cpumask = vm->def->cpumask;
+
+        if (!cpumask)
+            continue;

         if (virBitmapToData(cpumask, &map.map, (int *)&map.size) < 0)
             goto cleanup;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 2a6c2de..8965abd 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2472,6 +2472,8 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,

         if (pininfo && pininfo->cpumask)
             bitmap = pininfo->cpumask;
+        else if (targetDef->cpumask)
+            bitmap = targetDef->cpumask;
         else
             bitmap = allcpumap;

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index af44b0a..3e891e4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4682,33 +4682,6 @@ qemuDomainAddCgroupForThread(virCgroupPtr cgroup,
     return NULL;
 }

-static int
-qemuDomainHotplugAddPin(virBitmapPtr cpumask,
-                        int idx,
-                        virDomainPinDefPtr **pindef_list,
-                        size_t *npin)
-{
-    int ret = -1;
-    virDomainPinDefPtr pindef = NULL;
-
-    if (VIR_ALLOC(pindef) < 0)
-        goto cleanup;
-
-    if (!(pindef->cpumask = virBitmapNewCopy(cpumask))) {
-        VIR_FREE(pindef);
-        goto cleanup;
-    }
-    pindef->id = idx;
-    if (VIR_APPEND_ELEMENT_COPY(*pindef_list, *npin, pindef) < 0) {
-        virBitmapFree(pindef->cpumask);
-        VIR_FREE(pindef);
-        goto cleanup;
-    }
-    ret = 0;
-
- cleanup:
-    return ret;
-}

 static int
 qemuDomainHotplugPinThread(virBitmapPtr cpumask,
@@ -4825,11 +4798,6 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,

     /* Inherit def->cpuset */
     if (vm->def->cpumask) {
-        if (qemuDomainHotplugAddPin(vm->def->cpumask, vcpu,
-                                    &vm->def->cputune.vcpupin,
-                                    &vm->def->cputune.nvcpupin) < 0)
-            goto cleanup;
-
         if (qemuDomainHotplugPinThread(vm->def->cpumask, vcpu, vcpupid,
                                        cgroup_vcpu) < 0) {
             goto cleanup;
@@ -5357,6 +5325,8 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
         else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO &&
                  priv->autoCpuset)
             bitmap = priv->autoCpuset;
+        else if (def->cpumask)
+            bitmap = def->cpumask;
         else
             bitmap = allcpumap;

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f82158d..fa646f2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2207,7 +2207,8 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
          * VM default affinity, we must reject it
          */
         for (n = 0; n < def->cputune.nvcpupin; n++) {
-            if (!virBitmapEqual(def->cpumask,
+            if (def->cputune.vcpupin[n]->cpumask &&
+                !virBitmapEqual(def->cpumask,
                                 def->cputune.vcpupin[n]->cpumask)) {
                 virReportError(VIR_ERR_OPERATION_INVALID,
                                "%s", _("cpu affinity is not supported"));
@@ -2218,16 +2219,19 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
     }

     for (n = 0; n < virDomainDefGetVcpus(def); n++) {
+        virBitmapPtr bitmap;
         /* set affinity only for existing vcpus */
         if (!(pininfo = virDomainPinFind(def->cputune.vcpupin,
                                          def->cputune.nvcpupin,
                                          n)))
             continue;

-        if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, n),
-                                  pininfo->cpumask) < 0) {
+        if (!(bitmap = pininfo->cpumask) &&
+            !(bitmap = def->cpumask))
+            continue;
+
+        if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, n), bitmap) < 0)
             goto cleanup;
-        }
     }

     ret = 0;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index fde5e2d..1a7f43b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2575,6 +2575,8 @@ testDomainGetVcpuPinInfo(virDomainPtr dom,

         if (pininfo && pininfo->cpumask)
             bitmap = pininfo->cpumask;
+        else if (def->cpumask)
+            bitmap = def->cpumask;
         else
             bitmap = allcpumap;

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index d610979..7cc24d3 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -1959,8 +1959,8 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, virDomainDefPtr def)

     if (def->cputune.vcpupin) {
         for (i = 0; i < def->cputune.nvcpupin; i++) {
-            if (!virBitmapEqual(def->cpumask,
-                                def->cputune.vcpupin[i]->cpumask)) {
+            if (def->cputune.vcpupin[i]->cpumask &&
+                !virBitmapEqual(def->cpumask, def->cputune.vcpupin[i]->cpumask)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                "%s", _("vcpupin cpumask differs from default cpumask"));
                 return -1;
-- 
2.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]