render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
79b470
From fe08906feb3ab006c4013957895cfb4fa69b7396 Mon Sep 17 00:00:00 2001
79b470
Message-Id: <fe08906feb3ab006c4013957895cfb4fa69b7396@dist-git>
79b470
From: Michal Privoznik <mprivozn@redhat.com>
79b470
Date: Wed, 7 Oct 2020 18:45:43 +0200
79b470
Subject: [PATCH] qemu: Build HMAT command line
79b470
MIME-Version: 1.0
79b470
Content-Type: text/plain; charset=UTF-8
79b470
Content-Transfer-Encoding: 8bit
79b470
79b470
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1786303
79b470
79b470
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
79b470
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
79b470
(cherry picked from commit aeecbc87b7317e88a8ef8c82b29bcacd1005c8c2)
79b470
79b470
Apart from conflicts below, I had to remove '-cpu qemu64' from
79b470
tests/qemuxml2argvdata/numatune-hmat.x86_64-latest.args to make
79b470
qemuxml2argvtest happy. This is because
79b470
3b8feb4793cef66f5dbfb9bdabe4d40834f1e90e isn't backported.
79b470
79b470
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518
79b470
79b470
Conflicts:
79b470
- src/qemu/qemu_command.c: Context
79b470
- src/qemu/qemu_validate.c: The file doesn't exist in downstream.
79b470
I've made the change to validator that lives in qemu_domain.c.
79b470
79b470
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
79b470
Message-Id: <0e8dfded8022b564ec7d0563cd745a0d3ffc815f.1602087923.git.mprivozn@redhat.com>
79b470
Reviewed-by: Ján Tomko <jtomko@redhat.com>
79b470
---
79b470
 src/conf/numa_conf.c                          |   7 +
79b470
 src/qemu/qemu_command.c                       | 171 ++++++++++++++++++
79b470
 src/qemu/qemu_domain.c                        |   7 +
79b470
 .../numatune-hmat.x86_64-latest.args          |  52 ++++++
79b470
 tests/qemuxml2argvtest.c                      |   1 +
79b470
 tests/qemuxml2xmltest.c                       |   2 +-
79b470
 6 files changed, 239 insertions(+), 1 deletion(-)
79b470
 create mode 100644 tests/qemuxml2argvdata/numatune-hmat.x86_64-latest.args
79b470
79b470
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
79b470
index 277a695d84..5a92eb35cc 100644
79b470
--- a/src/conf/numa_conf.c
79b470
+++ b/src/conf/numa_conf.c
79b470
@@ -1875,6 +1875,13 @@ virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
79b470
     if (!numa || node >= numa->nmem_nodes)
79b470
         return -1;
79b470
 
79b470
+    /* A NUMA node which has at least one vCPU is initiator to itself by
79b470
+     * definition. */
79b470
+    if (numa->mem_nodes[node].cpumask)
79b470
+        return node;
79b470
+
79b470
+    /* For the rest, "NUMA node that has best performance (the lowest
79b470
+     * latency or largest bandwidth) to this NUMA node." */
79b470
     for (i = 0; i < numa->ninterconnects; i++) {
79b470
         const virDomainNumaInterconnect *l = &numa->interconnects[i];
79b470
 
79b470
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
79b470
index ac63d18a42..959207bfea 100644
79b470
--- a/src/qemu/qemu_command.c
79b470
+++ b/src/qemu/qemu_command.c
79b470
@@ -7172,6 +7172,9 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
79b470
             virBufferAsprintf(&buf, ",pflash1=%s", priv->pflash1->nodeformat);
79b470
     }
79b470
 
