5 A complete example of vCPU hotplug (and hot-unplug) using QMP
6 ``device_add`` and ``device_del``.
11 (1) Launch QEMU as follows (note that the "maxcpus" is mandatory to
14 $ qemu-system-x86_64 -display none -no-user-config -m 2048 \
15 -nodefaults -monitor stdio -machine pc,accel=kvm,usb=off \
16 -smp 1,maxcpus=2 -cpu IvyBridge-IBRS \
17 -qmp unix:/tmp/qmp-sock,server=on,wait=off
19 (2) Run 'qmp-shell' (located in the source tree, under: "scripts/qmp/)
20 to connect to the just-launched QEMU::
22 $> ./qmp-shell -p -v /tmp/qmp-sock
26 (3) Find out which CPU types could be plugged, and into which sockets::
28 (QEMU) query-hotpluggable-cpus
30 "execute": "query-hotpluggable-cpus",
41 "type": "IvyBridge-IBRS-x86_64-cpu",
50 "qom-path": "/machine/unattached/device[0]",
51 "type": "IvyBridge-IBRS-x86_64-cpu",
58 (4) The ``query-hotpluggable-cpus`` command returns an object for CPUs
59 that are present (containing a "qom-path" member) or which may be
60 hot-plugged (no "qom-path" member). From its output in step (3), we
61 can see that ``IvyBridge-IBRS-x86_64-cpu`` is present in socket 0 core 0,
62 while hot-plugging a CPU into socket 0 core 1 requires passing the listed
63 properties to QMP ``device_add``::
65 (QEMU) device_add id=cpu-2 driver=IvyBridge-IBRS-x86_64-cpu socket-id=0 core-id=1 thread-id=0
67 "execute": "device_add",
70 "driver": "IvyBridge-IBRS-x86_64-cpu",
81 (5) Optionally, run QMP ``query-cpus-fast`` for some details about the
84 (QEMU) query-cpus-fast
87 "execute": "query-cpus-fast",
98 "qom-path": "/machine/unattached/device[0]",
109 "qom-path": "/machine/peripheral/cpu-2",
120 From the 'qmp-shell', invoke the QMP ``device_del`` command::
122 (QEMU) device_del id=cpu-2
127 "execute": "device_del",
135 vCPU hot-unplug requires guest cooperation; so the ``device_del``
136 command above does not guarantee vCPU removal -- it's a "request to
137 unplug". At this point, the guest will get a System Control
138 Interrupt (SCI) and calls the ACPI handler for the affected vCPU
139 device. Then the guest kernel will bring the vCPU offline and tell