]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Change qemuDomainGetEmulatorPinInfo bitmap manipulation
authorJohn Ferlan <jferlan@redhat.com>
Fri, 6 Mar 2015 18:26:46 +0000 (13:26 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 9 Mar 2015 12:11:49 +0000 (08:11 -0400)
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

index 42e4b54c870a399e945a12d06748a909995817ea..ceceafaa4072d7700e2112041fa04d7309ecd0c8 100644 (file)
@@ -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;
-    }
-
-    for (pcpu = 0; pcpu < maxcpu; pcpu++) {
-        if (virBitmapGetBit(cpumask, pcpu, &pinned) < 0)
+        if (!(bitmap = virBitmapNew(hostcpus)))
             goto cleanup;
-        if (!pinned)
-            VIR_UNUSE_CPU(cpumaps, pcpu);
+        virBitmapSetAll(bitmap);
+        cpumask = bitmap;
     }
 
+    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;
 }