79b470
+    if (virDomainNumaHasHMAT(def->numa))
79b470
+        virBufferAddLit(&buf, ",hmat=on");
79b470
+
79b470
     virCommandAddArgBuffer(cmd, &buf;;
79b470
 
79b470
     return 0;
79b470
@@ -7355,6 +7358,134 @@ qemuBuildIOThreadCommandLine(virCommandPtr cmd,
79b470
 }
79b470
 
79b470
 
79b470
+static int
79b470
+qemuBuilNumaCellCache(virCommandPtr cmd,
79b470
+                      const virDomainDef *def,
79b470
+                      size_t cell)
79b470
+{
79b470
+    size_t ncaches = virDomainNumaGetNodeCacheCount(def->numa, cell);
79b470
+    size_t i;
79b470
+
79b470
+    if (ncaches == 0)
79b470
+        return 0;
79b470
+
79b470
+    for (i = 0; i < ncaches; i++) {
79b470
+        g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
79b470
+        unsigned int level;
79b470
+        unsigned int size;
79b470
+        unsigned int line;
79b470
+        virDomainCacheAssociativity associativity;
79b470
+        virDomainCachePolicy policy;
79b470
+
79b470
+        if (virDomainNumaGetNodeCache(def->numa, cell, i,
79b470
+                                      &level, &size, &line,
79b470
+                                      &associativity, &policy) < 0) {
79b470
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
79b470
+                           _("Unable to format NUMA node cache"));
79b470
+            return -1;
79b470
+        }
79b470
+
79b470
+        virBufferAsprintf(&buf,
79b470
+                          "hmat-cache,node-id=%zu,size=%uK,level=%u",
79b470
+                          cell, size, level);
79b470
+
79b470
+        switch (associativity) {
79b470
+        case VIR_DOMAIN_CACHE_ASSOCIATIVITY_NONE:
79b470
+            virBufferAddLit(&buf, ",associativity=none");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_ASSOCIATIVITY_DIRECT:
79b470
+            virBufferAddLit(&buf, ",associativity=direct");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_ASSOCIATIVITY_FULL:
79b470
+            virBufferAddLit(&buf, ",associativity=complex");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_ASSOCIATIVITY_LAST:
79b470
+            break;
79b470
+        }
79b470
+
79b470
+        switch (policy) {
79b470
+        case VIR_DOMAIN_CACHE_POLICY_NONE:
79b470
+            virBufferAddLit(&buf, ",policy=none");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_POLICY_WRITEBACK:
79b470
+            virBufferAddLit(&buf, ",policy=write-back");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_POLICY_WRITETHROUGH:
79b470
+            virBufferAddLit(&buf, ",policy=write-through");
79b470
+            break;
79b470
+        case VIR_DOMAIN_CACHE_POLICY_LAST:
79b470
+            break;
79b470
+        }
79b470
+
79b470
+        if (line > 0)
79b470
+            virBufferAsprintf(&buf, ",line=%u", line);
79b470
+
79b470
+        virCommandAddArg(cmd, "-numa");
79b470
+        virCommandAddArgBuffer(cmd, &buf;;
79b470
+    }
79b470
+
79b470
+    return 0;
79b470
+}
79b470
+
79b470
+
79b470
+VIR_ENUM_DECL(qemuDomainMemoryHierarchy);
79b470
+VIR_ENUM_IMPL(qemuDomainMemoryHierarchy,
79b470
+              4, /* Maximum level of cache */
79b470
+              "memory", /* Special case, whole memory not specific cache */
79b470
+              "first-level",
79b470
+              "second-level",
79b470
+              "third-level");
79b470
+
79b470
+static int
79b470
+qemuBuildNumaHMATCommandLine(virCommandPtr cmd,
79b470
+                             const virDomainDef *def)
79b470
+{
79b470
+    size_t nlatencies;
79b470
+    size_t i;
79b470
+
79b470
+    if (!def->numa)
79b470
+        return 0;
79b470
+
79b470
+    nlatencies = virDomainNumaGetInterconnectsCount(def->numa);
79b470
+    for (i = 0; i < nlatencies; i++) {
79b470
+        g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
79b470
+        virDomainNumaInterconnectType type;
79b470
+        unsigned int initiator;
79b470
+        unsigned int target;
79b470
+        unsigned int cache;
79b470
+        virDomainMemoryLatency accessType;
79b470
+        unsigned long value;
79b470
+        const char *hierarchyStr;
79b470
+        const char *accessStr;
79b470
+
79b470
+        if (virDomainNumaGetInterconnect(def->numa, i,
79b470
+                                         &type, &initiator, &target,
79b470
+                                         &cache, &accessType, &value) < 0)
79b470
+            return -1;
79b470
+
79b470
+        hierarchyStr = qemuDomainMemoryHierarchyTypeToString(cache);
79b470
+        accessStr = virDomainMemoryLatencyTypeToString(accessType);
79b470
+        virBufferAsprintf(&buf,
79b470
+                          "hmat-lb,initiator=%u,target=%u,hierarchy=%s,data-type=%s-",
79b470
+                          initiator, target, hierarchyStr, accessStr);
79b470
+
79b470
+        switch (type) {
79b470
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_LATENCY:
79b470
+            virBufferAsprintf(&buf, "latency,latency=%lu", value);
79b470
+            break;
79b470
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
79b470
+            virBufferAsprintf(&buf, "bandwidth,bandwidth=%luK", value);
79b470
+            break;
79b470
+        }
79b470
+
79b470
+        virCommandAddArg(cmd, "-numa");
79b470
+        virCommandAddArgBuffer(cmd, &buf;;
79b470
+    }
79b470
+
79b470
+    return 0;
79b470
+}
79b470
+
79b470
+
79b470
 static int
79b470
 qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg,
79b470
                          virDomainDefPtr def,
79b470
@@ -7367,13 +7498,20 @@ qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg,
79b470
     char *next = NULL;
79b470
     virBufferPtr nodeBackends = NULL;
79b470
     bool needBackend = false;
79b470
+    bool hmat = false;
79b470
     int rc;
79b470
     int ret = -1;
79b470
     size_t ncells = virDomainNumaGetNodeCount(def->numa);
79b470
+    ssize_t masterInitiator = -1;
79b470
 
79b470
     if (!virDomainNumatuneNodesetIsAvailable(def->numa, priv->autoNodeset))
79b470
         goto cleanup;
79b470
 
79b470
+    if (virDomainNumaHasHMAT(def->numa)) {
79b470
+        needBackend = true;
79b470
+        hmat = true;
79b470
+    }
79b470
+
79b470
     if (VIR_ALLOC_N(nodeBackends, ncells) < 0)
79b470
         goto cleanup;
79b470
 
79b470
@@ -7397,8 +7535,22 @@ qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg,
79b470
         qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
79b470
         goto cleanup;
79b470
 
79b470
+    for (i = 0; i < ncells; i++) {
79b470
+        if (virDomainNumaGetNodeCpumask(def->numa, i)) {
79b470
+            masterInitiator = i;
79b470
+            break;
79b470
+        }
79b470
+    }
79b470
+
79b470
+    if (masterInitiator) {
79b470
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
79b470
+                       _("At least one NUMA node has to have CPUs"));
79b470
+        goto cleanup;
79b470
+    }
79b470
+
79b470
     for (i = 0; i < ncells; i++) {
79b470
         virBitmapPtr cpumask = virDomainNumaGetNodeCpumask(def->numa, i);
79b470
+        ssize_t initiator = virDomainNumaGetNodeInitiator(def->numa, i);
79b470
 
79b470
         if (needBackend) {
79b470
             virCommandAddArg(cmd, "-object");
79b470
@@ -7423,6 +7575,13 @@ qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg,
79b470
             }
79b470
         }
79b470
 
79b470
+        if (hmat) {
79b470
+            if (initiator < 0)
79b470
+                initiator = masterInitiator;
79b470
+
79b470
+            virBufferAsprintf(&buf, ",initiator=%zd", initiator);
79b470
+        }
79b470
+
79b470
         if (needBackend)
79b470
             virBufferAsprintf(&buf, ",memdev=ram-node%zu", i);
79b470
         else
79b470
@@ -7448,6 +7607,18 @@ qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg,
79b470
         }
