404507
From da9b2f15ee80396d542057340a576cf65828191a Mon Sep 17 00:00:00 2001
404507
Message-Id: <da9b2f15ee80396d542057340a576cf65828191a@dist-git>
404507
From: Michal Privoznik <mprivozn@redhat.com>
404507
Date: Mon, 4 Dec 2017 13:38:52 +0100
404507
Subject: [PATCH] qemu: Support setting NUMA distances
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1454889
404507
404507
Since we already have such support for libxl all we need is qemu
404507
driver adjustment. And a test case.
404507
404507
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
404507
Reviewed-by: John Ferlan <jferlan@redhat.com>
404507
(cherry picked from commit 97a051f0f80ec076f3ff48ef830236675f128ade)
404507
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 docs/formatdomain.html.in                          |  2 +-
404507
 src/qemu/qemu_command.c                            | 39 ++++++++++++-
404507
 .../qemuxml2argv-numatune-distances.args           | 63 +++++++++++++++++++++
404507
 .../qemuxml2argv-numatune-distances.xml            | 65 ++++++++++++++++++++++
404507
 tests/qemuxml2argvtest.c                           |  2 +
404507
 5 files changed, 169 insertions(+), 2 deletions(-)
404507
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.args
404507
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.xml
404507
404507
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
404507
index a5adf5d9aa..cc1c5577cd 100644
404507
--- a/docs/formatdomain.html.in
404507
+++ b/docs/formatdomain.html.in
404507
@@ -1589,7 +1589,7 @@
404507
 
404507
     

404507
       Describing distances between NUMA cells is currently only supported
404507
-      by Xen. If no distances are given to describe
404507
+      by Xen and QEMU. If no distances are given to describe
404507
       the SLIT data between different cells, it will default to a scheme
404507
       using 10 for local and 20 for remote distances.
404507
     

404507
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
404507
index 18977480d9..624a50d0b3 100644
404507
--- a/src/qemu/qemu_command.c
404507
+++ b/src/qemu/qemu_command.c
404507
@@ -7807,7 +7807,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
404507
                     virCommandPtr cmd,
404507
                     qemuDomainObjPrivatePtr priv)
404507
 {
404507
-    size_t i;
404507
+    size_t i, j;
404507
     virQEMUCapsPtr qemuCaps = priv->qemuCaps;
404507
     virBuffer buf = VIR_BUFFER_INITIALIZER;
404507
     char *cpumask = NULL, *tmpmask = NULL, *next = NULL;
404507
@@ -7817,6 +7817,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
404507
     int ret = -1;
404507
     size_t ncells = virDomainNumaGetNodeCount(def->numa);
404507
     const long system_page_size = virGetSystemPageSizeKB();
404507
+    bool numa_distances = false;
404507
 
404507
     if (virDomainNumatuneHasPerNodeBinding(def->numa) &&
404507
         !(virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) ||
404507
@@ -7925,6 +7926,42 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
404507
 
404507
         virCommandAddArgBuffer(cmd, &buf;;
404507
     }
404507
+
404507
+    /* If NUMA node distance is specified for at least one pair
404507
+     * of nodes, we have to specify all the distances. Even
404507
+     * though they might be the default ones. */
404507
+    for (i = 0; i < ncells; i++) {
404507
+        for (j = 0; j < ncells; j++) {
404507
+            if (virDomainNumaNodeDistanceIsUsingDefaults(def->numa, i, j))
404507
+                continue;
404507
+
404507
+            numa_distances = true;
404507
+            break;
404507
+        }
404507
+        if (numa_distances)
404507
+            break;
404507
+    }
404507
+
404507
+    if (numa_distances) {
404507
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NUMA_DIST)) {
404507
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
+                           _("setting NUMA distances is not "
404507
+                             "supported with this qemu"));
404507
+            goto cleanup;
404507
+        }
404507
+
404507
+        for (i = 0; i < ncells; i++) {
404507
+            for (j = 0; j < ncells; j++) {
404507
+                size_t distance = virDomainNumaGetNodeDistance(def->numa, i, j);
404507
+
404507
+                virCommandAddArg(cmd, "-numa");
404507
+                virBufferAsprintf(&buf, "dist,src=%zu,dst=%zu,val=%zu", i, j, distance);
404507
+
404507
+                virCommandAddArgBuffer(cmd, &buf;;
404507
+            }
404507
+        }
404507
+    }
404507
+
404507
     ret = 0;
