[PATCH 3/3] qemu: Add support for setting vCPU and I/O thread scheduler setting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1178986

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  |  7 ++++-
 src/qemu/qemu_process.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_process.h |  5 +++-
 3 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cdf4173..fdfd4e9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1,7 +1,7 @@
 /*
  * qemu_driver.c: core driver methods for managing qemu guests
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -4491,6 +4491,11 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
             }

             virCgroupFree(&cgroup_vcpu);
+
+            if (qemuProcessSetSchedParams(i, cpupids[i],
+                                          vm->def->cputune.nvcpusched,
+                                          vm->def->cputune.vcpusched) < 0)
+                goto cleanup;
         }
     } else {
         for (i = oldvcpus - 1; i >= nvcpus; i--) {
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c18204b..0d69c43 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1,7 +1,7 @@
 /*
  * qemu_process.c: QEMU process management
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -2574,6 +2574,76 @@ qemuProcessSetIOThreadsAffinity(virDomainObjPtr vm)
     return ret;
 }

+/* Set Scheduler parameters for vCPU or I/O threads. */
+int
+qemuProcessSetSchedParams(int id,
+                          pid_t pid,
+                          size_t nsp,
+                          virDomainThreadSchedParamPtr sp)
+{
+    int sched = 0;
+    size_t i = 0;
+    virDomainThreadSchedParamPtr s = NULL;
+
+    for (i = 0; i < nsp; i++) {
+        if (id != sp[i].id)
+            continue;
+
+        s = sp + i;
+        break;
+    }
+
+    if (!s)
+        return 0;
+
+    switch (s->scheduler) {
+    case VIR_DOMAIN_THREAD_SCHED_BATCH:
+        sched = SCHED_BATCH;
+        break;
+
+    case VIR_DOMAIN_THREAD_SCHED_IDLE:
+        sched = SCHED_IDLE;
+        break;
+
+    case VIR_DOMAIN_THREAD_SCHED_FIFO:
+        sched = SCHED_FIFO;
+        break;
+
+    case VIR_DOMAIN_THREAD_SCHED_RR:
+        sched = SCHED_RR;
+        break;
+
+    case VIR_DOMAIN_THREAD_SCHED_OTHER:
+    case VIR_DOMAIN_THREAD_SCHED_LAST:
+        return 0;
+    }
+
+    return virProcessSetScheduler(pid, sched, s->priority);
+}
+
+static int
+qemuProcessSetSchedulers(virDomainObjPtr vm)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    size_t i = 0;
+
+    for (i = 0; i < vm->def->vcpus; i++) {
+        if (qemuProcessSetSchedParams(i, priv->vcpupids[i],
+                                      vm->def->cputune.nvcpusched,
+                                      vm->def->cputune.vcpusched) < 0)
+            return -1;
+    }
+
+    for (i = 0; i < vm->def->iothreads; i++) {
+        if (qemuProcessSetSchedParams(i, priv->iothreadpids[i],
+                                      vm->def->cputune.niothreadsched,
+                                      vm->def->cputune.iothreadsched) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
 static int
 qemuProcessInitPasswords(virConnectPtr conn,
                          virQEMUDriverPtr driver,
@@ -4750,6 +4820,10 @@ int qemuProcessStart(virConnectPtr conn,
     if (qemuProcessSetIOThreadsAffinity(vm) < 0)
         goto cleanup;

+    VIR_DEBUG("Setting scheduler parameters");
+    if (qemuProcessSetSchedulers(vm) < 0)
+        goto cleanup;
+
     VIR_DEBUG("Setting any required VM passwords");
     if (qemuProcessInitPasswords(conn, driver, vm, asyncJob) < 0)
         goto cleanup;
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 5948ea4..2e1d393 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -1,7 +1,7 @@
 /*
  * qemu_process.h: QEMU process management
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2012, 2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -104,4 +104,7 @@ virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,

 int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);

+int qemuProcessSetSchedParams(int id, pid_t pid, size_t nsp,
+                              virDomainThreadSchedParamPtr sp);
+
 #endif /* __QEMU_PROCESS_H__ */
-- 
2.2.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]