VM vCPU Hotplug
In the VM environment, vCPUs comply with the Advanced Configuration and Power Interface (ACPI) standard and implement functions by simulating ACPI GED. When a vCPU hotplug request is initiated in libvirt, QEMU operates the simulated ACPI GED device and sends interrupt signals to the VM. After receiving the interrupt, the ACPI firmware in the VM responds and invokes the corresponding CPU hotplug event handler to implement vCPU hotplug.
This mechanism not only supports online increase of vCPU threads, but also supports online decrease of vCPU threads.
Application Scenarios
This feature applies to scenarios where the service load fluctuates dynamically and the CPU needs to dynamically adjust resources to reduce costs.
Constraints
In openEuler 24.03 and later versions, the CPU hot removal function is added to the AArch64 architecture. However, the new community mainline solution is actually used, which is incompatible with the CPU hotplug protocol of earlier versions. The guest version must match the host version. That is, if the guest version is openEuler 24.03 or later, the host version must be openEuler 24.03 or later as well. If the guest version is earlier than openEuler 24.03, the host version must be earlier than openEuler 24.03. Otherwise, the CPU hotplug function cannot be used.
- For processors using the AArch64 architecture, the specified VM chipset type (machine) needs to be virt-4.2 or a later version when a VM is created.
- For an AArch64 VM, CPUs that exist during the initial startup do not support hotplug.
- When configuring Guest NUMA, you need to configure the vCPUs that belong to the same socket in the same vNode. Otherwise, the VM may be soft locked up after CPU hotplug, which may result in VM panic.
- VMs do not support CPU hotplug during migration, hibernation, wakeup, or snapshot.
- Whether the hot added CPU can automatically go online depends on the VM OS logic rather than the virtualization layer.
- CPU hotplug is restricted by the maximum number of CPUs supported by the hypervisor and guest OS.
- When a VM is being started, stopped, or restarted, the hot added CPU may become invalid. However, the hot added CPU takes effect after the VM is restarted.
- When a VM is being started, stopped, or restarted, the CPU hot removal may time out and fail. Wait until the VM is running properly and try again.
- During vCPU hotplug, if the number of added CPUs is not an integer multiple of the number of cores in the VM CPU topology configuration item, the CPU topology displayed in the VM may be disordered. You are advised to add or remove CPUs whose number is an integer multiple of the number of cores each time.
- If the CPU that is hot added or removed needs to take effect online and is still valid after the VM is restarted, the --config and --live options need to be transferred to the virsh setvcpus API to persist the CPU hotplug operation.