[PATCH 4/8] qemu: cgroup: Use priv->autoCpuset instead of using qemuPrepareCpumap()

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

 



Two places would call to qemuPrepareCpumap() with priv->autoNodeset to
convert it to a cpuset. Remove the function and use the prepared cpuset
automatically.
---
 src/qemu/qemu_cgroup.c  | 18 +++--------
 src/qemu/qemu_cgroup.h  |  3 +-
 src/qemu/qemu_process.c | 82 ++++++++++++-------------------------------------
 src/qemu/qemu_process.h |  2 --
 4 files changed, 25 insertions(+), 80 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 8674ab8..7ba3059 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -1099,11 +1099,9 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
 }

 int
-qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
-                           virDomainObjPtr vm)
+qemuSetupCgroupForEmulator(virDomainObjPtr vm)
 {
     virBitmapPtr cpumask = NULL;
-    virBitmapPtr cpumap = NULL;
     virCgroupPtr cgroup_emulator = NULL;
     virDomainDefPtr def = vm->def;
     qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -1135,15 +1133,12 @@ qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
     if (virCgroupMoveTask(priv->cgroup, cgroup_emulator) < 0)
         goto cleanup;

-    if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
-        if (!(cpumap = qemuPrepareCpumap(driver, priv->autoNodeset)))
-            goto cleanup;
-        cpumask = cpumap;
-    } else if (def->cputune.emulatorpin) {
+    if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
+        cpumask = priv->autoCpuset;
+    else if (def->cputune.emulatorpin)
         cpumask = def->cputune.emulatorpin->cpumask;
-    } else if (def->cpumask) {
+    else if (def->cpumask)
         cpumask = def->cpumask;
-    }

     if (cpumask) {
         if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET) &&
@@ -1159,12 +1154,9 @@ qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
     }

     virCgroupFree(&cgroup_emulator);
-    virBitmapFree(cpumap);
     return 0;

  cleanup:
-    virBitmapFree(cpumap);
-
     if (cgroup_emulator) {
         virCgroupRemove(cgroup_emulator);
         virCgroupFree(&cgroup_emulator);
diff --git a/src/qemu/qemu_cgroup.h b/src/qemu/qemu_cgroup.h
index b311af3..11893ef 100644
--- a/src/qemu/qemu_cgroup.h
+++ b/src/qemu/qemu_cgroup.h
@@ -63,8 +63,7 @@ int qemuSetupCgroupIOThreadsPin(virCgroupPtr cgroup,
                                 int iothreadid);
 int qemuSetupCgroupForVcpu(virDomainObjPtr vm);
 int qemuSetupCgroupForIOThreads(virDomainObjPtr vm);
-int qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
-                               virDomainObjPtr vm);
+int qemuSetupCgroupForEmulator(virDomainObjPtr vm);
 int qemuRemoveCgroup(virQEMUDriverPtr driver, virDomainObjPtr vm);
 int qemuAddToCgroup(virDomainObjPtr vm);

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4a786b1..69c44d9 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2273,67 +2273,12 @@ qemuProcessDetectIOThreadPIDs(virQEMUDriverPtr driver,
     return ret;
 }

