[libvirt] [PATCH] Explicitly pin hotplugged vcpu to all cpus

QEMU does not join vcpu threads after vcpu hotunplug. The thread might stay pinned when we hotplug the cpu again. We were already pinning the hotplugged vcpus when a per-domain pinning was specified. Explicitly pin the hotplugged vcpu to all cpus if there is no cpuset specified in domain XML, to make sure the vcpupin stays accurate. https://bugzilla.redhat.com/show_bug.cgi?id=1099836 --- src/qemu/qemu_driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6fda50d..a4fa488 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3994,6 +3994,7 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, pid_t *cpupids = NULL; int ncpupids; virCgroupPtr cgroup_vcpu = NULL; + virBitmapPtr cpumask = NULL; qemuDomainObjEnterMonitor(driver, vm); @@ -4117,6 +4118,24 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, goto cleanup; } } + } else { + /* QEMU doesn't destroy vcpu threads on vcpu unplug. + * Pin the vcpu to all CPUs just to be sure */ + cpumask = qemuPrepareCpumap(driver, NULL); + virBitmapSetAll(cpumask); + if (cgroup_vcpu) { + if (qemuSetupCgroupEmulatorPin(cgroup_vcpu, cpumask) < 0) + goto cleanup; + } else { + if (virProcessSetAffinity(cpupids[i], cpumask) < 0) { + virReportError(VIR_ERR_SYSTEM_ERROR, + _("failed to set cpu affinity for vcpu %zu"), + i); + ret = -1; + goto cleanup; + } + } + VIR_FREE(cpumask); } virCgroupFree(&cgroup_vcpu); @@ -4145,6 +4164,7 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, cleanup: qemuDomainObjExitMonitor(driver, vm); vm->def->vcpus = vcpus; + VIR_FREE(cpumask); VIR_FREE(cpupids); virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1); if (cgroup_vcpu) -- 1.8.3.2

On 05/23/14 14:37, Ján Tomko wrote:
QEMU does not join vcpu threads after vcpu hotunplug. The thread might stay pinned when we hotplug the cpu again.
We were already pinning the hotplugged vcpus when a per-domain pinning was specified.
Explicitly pin the hotplugged vcpu to all cpus if there is no cpuset specified in domain XML, to make sure the vcpupin stays accurate.
https://bugzilla.redhat.com/show_bug.cgi?id=1099836 --- src/qemu/qemu_driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
The statements about qemu are true only for the downstream version. Upstream qemu promises that it will clean up the threads once they implement vCPU hot unplug so we will not need to execute the code you've proposed in upstream. NACK for merging this upstream. Peter

On 05/23/14 14:45, Peter Krempa wrote:
On 05/23/14 14:37, Ján Tomko wrote:
QEMU does not join vcpu threads after vcpu hotunplug. The thread might stay pinned when we hotplug the cpu again.
We were already pinning the hotplugged vcpus when a per-domain pinning was specified.
Explicitly pin the hotplugged vcpu to all cpus if there is no cpuset specified in domain XML, to make sure the vcpupin stays accurate.
https://bugzilla.redhat.com/show_bug.cgi?id=1099836 --- src/qemu/qemu_driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
The statements about qemu are true only for the downstream version. Upstream qemu promises that it will clean up the threads once they implement vCPU hot unplug so we will not need to execute the code you've proposed in upstream.
Hmmm, re-reading the code ... pinning the currently hotplugged vcpu thread to all cpus isn't silly on the other hand. The stuff is that qemu upstream doesn't do hot unplug and thus the statements about qemu shouldn't be in libvirt's code. I'll respond to the original mail again to clarify my intent.
NACK for merging this upstream.
Peter
Peter
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Ján Tomko
-
Peter Krempa