render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From 72285626fa7b899ceb9c8d4358b4b1b3fa7081a4 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <72285626fa7b899ceb9c8d4358b4b1b3fa7081a4@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 16:32:32 +0100
c1c534
Subject: [PATCH] qemu: Add support for resctrl
c1c534
c1c534
We've been building up to this.  This adds support for cputune/cachetune
c1c534
settings for domains in the QEMU driver.  The addition into
c1c534
qemuProcessSetupVcpu() automatically adds support for hotplug.  For hot-unplug
c1c534
we need to remove the allocation only if all the vCPUs were unplugged.  But
c1c534
since the threads are left running, we can't really do much about it now.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
(cherry picked from commit 9a2fc2db8fe18da41c274d52b6e52316a4bbe52d)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_process.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-----
c1c534
 1 file changed, 55 insertions(+), 5 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c1c534
index c64088e4ca..57faf9cd79 100644
c1c534
--- a/src/qemu/qemu_process.c
c1c534
+++ b/src/qemu/qemu_process.c
c1c534
@@ -2504,6 +2504,32 @@ qemuProcessSetupEmulator(virDomainObjPtr vm)
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuProcessResctrlCreate(virQEMUDriverPtr driver,
c1c534
+                         virDomainObjPtr vm)
c1c534
+{
c1c534
+    int ret = -1;
c1c534
+    size_t i = 0;
c1c534
+    virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
c1c534
+    qemuDomainObjPrivatePtr priv = vm->privateData;
c1c534
+
c1c534
+    if (!caps)
c1c534
+        return -1;
c1c534
+
c1c534
+    for (i = 0; i < vm->def->ncachetunes; i++) {
c1c534
+        if (virResctrlAllocCreate(caps->host.resctrl,
c1c534
+                                  vm->def->cachetunes[i]->alloc,
c1c534
+                                  priv->machineName) < 0)
c1c534
+            goto cleanup;
c1c534
+    }
c1c534
+
c1c534
+    ret = 0;
c1c534
+ cleanup:
c1c534
+    virObjectUnref(caps);
c1c534
+    return ret;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuProcessInitPasswords(virConnectPtr conn,
c1c534
                          virQEMUDriverPtr driver,
c1c534
@@ -5015,12 +5041,26 @@ qemuProcessSetupVcpu(virDomainObjPtr vm,
c1c534
 {
c1c534
     pid_t vcpupid = qemuDomainGetVcpuPid(vm, vcpuid);
c1c534
     virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, vcpuid);
c1c534
+    size_t i = 0;
c1c534
 
c1c534
-    return qemuProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU,
c1c534
-                               vcpuid, vcpu->cpumask,
c1c534
-                               vm->def->cputune.period,
c1c534
-                               vm->def->cputune.quota,
c1c534
-                               &vcpu->sched);
c1c534
+    if (qemuProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU,
c1c534
+                            vcpuid, vcpu->cpumask,
c1c534
+                            vm->def->cputune.period,
c1c534
+                            vm->def->cputune.quota,
c1c534
+                            &vcpu->sched) < 0)
c1c534
+        return -1;
c1c534
+
c1c534
+    for (i = 0; i < vm->def->ncachetunes; i++) {
c1c534
+        virDomainCachetuneDefPtr ct = vm->def->cachetunes[i];
c1c534
+
c1c534
+        if (virBitmapIsBitSet(ct->vcpus, vcpuid)) {
c1c534
+            if (virResctrlAllocAddPID(ct->alloc, vcpupid) < 0)
c1c534
+                return -1;
c1c534
+            break;
c1c534
+        }
c1c534
+    }
c1c534
+
c1c534
+    return 0;
c1c534
 }
c1c534
 
c1c534
 
c1c534
@@ -5892,6 +5932,10 @@ qemuProcessLaunch(virConnectPtr conn,
c1c534
     if (qemuProcessSetupEmulator(vm) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
+    VIR_DEBUG("Setting up resctrlfs");
c1c534
+    if (qemuProcessResctrlCreate(driver, vm) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
     VIR_DEBUG("Setting domain security labels");
c1c534
     if (qemuSecuritySetAllLabel(driver,
c1c534
                                 vm,
c1c534
@@ -6540,6 +6584,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
c1c534
                  vm->def->name);
c1c534
     }
c1c534
 
c1c534
+    /* Remove resctrl allocation after cgroups are cleaned up which makes it
c1c534
+     * kind of safer (although removing the allocation should work even with
c1c534
+     * pids in tasks file */
c1c534
+    for (i = 0; i < vm->def->ncachetunes; i++)
c1c534
+        virResctrlAllocRemove(vm->def->cachetunes[i]->alloc);
c1c534
+
c1c534
     qemuProcessRemoveDomainStatus(driver, vm);
c1c534
 
c1c534
     /* Remove VNC and Spice ports from port reservation bitmap, but only if
c1c534
-- 
c1c534
2.16.1
c1c534