From 6b6166329fe18c23c69cf76c186c31e404515721 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 12 Feb 2015 09:37:13 +0100 Subject: [PATCH] conf: numa: Recalculate rather than remember total NUMA cpu count It's easier to recalculate the number in the one place it's used as having a separate variable 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 49236186e..0e3ce26a3 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 01633840f..d2563e2b8 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 cddbd50be..e399a3301 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 exceeds the" " count")); diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index dfd260637..d21d62e74 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 107c83f5c..efb1bf01e 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -128,4 +128,7 @@ bool virDomainNumatuneNodeSpecified(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 64f709ae6..4a3df8ab2 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.39.5