Re: [libvirt] [PATCH v2] Memory : Allow specification of 'units' for numa nodes.
On 07.11.2014 12:17, Prerna Saxena wrote: Reference : === v1: http://www.spinics.net/linux/fedora/libvir/msg105516.html Changes since v1: === 1) As suggested by Michal, a new function "virCPUNumaCellMemoryParseXML" has been introduced for neat computation of NUMA memory. 2) Patches 2 & 3 of v1 have been merged together into this cumulative patch. 3) Corresponding documentation added. From 2199d97b88cf9eab29788fb0e440c4b0a0bb23ec Mon Sep 17 00:00:00 2001 From: Prerna Saxena 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. 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 --- docs/formatdomain.html.in | 6 ++- docs/schemas/domaincommon.rng | 5 ++ src/conf/cpu_conf.c| 62 -- .../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, 97 insertions(+), 60 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0099ce7..24afc87 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1140,8 +1140,8 @@... @@ -1152,6 +1152,8 @@ cpus specifies the CPU or range of CPUs that are part of the node. memory specifies the node memory in kibibytes (i.e. blocks of 1024 bytes). + Since 1.2.11 one can specify an additional + unit attribute to describe the node memory unit. I'd make "unit" a link to that part of docs, which explains what values are accepted and what scale they refer to. Since 1.2.7 all cells should have id 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 @@ + + + + + shared diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 5475c07..a0a60c8 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -177,6 +177,48 @@ virCPUDefCopy(const virCPUDef *cpu) return NULL; } +static int +virCPUNumaCellMemoryParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned long long* cellMemory) +{ +int ret = -1; +xmlNodePtr oldnode = ctxt->node; +unsigned long long bytes, max; +char *unit = NULL; + +ctxt->node = node; + +/* 32 vs 64 bit will differ in value of upper memory bound. + * On 32-bit machines, our bound is 0x * KiB. On 64-bit + * machines, our bound is off_t (2^63). + */ +if (sizeof(unsigned long) < sizeof(long long)) +max = 1024ull * ULONG_MAX; +else +max = LLONG_MAX; + +if (virXPathULongLong("string(./@memory)", ctxt, &bytes) < 0) { +virReportError(VIR_ERR_XML_DETAIL, "%s", + _("unable to parse memory size attribute")); +goto cleanup; +} + +unit = virXPathString("string(./@unit)", ctxt); + +if (virScaleInteger(&bytes, unit, 1024, max) < 0) +goto cleanup; + +*cellMemory = VIR_DIV_UP(bytes, 102- ...- | + | + | |
[libvirt] [PATCH v2] Memory : Allow specification of 'units' for numa nodes.
Reference : === v1: http://www.spinics.net/linux/fedora/libvir/msg105516.html Changes since v1: === 1) As suggested by Michal, a new function "virCPUNumaCellMemoryParseXML" has been introduced for neat computation of NUMA memory. 2) Patches 2 & 3 of v1 have been merged together into this cumulative patch. 3) Corresponding documentation added. >From 2199d97b88cf9eab29788fb0e440c4b0a0bb23ec Mon Sep 17 00:00:00 2001 From: Prerna Saxena 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. 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 --- docs/formatdomain.html.in | 6 ++- docs/schemas/domaincommon.rng | 5 ++ src/conf/cpu_conf.c| 62 -- .../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, 97 insertions(+), 60 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0099ce7..24afc87 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1140,8 +1140,8 @@... @@ -1152,6 +1152,8 @@ cpus specifies the CPU or range of CPUs that are part of the node. memory specifies the node memory in kibibytes (i.e. blocks of 1024 bytes). + Since 1.2.11 one can specify an additional + unit attribute to describe the node memory unit. Since 1.2.7 all cells should have id 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 @@ + + + + + shared diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 5475c07..a0a60c8 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -177,6 +177,48 @@ virCPUDefCopy(const virCPUDef *cpu) return NULL; } +static int +virCPUNumaCellMemoryParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned long long* cellMemory) +{ +int ret = -1; +xmlNodePtr oldnode = ctxt->node; +unsigned long long bytes, max; +char *unit = NULL; + +ctxt->node = node; + +/* 32 vs 64 bit will differ in value of upper memory bound. + * On 32-bit machines, our bound is 0x * KiB. On 64-bit + * machines, our bound is off_t (2^63). + */ +if (sizeof(unsigned long) < sizeof(long long)) +max = 1024ull * ULONG_MAX; +else +max = LLONG_MAX; + +if (virXPathULongLong("string(./@memory)", ctxt, &bytes) < 0) { +virReportError(VIR_ERR_XML_DETAIL, "%s", + _("unable to parse memory size attribute")); +goto cleanup; +} + +unit = virXPathString("string(./@unit)", ctxt); + +if (virScaleInteger(&bytes, unit, 1024, max) < 0) +goto cleanup; + +*cellMemory = VIR_DIV_UP(bytes, 1024); + +ret = 0; + cleanup: +VIR_FREE(unit); +ctxt->node = oldnode; +return ret; + +} + virCPUDefPtr virCPUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -440,7 +48- ...- | + | + | |