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.
This commit is contained in:
John Ferlan 2015-03-06 13:26:46 -05:00
parent 10f2740ae3
commit 86ef105a1d

View File

@ -5368,10 +5368,12 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainDefPtr targetDef = NULL; virDomainDefPtr targetDef = NULL;
int ret = -1; int ret = -1;
int maxcpu, hostcpus, pcpu; int hostcpus;
virBitmapPtr cpumask = NULL; virBitmapPtr cpumask = NULL;
bool pinned; virBitmapPtr bitmap = NULL;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
unsigned char *tmpmap = NULL;
int tmpmaplen;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
@ -5398,36 +5400,30 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
goto cleanup; 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) { if (targetDef->cputune.emulatorpin) {
cpumask = targetDef->cputune.emulatorpin->cpumask; cpumask = targetDef->cputune.emulatorpin->cpumask;
} else if (targetDef->cpumask) { } else if (targetDef->cpumask) {
cpumask = targetDef->cpumask; cpumask = targetDef->cpumask;
} else { } else {
ret = 0; if (!(bitmap = virBitmapNew(hostcpus)))
goto cleanup; goto cleanup;
virBitmapSetAll(bitmap);
cpumask = bitmap;
} }
for (pcpu = 0; pcpu < maxcpu; pcpu++) { if (virBitmapToData(cpumask, &tmpmap, &tmpmaplen) < 0)
if (virBitmapGetBit(cpumask, pcpu, &pinned) < 0)
goto cleanup; goto cleanup;
if (!pinned) if (tmpmaplen > maplen)
VIR_UNUSE_CPU(cpumaps, pcpu); tmpmaplen = maplen;
} memcpy(cpumaps, tmpmap, tmpmaplen);
VIR_FREE(tmpmap);
ret = 1; ret = 1;
cleanup: cleanup:
qemuDomObjEndAPI(&vm); qemuDomObjEndAPI(&vm);
virObjectUnref(caps); virObjectUnref(caps);
virBitmapFree(bitmap);
return ret; return ret;
} }