[libvirt] [PATCH v3 0/2] Numa : Allow specification of memory units

Present XML specification of NUMA node accepts memory in 'KiB' only. This series adds support for input of cell memory in units of choice. Description: ======= Patch 1/2 : Export virDomainParseMemory for use outside domain_conf Patch 2/2 : Allow specification of 'units' for NUMA nodes. Reference: ====== v1: http://www.spinics.net/linux/fedora/libvir/msg105516.html v2: http://www.mail-archive.com/libvir-list@redhat.com/msg104577.html Changes Since v2: =========== * Patch 1 is newly introduced. It follows Michal's suggestion of reusing virDomainParseMemory, exposed by 01b4de2b9f5ca82 * Patch 2 : Now uses virDomainParseMemory() * Also, documentation in patch 2 is now fixed to link to memory unit specification -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India

From 4978c8c2df19bdf738695d6cc64864f11071a08e Mon Sep 17 00:00:00 2001 From: Prerna Saxena <prerna@linux.vnet.ibm.com> Date: Mon, 10 Nov 2014 14:48:03 +0530
Commit 01b4de2b9f5ca82 abstracts virDomainParseMemory() for use by other functions in domain_conf.c Extend the same for use, for functions outside of this file. Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e8d8f7d..5909655 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6421,7 +6421,7 @@ virDomainParseScaledValue(const char *xpath, * * Return 0 on success, -1 on failure after issuing error. */ -static int +int virDomainParseMemory(const char *xpath, const char *units_xpath, xmlXPathContextPtr ctxt, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fbb3b2f..9fb05c8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2847,6 +2847,14 @@ int virDomainObjSetMetadata(virDomainObjPtr vm, const char *configDir, unsigned int flags); +int +virDomainParseMemory(const char *xpath, + const char *units_xpath, + xmlXPathContextPtr ctxt, + unsigned long long *mem, + bool required, + bool capped); + bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); -- 1.9.3 -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India

On 10.11.2014 12:52, Prerna Saxena wrote:
From 4978c8c2df19bdf738695d6cc64864f11071a08e Mon Sep 17 00:00:00 2001 From: Prerna Saxena <prerna@linux.vnet.ibm.com> Date: Mon, 10 Nov 2014 14:48:03 +0530
Commit 01b4de2b9f5ca82 abstracts virDomainParseMemory() for use by other functions in domain_conf.c Extend the same for use, for functions outside of this file.
Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e8d8f7d..5909655 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6421,7 +6421,7 @@ virDomainParseScaledValue(const char *xpath, * * Return 0 on success, -1 on failure after issuing error. */ -static int +int virDomainParseMemory(const char *xpath, const char *units_xpath, xmlXPathContextPtr ctxt, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fbb3b2f..9fb05c8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2847,6 +2847,14 @@ int virDomainObjSetMetadata(virDomainObjPtr vm, const char *configDir, unsigned int flags);
+int +virDomainParseMemory(const char *xpath, + const char *units_xpath, + xmlXPathContextPtr ctxt, + unsigned long long *mem, + bool required, + bool capped); + bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def) ATTRIBUTE_NONNULL(1);
Any symbol that is to be exported as an internal API must be in src/libvirt_private.syms. So ACK with this squashed in: diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7e38cc6..b8f35e8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -364,6 +364,7 @@ virDomainObjSetDefTransient; virDomainObjSetMetadata; virDomainObjSetState; virDomainObjTaint; +virDomainParseMemory; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; virDomainPMSuspendedReasonTypeFromString; Michal

From 1ead736712eec3bd098daf222a872c67b67e94ce Mon Sep 17 00:00:00 2001 From: Prerna Saxena <prerna@linux.vnet.ibm.com> Date: Mon, 3 Nov 2014 07:53:59 +0530
CPU numa topology implicitly allows memory specification in 'KiB'. Enabling this to accept the 'unit' in which memory needs to be specified. This now allows users to specify memory in units of choice, and lists the same in 'KiB' -- just like other 'memory' elements in XML. <numa> <cell cpus='0-3' memory='1024' unit='MiB' /> <cell cpus='4-7' memory='1024' unit='MiB' /> </numa> Also augment test cases to correctly model NUMA memory specification. This adds the tag 'unit="KiB"' for memory attribute in NUMA cells. Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com> --- docs/formatdomain.html.in | 8 +++- docs/schemas/domaincommon.rng | 5 +++ src/conf/cpu_conf.c | 44 ++++++++++++++-------- .../qemuxml2argv-cpu-numa-disjoint.xml | 4 +- .../qemuxml2argv-cpu-numa-memshared.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml | 4 +- .../qemuxml2argv-hugepages-pages.xml | 8 ++-- .../qemuxml2argv-hugepages-pages2.xml | 4 +- .../qemuxml2argv-hugepages-pages3.xml | 4 +- .../qemuxml2argv-hugepages-pages4.xml | 8 ++-- .../qemuxml2argv-hugepages-shared.xml | 8 ++-- .../qemuxml2argv-numatune-auto-prefer.xml | 2 +- .../qemuxml2argv-numatune-memnode-no-memory.xml | 4 +- .../qemuxml2argv-numatune-memnode.xml | 6 +-- .../qemuxml2argv-numatune-memnodes-problematic.xml | 4 +- .../qemuxml2xmlout-cpu-numa1.xml | 4 +- .../qemuxml2xmlout-cpu-numa2.xml | 4 +- .../qemuxml2xmlout-numatune-auto-prefer.xml | 2 +- .../qemuxml2xmlout-numatune-memnode.xml | 6 +-- 21 files changed, 81 insertions(+), 60 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 7196e75..f103a13 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1153,8 +1153,8 @@ <cpu> ... <numa> - <cell id='0' cpus='0-3' memory='512000'/> - <cell id='1' cpus='4-7' memory='512000' memAccess='shared'/> + <cell id='0' cpus='0-3' memory='512000' unit='KiB'/> + <cell id='1' cpus='4-7' memory='512000' unit='KiB' memAccess='shared'/> </numa> ... </cpu> @@ -1165,6 +1165,10 @@ <code>cpus</code> specifies the CPU or range of CPUs that are part of the node. <code>memory</code> specifies the node memory in kibibytes (i.e. blocks of 1024 bytes). + <span class="since">Since 1.2.11</span> one can specify an additional + <code>unit</code> attribute to describe the node memory unit. + The detailed syntax for allocation of memory units follows: + <a href="#elementsMemoryAllocation"><code>unit</code></a> <span class="since">Since 1.2.7</span> all cells should have <code>id</code> attribute in case referring to some cell is necessary in the code, otherwise the cells are diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 20d81ae..44cabad 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4144,6 +4144,11 @@ <ref name="memoryKB"/> </attribute> <optional> + <attribute name="unit"> + <ref name="unit"/> + </attribute> + </optional> + <optional> <attribute name="memAccess"> <choice> <value>shared</value> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 1c74c66..d0323b0 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -177,6 +177,30 @@ virCPUDefCopy(const virCPUDef *cpu) return NULL; } +static int +virCPUNumaCellMemoryParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned long long* cellMemory) +{ + int ret = -1; + xmlNodePtr oldnode = ctxt->node; + + ctxt->node = node; + + if (virDomainParseMemory("./@memory", "./@unit", ctxt, + cellMemory, true, false) < 0) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Unable to parse NUMA memory size attribute")); + goto cleanup; + } + + ret = 0; + cleanup: + ctxt->node = oldnode; + return ret; + +} + virCPUDefPtr virCPUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -440,7 +464,7 @@ virCPUDefParseXML(xmlNodePtr node, def->ncells = n; for (i = 0; i < n; i++) { - char *cpus, *memory, *memAccessStr; + char *cpus, *memAccessStr; int ret, ncpus = 0; unsigned int cur_cell; char *tmp = NULL; @@ -489,21 +513,8 @@ virCPUDefParseXML(xmlNodePtr node, goto error; def->cells_cpus += ncpus; - memory = virXMLPropString(nodes[i], "memory"); - if (!memory) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'memory' attribute in NUMA cell")); - goto error; - } - - ret = virStrToLong_ull(memory, NULL, 10, &def->cells[cur_cell].mem); - if (ret == -1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'memory' attribute in NUMA cell")); - VIR_FREE(memory); - goto error; - } - VIR_FREE(memory); + virCPUNumaCellMemoryParseXML(nodes[i], + ctxt, &def->cells[cur_cell].mem); memAccessStr = virXMLPropString(nodes[i], "memAccess"); if (memAccessStr) { @@ -704,6 +715,7 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, " id='%zu'", i); virBufferAsprintf(buf, " cpus='%s'", def->cells[i].cpustr); virBufferAsprintf(buf, " memory='%llu'", def->cells[i].mem); + virBufferAddLit(buf, " unit='KiB'"); if (memAccess) virBufferAsprintf(buf, " memAccess='%s'", virMemAccessTypeToString(memAccess)); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-disjoint.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-disjoint.xml index 474a238..bdffcd1 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-disjoint.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-disjoint.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='0' cpus='0-3,8-11' memory='109550'/> - <cell id='1' cpus='4-7,12-15' memory='109550'/> + <cell id='0' cpus='0-3,8-11' memory='109550' unit='KiB'/> + <cell id='1' cpus='4-7,12-15' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.xml index cf7c040..c638ffa 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='0' cpus='0-7' memory='109550' memAccess='shared'/> - <cell id='1' cpus='8-15' memory='109550' memAccess='private'/> + <cell id='0' cpus='0-7' memory='109550' unit='KiB' memAccess='shared'/> + <cell id='1' cpus='8-15' memory='109550' unit='KiB' memAccess='private'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml index 0543f7f..20120e9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell cpus='0-7' memory='109550'/> - <cell cpus='8-15' memory='109550'/> + <cell cpus='0-7' memory='109550' unit='KiB'/> + <cell cpus='8-15' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml index 0a5f9fc..a90e7a2 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='1' cpus='8-15' memory='109550'/> - <cell id='0' cpus='0-7' memory='109550'/> + <cell id='1' cpus='8-15' memory='109550' unit='KiB'/> + <cell id='0' cpus='0-7' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml index fa3070d..ea2dc81 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='1' cpus='0-7' memory='109550'/> - <cell id='2' cpus='8-15' memory='109550'/> + <cell id='1' cpus='0-7' memory='109550' unit='KiB'/> + <cell id='2' cpus='8-15' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages.xml index 5ad0695..b67df2f 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages.xml @@ -20,10 +20,10 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='1048576'/> - <cell id='1' cpus='1' memory='1048576'/> - <cell id='2' cpus='2' memory='1048576'/> - <cell id='3' cpus='3' memory='1048576'/> + <cell id='0' cpus='0' memory='1048576' unit='KiB'/> + <cell id='1' cpus='1' memory='1048576' unit='KiB'/> + <cell id='2' cpus='2' memory='1048576' unit='KiB'/> + <cell id='3' cpus='3' memory='1048576' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages2.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages2.xml index 3df870b..6afa6ef 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages2.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages2.xml @@ -15,8 +15,8 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='262144'/> - <cell id='1' cpus='1' memory='786432'/> + <cell id='0' cpus='0' memory='262144' unit='KiB'/> + <cell id='1' cpus='1' memory='786432' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.xml index 35aa2cf..21f4985 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.xml @@ -15,8 +15,8 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='262144'/> - <cell id='1' cpus='1' memory='786432'/> + <cell id='0' cpus='0' memory='262144' unit='KiB'/> + <cell id='1' cpus='1' memory='786432' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml index a3ed29b..eb18f24 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml @@ -20,10 +20,10 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='1048576'/> - <cell id='1' cpus='1' memory='1048576'/> - <cell id='2' cpus='2' memory='1048576'/> - <cell id='3' cpus='3' memory='1048576'/> + <cell id='0' cpus='0' memory='1048576' unit='KiB'/> + <cell id='1' cpus='1' memory='1048576' unit='KiB'/> + <cell id='2' cpus='2' memory='1048576' unit='KiB'/> + <cell id='3' cpus='3' memory='1048576' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-shared.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-shared.xml index e7db69c..52ca2f9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-shared.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-shared.xml @@ -20,10 +20,10 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='1048576'/> - <cell id='1' cpus='1' memory='1048576' memAccess='shared'/> - <cell id='2' cpus='2' memory='1048576' memAccess='private'/> - <cell id='3' cpus='3' memory='1048576'/> + <cell id='0' cpus='0' memory='1048576' unit='KiB'/> + <cell id='1' cpus='1' memory='1048576' unit='KiB' memAccess='shared'/> + <cell id='2' cpus='2' memory='1048576' unit='KiB' memAccess='private'/> + <cell id='3' cpus='3' memory='1048576' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.xml b/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.xml index 63f0d1f..8f80962 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.xml @@ -13,7 +13,7 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='65536'/> + <cell id='0' cpus='0' memory='65536' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.xml b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.xml index 4b2efa2..886a07a 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.xml @@ -13,8 +13,8 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='32768'/> - <cell id='1' cpus='1' memory='32768'/> + <cell id='0' cpus='0' memory='32768' unit='KiB'/> + <cell id='1' cpus='1' memory='32768' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode.xml b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode.xml index 440413b..8912017 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode.xml @@ -15,9 +15,9 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='20002'/> - <cell id='1' cpus='1-27,29' memory='660066'/> - <cell id='2' cpus='28-31,^29' memory='24002400'/> + <cell id='0' cpus='0' memory='20002' unit='KiB'/> + <cell id='1' cpus='1-27,29' memory='660066' unit='KiB'/> + <cell id='2' cpus='28-31,^29' memory='24002400' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnodes-problematic.xml b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnodes-problematic.xml index bb4e4af..e1d115c 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnodes-problematic.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnodes-problematic.xml @@ -14,8 +14,8 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='32768'/> - <cell id='1' cpus='1' memory='32768'/> + <cell id='0' cpus='0' memory='32768' unit='KiB'/> + <cell id='1' cpus='1' memory='32768' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa1.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa1.xml index 227bf1c..58f40b9 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa1.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa1.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='0' cpus='0-7' memory='109550'/> - <cell id='1' cpus='8-15' memory='109550'/> + <cell id='0' cpus='0-7' memory='109550' unit='KiB'/> + <cell id='1' cpus='8-15' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa2.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa2.xml index 227bf1c..58f40b9 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa2.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa2.xml @@ -11,8 +11,8 @@ <cpu> <topology sockets='2' cores='4' threads='2'/> <numa> - <cell id='0' cpus='0-7' memory='109550'/> - <cell id='1' cpus='8-15' memory='109550'/> + <cell id='0' cpus='0-7' memory='109550' unit='KiB'/> + <cell id='1' cpus='8-15' memory='109550' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-auto-prefer.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-auto-prefer.xml index 19761b4..1000e9f 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-auto-prefer.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-auto-prefer.xml @@ -13,7 +13,7 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='65536'/> + <cell id='0' cpus='0' memory='65536' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-memnode.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-memnode.xml index 82b5f61..ffc57cf 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-memnode.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-numatune-memnode.xml @@ -15,9 +15,9 @@ </os> <cpu> <numa> - <cell id='0' cpus='0' memory='20002'/> - <cell id='1' cpus='1-27,29' memory='660066'/> - <cell id='2' cpus='28-31,^29' memory='24002400'/> + <cell id='0' cpus='0' memory='20002' unit='KiB'/> + <cell id='1' cpus='1-27,29' memory='660066' unit='KiB'/> + <cell id='2' cpus='28-31,^29' memory='24002400' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> -- 1.9.3 -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India

On 10.11.2014 12:52, Prerna Saxena wrote:
From 1ead736712eec3bd098daf222a872c67b67e94ce Mon Sep 17 00:00:00 2001 From: Prerna Saxena <prerna@linux.vnet.ibm.com> Date: Mon, 3 Nov 2014 07:53:59 +0530
CPU numa topology implicitly allows memory specification in 'KiB'.
Enabling this to accept the 'unit' in which memory needs to be specified. This now allows users to specify memory in units of choice, and lists the same in 'KiB' -- just like other 'memory' elements in XML.
<numa> <cell cpus='0-3' memory='1024' unit='MiB' /> <cell cpus='4-7' memory='1024' unit='MiB' /> </numa>
Also augment test cases to correctly model NUMA memory specification. This adds the tag 'unit="KiB"' for memory attribute in NUMA cells.
Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com> --- docs/formatdomain.html.in | 8 +++- docs/schemas/domaincommon.rng | 5 +++ src/conf/cpu_conf.c | 44 ++++++++++++++-------- .../qemuxml2argv-cpu-numa-disjoint.xml | 4 +- .../qemuxml2argv-cpu-numa-memshared.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml | 4 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa3.xml | 4 +- .../qemuxml2argv-hugepages-pages.xml | 8 ++-- .../qemuxml2argv-hugepages-pages2.xml | 4 +- .../qemuxml2argv-hugepages-pages3.xml | 4 +- .../qemuxml2argv-hugepages-pages4.xml | 8 ++-- .../qemuxml2argv-hugepages-shared.xml | 8 ++-- .../qemuxml2argv-numatune-auto-prefer.xml | 2 +- .../qemuxml2argv-numatune-memnode-no-memory.xml | 4 +- .../qemuxml2argv-numatune-memnode.xml | 6 +-- .../qemuxml2argv-numatune-memnodes-problematic.xml | 4 +- .../qemuxml2xmlout-cpu-numa1.xml | 4 +- .../qemuxml2xmlout-cpu-numa2.xml | 4 +- .../qemuxml2xmlout-numatune-auto-prefer.xml | 2 +- .../qemuxml2xmlout-numatune-memnode.xml | 6 +-- 21 files changed, 81 insertions(+), 60 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 7196e75..f103a13 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1153,8 +1153,8 @@ <cpu> ... <numa> - <cell id='0' cpus='0-3' memory='512000'/> - <cell id='1' cpus='4-7' memory='512000' memAccess='shared'/> + <cell id='0' cpus='0-3' memory='512000' unit='KiB'/> + <cell id='1' cpus='4-7' memory='512000' unit='KiB' memAccess='shared'/> </numa> ... </cpu> @@ -1165,6 +1165,10 @@ <code>cpus</code> specifies the CPU or range of CPUs that are part of the node. <code>memory</code> specifies the node memory in kibibytes (i.e. blocks of 1024 bytes). + <span class="since">Since 1.2.11</span> one can specify an additional + <code>unit</code> attribute to describe the node memory unit. + The detailed syntax for allocation of memory units follows: + <a href="#elementsMemoryAllocation"><code>unit</code></a> <span class="since">Since 1.2.7</span> all cells should have <code>id</code> attribute in case referring to some cell is necessary in the code, otherwise the cells are diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 20d81ae..44cabad 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4144,6 +4144,11 @@ <ref name="memoryKB"/> </attribute> <optional> + <attribute name="unit"> + <ref name="unit"/> + </attribute> + </optional> + <optional> <attribute name="memAccess"> <choice> <value>shared</value> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 1c74c66..d0323b0 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -177,6 +177,30 @@ virCPUDefCopy(const virCPUDef *cpu) return NULL; }
+static int +virCPUNumaCellMemoryParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned long long* cellMemory) +{ + int ret = -1; + xmlNodePtr oldnode = ctxt->node; + + ctxt->node = node; + + if (virDomainParseMemory("./@memory", "./@unit", ctxt, + cellMemory, true, false) < 0) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Unable to parse NUMA memory size attribute"));
There's no need for virReportError() here. The helper reported error already.
+ goto cleanup; + } + + ret = 0; + cleanup: + ctxt->node = oldnode; + return ret; + +} +
Huh, I don't think it's necessary to have this as a function, but compiler will surely optimize it. So I can live with this as-is.
virCPUDefPtr virCPUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -440,7 +464,7 @@ virCPUDefParseXML(xmlNodePtr node, def->ncells = n;
for (i = 0; i < n; i++) { - char *cpus, *memory, *memAccessStr; + char *cpus, *memAccessStr; int ret, ncpus = 0; unsigned int cur_cell; char *tmp = NULL; @@ -489,21 +513,8 @@ virCPUDefParseXML(xmlNodePtr node, goto error; def->cells_cpus += ncpus;
- memory = virXMLPropString(nodes[i], "memory"); - if (!memory) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'memory' attribute in NUMA cell")); - goto error; - } - - ret = virStrToLong_ull(memory, NULL, 10, &def->cells[cur_cell].mem); - if (ret == -1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'memory' attribute in NUMA cell")); - VIR_FREE(memory); - goto error; - } - VIR_FREE(memory); + virCPUNumaCellMemoryParseXML(nodes[i], + ctxt, &def->cells[cur_cell].mem);
What I can't live with is ignoring return value here.
memAccessStr = virXMLPropString(nodes[i], "memAccess"); if (memAccessStr) { @@ -704,6 +715,7 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, " id='%zu'", i); virBufferAsprintf(buf, " cpus='%s'", def->cells[i].cpustr); virBufferAsprintf(buf, " memory='%llu'", def->cells[i].mem); + virBufferAddLit(buf, " unit='KiB'"); if (memAccess) virBufferAsprintf(buf, " memAccess='%s'", virMemAccessTypeToString(memAccess));
So ACK with this squashed in: diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index d0323b0..0604eab 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -513,8 +513,9 @@ virCPUDefParseXML(xmlNodePtr node, goto error; def->cells_cpus += ncpus; - virCPUNumaCellMemoryParseXML(nodes[i], - ctxt, &def->cells[cur_cell].mem); + if (virCPUNumaCellMemoryParseXML(nodes[i], ctxt, + &def->cells[cur_cell].mem) < 0) + goto error; memAccessStr = virXMLPropString(nodes[i], "memAccess"); if (memAccessStr) { However, since I need to modify the patch anyway, I'm gonna drop the virCPUNumaCellMemoryParseXML() function and call virDomainParseMemory() directly. ACK once I fix the issues. Michal

On 10.11.2014 12:49, Prerna Saxena wrote:
Present XML specification of NUMA node accepts memory in 'KiB' only. This series adds support for input of cell memory in units of choice.
Description: ======= Patch 1/2 : Export virDomainParseMemory for use outside domain_conf Patch 2/2 : Allow specification of 'units' for NUMA nodes.
Reference: ====== v1: http://www.spinics.net/linux/fedora/libvir/msg105516.html v2: http://www.mail-archive.com/libvir-list@redhat.com/msg104577.html
Changes Since v2: =========== * Patch 1 is newly introduced. It follows Michal's suggestion of reusing virDomainParseMemory, exposed by 01b4de2b9f5ca82 * Patch 2 : Now uses virDomainParseMemory() * Also, documentation in patch 2 is now fixed to link to memory unit specification
I've fixed the issues and pushed this. Michal

On Monday 10 November 2014 07:36 PM, Michal Privoznik wrote:
On 10.11.2014 12:49, Prerna Saxena wrote:
Present XML specification of NUMA node accepts memory in 'KiB' only. This series adds support for input of cell memory in units of choice.
Description: ======= Patch 1/2 : Export virDomainParseMemory for use outside domain_conf Patch 2/2 : Allow specification of 'units' for NUMA nodes.
Reference: ====== v1: http://www.spinics.net/linux/fedora/libvir/msg105516.html v2: http://www.mail-archive.com/libvir-list@redhat.com/msg104577.html
Changes Since v2: =========== * Patch 1 is newly introduced. It follows Michal's suggestion of reusing virDomainParseMemory, exposed by 01b4de2b9f5ca82 * Patch 2 : Now uses virDomainParseMemory() * Also, documentation in patch 2 is now fixed to link to memory unit specification
I've fixed the issues and pushed this.
Thanks, I'll make sure I remember these points in the subsequent libvirt patches I send :-) -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India
participants (2)
-
Michal Privoznik
-
Prerna Saxena