[PATCH kvmtool 0/7] Fix --vcpu-affinity
Alexandru Elisei
alexandru.elisei at arm.com
Thu Sep 17 08:49:25 PDT 2026
This is my attempt at fixing --vcpu-affinity, which I introduced. Patches #1-#4
are straightforward fixes, and they don't modify the current (broken) behaviour
in any way. Patch #5 fixes is most of the fix: with it, the VCPU threads run on
the physical CPUs passed to --vcpu-affinity, and most of the kvmtool threads,
except the virtio threads, use the main thread affinity.
The virtio threads are special because they are spawned from the VCPU threads,
and they inherit the VCPU thread affinity. Note that there might be other cases
where this happens.
Patches #6-#7 attempt to fix the remaining issue: #6 switch the entire codebase
to kvm_create_thread() instead of pthread_create(). In #7, kvm_create_thread()
will use the main thread affinity when creating new threads. These two patches
are RFC because they cause a lot of churn and I would like some feedback if it's
worth it.
Why is it useful to run the VCPUs on different physical CPUs than the other
threads? I can think of two situations:
1. Testing heterogenous hardware configurations, where the VM creation and setup
happens on a set of physical CPUs, and the VCPUs are run on a different set. I
used these patches for the KVM SPE series.
2. I/O testing. Maybe?
Tested on an Orion board and a x86 machine. On the x86 machine, there's was this
one thread called 'kvm-nx-lpage-re' which had affinity of the VCPUs, but I
couldn't figure out where it was created. I grep'ed for each part of the name in
the source node, no luck. I used strace, and couldn't see a clone call that
returned the corresponding pid. Any clues would be appreciated.
Alexandru Elisei (7):
arm64: Pass the number of elements as the first argument to calloc()
arm64: Consistently treat vcpu_affinity_cpuset as dynamically
allocated
arm64: Free the temporary cpumask in vcpu_affinity_parser()
arm64/pmu: Consider kvmtool's affinity when searching for a PMU
Correctly apply --vcpu-affinity to the VCPU threads
Introduce kvm_create_thread()
Don't apply --vcpu-affinity to threads spawned from VCPUs
arm64/include/kvm/kvm-arch.h | 2 --
arm64/include/kvm/kvm-config-arch.h | 5 ----
arm64/kvm-cpu.c | 9 ------
arm64/kvm.c | 31 --------------------
arm64/pmu.c | 31 +++++++++++---------
builtin-run.c | 41 +++++++++++++++++++++++++--
disk/aio.c | 3 +-
disk/blk.c | 12 ++++++--
disk/core.c | 29 ++++++++++---------
disk/qcow.c | 44 ++++++++++++++++++++---------
disk/raw.c | 21 +++++++++++---
epoll.c | 2 +-
include/kvm/disk-image.h | 28 ++++++++++++------
include/kvm/kvm-config.h | 1 +
include/kvm/kvm.h | 2 ++
include/kvm/qcow.h | 3 +-
include/kvm/uip.h | 2 ++
include/kvm/util.h | 6 ++++
kvm.c | 18 ++++++++++++
net/uip/tcp.c | 7 ++---
net/uip/udp.c | 5 ++--
term.c | 4 +--
ui/gtk3.c | 2 +-
ui/sdl.c | 2 +-
ui/vnc.c | 2 +-
util/threadpool.c | 9 +++---
util/util.c | 42 +++++++++++++++++++++++++++
virtio/blk.c | 2 +-
virtio/net.c | 26 +++++++++++------
29 files changed, 258 insertions(+), 133 deletions(-)
base-commit: f67bc0bdae9433a9cfd05e65ea2c1bb6102566d9
--
2.55.0
More information about the linux-arm-kernel
mailing list