From 9b6bb0fef64a944e2c6808d6b449fbb636e6ce53 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 11 Nov 2011 18:23:04 +0530 Subject: [PATCH] qemu: Generate -numa option Add routines to generate -numa QEMU command line option based on ... XML specifications. Signed-off-by: Bharata B Rao --- src/conf/cpu_conf.c | 3 +- src/qemu/qemu_command.c | 63 +++++++++++++++++++ .../qemuxml2argv-cpu-numa1.args | 5 ++ .../qemuxml2argv-cpu-numa1.xml | 25 ++++++++ .../qemuxml2argv-cpu-numa2.args | 6 ++ .../qemuxml2argv-cpu-numa2.xml | 25 ++++++++ tests/qemuxml2argvtest.c | 2 + 7 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 4aabe98525..7c5bf69a37 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -352,11 +352,12 @@ virCPUDefParseXML(const xmlNodePtr node, ret = virStrToLong_ui(memory, NULL, 10, &def->cells[i].mem); if (ret == -1) { + virCPUReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Invalid 'memory' attribute in NUMA cell")); VIR_FREE(cpus); VIR_FREE(memory); goto error; } - VIR_FREE(cpus); VIR_FREE(memory); } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index bb1201695d..03a3fe207f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3401,6 +3401,65 @@ qemuBuildSmpArgStr(const virDomainDefPtr def, return virBufferContentAndReset(&buf); } +static void +qemuBuildNumaCPUArgStr(char *cpumask, virBufferPtr buf) +{ + int i, first, last; + int cpuSet = 0; + + for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) { + if (cpumask[i]) { + if (cpuSet) { + last = i; + } else { + first = last = i; + cpuSet = 1; + } + } else { + if (!cpuSet) + continue; + if (first == last) + virBufferAsprintf(buf, "%d,", first); + else + virBufferAsprintf(buf, "%d-%d,", first, last); + cpuSet = 0; + } + } + + if (cpuSet) { + if (first == last) + virBufferAsprintf(buf, "%d,", first); + else + virBufferAsprintf(buf, "%d-%d,", first, last); + } +} + +static int +qemuBuildNumaArgStr(const virDomainDefPtr def, virCommandPtr cmd) +{ + int i; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + for (i = 0; i < def->cpu->ncells; i++) { + virCommandAddArg(cmd, "-numa"); + virBufferAsprintf(&buf, "node,nodeid=%d", def->cpu->cells[i].cellid); + virBufferAddLit(&buf, ",cpus="); + qemuBuildNumaCPUArgStr(def->cpu->cells[i].cpumask, &buf); + virBufferAsprintf(&buf, "mem=%d", + VIR_DIV_UP(def->cpu->cells[i].mem, 1024)); + + if (virBufferError(&buf)) + goto error; + + virCommandAddArgBuffer(cmd, &buf); + } + return 0; + +error: + virBufferFreeAndReset(&buf); + virReportOOMError(); + return -1; +} /* * Constructs a argv suitable for launching qemu with config defined @@ -3562,6 +3621,10 @@ qemuBuildCommandLine(virConnectPtr conn, virCommandAddArg(cmd, smp); VIR_FREE(smp); + if (def->cpu && def->cpu->ncells) + if (qemuBuildNumaArgStr(def, cmd) < 0) + goto error; + if (qemuCapsGet(qemuCaps, QEMU_CAPS_NAME)) { virCommandAddArg(cmd, "-name"); if (driver->setProcessName && diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.args new file mode 100644 index 0000000000..7c0dd3029e --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \ +-m 214 -smp 16 -numa node,nodeid=0,cpus=0-7,mem=107 \ +-numa node,nodeid=1,cpus=8-15,mem=107 -nographic -monitor \ +unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \ +-parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml new file mode 100644 index 0000000000..9fcdda82ab --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 16 + + hvm + + + + + + + + + + + destroy + restart + destroy + + /./qemu.sh + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args new file mode 100644 index 0000000000..2ac25683c7 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args @@ -0,0 +1,6 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \ +-m 214 -smp 16,sockets=2,cores=4,threads=2 \ +-numa node,nodeid=0,cpus=0-7,mem=107 \ +-numa node,nodeid=1,cpus=8-15,mem=107 -nographic -monitor \ +unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \ +-parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml new file mode 100644 index 0000000000..9fcdda82ab --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 16 + + hvm + + + + + + + + + + + destroy + restart + destroy + + /./qemu.sh + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 3cd27bb14a..b54dc982ca 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -638,6 +638,8 @@ mymain(void) DO_TEST("cpu-exact1", false, NONE); DO_TEST("cpu-exact2", false, NONE); DO_TEST("cpu-strict1", false, NONE); + DO_TEST("cpu-numa1", false, NONE); + DO_TEST("cpu-numa2", false, QEMU_CAPS_SMP_TOPOLOGY); DO_TEST("memtune", false, QEMU_CAPS_NAME); DO_TEST("blkiotune", false, QEMU_CAPS_NAME);