[PATCH v3 7/8] qemu: Enable SCHED_CORE for vCPUs

Michal Privoznik posted 8 patches 3 years, 5 months ago
There is a newer version of this series
[PATCH v3 7/8] qemu: Enable SCHED_CORE for vCPUs
Posted by Michal Privoznik 3 years, 5 months ago
For QEMU_SCHED_CORE_VCPUS case, the vCPU threads should be placed
all into one scheduling group, but not the emulator or any of its
threads. Therefore, as soon as vCPU TIDs are detected, fork off a
child which then creates a separate scheduling group and adds all
vCPU threads into it.

Please note, this commit only handles the cold boot case. Hotplug
is going to be implemented in the next commit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_process.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index a8f8a7cb47..f9c4f72496 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5874,9 +5874,44 @@ qemuProcessSetupVcpu(virDomainObj *vm,
 }
 
 
+static int
+qemuProcessSetupAllVcpusSchedCoreHelper(pid_t ppid G_GNUC_UNUSED,
+                                        void *opaque)
+{
+    virDomainObj *vm = opaque;
+    size_t i;
+
+    /* Since we are setting all vCPU threads at once and from a forked off
+     * child, we don't need the dummy schedCoreChildPID and can create one on
+     * our own. */
+    if (virProcessSchedCoreCreate() < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to set SCHED_CORE"));
+
+        return -1;
+    }
+
+    for (i = 0; i < virDomainDefGetVcpusMax(vm->def); i++) {
+        pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
+
+        if (vcpupid > 0 &&
+            virProcessSchedCoreShareTo(vcpupid) < 0) {
+            virReportSystemError(errno,
+                                 _("unable to share scheduling cookie to %lld"),
+                                 (long long) vcpupid);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static int
 qemuProcessSetupVcpus(virDomainObj *vm)
 {
+    qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
     virDomainVcpuDef *vcpu;
     unsigned int maxvcpus = virDomainDefGetVcpusMax(vm->def);
     size_t i;
@@ -5919,6 +5954,10 @@ qemuProcessSetupVcpus(virDomainObj *vm)
             return -1;
     }
 
+    if (cfg->schedCore == QEMU_SCHED_CORE_VCPUS &&
+        virProcessRunInFork(qemuProcessSetupAllVcpusSchedCoreHelper, vm) < 0)
+        return -1;
+
     return 0;
 }
 
-- 
2.35.1
Re: [PATCH v3 7/8] qemu: Enable SCHED_CORE for vCPUs
Posted by Daniel P. Berrangé 3 years, 5 months ago
On Fri, Aug 12, 2022 at 12:04:22PM +0200, Michal Privoznik wrote:
> For QEMU_SCHED_CORE_VCPUS case, the vCPU threads should be placed
> all into one scheduling group, but not the emulator or any of its
> threads. Therefore, as soon as vCPU TIDs are detected, fork off a
> child which then creates a separate scheduling group and adds all
> vCPU threads into it.
> 
> Please note, this commit only handles the cold boot case. Hotplug
> is going to be implemented in the next commit.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_process.c | 39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|