Features/CPUHotplug
Summary
There are 2 ways to hotplug CPU in QEMU:
- dedicated legacy interface: cpu-add QMP command
- generic device-add/device-del interface for hot-(un)plugging CPUs
Owner
- Name: Igor Mammedov
- Email: imammedo@redhat.com
cpu-add interface
Summary
{ 'command': 'cpu-add', 'data': {'id': 'int'} }
- ID - a number in range [0..max-cpus)
- Available since: 1.5
- Supported targets: i386-softmmu, x86_64-softmmu, s399x (since 2.6)
Description
Command is a legacy solution for CPU hot-add and gives a simplified interface for it. It provides an opportunity to implement the feature for targets that currently can't implement CPU hot-add using device_add command due to their present design. Later targets that implement it could rewrite it to become a wrapper over device_add when it becomes usable for target.
Usage example
1. start QEMU with QMP socket available and with startup amount of CPUs less than maxcpus
./qemu-system-x86_64 -qmp unix:/tmp/qmp-sock,server,nowait -smp 1,maxcpus=4
2. Connect to QMP socket using qmp-shell command
./QMP/qmp-shell /tmp/qmp-sock
3. Add CPUs issuing cpu-add command in qmp-shell command prompt
cpu-add id=1
4. Optionally online newly added CPU inside guest
Linux kernel doesn't online hot-added CPUs automatically. Once CPU is hot-added it should be onlined using an appropriate udev script or manually by issuing a following command:
echo 1 > /sys/devices/system/cpu/cpu1/online
Sample udev script: Add the following line to /etc/udev/rules.d/99-hotPlugCPU.rules
SUBSYSTEM=="cpu",ACTION=="add",RUN+="/bin/sh -c '[ ! -e /sys$devpath/online ] || echo 1 > /sys$devpath/online'"
Current limitations
- migration target should be started with initial CPU count '-smp XX' that includes hot-added CPUs on migration source side.
- CPU shouldn't be hot-plugged during migration.
- adding CPUs should be done in successive order from lower to higher IDs in [0..max-cpus) range.
It's possible to add arbitrary CPUs in random order, however that would cause migration to fail on its target side.
device_add/device_del interface
Summary
{ 'command': 'device_add', 'data': {'driver': 'str', 'id': 'str', ... }}
- mandatory properties for every CPU:
- driver: cpu model type name
- id: unique device name
- target
- socket-id: socket number in range [0..max sockets)
- core-id: core number in range [0..max cores)
- thread-id: thread-id in range [..max threads)