render / rpms / libvirt

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

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

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