[libvirt] [PATCH 20/21] qemu: Add support for resctrl

Martin Kletzander posted 21 patches 7 years, 6 months ago
Only 20 patches received!
[libvirt] [PATCH 20/21] qemu: Add support for resctrl
Posted by Martin Kletzander 7 years, 6 months ago
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/qemu/qemu_process.c | 61 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7df440ee4345..335146ab71b8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2478,6 +2478,33 @@ qemuProcessSetupEmulator(virDomainObjPtr vm)
 }
 
 
+static int
+qemuProcessResctrlCreate(virQEMUDriverPtr driver,
+                         virDomainObjPtr vm)
+{
+    int ret = -1;
+    size_t i = 0;
+    virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+
+    if (!caps)
+        return -1;
+
+    for (i = 0; i < vm->def->ncachetunes; i++) {
+        if (virResctrlAllocCreate(caps->host.resctrl,
+                                  vm->def->cachetunes[i]->alloc,
+                                  "qemu",
+                                  priv->machineName) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 static int
 qemuProcessInitPasswords(virConnectPtr conn,
                          virQEMUDriverPtr driver,
@@ -4899,12 +4926,26 @@ qemuProcessSetupVcpu(virDomainObjPtr vm,
 {
     pid_t vcpupid = qemuDomainGetVcpuPid(vm, vcpuid);
     virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, vcpuid);
+    size_t i = 0;
 
-    return qemuProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU,
-                               vcpuid, vcpu->cpumask,
-                               vm->def->cputune.period,
-                               vm->def->cputune.quota,
-                               &vcpu->sched);
+    if (qemuProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU,
+                            vcpuid, vcpu->cpumask,
+                            vm->def->cputune.period,
+                            vm->def->cputune.quota,
+                            &vcpu->sched) < 0)
+        return -1;
+
+    for (i = 0; i < vm->def->ncachetunes; i++) {
+        virDomainCachetuneDefPtr ct = vm->def->cachetunes[i];
+
+        if (virBitmapIsBitSet(ct->vcpus, vcpuid)) {
+            if (virResctrlAllocAddPID(ct->alloc, vcpupid) < 0)
+                return -1;
+            break;
+        }
+    }
+
+    return 0;
 }
 
 
@@ -5786,6 +5827,10 @@ qemuProcessLaunch(virConnectPtr conn,
     if (qemuProcessSetupEmulator(vm) < 0)
         goto cleanup;
 
+    VIR_DEBUG("Setting up resctrlfs");
+    if (qemuProcessResctrlCreate(driver, vm) < 0)
+        goto cleanup;
+
     VIR_DEBUG("Setting domain security labels");
     if (qemuSecuritySetAllLabel(driver,
                                 vm,
@@ -6434,6 +6479,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
                  vm->def->name);
     }
 
+    /* Remove resctrl allocation after cgroups are cleaned up which makes it
+     * kind of safer (although removing the allocation should work even with
+     * pids in tasks file */
+    for (i = 0; i < vm->def->ncachetunes; i++)
+        virResctrlAllocRemove(vm->def->cachetunes[i]->alloc);
+
     qemuProcessRemoveDomainStatus(driver, vm);
 
     /* Remove VNC and Spice ports from port reservation bitmap, but only if
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 20/21] qemu: Add support for resctrl
Posted by John Ferlan 7 years, 6 months ago
Commit messages have either gone on a diet or the writer is on strike

On 11/13/2017 03:50 AM, Martin Kletzander wrote:
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/qemu/qemu_process.c | 61 +++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 56 insertions(+), 5 deletions(-)
> 

This seems reasonable too,

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 7df440ee4345..335146ab71b8 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c

[...]

> @@ -6434,6 +6479,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
>                   vm->def->name);
>      }
>  
> +    /* Remove resctrl allocation after cgroups are cleaned up which makes it
> +     * kind of safer (although removing the allocation should work even with
> +     * pids in tasks file */
> +    for (i = 0; i < vm->def->ncachetunes; i++)
> +        virResctrlAllocRemove(vm->def->cachetunes[i]->alloc);
> +

Oh and here is Stop doing the Remove... Perhaps why earlier since I
hadn't read something like this so perhaps why I asked about it before
checking consumers of AllocRemove


>      qemuProcessRemoveDomainStatus(driver, vm);
>  
>      /* Remove VNC and Spice ports from port reservation bitmap, but only if
> 

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