[PATCH 3/3] qemu: Generate -numa command line option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



qemu: Generate -numa option

From: Bharata B Rao <bharata@xxxxxxxxxxxxxxxxxx>

Add routines to generate -numa QEMU command line option based on
<numa> ... </numa> XML specifications.

Signed-off-by: Bharata B Rao <bharata@xxxxxxxxxxxxxxxxxx>
---

 src/qemu/qemu_command.c                            |   71 ++++++++++++++++++++
 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.args |    5 +
 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml  |   25 +++++++
 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args |    6 ++
 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml  |   25 +++++++
 tests/qemuxml2argvtest.c                           |    2 +
 6 files changed, 134 insertions(+), 0 deletions(-)
 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/qemu/qemu_command.c b/src/qemu/qemu_command.c
index dc92fa3..b042e34 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3251,6 +3251,74 @@ qemuBuildSmpArgStr(const virDomainDefPtr def,
     return virBufferContentAndReset(&buf);
 }
 
+static int
+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);
+    }
+
+    /* Remove the trailing comma */
+    return virBufferTruncate(buf, 1);
+}
+
+static int
+qemuBuildNumaArgStr(const virDomainDefPtr def, virCommandPtr cmd)
+{
+    int i;
+    char *node;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    for (i = 0; i < def->cpu->ncells; i++) {
+        virCommandAddArg(cmd, "-numa");
+        virBufferAsprintf(&buf, "%s", "node");
+        virBufferAsprintf(&buf, ",nodeid=%d", def->cpu->cells[i].cellid);
+        virBufferAsprintf(&buf, ",cpus=");
+
+        if (qemuBuildNumaCPUArgStr(def->cpu->cells[i].cpumask, &buf))
+            goto error;
+
+        virBufferAsprintf(&buf, ",mems=%d", def->cpu->cells[i].mem);
+
+        if (virBufferError(&buf))
+            goto error;
+
+        node = virBufferContentAndReset(&buf);
+        virCommandAddArg(cmd, node);
+        VIR_FREE(node);
+    }
+    return 0;
+
+error:
+    virBufferFreeAndReset(&buf);
+    virReportOOMError();
+    return -1;
+}
 
 /*
  * Constructs a argv suitable for launching qemu with config defined
@@ -3414,6 +3482,9 @@ qemuBuildCommandLine(virConnectPtr conn,
     virCommandAddArg(cmd, smp);
     VIR_FREE(smp);
 
+    if (def->cpu && def->cpu->ncells && qemuBuildNumaArgStr(def, cmd))
+        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 0000000..e8fd277
--- /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,mems=109550 \
+-numa node,nodeid=1,cpus=8-15,mems=109550 -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 0000000..07fe891
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa1.xml
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>16</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu>
+    <topology sockets="2" cores="4" threads="2"/>
+    <numa>
+      <cell cpus="0-7" mems="109550"/>
+      <cell cpus="8-15" mems="109550"/>
+    </numa>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/./qemu.sh</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.args
new file mode 100644
index 0000000..bc96cef
--- /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,mems=109550 \
+-numa node,nodeid=1,cpus=8-15,mems=109550 -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 0000000..07fe891
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa2.xml
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>16</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu>
+    <topology sockets="2" cores="4" threads="2"/>
+    <numa>
+      <cell cpus="0-7" mems="109550"/>
+      <cell cpus="8-15" mems="109550"/>
+    </numa>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/./qemu.sh</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 4d6db01..da8c016 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -578,6 +578,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);

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]