From 86ef105a1dc3c374886027f1b8983989d719a462 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Fri, 6 Mar 2015 13:26:46 -0500 Subject: [PATCH] qemu: Change qemuDomainGetEmulatorPinInfo bitmap manipulation Follow-up to the IOThread review on CPU affinity map manipulation: http://www.redhat.com/archives/libvir-list/2015-March/msg00294.html indicates that the GetEmulatorPinInfo could use similar algorithm adjustments which is what this patch does. --- src/qemu/qemu_driver.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 42e4b54c87..ceceafaa40 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5368,10 +5368,12 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, virDomainObjPtr vm = NULL; virDomainDefPtr targetDef = NULL; int ret = -1; - int maxcpu, hostcpus, pcpu; + int hostcpus; virBitmapPtr cpumask = NULL; - bool pinned; + virBitmapPtr bitmap = NULL; virCapsPtr caps = NULL; + unsigned char *tmpmap = NULL; + int tmpmaplen; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -5398,36 +5400,30 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, if ((hostcpus = nodeGetCPUCount()) < 0) goto cleanup; - maxcpu = maplen * 8; - if (maxcpu > hostcpus) - maxcpu = hostcpus; - - /* initialize cpumaps */ - memset(cpumaps, 0xff, maplen); - if (maxcpu % 8) - cpumaps[maplen - 1] &= (1 << maxcpu % 8) - 1; - if (targetDef->cputune.emulatorpin) { cpumask = targetDef->cputune.emulatorpin->cpumask; } else if (targetDef->cpumask) { cpumask = targetDef->cpumask; } else { - ret = 0; - goto cleanup; + if (!(bitmap = virBitmapNew(hostcpus))) + goto cleanup; + virBitmapSetAll(bitmap); + cpumask = bitmap; } - for (pcpu = 0; pcpu < maxcpu; pcpu++) { - if (virBitmapGetBit(cpumask, pcpu, &pinned) < 0) - goto cleanup; - if (!pinned) - VIR_UNUSE_CPU(cpumaps, pcpu); - } + if (virBitmapToData(cpumask, &tmpmap, &tmpmaplen) < 0) + goto cleanup; + if (tmpmaplen > maplen) + tmpmaplen = maplen; + memcpy(cpumaps, tmpmap, tmpmaplen); + VIR_FREE(tmpmap); ret = 1; cleanup: qemuDomObjEndAPI(&vm); virObjectUnref(caps); + virBitmapFree(bitmap); return ret; }