diff options
author | Bibo Mao <maobibo@loongson.cn> | 2025-02-10 17:03:29 +0800 |
---|---|---|
committer | Bibo Mao <maobibo@loongson.cn> | 2025-03-05 09:39:18 +0800 |
commit | a97cceb1d7ed05070dc52e7850112f906d7e3512 (patch) | |
tree | dc8f40fbdeebbd80be2461c25dfcbd0809f39519 | |
parent | 25cdac981fd012d9b96d8db9a809841c7e521154 (diff) | |
download | qemu-a97cceb1d7ed05070dc52e7850112f906d7e3512.zip qemu-a97cceb1d7ed05070dc52e7850112f906d7e3512.tar.gz qemu-a97cceb1d7ed05070dc52e7850112f906d7e3512.tar.bz2 |
hw/loongarch/virt: Enable cpu hotplug feature on virt machine
On virt machine, enable CPU hotplug feature has_hotpluggable_cpus. For
hot-added CPUs, there is socket-id/core-id/thread-id property set,
arch_id can be caculated from these properties. So that cpu slot can be
searched from its arch_id.
Co-developed-by: Xianglai Li <lixianglai@loongson.cn>
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
-rw-r--r-- | hw/loongarch/virt.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 8aba145..a5840ff 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -861,10 +861,42 @@ static void virt_cpu_pre_plug(HotplugHandler *hotplug_dev, CPUArchId *cpu_slot; Error *err = NULL; LoongArchCPUTopo topo; + int arch_id; if (lvms->acpi_ged) { - error_setg(&err, "CPU hotplug not supported"); - goto out; + if ((cpu->thread_id < 0) || (cpu->thread_id >= ms->smp.threads)) { + error_setg(&err, + "Invalid thread-id %u specified, must be in range 1:%u", + cpu->thread_id, ms->smp.threads - 1); + goto out; + } + + if ((cpu->core_id < 0) || (cpu->core_id >= ms->smp.cores)) { + error_setg(&err, + "Invalid core-id %u specified, must be in range 1:%u", + cpu->core_id, ms->smp.cores - 1); + goto out; + } + + if ((cpu->socket_id < 0) || (cpu->socket_id >= ms->smp.sockets)) { + error_setg(&err, + "Invalid socket-id %u specified, must be in range 1:%u", + cpu->socket_id, ms->smp.sockets - 1); + goto out; + } + + topo.socket_id = cpu->socket_id; + topo.core_id = cpu->core_id; + topo.thread_id = cpu->thread_id; + arch_id = virt_get_arch_id_from_topo(ms, &topo); + cpu_slot = virt_find_cpu_slot(ms, arch_id); + if (CPU(cpu_slot->cpu)) { + error_setg(&err, + "cpu(id%d=%d:%d:%d) with arch-id %" PRIu64 " exists", + cs->cpu_index, cpu->socket_id, cpu->core_id, + cpu->thread_id, cpu_slot->arch_id); + goto out; + } } else { /* For cold-add cpu, find empty cpu slot */ cpu_slot = virt_find_empty_cpu_slot(ms); @@ -967,6 +999,13 @@ static void virt_cpu_plug(HotplugHandler *hotplug_dev, } } + if (lvms->acpi_ged) { + hotplug_handler_plug(HOTPLUG_HANDLER(lvms->acpi_ged), dev, &err); + if (err) { + error_propagate(errp, err); + } + } + return; } @@ -1149,6 +1188,7 @@ static void virt_class_init(ObjectClass *oc, void *data) mc->numa_mem_supported = true; mc->auto_enable_numa_with_memhp = true; mc->auto_enable_numa_with_memdev = true; + mc->has_hotpluggable_cpus = true; mc->get_hotplug_handler = virt_get_hotplug_handler; mc->default_nic = "virtio-net-pci"; hc->plug = virt_device_plug_cb; |