[PATCHv2 1/3] qemu, lxc: Change host CPU detection logic.

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

 



The drivers for QEMU and LXC use virNodeGetInfo to determine the
number of host CPUs. This approach can lead to a wrong (too small)
number if one or more CPUs are offline.
It is better to use nodeGetCPUCount on Linux hosts.
---
V2 Changes:
Use nodeGetCPUCount as suggested by Eric, nodeGetCPUMap is too
"heavyweight".

 src/lxc/lxc_controller.c |  8 +++-----
 src/qemu/qemu_driver.c   | 14 +++++---------
 src/qemu/qemu_process.c  |  8 +++-----
 3 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index a41c903..ed3d3d0 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -492,17 +492,15 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
 static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
 {
     int hostcpus, maxcpu = CPU_SETSIZE;
-    virNodeInfo nodeinfo;
     virBitmapPtr cpumap, cpumapToSet;
 
     VIR_DEBUG("Setting CPU affinity");
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
-        return -1;
-
     /* setaffinity fails if you set bits for CPUs which
      * aren't present, so we have to limit ourselves */
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    if ((hostcpus = nodeGetCPUCount()) < 0)
+        return -1;
+
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3980c10..6ae33d3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4097,7 +4097,6 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
 
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm = NULL;
-    virNodeInfo nodeinfo;
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
     int maxcpu, hostcpus, vcpu, pcpu;
@@ -4133,9 +4132,9 @@ qemudDomainGetVcpuPinInfo(virDomainPtr dom,
     /* Coverity didn't realize that targetDef must be set if we got here.  */
     sa_assert(targetDef);
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
@@ -4348,7 +4347,6 @@ qemudDomainGetEmulatorPinInfo(virDomainPtr dom,
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm = NULL;
-    virNodeInfo nodeinfo;
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
     int maxcpu, hostcpus, pcpu;
@@ -4381,9 +4379,9 @@ qemudDomainGetEmulatorPinInfo(virDomainPtr dom,
     /* Coverity didn't realize that targetDef must be set if we got here. */
     sa_assert(targetDef);
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
@@ -4425,7 +4423,6 @@ qemudDomainGetVcpus(virDomainPtr dom,
                     int maplen) {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    virNodeInfo nodeinfo;
     int i, v, maxcpu, hostcpus;
     int ret = -1;
     qemuDomainObjPrivatePtr priv;
@@ -4451,10 +4448,9 @@ qemudDomainGetVcpus(virDomainPtr dom,
 
     priv = vm->privateData;
 
-    if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
+    if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;
 
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
     maxcpu = maplen * 8;
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3ac5282..74e43b8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1902,15 +1902,13 @@ qemuPrepareCpumap(struct qemud_driver *driver,
                   virBitmapPtr nodemask)
 {
     int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
-    virNodeInfo nodeinfo;
     virBitmapPtr cpumap = NULL;
 
-    if (nodeGetInfo(NULL, &nodeinfo) < 0)
-        return NULL;
-
     /* setaffinity fails if you set bits for CPUs which
      * aren't present, so we have to limit ourselves */
-    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    if ((hostcpus = nodeGetCPUCount()) < 0)
+        return NULL;
+
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
 
-- 
1.7.12.4

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