]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf, qemu: consider available CPUs in vcpupin/emulatorpin output
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 26 Jun 2020 22:10:44 +0000 (19:10 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Jul 2020 17:39:44 +0000 (19:39 +0200)
The output of vcpupin and emulatorpin for a domain with vcpu
placement='static' is based on a default bitmap that contains
all possible CPUs in the host, regardless of the CPUs being offline
or not. E.g. for a Linux host with this CPU setup (from lscpu):

On-line CPU(s) list:   0,8,16,24,32,40,(...),184
Off-line CPU(s) list: 1-7,9-15,17-23,25-31,(...),185-191

And a domain with this configuration:

  <vcpu placement='static'>1</vcpu>

'virsh vcpupin' will return the following:

$ sudo ./run tools/virsh vcpupin vcpupin_test
 VCPU   CPU Affinity
----------------------
 0      0-191

This is benign by its own, but can make the user believe that all
CPUs from the 0-191 range are eligible for pinning. Which can lead
to situations like this:

$ sudo ./run tools/virsh vcpupin vcpupin_test 0 1
error: Invalid value '1' for 'cpuset.cpus': Invalid argument

This is exarcebated by the fact that 'virsh vcpuinfo' considers only
available host CPUs in the 'CPU Affinity' field:

$ sudo ./run tools/virsh vcpuinfo vcpupin_test
(...)
CPU Affinity:   y-------y-------y-------(...)

This patch changes the default bitmap of vcpupin and emulatorpin, in
the case of domains with static vcpu placement, to all available CPUs
instead of all possible CPUs. Aside from making it consistent with
the behavior of 'vcpuinfo', users will now have one less incentive to
try to pin a vcpu in an offline CPU.

https://bugzilla.redhat.com/show_bug.cgi?id=1434276

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/qemu/qemu_driver.c

index e9803b85143e33b9d9e4920c7b7387cf668316df..abea23542ac428acd7d5bdf33726440c6c3a4df5 100644 (file)
@@ -2089,11 +2089,9 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
     if (hostcpus < 0)
         return -1;
 
-    if (!(allcpumap = virBitmapNew(hostcpus)))
+    if (!(allcpumap = virHostCPUGetAvailableCPUsBitmap()))
         return -1;
 
-    virBitmapSetAll(allcpumap);
-
     for (i = 0; i < maxvcpus && i < ncpumaps; i++) {
         virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
         virBitmapPtr bitmap = NULL;
index 350e6f5368b6cf42e0c0dd31fc25fc5223402a44..f36179570977ac8f1ecd32aafe8d184b26da3982 100644 (file)
@@ -5425,7 +5425,6 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
     virDomainDefPtr def;
     bool live;
     int ret = -1;
-    int hostcpus;
     virBitmapPtr cpumask = NULL;
     g_autoptr(virBitmap) bitmap = NULL;
     virBitmapPtr autoCpuset = NULL;
@@ -5442,9 +5441,6 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
     if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
         goto cleanup;
 
-    if ((hostcpus = virHostCPUGetCount()) < 0)
-        goto cleanup;
-
     if (live)
         autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset;
 
@@ -5456,9 +5452,8 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
                autoCpuset) {
         cpumask = autoCpuset;
     } else {
-        if (!(bitmap = virBitmapNew(hostcpus)))
+        if (!(bitmap = virHostCPUGetAvailableCPUsBitmap()))
             goto cleanup;
-        virBitmapSetAll(bitmap);
         cpumask = bitmap;
     }