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,nowait
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",
36 "type": "IvyBridge-IBRS-x86_64-cpu",
45 "qom-path": "/machine/unattached/device[0]",
46 "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,
62 while hot-plugging a CPU into socket 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=1 core-id=0 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
86 "execute": "query-cpus-fast",
92 "qom-path": "/machine/unattached/device[0]",
104 "qom-path": "/machine/peripheral/cpu-2",
122 From the 'qmp-shell', invoke the QMP ``device_del`` command::
124 (QEMU) device_del id=cpu-2
126 "execute": "device_del",
137 vCPU hot-unplug requires guest cooperation; so the ``device_del``
138 command above does not guarantee vCPU removal -- it's a "request to
139 unplug". At this point, the guest will get a System Control
140 Interrupt (SCI) and calls the ACPI handler for the affected vCPU
141 device. Then the guest kernel will bring the vCPU offline and tell