[libvirt] [PATCH 08/24] conf: numa: Recalculate rather than remember total NUMA cpu count

Peter Krempa pkrempa at redhat.com
Mon Feb 16 18:51:56 UTC 2015


It's easier to recalculate the number in the one place it's used as
having a separate varialbe to track it. It will also help with moving
the NUMA code to the separate module.
---
 src/conf/cpu_conf.c    |  1 -
 src/conf/cpu_conf.h    |  1 -
 src/conf/domain_conf.c |  2 +-
 src/conf/numa_conf.c   | 23 +++++++++++++++++------
 src/conf/numa_conf.h   |  3 +++
 tests/testutilsqemu.c  |  1 -
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 4923618..0e3ce26 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -155,7 +155,6 @@ virCPUDefCopy(const virCPUDef *cpu)
             if (!copy->cells[i].cpumask)
                 goto error;
         }
-        copy->cells_cpus = cpu->cells_cpus;
     }

     return copy;
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 0163384..d2563e2 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -117,7 +117,6 @@ struct _virCPUDef {
     virCPUFeatureDefPtr features;
     size_t ncells;
     virCellDefPtr cells;
-    unsigned int cells_cpus;
 };


diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c9a65e1..870efc9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13501,7 +13501,7 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;

     if (def->cpu &&
-        def->cpu->cells_cpus > def->maxvcpus) {
+        virDomainNumaGetCPUCountTotal(def->cpu) > def->maxvcpus) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Number of CPUs in <numa> exceeds the"
                          " <vcpu> count"));
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index eea4172..41a7e01 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -713,7 +713,7 @@ virDomainNumaDefCPUParseXML(virCPUDefPtr def,
     def->ncells = n;

     for (i = 0; i < n; i++) {
-        int rc, ncpus = 0;
+        int rc;
         unsigned int cur_cell = i;

         /* cells are in order of parsing or explicitly numbered */
@@ -748,12 +748,10 @@ virDomainNumaDefCPUParseXML(virCPUDefPtr def,
             goto cleanup;
         }

-        ncpus = virBitmapParse(tmp, 0, &def->cells[cur_cell].cpumask,
-                               VIR_DOMAIN_CPUMASK_LEN);
-
-        if (ncpus <= 0)
+        if (virBitmapParse(tmp, 0, &def->cells[cur_cell].cpumask,
+                           VIR_DOMAIN_CPUMASK_LEN) <= 0)
             goto cleanup;
-        def->cells_cpus += ncpus;
+
         VIR_FREE(tmp);

         ctxt->node = nodes[i];
@@ -819,3 +817,16 @@ virDomainNumaDefCPUFormat(virBufferPtr buf,

     return 0;
 }
+
+
+unsigned int
+virDomainNumaGetCPUCountTotal(virCPUDefPtr numa)
+{
+    size_t i;
+    unsigned int ret = 0;
+
+    for (i = 0; i < numa->ncells; i++)
+        ret += virBitmapCountBits(numa->cells[i].cpumask);
+
+    return ret;
+}
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
index ca89e05..fa6b89b 100644
--- a/src/conf/numa_conf.h
+++ b/src/conf/numa_conf.h
@@ -125,4 +125,7 @@ bool virDomainNumatuneNodesetIsAvailable(virDomainNumaPtr numatune,
 int virDomainNumaDefCPUParseXML(virCPUDefPtr def, xmlXPathContextPtr ctxt);
 int virDomainNumaDefCPUFormat(virBufferPtr buf, virCPUDefPtr def);

+unsigned int virDomainNumaGetCPUCountTotal(virCPUDefPtr numa);
+
+
 #endif /* __NUMA_CONF_H__ */
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 64f709a..4a3df8a 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -244,7 +244,6 @@ virCapsPtr testQemuCapsInit(void)
         host_cpu_features,      /* features */
         0,                      /* ncells */
         NULL,                   /* cells */
-        0,                      /* cells_cpus */
     };

     if ((caps = virCapabilitiesNew(host_cpu.arch,
-- 
2.2.2




More information about the libvir-list mailing list