---
src/conf/domain_conf.c | 20 +++++++++-
src/conf/domain_conf.h | 2 +
src/qemu/qemu_cgroup.c | 43 +++++++++++++++++++----
tests/qemuxml2argvdata/qemuxml2argv-cputune.xml | 2 +
4 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7393690..1572043 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5841,6 +5841,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
&def->cputune.shares) < 0)
def->cputune.shares = 0;
+ if (virXPathULongLong("string(./cputune/period[1])", ctxt,
+ &def->cputune.period) < 0)
+ def->cputune.period = 0;
+
+ if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
+ &def->cputune.quota) < 0)
+ def->cputune.quota = 0;
+
if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) {
goto error;
}
@@ -9426,12 +9434,19 @@ char *virDomainDefFormat(virDomainDefPtr def,
virBufferAsprintf(&buf, " current='%u'", def->vcpus);
virBufferAsprintf(&buf, ">%u</vcpu>\n", def->maxvcpus);
- if (def->cputune.shares || def->cputune.vcpupin)
+ if (def->cputune.shares || def->cputune.vcpupin ||
+ def->cputune.period || def->cputune.quota)
virBufferAddLit(&buf, " <cputune>\n");
if (def->cputune.shares)
virBufferAsprintf(&buf, " <shares>%lu</shares>\n",
def->cputune.shares);
+ if (def->cputune.period)
+ virBufferAsprintf(&buf, " <period>%llu</period>\n",
+ def->cputune.period);
+ if (def->cputune.quota)
+ virBufferAsprintf(&buf, " <quota>%lld</quota>\n",
+ def->cputune.quota);
if (def->cputune.vcpupin) {
int i;
for (i = 0; i < def->cputune.nvcpupin; i++) {
@@ -9453,7 +9468,8 @@ char *virDomainDefFormat(virDomainDefPtr def,
}
}
- if (def->cputune.shares || def->cputune.vcpupin)
+ if (def->cputune.shares || def->cputune.vcpupin ||
+ def->cputune.period || def->cputune.quota)
virBufferAddLit(&buf, " </cputune>\n");
if (def->sysinfo)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3ef48d1..d2a5804 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1151,6 +1151,8 @@ struct _virDomainDef {
struct {
unsigned long shares;
+ unsigned long long period;
+ long long quota;
int nvcpupin;
virDomainVcpupinDefPtr *vcpupin;
} cputune;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 1298924..b14b8b6 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -349,14 +349,43 @@ int qemuSetupCgroup(struct qemud_driver *driver,
}
}
- if (vm->def->cputune.shares != 0) {
+ if (vm->def->cputune.shares != 0 ||
+ vm->def->cputune.period != 0 ||
+ vm->def->cputune.quota != 0) {
if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
- rc = virCgroupSetCpuShares(cgroup, vm->def->cputune.shares);
- if(rc != 0) {
- virReportSystemError(-rc,
- _("Unable to set io cpu shares for domain
%s"),
- vm->def->name);
- goto cleanup;
+ if (vm->def->cputune.shares != 0) {
+ rc = virCgroupSetCpuShares(cgroup, vm->def->cputune.shares);
+ if(rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set io cpu shares for"
+ " domain %s"),
+ vm->def->name);
+ goto cleanup;
+ }
+ }
+
+ if (vm->def->cputune.period != 0) {
+ rc = virCgroupSetCpuCfsPeriod(cgroup,
+ vm->def->cputune.period);
+ if(rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set cpu bandwidth
period"
+ " for domain %s"),
+ vm->def->name);
+ goto cleanup;
+ }
+ }
+
+ if (vm->def->cputune.quota != 0) {
+ rc = virCgroupSetCpuCfsQuota(cgroup,
+ vm->def->cputune.quota);
+ if(rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set cpu bandwidth for"
+ " domain %s"),
+ vm->def->name);
+ goto cleanup;
+ }
}
} else {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
index 0afbadb..091865a 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
@@ -6,6 +6,8 @@
<vcpu>2</vcpu>
<cputune>
<shares>2048</shares>
+ <period>1000000</period>
+ <quota>-1</quota>
<vcpupin vcpu='0' cpuset='0'/>
<vcpupin vcpu='1' cpuset='1'/>
</cputune>
--
1.7.1