On Tue, Aug 21, 2012 at 05:18:44PM +0800, Hu Tao wrote:
From: Wen Congyang <wency(a)cn.fujitsu.com>
allow the user change/get emulator's period and quota when the vm is running.
---
src/qemu/qemu_driver.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 132 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8314375..0e7dc32 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6603,7 +6603,7 @@ static char *qemuGetSchedulerType(virDomainPtr dom,
else if (rc == 0)
*nparams = 1;
else
- *nparams = 3;
+ *nparams = 5;
}
ret = strdup("posix");
@@ -7734,6 +7734,40 @@ cleanup:
}
static int
+qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup,
+ unsigned long long period, long long quota)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ virCgroupPtr cgroup_emulator = NULL;
+ int rc;
+
+ if (period == 0 && quota == 0)
+ return 0;
+
+ if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid) {
+ return 0;
+ }
+
+ rc = virCgroupForEmulator(cgroup, &cgroup_emulator, 0);
+ if (rc < 0) {
+ virReportSystemError(-rc,
+ _("Unable to find emulator cgroup for %s"),
+ vm->def->name);
+ goto cleanup;
+ }
+
+ if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0)
+ goto cleanup;
+
+ virCgroupFree(&cgroup_emulator);
+ return 0;
+
+cleanup:
+ virCgroupFree(&cgroup_emulator);
+ return -1;
+}
+
+static int
qemuSetSchedulerParametersFlags(virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
@@ -7756,6 +7790,10 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
VIR_TYPED_PARAM_ULLONG,
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
VIR_TYPED_PARAM_LLONG,
+ VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
+ VIR_TYPED_PARAM_ULLONG,
+ VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
+ VIR_TYPED_PARAM_LLONG,
NULL) < 0)
return -1;
@@ -7838,6 +7876,32 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vmdef->cputune.quota = params[i].value.l;
}
+ } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+ rc = qemuSetEmulatorBandwidthLive(vm, group, params[i].value.ul, 0);
+ if (rc != 0)
+ goto cleanup;
+
+ if (params[i].value.ul)
+ vm->def->cputune.emulator_period = params[i].value.ul;
+ }
+
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ vmdef->cputune.emulator_period = params[i].value.ul;
+ }
+ } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+ rc = qemuSetEmulatorBandwidthLive(vm, group, 0, params[i].value.l);
+ if (rc != 0)
+ goto cleanup;
+
+ if (params[i].value.l)
+ vm->def->cputune.emulator_quota = params[i].value.l;
+ }
+
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ vmdef->cputune.emulator_quota = params[i].value.l;
+ }
}
}
@@ -7942,6 +8006,43 @@ cleanup:
}
static int
+qemuGetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup,
+ unsigned long long *period, long long *quota)
+{
+ virCgroupPtr cgroup_emulator = NULL;
+ qemuDomainObjPrivatePtr priv = NULL;
+ int rc;
+ int ret = -1;
+
+ priv = vm->privateData;
+ if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid) {
+ /* We don't create sub dir for each vcpu */
+ *period = 0;
+ *quota = 0;
+ return 0;
+ }
+
+ /* get period and quota for emulator */
+ rc = virCgroupForEmulator(cgroup, &cgroup_emulator, 0);
+ if (!cgroup_emulator) {
+ virReportSystemError(-rc,
+ _("Unable to find emulator cgroup for %s"),
+ vm->def->name);
+ goto cleanup;
+ }
+
+ rc = qemuGetVcpuBWLive(cgroup_emulator, period, quota);
+ if (rc < 0)
+ goto cleanup;
+
+ ret = 0;
+
+cleanup:
+ virCgroupFree(&cgroup_emulator);
+ return ret;
+}
+
+static int
qemuGetSchedulerParametersFlags(virDomainPtr dom,
virTypedParameterPtr params,
int *nparams,
@@ -7953,6 +8054,8 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
unsigned long long shares;
unsigned long long period;
long long quota;
+ unsigned long long emulator_period;
+ long long emulator_quota;
int ret = -1;
int rc;
bool cpu_bw_status = false;
@@ -7992,6 +8095,8 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
if (*nparams > 1 && cpu_bw_status) {
period = persistentDef->cputune.period;
quota = persistentDef->cputune.quota;
+ emulator_period = persistentDef->cputune.emulator_period;
+ emulator_quota = persistentDef->cputune.emulator_quota;
}
goto out;
}
@@ -8020,6 +8125,14 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom,
if (rc != 0)
goto cleanup;
}
+
+ if (*nparams > 3 && cpu_bw_status) {
+ rc = qemuGetEmulatorBandwidthLive(vm, group, &emulator_period,
+ &emulator_quota);
+ if (rc != 0)
+ goto cleanup;
+ }
+
out:
if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_SCHEDULER_CPU_SHARES,
VIR_TYPED_PARAM_ULLONG, shares) < 0)
@@ -8042,6 +8155,24 @@ out:
goto cleanup;
saved_nparams++;
}
+
+ if (*nparams > saved_nparams) {
+ if (virTypedParameterAssign(¶ms[3],
+ VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
+ VIR_TYPED_PARAM_ULLONG,
+ emulator_period) < 0)
+ goto cleanup;
+ saved_nparams++;
+ }
+
+ if (*nparams > saved_nparams) {
+ if (virTypedParameterAssign(¶ms[4],
+ VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
+ VIR_TYPED_PARAM_LLONG,
+ emulator_quota) < 0)
+ goto cleanup;
+ saved_nparams++;
+ }
}
*nparams = saved_nparams;
Okay, we now have 5 parameters instead of 3. that looks fine, ACK,
the question I have is if virsh is actually able to display the 5
parameters by default now, if yes the patch set seems complete !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit
http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine
http://rpmfind.net/
http://veillard.com/ | virtualization library
http://libvirt.org/