404507
 
404507
  cleanup:
404507
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.args b/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.args
404507
new file mode 100644
404507
index 0000000000..23b66246c7
404507
--- /dev/null
404507
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.args
404507
@@ -0,0 +1,63 @@
404507
+LC_ALL=C \
404507
+PATH=/bin \
404507
+HOME=/home/test \
404507
+USER=test \
404507
+LOGNAME=test \
404507
+QEMU_AUDIO_DRV=none \
404507
+/usr/bin/qemu-system-x86_64 \
404507
+-name QEMUGuest \
404507
+-S \
404507
+-M xenfv \
404507
+-m 12288 \
404507
+-smp 12,sockets=12,cores=1,threads=1 \
404507
+-numa node,nodeid=0,cpus=0,cpus=11,mem=2048 \
404507
+-numa node,nodeid=1,cpus=1,cpus=10,mem=2048 \
404507
+-numa node,nodeid=2,cpus=2,cpus=9,mem=2048 \
404507
+-numa node,nodeid=3,cpus=3,cpus=8,mem=2048 \
404507
+-numa node,nodeid=4,cpus=4,cpus=7,mem=2048 \
404507
+-numa node,nodeid=5,cpus=5-6,mem=2048 \
404507
+-numa dist,src=0,dst=0,val=10 \
404507
+-numa dist,src=0,dst=1,val=21 \
404507
+-numa dist,src=0,dst=2,val=31 \
404507
+-numa dist,src=0,dst=3,val=41 \
404507
+-numa dist,src=0,dst=4,val=51 \
404507
+-numa dist,src=0,dst=5,val=61 \
404507
+-numa dist,src=1,dst=0,val=21 \
404507
+-numa dist,src=1,dst=1,val=10 \
404507
+-numa dist,src=1,dst=2,val=21 \
404507
+-numa dist,src=1,dst=3,val=31 \
404507
+-numa dist,src=1,dst=4,val=41 \
404507
+-numa dist,src=1,dst=5,val=51 \
404507
+-numa dist,src=2,dst=0,val=31 \
404507
+-numa dist,src=2,dst=1,val=21 \
404507
+-numa dist,src=2,dst=2,val=10 \
404507
+-numa dist,src=2,dst=3,val=21 \
404507
+-numa dist,src=2,dst=4,val=31 \
404507
+-numa dist,src=2,dst=5,val=41 \
404507
+-numa dist,src=3,dst=0,val=41 \
404507
+-numa dist,src=3,dst=1,val=31 \
404507
+-numa dist,src=3,dst=2,val=21 \
404507
+-numa dist,src=3,dst=3,val=10 \
404507
+-numa dist,src=3,dst=4,val=21 \
404507
+-numa dist,src=3,dst=5,val=31 \
404507
+-numa dist,src=4,dst=0,val=51 \
404507
+-numa dist,src=4,dst=1,val=41 \
404507
+-numa dist,src=4,dst=2,val=31 \
404507
+-numa dist,src=4,dst=3,val=21 \
404507
+-numa dist,src=4,dst=4,val=10 \
404507
+-numa dist,src=4,dst=5,val=21 \
404507
+-numa dist,src=5,dst=0,val=61 \
404507
+-numa dist,src=5,dst=1,val=51 \
404507
+-numa dist,src=5,dst=2,val=41 \
404507
+-numa dist,src=5,dst=3,val=31 \
404507
+-numa dist,src=5,dst=4,val=21 \
404507
+-numa dist,src=5,dst=5,val=10 \
404507
+-uuid c7a5fdb2-cdaf-9455-926a-d65c16db1809 \
404507
+-nographic \
404507
+-nodefaults \
404507
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest/monitor.sock,\
404507
+server,nowait \
404507
+-mon chardev=charmonitor,id=monitor,mode=readline \
404507
+-boot c \
404507
+-usb \
404507
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2
404507
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.xml b/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.xml
404507
new file mode 100644
404507
index 0000000000..0f33526b46
404507
--- /dev/null
404507
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-distances.xml
404507
@@ -0,0 +1,65 @@
404507
+<domain type='qemu'>
404507
+  <name>QEMUGuest</name>
404507
+  <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
404507
+  <memory unit='KiB'>8388608</memory>
404507
+  <currentMemory unit='KiB'>8388608</currentMemory>
404507
+  <vcpu placement='static'>12</vcpu>
404507
+  <os>
404507
+    <type arch='x86_64' machine='xenfv'>hvm</type>
404507
+    <boot dev='hd'/>
404507
+  </os>
404507
+  <features>
404507
+    <acpi/>
404507
+    <apic/>
404507
+    <pae/>
404507
+  </features>
404507
+  <cpu>
404507
+    <numa>
404507
+      <cell id='0' cpus='0,11' memory='2097152' unit='KiB'>
404507
+        <distances>
404507
+          <sibling id='1' value='21'/>
404507
+          <sibling id='2' value='31'/>
404507
+          <sibling id='3' value='41'/>
404507
+          <sibling id='4' value='51'/>
404507
+          <sibling id='5' value='61'/>
404507
+        </distances>
404507
+      </cell>
404507
+      <cell id='1' cpus='1,10' memory='2097152' unit='KiB'>
404507
+        <distances>
404507
+          <sibling id='2' value='21'/>
404507
+          <sibling id='3' value='31'/>
404507
+          <sibling id='4' value='41'/>
404507
+          <sibling id='5' value='51'/>
404507
+        </distances>
404507
+      </cell>
404507
+      <cell id='2' cpus='2,9' memory='2097152' unit='KiB'>
404507
+        <distances>
404507
+          <sibling id='3' value='21'/>
404507
+          <sibling id='4' value='31'/>
404507
+          <sibling id='5' value='41'/>
404507
+        </distances>
404507
+      </cell>
404507
+      <cell id='3' cpus='3,8' memory='2097152' unit='KiB'>
404507
+        <distances>
404507
+          <sibling id='4' value='21'/>
404507
+          <sibling id='5' value='31'/>
404507
+        </distances>
404507
+      </cell>
404507
+      <cell id='4' cpus='4,7' memory='2097152' unit='KiB'>
404507
+        <distances>
404507
+          <sibling id='5' value='21'/>
404507
+        </distances>
404507
+      </cell>
404507
+      <cell id='5' cpus='5-6' memory='2097152' unit='KiB'/>
404507
+    </numa>
404507
+  </cpu>
404507
+  <on_poweroff>destroy</on_poweroff>
404507
+  <on_reboot>restart</on_reboot>
404507
+  <on_crash>restart</on_crash>
404507
+  <devices>
404507
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
404507
+    <controller type='usb' index='0'/>
404507
+    <controller type='pci' index='0' model='pci-root'/>
404507
+    <memballoon model='virtio'/>
404507
+  </devices>
404507
+</domain>
404507
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
404507
index 77c9783929..72cefe4906 100644
404507
--- a/tests/qemuxml2argvtest.c
404507
+++ b/tests/qemuxml2argvtest.c
404507
@@ -1726,6 +1726,8 @@ mymain(void)
404507
                   QEMU_CAPS_OBJECT_MEMORY_RAM);
404507
     DO_TEST_FAILURE("numatune-memnode-no-memory", NONE);
404507
 
404507
+    DO_TEST("numatune-distances", QEMU_CAPS_NUMA, QEMU_CAPS_NUMA_DIST);
404507
+
404507
     DO_TEST("numatune-auto-nodeset-invalid", NONE);
404507
     DO_TEST("numatune-auto-prefer", QEMU_CAPS_OBJECT_MEMORY_RAM,
404507
             QEMU_CAPS_OBJECT_MEMORY_FILE);
404507
-- 
404507
2.15.1
404507