On Mon, Feb 08, 2016 at 12:26:30PM +0100, Peter Krempa wrote:
Rather than iterating 3 times for various settings this function
aggregates all the code into single place. One of the other advantages
is that it can then be reused for properly setting vCPU info on hotplug.
With this approach autoCpuset is also used when setting the process
affinity rather than just via cgroups.
---
src/qemu/qemu_cgroup.c | 95 ----------------------
src/qemu/qemu_cgroup.h | 1 -
src/qemu/qemu_process.c | 212 ++++++++++++++++++++++++++++++++----------------
src/qemu/qemu_process.h | 4 +
4 files changed, 148 insertions(+), 164 deletions(-)
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 3cfc9e3..f3a9b5c 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -1018,101 +1018,6 @@ qemuSetupCgroupCpusetCpus(virCgroupPtr cgroup,
return ret;
}
-int
-qemuSetupCgroupForVcpu(virDomainObjPtr vm)
-{
- virCgroupPtr cgroup_vcpu = NULL;
- qemuDomainObjPrivatePtr priv = vm->privateData;
- virDomainDefPtr def = vm->def;
- size_t i;
- unsigned long long period = vm->def->cputune.period;
- long long quota = vm->def->cputune.quota;
- char *mem_mask = NULL;
- virDomainNumatuneMemMode mem_mode;
-
- if ((period || quota) &&
- !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("cgroup cpu is required for scheduler tuning"));
- return -1;
- }
-
Before, this error was reported...
- /*
- * If CPU cgroup controller is not initialized here, then we need
- * neither period nor quota settings. And if CPUSET controller is
- * not initialized either, then there's nothing to do anyway. CPU pinning
- * will be set via virProcessSetAffinity.
- */
- if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU) &&
- !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET))
- return 0;
-
- /* If vCPU<->pid mapping is missing we can't do vCPU pinning */
- if (!qemuDomainHasVcpuPids(vm))
- return 0;
... before the VCPU pid check here.
-
- if (virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) == 0
&&
- mem_mode == VIR_DOMAIN_NUMATUNE_MEM_STRICT &&
- virDomainNumatuneMaybeFormatNodeset(vm->def->numa,
- priv->autoNodeset,
- &mem_mask, -1) < 0)
/**
+ * qemuProcessSetupVcpu:
+ * @vm: domain object
+ * @vcpuid: id of VCPU to set defaults
+ *
+ * This function sets resource properities (affinity, cgroups, scheduler) for a
*properties.
Also, cgroups, affinity, scheduler is the order.
+ * vCPU. This function expects that the vCPU is online and the vCPU
pids were
+ * correctly detected at the point when it's called.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int
+qemuProcessSetupVcpu(virDomainObjPtr vm,
+ unsigned int vcpuid)
+{
+ pid_t vcpupid = qemuDomainGetVcpuPid(vm, vcpuid);
+ virDomainVcpuInfoPtr vcpu = virDomainDefGetVcpu(vm->def, vcpuid);
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ char *mem_mask = NULL;
+ virDomainNumatuneMemMode mem_mode;
+ unsigned long long period = vm->def->cputune.period;
+ long long quota = vm->def->cputune.quota;
+ virCgroupPtr cgroup_vcpu = NULL;
+ virBitmapPtr cpumask;
+ int ret = -1;
+
+ if ((period || quota) &&
+ !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("cgroup cpu is required for scheduler tuning"));
+ goto cleanup;
+ }
+
This error won't be displayed if the domain has no VCPU pids.
ACK if you move it to the caller.
Jan