79b470
     }
79b470
 
79b470
+    if (hmat) {
79b470
+        if (qemuBuildNumaHMATCommandLine(cmd, def) < 0)
79b470
+            goto cleanup;
79b470
+
79b470
+        /* This can't be moved into any of the loops above,
79b470
+         * because hmat-cache can be specified only after hmat-lb. */
79b470
+        for (i = 0; i < ncells; i++) {
79b470
+            if (qemuBuilNumaCellCache(cmd, def, i) < 0)
79b470
+                goto cleanup;
79b470
+        }
79b470
+    }
79b470
+
79b470
     ret = 0;
79b470
 
79b470
  cleanup:
79b470
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
79b470
index be25790f12..e51e176a80 100644
79b470
--- a/src/qemu/qemu_domain.c
79b470
+++ b/src/qemu/qemu_domain.c
79b470
@@ -5904,6 +5904,13 @@ qemuDomainDefValidate(const virDomainDef *def,
79b470
         }
79b470
     }
79b470
 
79b470
+    if (virDomainNumaHasHMAT(def->numa) &&
79b470
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NUMA_HMAT)) {
79b470
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
79b470
+                       _("HMAT is not supported with this QEMU"));
79b470
+        return -1;
79b470
+    }
79b470
+
79b470
     if (def->genidRequested &&
79b470
         !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMGENID)) {
79b470
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
79b470
diff --git a/tests/qemuxml2argvdata/numatune-hmat.x86_64-latest.args b/tests/qemuxml2argvdata/numatune-hmat.x86_64-latest.args
79b470
new file mode 100644
79b470
index 0000000000..413d247a4d
79b470
--- /dev/null
79b470
+++ b/tests/qemuxml2argvdata/numatune-hmat.x86_64-latest.args
79b470
@@ -0,0 +1,52 @@
79b470
+LC_ALL=C \
79b470
+PATH=/bin \
79b470
+HOME=/tmp/lib/domain--1-QEMUGuest \
79b470
+USER=test \
79b470
+LOGNAME=test \
79b470
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest/.local/share \
79b470
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest/.cache \
79b470
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest/.config \
79b470
+QEMU_AUDIO_DRV=none \
79b470
+/usr/bin/qemu-system-x86_64 \
79b470
+-name guest=QEMUGuest,debug-threads=on \
79b470
+-S \
79b470
+-object secret,id=masterKey0,format=raw,\
79b470
+file=/tmp/lib/domain--1-QEMUGuest/master-key.aes \
79b470
+-machine pc,accel=tcg,usb=off,dump-guest-core=off,hmat=on \
79b470
+-m 12288 \
79b470
+-overcommit mem-lock=off \
79b470
+-smp 12,sockets=12,cores=1,threads=1 \
79b470
+-object memory-backend-ram,id=ram-node0,size=2147483648 \
79b470
+-numa node,nodeid=0,cpus=0-3,initiator=0,memdev=ram-node0 \
79b470
+-object memory-backend-ram,id=ram-node1,size=2147483648 \
79b470
+-numa node,nodeid=1,cpus=4-7,initiator=1,memdev=ram-node1 \
79b470
+-object memory-backend-ram,id=ram-node2,size=2147483648 \
79b470
+-numa node,nodeid=2,cpus=8-11,initiator=2,memdev=ram-node2 \
79b470
+-object memory-backend-ram,id=ram-node3,size=2147483648 \
79b470
+-numa node,nodeid=3,initiator=0,memdev=ram-node3 \
79b470
+-object memory-backend-ram,id=ram-node4,size=2147483648 \
79b470
+-numa node,nodeid=4,initiator=0,memdev=ram-node4 \
79b470
+-object memory-backend-ram,id=ram-node5,size=2147483648 \
79b470
+-numa node,nodeid=5,initiator=0,memdev=ram-node5 \
79b470
+-numa hmat-lb,initiator=0,target=0,hierarchy=memory,data-type=access-latency,\
79b470
+latency=5 \
79b470
+-numa hmat-lb,initiator=0,target=0,hierarchy=first-level,\
79b470
+data-type=access-latency,latency=10 \
79b470
+-numa hmat-lb,initiator=0,target=0,hierarchy=memory,data-type=access-bandwidth,\
79b470
+bandwidth=204800K \
79b470
+-numa hmat-cache,node-id=0,size=10K,level=1,associativity=direct,\
79b470
+policy=write-back,line=8 \
79b470
+-uuid c7a5fdb2-cdaf-9455-926a-d65c16db1809 \
79b470
+-display none \
79b470
+-no-user-config \
79b470
+-nodefaults \
79b470
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
79b470
+-mon chardev=charmonitor,id=monitor,mode=control \
79b470
+-rtc base=utc \
79b470
+-no-shutdown \
79b470
+-boot strict=on \
79b470
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
79b470
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
79b470
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
79b470
+resourcecontrol=deny \
79b470
+-msg timestamp=on
79b470
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
79b470
index 49699e495d..629f5ac100 100644
79b470
--- a/tests/qemuxml2argvtest.c
79b470
+++ b/tests/qemuxml2argvtest.c
79b470
@@ -1813,6 +1813,7 @@ mymain(void)
79b470
 
79b470
     DO_TEST("numatune-distances", QEMU_CAPS_NUMA, QEMU_CAPS_NUMA_DIST);
79b470
     DO_TEST("numatune-no-vcpu", NONE);
79b470
+    DO_TEST_CAPS_LATEST("numatune-hmat");
79b470
 
79b470
     DO_TEST("numatune-auto-nodeset-invalid", NONE);
79b470
     DO_TEST("numatune-auto-prefer", QEMU_CAPS_OBJECT_MEMORY_RAM,
79b470
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
79b470
index de1d720e1d..f790bbc6f1 100644
79b470
--- a/tests/qemuxml2xmltest.c
79b470
+++ b/tests/qemuxml2xmltest.c
79b470
@@ -1106,7 +1106,7 @@ mymain(void)
79b470
     DO_TEST("numatune-memnode-no-memory", QEMU_CAPS_OBJECT_MEMORY_FILE);
79b470
     DO_TEST("numatune-distances", QEMU_CAPS_NUMA, QEMU_CAPS_NUMA_DIST);
79b470
     DO_TEST("numatune-no-vcpu", QEMU_CAPS_NUMA);
79b470
-    DO_TEST("numatune-hmat", NONE);
79b470
+    DO_TEST("numatune-hmat", QEMU_CAPS_NUMA_HMAT);
79b470
 
79b470
     DO_TEST("bios-nvram", NONE);
79b470
     DO_TEST("bios-nvram-os-interleave", NONE);
79b470
-- 
79b470
2.29.2
79b470