From 104ba5966a440f40e0287f49fa46f04add52b1c5 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Thu, 8 Jan 2015 15:37:50 +0100 Subject: [PATCH] qemu: Add support for setting vCPU and I/O thread scheduler setting Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1178986 Signed-off-by: Martin Kletzander --- src/qemu/qemu_driver.c | 5 ++++ src/qemu/qemu_process.c | 57 ++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_process.h | 5 +++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 26fc6a2a0c..274278c014 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4620,6 +4620,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 d5df60dfc2..4773120f51 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,57 @@ 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) +{ + bool val = false; + size_t i = 0; + virDomainThreadSchedParamPtr s = NULL; + + for (i = 0; i < nsp; i++) { + if (virBitmapGetBit(sp[i].ids, id, &val) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get bit from bitmap")); + } + if (val) { + s = &sp[i]; + break; + } + } + + if (!s) + return 0; + + return virProcessSetScheduler(pid, s->scheduler, s->priority); +} + +static int +qemuProcessSetSchedulers(virDomainObjPtr vm) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + size_t i = 0; + + for (i = 0; i < priv->nvcpupids; i++) { + if (qemuProcessSetSchedParams(i, priv->vcpupids[i], + vm->def->cputune.nvcpusched, + vm->def->cputune.vcpusched) < 0) + return -1; + } + + for (i = 0; i < priv->niothreadpids; i++) { + if (qemuProcessSetSchedParams(i + 1, priv->iothreadpids[i], + vm->def->cputune.niothreadsched, + vm->def->cputune.iothreadsched) < 0) + return -1; + } + + return 0; +} + static int qemuProcessInitPasswords(virConnectPtr conn, virQEMUDriverPtr driver, @@ -4869,6 +4920,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 5948ea4704..2e1d393219 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__ */