Store the emulator pinning cpu mask as a pure virBitmap rather than the virDomainPinDef since it stores only the bitmap and refactor qemuDomainPinEmulator to do the same operations in a much saner way. As a side effect virDomainEmulatorPinAdd and virDomainEmulatorPinDel can be removed since they don't add any value. --- src/conf/domain_conf.c | 66 +++------------------------------ src/conf/domain_conf.h | 8 +--- src/libvirt_private.syms | 2 - src/qemu/qemu_cgroup.c | 2 +- src/qemu/qemu_driver.c | 96 +++++++++++++----------------------------------- src/qemu/qemu_process.c | 2 +- 6 files changed, 34 insertions(+), 142 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6e57425..8a45682 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2473,7 +2473,7 @@ void virDomainDefFree(virDomainDefPtr def) virDomainPinDefArrayFree(def->cputune.vcpupin, def->cputune.nvcpupin); - virDomainPinDefFree(def->cputune.emulatorpin); + virBitmapFree(def->cputune.emulatorpin); for (i = 0; i < def->cputune.nvcpusched; i++) virBitmapFree(def->cputune.vcpusched[i].ids); @@ -13565,36 +13565,26 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, } - /* Parse the XML definition for emulatorpin. * emulatorpin has the form of * <emulatorpin cpuset='0'/> */ -static virDomainPinDefPtr +static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { - virDomainPinDefPtr def; + virBitmapPtr def = NULL; char *tmp = NULL; - if (VIR_ALLOC(def) < 0) - return NULL; - if (!(tmp = virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for emulatorpin")); - goto error; + return NULL; } - if (virBitmapParse(tmp, 0, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto error; + ignore_value(virBitmapParse(tmp, 0, &def, VIR_DOMAIN_CPUMASK_LEN)); VIR_FREE(tmp); return def; - - error: - VIR_FREE(tmp); - VIR_FREE(def); - return NULL; } @@ -17762,50 +17752,6 @@ virDomainPinDel(virDomainPinDefPtr **pindef_list, } } -int -virDomainEmulatorPinAdd(virDomainDefPtr def, - unsigned char *cpumap, - int maplen) -{ - virDomainPinDefPtr emulatorpin = NULL; - - if (!def->cputune.emulatorpin) { - /* No emulatorpin exists yet. */ - if (VIR_ALLOC(emulatorpin) < 0) - return -1; - - emulatorpin->id = -1; - emulatorpin->cpumask = virBitmapNewData(cpumap, maplen); - if (!emulatorpin->cpumask) { - virDomainPinDefFree(emulatorpin); - return -1; - } - - def->cputune.emulatorpin = emulatorpin; - } else { - /* Since there is only 1 emulatorpin for each vm, - * juest replace the old one. - */ - virBitmapFree(def->cputune.emulatorpin->cpumask); - def->cputune.emulatorpin->cpumask = virBitmapNewData(cpumap, maplen); - if (!def->cputune.emulatorpin->cpumask) - return -1; - } - - return 0; -} - -int -virDomainEmulatorPinDel(virDomainDefPtr def) -{ - if (!def->cputune.emulatorpin) - return 0; - - virDomainPinDefFree(def->cputune.emulatorpin); - def->cputune.emulatorpin = NULL; - - return 0; -} static int virDomainEventActionDefFormat(virBufferPtr buf, @@ -21099,7 +21045,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, char *cpumask; virBufferAddLit(buf, "<emulatorpin "); - if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin->cpumask))) + if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin))) goto error; virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0fcf52e..c36dfd1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2068,7 +2068,7 @@ struct _virDomainCputune { long long emulator_quota; size_t nvcpupin; virDomainPinDefPtr *vcpupin; - virDomainPinDefPtr emulatorpin; + virBitmapPtr emulatorpin; size_t nvcpusched; virDomainThreadSchedParamPtr vcpusched; @@ -2673,12 +2673,6 @@ void virDomainPinDel(virDomainPinDefPtr **pindef_list, size_t *npin, int vcpu); -int virDomainEmulatorPinAdd(virDomainDefPtr def, - unsigned char *cpumap, - int maplen); - -int virDomainEmulatorPinDel(virDomainDefPtr def); - void virDomainRNGDefFree(virDomainRNGDefPtr def); bool virDomainDiskDefDstDuplicates(virDomainDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6a95fb9..a90a1b7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -273,8 +273,6 @@ virDomainDiskSetFormat; virDomainDiskSetSource; virDomainDiskSetType; virDomainDiskSourceIsBlockType; -virDomainEmulatorPinAdd; -virDomainEmulatorPinDel; virDomainFSDefFree; virDomainFSIndexByName; virDomainFSInsert; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 96677dd..7d1f009 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1114,7 +1114,7 @@ qemuSetupCgroupForEmulator(virDomainObjPtr vm) goto cleanup; if (def->cputune.emulatorpin) - cpumask = def->cputune.emulatorpin->cpumask; + cpumask = def->cputune.emulatorpin; else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) cpumask = priv->autoCpuset; else if (def->cpumask) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d1b00a2..e34cb6c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5374,23 +5374,19 @@ qemuDomainPinEmulator(virDomainPtr dom, virQEMUDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm; virCgroupPtr cgroup_emulator = NULL; - pid_t pid; virDomainDefPtr persistentDef = NULL; int ret = -1; qemuDomainObjPrivatePtr priv; bool doReset = false; - size_t newVcpuPinNum = 0; - virDomainPinDefPtr *newVcpuPin = NULL; virBitmapPtr pcpumap = NULL; virQEMUDriverConfigPtr cfg = NULL; virCapsPtr caps = NULL; virObjectEventPtr event = NULL; - char * str = NULL; + char *str = NULL; virTypedParameterPtr eventParams = NULL; int eventNparams = 0; int eventMaxparams = 0; - virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -5436,65 +5432,33 @@ qemuDomainPinEmulator(virDomainPtr dom, if (virBitmapIsAllSet(pcpumap)) doReset = true; - pid = vm->pid; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { - - if (priv->vcpupids != NULL) { - if (VIR_ALLOC(newVcpuPin) < 0) + if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) { + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, + 0, false, &cgroup_emulator) < 0) goto endjob; - if (virDomainPinAdd(&newVcpuPin, &newVcpuPinNum, cpumap, maplen, -1) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to update vcpupin")); - virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum); + if (qemuSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("failed to set cpuset.cpus in cgroup" + " for emulator threads")); goto endjob; } - - if (virCgroupHasController(priv->cgroup, - VIR_CGROUP_CONTROLLER_CPUSET)) { - /* - * Configure the corresponding cpuset cgroup. - */ - if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, - 0, false, &cgroup_emulator) < 0) - goto endjob; - if (qemuSetupCgroupCpusetCpus(cgroup_emulator, - newVcpuPin[0]->cpumask) < 0) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("failed to set cpuset.cpus in cgroup" - " for emulator threads")); - goto endjob; - } - } else { - if (virProcessSetAffinity(pid, pcpumap) < 0) { - virReportError(VIR_ERR_SYSTEM_ERROR, "%s", - _("failed to set cpu affinity for " - "emulator threads")); - goto endjob; - } + } else { + if (virProcessSetAffinity(vm->pid, pcpumap) < 0) { + virReportError(VIR_ERR_SYSTEM_ERROR, "%s", + _("failed to set cpu affinity for " + "emulator thread")); + goto endjob; } + } - if (doReset) { - if (virDomainEmulatorPinDel(vm->def) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to delete emulatorpin xml of " - "a running domain")); - goto endjob; - } - } else { - virDomainPinDefFree(vm->def->cputune.emulatorpin); - vm->def->cputune.emulatorpin = newVcpuPin[0]; - VIR_FREE(newVcpuPin); - } + virBitmapFree(vm->def->cputune.emulatorpin); + vm->def->cputune.emulatorpin = NULL; - if (newVcpuPin) - virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum); - } else { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cpu affinity is not supported")); + if (!doReset && + !(vm->def->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) goto endjob; - } if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto endjob; @@ -5510,22 +5474,12 @@ qemuDomainPinEmulator(virDomainPtr dom, } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + virBitmapFree(persistentDef->cputune.emulatorpin); + persistentDef->cputune.emulatorpin = NULL; - if (doReset) { - if (virDomainEmulatorPinDel(persistentDef) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to delete emulatorpin xml of " - "a persistent domain")); - goto endjob; - } - } else { - if (virDomainEmulatorPinAdd(persistentDef, cpumap, maplen) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to update or add emulatorpin xml " - "of a persistent domain")); - goto endjob; - } - } + if (!doReset && + !(persistentDef->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) + goto endjob; ret = virDomainSaveConfig(cfg->configDir, persistentDef); goto endjob; @@ -5592,7 +5546,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, goto cleanup; if (targetDef->cputune.emulatorpin) { - cpumask = targetDef->cputune.emulatorpin->cpumask; + cpumask = targetDef->cputune.emulatorpin; } else if (targetDef->cpumask) { cpumask = targetDef->cpumask; } else { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f2b2229..cc588d7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2414,7 +2414,7 @@ qemuProcessSetEmulatorAffinity(virDomainObjPtr vm) int ret = -1; if (def->cputune.emulatorpin) - cpumask = def->cputune.emulatorpin->cpumask; + cpumask = def->cputune.emulatorpin; else if (def->cpumask) cpumask = def->cpumask; else -- 2.4.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list