}
int
-qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+qemuSetupCgroupForEmulator(virDomainObjPtr vm)
{
virBitmapPtr cpumask = NULL;
- virBitmapPtr cpumap = NULL;
virCgroupPtr cgroup_emulator = NULL;
virDomainDefPtr def = vm->def;
qemuDomainObjPrivatePtr priv = vm->privateData;
if (virCgroupMoveTask(priv->cgroup, cgroup_emulator) < 0)
goto cleanup;
- if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
- if (!(cpumap = qemuPrepareCpumap(driver, priv->autoNodeset)))
- goto cleanup;
- cpumask = cpumap;
- } else if (def->cputune.emulatorpin) {
+ if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
+ cpumask = priv->autoCpuset;
+ else if (def->cputune.emulatorpin)
cpumask = def->cputune.emulatorpin->cpumask;
- } else if (def->cpumask) {
+ else if (def->cpumask)
cpumask = def->cpumask;
- }
if (cpumask) {
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET) &&
}
virCgroupFree(&cgroup_emulator);
- virBitmapFree(cpumap);
return 0;
cleanup:
- virBitmapFree(cpumap);
-
if (cgroup_emulator) {
virCgroupRemove(cgroup_emulator);
virCgroupFree(&cgroup_emulator);
return ret;
}
-/* Helper to prepare cpumap for affinity setting, convert
- * NUMA nodeset into cpuset if @nodemask is not NULL, otherwise
- * just return a new allocated bitmap.
- */
-virBitmapPtr
-qemuPrepareCpumap(virQEMUDriverPtr driver,
- virBitmapPtr nodemask)
-{
- size_t i;
- int hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
- virBitmapPtr cpumap = NULL;
- virCapsPtr caps = NULL;
-
- /* setaffinity fails if you set bits for CPUs which
- * aren't present, so we have to limit ourselves */
- if ((hostcpus = nodeGetCPUCount()) < 0)
- return NULL;
-
- if (maxcpu > hostcpus)
- maxcpu = hostcpus;
-
- if (!(cpumap = virBitmapNew(maxcpu)))
- return NULL;
-
- if (nodemask) {
- if (!(caps = virQEMUDriverGetCapabilities(driver, false))) {
- virBitmapFree(cpumap);
- cpumap = NULL;
- goto cleanup;
- }
-
- for (i = 0; i < caps->host.nnumaCell; i++) {
- size_t j;
- int cur_ncpus = caps->host.numaCell[i]->ncpus;
- bool result;
- if (virBitmapGetBit(nodemask, caps->host.numaCell[i]->num, &result) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Failed to convert nodeset to cpuset"));
- virBitmapFree(cpumap);
- cpumap = NULL;
- goto cleanup;
- }
- if (result) {
- for (j = 0; j < cur_ncpus; j++)
- ignore_value(virBitmapSetBit(cpumap,
- caps->host.numaCell[i]->cpus[j].id));
- }
- }
- }
-
- cleanup:
- virObjectUnref(caps);
- return cpumap;
-}
/*
* To be run between fork/exec of QEMU only
*/
static int
-qemuProcessInitCpuAffinity(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+qemuProcessInitCpuAffinity(virDomainObjPtr vm)
{
int ret = -1;
virBitmapPtr cpumap = NULL;
return -1;
}
- if (!(cpumap = qemuPrepareCpumap(driver, priv->autoNodeset)))
- return -1;
-
if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
VIR_DEBUG("Set CPU affinity with advisory nodeset from numad");
- cpumapToSet = cpumap;
+ cpumapToSet = priv->autoCpuset;
} else {
VIR_DEBUG("Set CPU affinity with specified cpuset");
if (vm->def->cpumask) {
cpumapToSet = vm->def->cpumask;
} else {
- cpumapToSet = cpumap;
/* You may think this is redundant, but we can't assume libvirtd
* itself is running on all pCPUs, so we need to explicitly set
* the spawned QEMU instance to all pCPUs if no map is given in
* its config file */
+ int hostcpus;
+
+ /* setaffinity fails if you set bits for CPUs which
+ * aren't present, so we have to limit ourselves */
+ if ((hostcpus = nodeGetCPUCount()) < 0)
+ goto cleanup;
+
+ if (hostcpus > QEMUD_CPUMASK_LEN)
+ hostcpus = QEMUD_CPUMASK_LEN;
+
+ if (!(cpumap = virBitmapNew(hostcpus)))
+ goto cleanup;
+
virBitmapSetAll(cpumap);
+
+ cpumapToSet = cpumap;
}
}
/* This must be done after cgroup placement to avoid resetting CPU
* affinity */
if (!vm->def->cputune.emulatorpin &&
- qemuProcessInitCpuAffinity(driver, vm) < 0)
+ qemuProcessInitCpuAffinity(vm) < 0)
goto cleanup;
VIR_DEBUG("Setting domain security labels");
goto cleanup;
VIR_DEBUG("Setting cgroup for emulator (if required)");
- if (qemuSetupCgroupForEmulator(driver, vm) < 0)
+ if (qemuSetupCgroupForEmulator(vm) < 0)
goto cleanup;
VIR_DEBUG("Setting affinity of emulator threads");