[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC qom-cpu v4 08/10] i386: implement pc interface pc_hot_
From: |
Chen Fan |
Subject: |
[Qemu-devel] [RFC qom-cpu v4 08/10] i386: implement pc interface pc_hot_del_cpu() |
Date: |
Wed, 9 Oct 2013 17:43:16 +0800 |
Implement cpu interface pc_hot_del_cpu() for unrealizing device vCPU.
emiting vcpu-remove notifier to ACPI, then ACPI could send sci interrupt
to OS for hot-remove vcpu.
Signed-off-by: Chen Fan <address@hidden>
---
hw/i386/pc.c | 30 ++++++++++++++++++++++++++++--
qom/cpu.c | 12 ++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 8ab6e4f..a6b9b78 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -958,8 +958,34 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
void pc_hot_del_cpu(const int64_t id, Error **errp)
{
- /* TODO: hot remove vCPU. */
- error_setg(errp, "Hot-remove CPU is not supported.");
+ CPUState *cpu;
+ bool found = false;
+ X86CPUClass *xcc;
+
+ CPU_FOREACH(cpu) {
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ int64_t cpuid = cc->get_arch_id(cpu);
+
+ if (cpuid == id) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ error_setg(errp, "Unable to find cpu-index: %" PRIi64
+ ", it doesn't exist or has been deleted.", id);
+ return;
+ }
+
+ if (cpu == first_cpu && !CPU_NEXT(cpu)) {
+ error_setg(errp, "Unable to delete the last "
+ "one cpu when VM running.");
+ return;
+ }
+
+ xcc = X86_CPU_GET_CLASS(DEVICE(cpu));
+ xcc->parent_unrealize(DEVICE(cpu), errp);
}
void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
diff --git a/qom/cpu.c b/qom/cpu.c
index d20783b..89fc8bd 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -228,6 +228,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error
**errp)
}
}
+static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
+{
+ CPUNotifier notifier;
+
+ notifier.dev = dev;
+ notifier.type = UNPLUG;
+
+ notifier_list_notify(&cpu_hotplug_notifiers, ¬ifier);
+}
+
+
static void cpu_common_initfn(Object *obj)
{
CPUState *cpu = CPU(obj);
@@ -258,6 +269,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
dc->realize = cpu_common_realizefn;
+ dc->unrealize = cpu_common_unrealizefn;
dc->no_user = 1;
}
--
1.8.1.4
- [Qemu-devel] [RFC qom-cpu v4 00/10] i386: add cpu hot remove support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 02/10] apic: remove redundant variable 'apic_no' from apic_init_common(), Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 04/10] x86: add x86_cpu_unrealizefn() for cpu apic remove, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 01/10] x86: move apic_state field from CPUX86State to X86CPU, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 03/10] apic: remove local_apics array and using CPU_FOREACH instead, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 05/10] qmp: add 'cpu-del' command support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 07/10] qom cpu: add UNPLUG cpu notifier support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 08/10] i386: implement pc interface pc_hot_del_cpu(),
Chen Fan <=
- [Qemu-devel] [RFC qom-cpu v4 09/10] piix4: implement function cpu_status_write() for vcpu ejection, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 10/10] cpus: reclaim allocated vCPU objects, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 06/10] qom cpu: rename variable 'cpu_added_notifier' to 'cpu_hotplug_notifier', Chen Fan, 2013/10/09