[PATCH v3 6/8] qemu: Enable SCHED_CORE for helper processes

Michal Privoznik posted 8 patches 3 years, 6 months ago
There is a newer version of this series
[PATCH v3 6/8] qemu: Enable SCHED_CORE for helper processes
Posted by Michal Privoznik 3 years, 6 months ago
For QEMU_SCHED_CORE_FULL case, all helper processes should be
placed into the same scheduling group as the QEMU process they
serve. It may happen though, that a helper process is started
before QEMU (cold start of a domain). But we have the dummy
process running from which the QEMU process will inherit the
scheduling group, so we can use the dummy process PID as an
argument to virCommandSetRunAmong().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_process.c  |  9 +++++++++
 src/qemu/qemu_security.c | 11 +++++++++++
 src/qemu/qemu_virtiofs.c | 11 +++++++++++
 3 files changed, 31 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f112209ae6..a8f8a7cb47 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2852,6 +2852,15 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm)
      * qemu (so that it shares the same view of the system). */
     virCommandSetPreExecHook(cmd, qemuProcessStartPRDaemonHook, vm);
 
+    if (cfg->schedCore == QEMU_SCHED_CORE_FULL) {
+        pid_t cookie_pid = vm->pid;
+
+        if (cookie_pid <= 0)
+            cookie_pid = priv->schedCoreChildPID;
+
+        virCommandSetRunAmong(cmd, cookie_pid);
+    }
+
     if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
 
diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c
index 3be1766764..5b7d5f30c2 100644
--- a/src/qemu/qemu_security.c
+++ b/src/qemu/qemu_security.c
@@ -683,6 +683,9 @@ qemuSecurityCommandRun(virQEMUDriver *driver,
                        int *exitstatus,
                        int *cmdret)
 {
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    qemuDomainObjPrivate *priv = vm->privateData;
+
     if (virSecurityManagerSetChildProcessLabel(driver->securityManager,
                                                vm->def, cmd) < 0)
         return -1;
@@ -691,6 +694,14 @@ qemuSecurityCommandRun(virQEMUDriver *driver,
         virCommandSetUID(cmd, uid);
     if (gid != (gid_t) -1)
         virCommandSetGID(cmd, gid);
+    if (cfg->schedCore == QEMU_SCHED_CORE_FULL) {
+        pid_t pid = vm->pid;
+
+        if (pid <= 0)
+            pid = priv->schedCoreChildPID;
+
+        virCommandSetRunAmong(cmd, pid);
+    }
 
     if (virSecurityManagerPreFork(driver->securityManager) < 0)
         return -1;
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index ce55286ab5..348908eb43 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -179,6 +179,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
                   virDomainFSDef *fs)
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    qemuDomainObjPrivate *priv = vm->privateData;
     g_autoptr(virCommand) cmd = NULL;
     g_autofree char *socket_path = NULL;
     g_autofree char *pidfile = NULL;
@@ -252,6 +253,16 @@ qemuVirtioFSStart(virQEMUDriver *driver,
     virCommandNonblockingFDs(cmd);
     virCommandDaemonize(cmd);
 
+    if (cfg->schedCore == QEMU_SCHED_CORE_FULL) {
+        pid_t cookie_pid = vm->pid;
+
+        if (cookie_pid <= 0)
+            cookie_pid = priv->schedCoreChildPID;
+
+        virCommandSetRunAmong(cmd, cookie_pid);
+    }
+
+
     if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0)
         goto error;
 
-- 
2.35.1
Re: [PATCH v3 6/8] qemu: Enable SCHED_CORE for helper processes
Posted by Daniel P. Berrangé 3 years, 5 months ago
On Fri, Aug 12, 2022 at 12:04:21PM +0200, Michal Privoznik wrote:
> For QEMU_SCHED_CORE_FULL case, all helper processes should be
> placed into the same scheduling group as the QEMU process they
> serve. It may happen though, that a helper process is started
> before QEMU (cold start of a domain). But we have the dummy
> process running from which the QEMU process will inherit the
> scheduling group, so we can use the dummy process PID as an
> argument to virCommandSetRunAmong().
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_process.c  |  9 +++++++++
>  src/qemu/qemu_security.c | 11 +++++++++++
>  src/qemu/qemu_virtiofs.c | 11 +++++++++++
>  3 files changed, 31 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 :|