From bdffab0d5c52d31bd71422b0b69665efb6650953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 4 Mar 2014 12:39:46 +0100 Subject: [PATCH] Treat zero cpu shares as a valid value Currently, 0 is treated as if it were not specified. Treat is as a valid value if it was explicitly specified and write it to the cgroups. --- src/conf/domain_conf.c | 12 ++++--- src/conf/domain_conf.h | 1 + src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_driver.c | 2 ++ src/lxc/lxc_native.c | 8 +++-- src/parallels/parallels_driver.c | 1 + src/qemu/qemu_cgroup.c | 4 +-- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_driver.c | 6 +++- src/vmx/vmx.c | 3 +- .../qemuxml2argv-cputune-zero-shares.args | 5 +++ .../qemuxml2argv-cputune-zero-shares.xml | 35 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c | 1 + 14 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b2bb61a884..6fb216e782 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11543,11 +11543,13 @@ virDomainDefParseXML(xmlDocPtr xml, } /* Extract cpu tunables. */ - if (virXPathULong("string(./cputune/shares[1])", ctxt, - &def->cputune.shares) < -1) { + if ((n = virXPathULong("string(./cputune/shares[1])", ctxt, + &def->cputune.shares)) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune shares value")); goto error; + } else if (n == 0) { + def->cputune.sharesSpecified = true; } if (virXPathULongLong("string(./cputune/period[1])", ctxt, @@ -17276,7 +17278,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAsprintf(buf, " current='%u'", def->vcpus); virBufferAsprintf(buf, ">%u\n", def->maxvcpus); - if (def->cputune.shares || + if (def->cputune.sharesSpecified || (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) || def->cputune.period || def->cputune.quota || def->cputune.emulatorpin || @@ -17284,7 +17286,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - if (def->cputune.shares) + if (def->cputune.sharesSpecified) virBufferAsprintf(buf, "%lu\n", def->cputune.shares); if (def->cputune.period) @@ -17339,7 +17341,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, VIR_FREE(cpumask); } virBufferAdjustIndent(buf, -2); - if (def->cputune.shares || + if (def->cputune.sharesSpecified || (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) || def->cputune.period || def->cputune.quota || def->cputune.emulatorpin || diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 59892e1359..f3f24c4777 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2011,6 +2011,7 @@ struct _virDomainDef { struct { unsigned long shares; + bool sharesSpecified; unsigned long long period; long long quota; unsigned long long emulator_period; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index bab3052ea5..2bf0c72034 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -38,7 +38,7 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, virCgroupPtr cgroup) { int ret = -1; - if (def->cputune.shares != 0 && + if (def->cputune.sharesSpecified && virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0) goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e1afb5c644..c416190ee3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1902,10 +1902,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; vm->def->cputune.shares = params[i].value.ul; + vm->def->cputune.sharesSpecified = true; } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { vmdef->cputune.shares = params[i].value.ul; + vmdef->cputune.sharesSpecified = true; } } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) { if (flags & VIR_DOMAIN_AFFECT_LIVE) { diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index fad51db9e9..2b09fae437 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -678,9 +678,11 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) virConfValuePtr value; if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.shares")) && - value->str && virStrToLong_ul(value->str, NULL, 10, - &def->cputune.shares) < 0) - goto error; + value->str) { + if (virStrToLong_ul(value->str, NULL, 10, &def->cputune.shares) < 0) + goto error; + def->cputune.sharesSpecified = true; + } if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.cfs_quota_us")) && diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 9deb045d5b..c72da0fcc3 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -2051,6 +2051,7 @@ parallelsApplyChanges(virConnectPtr conn, virDomainObjPtr dom, virDomainDefPtr n } if (old->cputune.shares != new->cputune.shares || + old->cputune.sharesSpecified != new->cputune.sharesSpecified || old->cputune.period != new->cputune.period || old->cputune.quota != new->cputune.quota || old->cputune.nvcpupin != new->cputune.nvcpupin) { diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index e625206f9f..8a31ae23ad 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -646,7 +646,7 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) qemuDomainObjPrivatePtr priv = vm->privateData; if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { - if (vm->def->cputune.shares) { + if (vm->def->cputune.sharesSpecified) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("CPU tuning is not available on this host")); return -1; @@ -655,7 +655,7 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) } } - if (vm->def->cputune.shares && + if (vm->def->cputune.sharesSpecified && virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0) return -1; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b09a5b4c1d..9a314bf8d5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7784,7 +7784,7 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } - if (def->cputune.shares || def->cputune.period || + if (def->cputune.sharesSpecified || def->cputune.period || def->cputune.quota || def->cputune.emulator_period || def->cputune.emulator_quota) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6b8110310f..fca313b66b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9088,10 +9088,14 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0) goto cleanup; vm->def->cputune.shares = value_ul; + vm->def->cputune.sharesSpecified = true; } - if (flags & VIR_DOMAIN_AFFECT_CONFIG) + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { vmdef->cputune.shares = value_ul; + vmdef->cputune.sharesSpecified = true; + } + } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) { SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD, diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 272d873967..32ddd05a3e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1511,6 +1511,7 @@ virVMXParseConfig(virVMXContext *ctx, "found '%s'"), sched_cpu_shares); goto cleanup; } + def->cputune.sharesSpecified = true; } /* def:lifecycle */ @@ -3196,7 +3197,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } /* def:cputune.shares -> vmx:sched.cpu.shares */ - if (def->cputune.shares > 0) { + if (def->cputune.sharesSpecified) { /* See http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.SharesInfo.Level.html */ if (def->cputune.shares == def->vcpus * 500) { virBufferAddLit(&buffer, "sched.cpu.shares = \"low\"\n"); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.args b/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.args new file mode 100644 index 0000000000..bc6d24105f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 -S -M pc -m 214 -smp 2 -nographic \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ +-hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.xml b/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.xml new file mode 100644 index 0000000000..d5970540bd --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune-zero-shares.xml @@ -0,0 +1,35 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 2 + + 0 + 1000000 + -1 + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index f6800c8123..56854dcdaa 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1163,6 +1163,7 @@ mymain(void) DO_TEST("blkiotune", QEMU_CAPS_NAME); DO_TEST("blkiotune-device", QEMU_CAPS_NAME); DO_TEST("cputune", QEMU_CAPS_NAME); + DO_TEST("cputune-zero-shares", QEMU_CAPS_NAME); DO_TEST("numatune-memory", NONE); DO_TEST("numatune-auto-nodeset-invalid", NONE); DO_TEST("numad", NONE); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 5dc3afd907..c8a1c10691 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -260,6 +260,7 @@ mymain(void) DO_TEST("blkiotune"); DO_TEST("blkiotune-device"); DO_TEST("cputune"); + DO_TEST("cputune-zero-shares"); DO_TEST("smp"); DO_TEST("lease");