-/* Helper to prepare cpumap for affinity setting, convert
- * NUMA nodeset into cpuset if @nodemask is not NULL, otherwise
- * just return a new allocated bitmap.
- */
-virBitmapPtr
-qemuPrepareCpumap(virQEMUDriverPtr driver,
-                  virBitmapPtr nodemask)
-{
-    size_t i;
-    int hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
-    virBitmapPtr cpumap = NULL;
-    virCapsPtr caps = NULL;
-
-    /* setaffinity fails if you set bits for CPUs which
-     * aren't present, so we have to limit ourselves */
-    if ((hostcpus = nodeGetCPUCount()) < 0)
-        return NULL;
-
-    if (maxcpu > hostcpus)
-        maxcpu = hostcpus;
-
-    if (!(cpumap = virBitmapNew(maxcpu)))
-        return NULL;
-
-    if (nodemask) {
-        if (!(caps = virQEMUDriverGetCapabilities(driver, false))) {
-            virBitmapFree(cpumap);
-            cpumap = NULL;
-            goto cleanup;
-        }
-
-        for (i = 0; i < caps->host.nnumaCell; i++) {
-            size_t j;
-            int cur_ncpus = caps->host.numaCell[i]->ncpus;
-            bool result;
-            if (virBitmapGetBit(nodemask, caps->host.numaCell[i]->num, &result) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("Failed to convert nodeset to cpuset"));
-                virBitmapFree(cpumap);
-                cpumap = NULL;
-                goto cleanup;
-            }
-            if (result) {
-                for (j = 0; j < cur_ncpus; j++)
-                    ignore_value(virBitmapSetBit(cpumap,
-                                                 caps->host.numaCell[i]->cpus[j].id));
-            }
-        }
-    }
-
- cleanup:
-    virObjectUnref(caps);
-    return cpumap;
-}

 /*
  * To be run between fork/exec of QEMU only
  */
 static int
-qemuProcessInitCpuAffinity(virQEMUDriverPtr driver,
-                           virDomainObjPtr vm)
+qemuProcessInitCpuAffinity(virDomainObjPtr vm)
 {
     int ret = -1;
     virBitmapPtr cpumap = NULL;
@@ -2346,23 +2291,34 @@ qemuProcessInitCpuAffinity(virQEMUDriverPtr driver,
         return -1;
     }

-    if (!(cpumap = qemuPrepareCpumap(driver, priv->autoNodeset)))
-        return -1;
-
     if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
         VIR_DEBUG("Set CPU affinity with advisory nodeset from numad");
-        cpumapToSet = cpumap;
+        cpumapToSet = priv->autoCpuset;
     } else {
         VIR_DEBUG("Set CPU affinity with specified cpuset");
         if (vm->def->cpumask) {
             cpumapToSet = vm->def->cpumask;
         } else {
-            cpumapToSet = cpumap;
             /* You may think this is redundant, but we can't assume libvirtd
              * itself is running on all pCPUs, so we need to explicitly set
              * the spawned QEMU instance to all pCPUs if no map is given in
              * its config file */
+            int hostcpus;
+
+            /* setaffinity fails if you set bits for CPUs which
+             * aren't present, so we have to limit ourselves */
+            if ((hostcpus = nodeGetCPUCount()) < 0)
+                goto cleanup;
+
+            if (hostcpus > QEMUD_CPUMASK_LEN)
+                hostcpus = QEMUD_CPUMASK_LEN;
+
+            if (!(cpumap = virBitmapNew(hostcpus)))
+                goto cleanup;
+
             virBitmapSetAll(cpumap);
+
+            cpumapToSet = cpumap;
         }
     }

@@ -4787,7 +4743,7 @@ int qemuProcessStart(virConnectPtr conn,
     /* This must be done after cgroup placement to avoid resetting CPU
      * affinity */
     if (!vm->def->cputune.emulatorpin &&
-        qemuProcessInitCpuAffinity(driver, vm) < 0)
+        qemuProcessInitCpuAffinity(vm) < 0)
         goto cleanup;

     VIR_DEBUG("Setting domain security labels");
@@ -4834,7 +4790,7 @@ int qemuProcessStart(virConnectPtr conn,
         goto cleanup;

     VIR_DEBUG("Setting cgroup for emulator (if required)");
-    if (qemuSetupCgroupForEmulator(driver, vm) < 0)
+    if (qemuSetupCgroupForEmulator(vm) < 0)
         goto cleanup;

     VIR_DEBUG("Setting affinity of emulator threads");
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 3c04179..c67b0cb 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -99,8 +99,6 @@ int qemuProcessAutoDestroyRemove(virQEMUDriverPtr driver,
                                  virDomainObjPtr vm);
 bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm);
-virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
-                               virBitmapPtr nodemask);

 int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);

-- 
2.2.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]