[libvirt] [PATCH 0/2 v2] List only online cpus for vcpupin/emulatorpin when vcpu placement static

Currently when the vcpu placement is static and cpuset is not specified, CPU Affinity shows 0.. CPUMAX. This patchset will result in display of only online CPU's under CPU Affinity on linux. Nitesh Konkar (2): conf: List only online cpus for virsh vcpupin conf: List only online cpus for virsh emulatorpin src/conf/domain_conf.c | 8 +++++++- src/qemu/qemu_driver.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) -- 2.1.0

Currently when the vcpu placement is static and cpuset is not specified, CPU Affinity under virsh vcpupin shows 0..CPUMAX. This patchset will result in display of only online CPU's under CPU Affinity on linux. Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a233c0c..78efbc6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -55,6 +55,7 @@ #include "virtpm.h" #include "virstring.h" #include "virnetdev.h" +#include "virhostcpu.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -1543,6 +1544,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, { int maxvcpus = virDomainDefGetVcpusMax(def); virBitmapPtr allcpumap = NULL; + virBitmapPtr bitmap = NULL; size_t i; if (hostcpus < 0) @@ -1555,13 +1557,16 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, for (i = 0; i < maxvcpus && i < ncpumaps; i++) { virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i); - virBitmapPtr bitmap = NULL; + bitmap = NULL; if (vcpu && vcpu->cpumask) bitmap = vcpu->cpumask; else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && autoCpuset) bitmap = autoCpuset; + else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC && + virHostCPUGetOnlineBitmap()) + bitmap = virHostCPUGetOnlineBitmap(); else if (def->cpumask) bitmap = def->cpumask; else @@ -1571,6 +1576,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, } virBitmapFree(allcpumap); + virBitmapFree(bitmap); return i; } -- 2.1.0

On Thu, Nov 10, 2016 at 12:30:00 +0530, Nitesh Konkar wrote:
Currently when the vcpu placement is static and cpuset is not specified, CPU Affinity under virsh vcpupin shows 0..CPUMAX. This patchset will result in display of only online CPU's under CPU Affinity on linux.
Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a233c0c..78efbc6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -55,6 +55,7 @@ #include "virtpm.h" #include "virstring.h" #include "virnetdev.h" +#include "virhostcpu.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN
@@ -1543,6 +1544,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, { int maxvcpus = virDomainDefGetVcpusMax(def); virBitmapPtr allcpumap = NULL; + virBitmapPtr bitmap = NULL; size_t i;
if (hostcpus < 0) @@ -1555,13 +1557,16 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
for (i = 0; i < maxvcpus && i < ncpumaps; i++) { virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i); - virBitmapPtr bitmap = NULL; + bitmap = NULL;
if (vcpu && vcpu->cpumask) bitmap = vcpu->cpumask;
By assigning vcpu->cpumask to bitmap here, you free it at the end and break the domain definition by freeing it's content.
else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && autoCpuset) bitmap = autoCpuset; + else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC && + virHostCPUGetOnlineBitmap())
This first call returns a different instance of the bitmap which is leaked afterwards since it's not put into a variable. Additionally on non-linux platforms the function call would report an error which would not be used later.
+ bitmap = virHostCPUGetOnlineBitmap();
And this may still return NULL since it's a separate call.
else if (def->cpumask) bitmap = def->cpumask; else
Peter

Currently when the vcpu placement is static and cpuset is not specified, CPU Affinity under virsh emulatorpin shows 0..CPUMAX. This patchset will result in display of only online CPU's under CPU Affinity on linux. Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com> --- src/qemu/qemu_driver.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a82e58b..5456596 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5435,6 +5435,9 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, } else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && autoCpuset) { cpumask = autoCpuset; + } else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC && + virHostCPUGetOnlineBitmap()) { + cpumask = virHostCPUGetOnlineBitmap(); } else { if (!(bitmap = virBitmapNew(hostcpus))) goto cleanup; @@ -5449,6 +5452,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); virBitmapFree(bitmap); + virBitmapFree(cpumask); return ret; } -- 2.1.0
participants (2)
-
Nitesh Konkar
-
Peter Krempa