Skip to contentSkip to conversation

cpu: add device_add foo-x86_64-cpu support

PATCH In review Zhu Guihua 7 participants 26 messages Feb 13, 2015 – Mar 13, 2015

lore
Share & tools
lore

Zhu Guihua

author
#0 lore raw

v4 cover cpu: add device_add foo-x86_64-cpu support

This series is based on the previous patchset from Chen Fan:
https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html

We try to make cpu hotplug with device_add, and make "-device foo-x86_64-cpu" available, also we can set apic-id property with command line, if without setting apic-id property, we offer the first unoccupied apic id as the default new apic id. When hotplug cpu with device_add, additional check of APIC ID will be done after cpu object initialization which was different from 'cpu_add' command that check 'ids' at the beginning.

The is the first half of the previous series:
[RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support
https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html

---
Changelog since v3:
-fix cross version migration issue
-drop ICC bus impl
-do a generic for apic to send gpe event
-do not use migration code for CONFIG_USER_ONLY target

Changelog since v2:
-rebase on latest upstream.
-add cpu instance finalize.

Changelog since v1:
-rebased on latest upstream.
-introduce a help function to hide the access to icc_bus. -use a macro ACPI_ID_NOT_SET to replace the magic number(0xFFFFFFFF).

Changelog since RFC:
-split out APIC vmstate/QMP-monitor changes into separate patches. -add the handle of the startup cpus(-device foo).
-remove duplicated checking about env->cpuid_apic_id.
-do actual APIC ID allocation at realize time if it is not set before. -remove the unneeded x86_cpu_cpudef_instance_init().
-split off device_del support out here.
---

Chen Fan (4):
cpu/apic: drop icc bus/bridge/
icc_bus: remove icc related files
cpu: introduce CpuTopoInfo structure for argument simplification
cpu: add device_add foo-x86_64-cpu support

Gu Zheng (4):
qom/cpu: move register_vmstate to common CPUClass.realizefn qom/cpu: move apic vmstate register into x86_cpu_apic_realize
monitor: use cc->get_arch_id as the cpu index i386/cpu: add instance finalize callback

Zhu Guihua (2):
cpu: introduce get_compat_arch_id() method and override it for X86CPU
acpi: introduce acpi_send_gpe_event()

 MAINTAINERS                        |   6 --
 cpus.c                             |   4 +-
 default-configs/i386-softmmu.mak   |   1 -
 default-configs/x86_64-softmmu.mak |   1 -
 exec.c                             |  25 +++++---
 hw/acpi/core.c                     |   7 +++
 hw/acpi/cpu_hotplug.c              |   6 +-
 hw/cpu/Makefile.objs               |   2 -
 hw/cpu/icc_bus.c                   | 118 -------------------------------------
 hw/i386/kvm/apic.c                 |  10 +++-
 hw/i386/pc.c                       |  27 ++-------
 hw/i386/pc_piix.c                  |   9 +--
 hw/i386/pc_q35.c                   |   9 +--
 hw/intc/apic.c                     |  16 +++--
 hw/intc/apic_common.c              |  17 +++---
 include/hw/acpi/acpi.h             |   3 +
 include/hw/cpu/icc_bus.h           |  82 --------------------------
 include/hw/i386/apic_internal.h    |   9 +--
 include/hw/i386/pc.h               |   3 +-
 include/qom/cpu.h                  |   6 ++
 monitor.c                          |   4 +-
 qom/cpu.c                          |  10 ++++
 target-i386/cpu.c                  |  95 ++++++++++++++++++++++-------
 target-i386/cpu.h                  |   3 +-
 target-i386/topology.h             |  66 ++++++++++++++++-----
 25 files changed, 223 insertions(+), 316 deletions(-)
 delete mode 100644 hw/cpu/icc_bus.c
 delete mode 100644 include/hw/cpu/icc_bus.h
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v4 1/10 cpu/apic: drop icc bus/bridge/

From: Chen Fan <[email protected]>

ICC bus was invented only to provide hotplug capability to CPU and APIC because at the time being hotplug was available only for BUS attached devices.

Now this patch is to drop ICC bus impl, and switch to bus-less CPU+APIC hotplug, handling them in the same manner as pc-dimm.

---
 hw/i386/kvm/apic.c              | 10 ++++++++--
 hw/i386/pc.c                    | 21 +++++----------------
 hw/i386/pc_piix.c               |  9 +--------
 hw/i386/pc_q35.c                |  9 +--------
 hw/intc/apic.c                  | 16 +++++++++++-----
 hw/intc/apic_common.c           | 14 +++++++++-----
 include/hw/i386/apic_internal.h |  6 ++----
 include/hw/i386/pc.h            |  3 ++-
 target-i386/cpu.c               | 19 +++----------------
 target-i386/cpu.h               |  3 +--
 10 files changed, 43 insertions(+), 67 deletions(-)
hw/i386/kvm/apic.c +8 -2
index 5b47056..4b7ce57 100644
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory.
  */
 #include "hw/i386/apic_internal.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/msi.h"
 #include "sysemu/kvm.h"
 
@@ -180,9 +181,14 @@ static void kvm_apic_reset(APICCommonState *s)
 static void kvm_apic_realize(DeviceState *dev, Error **errp)
 {
     APICCommonState *s = APIC_COMMON(dev);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    static bool mmio_registered;
 
-    memory_region_init_io(&s->io_memory, NULL, &kvm_apic_io_ops, s, "kvm-apic-msi",
-                          APIC_SPACE_SIZE);
+    if (!mmio_registered) {
+        memory_region_init_io(&pcms->apic_mmio, NULL, &kvm_apic_io_ops, s,
+                              "kvm-apic-msi", APIC_SPACE_SIZE);
+        mmio_registered = true;
+    }
 
     if (kvm_has_gsi_routing()) {
         msi_supported = true;
hw/i386/pc.c +5 -16
index c7af6aa..500d369 100644
@@ -54,7 +54,6 @@
 #include "qemu/config-file.h"
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu_hotplug.h"
-#include "hw/cpu/icc_bus.h"
 #include "hw/boards.h"
 #include "hw/pci/pci_host.h"
 #include "acpi-build.h"
@@ -954,12 +953,12 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
 }
 
 static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id,
-                          DeviceState *icc_bridge, Error **errp)
+                          Error **errp)
 {
     X86CPU *cpu;
     Error *local_err = NULL;
 
-    cpu = cpu_x86_create(cpu_model, icc_bridge, &local_err);
+    cpu = cpu_x86_create(cpu_model, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return NULL;
@@ -980,7 +979,6 @@ static const char *current_cpu_model;
 
 void pc_hot_add_cpu(const int64_t id, Error **errp)
 {
-    DeviceState *icc_bridge;
     int64_t apic_id = x86_cpu_apic_id_from_index(id);
 
     if (id < 0) {
@@ -1007,12 +1005,10 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
         return;
     }
 
-    icc_bridge = DEVICE(object_resolve_path_type("icc-bridge",
-                                                 TYPE_ICC_BRIDGE, NULL));
-    pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp);
+    pc_new_cpu(current_cpu_model, apic_id, errp);
 }
 
-void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
+void pc_cpus_init(const char *cpu_model)
 {
     int i;
     X86CPU *cpu = NULL;
@@ -1038,7 +1034,7 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
 
     for (i = 0; i < smp_cpus; i++) {
         cpu = pc_new_cpu(cpu_model, x86_cpu_apic_id_from_index(i),
-                         icc_bridge, &error);
+                         &error);
         if (error) {
             error_report("%s", error_get_pretty(error));
             error_free(error);
@@ -1046,13 +1042,6 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
         }
     }
 
-    /* map APIC MMIO area if CPU has APIC */
-    if (cpu && cpu->apic_state) {
-        /* XXX: what if the base changes? */
-        sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0,
-                                APIC_DEFAULT_ADDRESS, 0x1000);
-    }
-
     /* tell smbios about cpuid version and features */
     smbios_set_cpuid(cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX]);
 }
hw/i386/pc_piix.c +1 -8
index 38b42b0..7a581f2 100644
@@ -39,7 +39,6 @@
 #include "hw/kvm/clock.h"
 #include "sysemu/sysemu.h"
 #include "hw/sysbus.h"
-#include "hw/cpu/icc_bus.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/block-backend.h"
 #include "hw/i2c/smbus.h"
@@ -97,7 +96,6 @@ static void pc_init1(MachineState *machine,
     MemoryRegion *ram_memory;
     MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
-    DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
     PcGuestInfo *guest_info;
     ram_addr_t lowmem;
@@ -142,11 +140,7 @@ static void pc_init1(MachineState *machine,
         exit(1);
     }
 
-    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
-    object_property_add_child(qdev_get_machine(), "icc-bridge",
-                              OBJECT(icc_bridge), NULL);
-
-    pc_cpus_init(machine->cpu_model, icc_bridge);
+    pc_cpus_init(machine->cpu_model);
 
     if (kvm_enabled() && kvmclock_enabled) {
         kvmclock_create();
@@ -228,7 +222,6 @@ static void pc_init1(MachineState *machine,
     if (pci_enabled) {
         ioapic_init_gsi(gsi_state, "i440fx");
     }
-    qdev_init_nofail(icc_bridge);
 
     pc_register_ferr_irq(gsi[13]);
 
hw/i386/pc_q35.c +1 -8
index 63027ee..baceafb 100644
@@ -43,7 +43,6 @@
 #include "hw/ide/pci.h"
 #include "hw/ide/ahci.h"
 #include "hw/usb.h"
-#include "hw/cpu/icc_bus.h"
 #include "qemu/error-report.h"
 
 /* ICH9 AHCI has 6 ports */
@@ -84,7 +83,6 @@ static void pc_q35_init(MachineState *machine)
     int i;
     ICH9LPCState *ich9_lpc;
     PCIDevice *ahci;
-    DeviceState *icc_bridge;
     PcGuestInfo *guest_info;
     ram_addr_t lowmem;
     DriveInfo *hd[MAX_SATA_PORTS];
@@ -131,11 +129,7 @@ static void pc_q35_init(MachineState *machine)
         exit(1);
     }
 
-    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
-    object_property_add_child(qdev_get_machine(), "icc-bridge",
-                              OBJECT(icc_bridge), NULL);
-
-    pc_cpus_init(machine->cpu_model, icc_bridge);
+    pc_cpus_init(machine->cpu_model);
     pc_acpi_init("q35-acpi-dsdt.aml");
 
     kvmclock_create();
@@ -238,7 +232,6 @@ static void pc_q35_init(MachineState *machine)
     if (pci_enabled) {
         ioapic_init_gsi(gsi_state, "q35");
     }
-    qdev_init_nofail(icc_bridge);
 
     pc_register_ferr_irq(gsi[13]);
 
hw/intc/apic.c +11 -5
index 0f97b47..e48974f 100644
@@ -376,7 +376,8 @@ static void apic_update_irq(APICCommonState *s)
         cpu_interrupt(cpu, CPU_INTERRUPT_POLL);
     } else if (apic_irq_pending(s) > 0) {
         cpu_interrupt(cpu, CPU_INTERRUPT_HARD);
-    } else if (!apic_accept_pic_intr(&s->busdev.qdev) || !pic_get_output(isa_pic)) {
+    } else if (!apic_accept_pic_intr(s->cpu->apic_state) ||
+               !pic_get_output(isa_pic)) {
         cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD);
     }
 }
@@ -549,10 +550,10 @@ static void apic_deliver(DeviceState *dev, uint8_t dest, uint8_t dest_mode,
 
 static bool apic_check_pic(APICCommonState *s)
 {
-    if (!apic_accept_pic_intr(&s->busdev.qdev) || !pic_get_output(isa_pic)) {
+    if (!apic_accept_pic_intr(s->cpu->apic_state) || !pic_get_output(isa_pic)) {
         return false;
     }
-    apic_deliver_pic_intr(&s->busdev.qdev, 1);
+    apic_deliver_pic_intr(s->cpu->apic_state, 1);
     return true;
 }
 
@@ -879,9 +880,14 @@ static const MemoryRegionOps apic_io_ops = {
 static void apic_realize(DeviceState *dev, Error **errp)
 {
     APICCommonState *s = APIC_COMMON(dev);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    static bool mmio_registered;
 
-    memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s, "apic-msi",
-                          APIC_SPACE_SIZE);
+    if (!mmio_registered) {
+        memory_region_init_io(&pcms->apic_mmio, OBJECT(s), &apic_io_ops, s,
+                              "apic-msi", APIC_SPACE_SIZE);
+        mmio_registered = true;
+    }
 
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s);
     local_apics[s->idx] = s;
hw/intc/apic_common.c +9 -5
index 0858b45..bfaebe2 100644
@@ -19,6 +19,7 @@
  */
 #include "hw/i386/apic.h"
 #include "hw/i386/apic_internal.h"
+#include "hw/i386/pc.h"
 #include "trace.h"
 #include "sysemu/kvm.h"
 #include "hw/qdev.h"
@@ -302,6 +303,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp)
     APICCommonClass *info;
     static DeviceState *vapic;
     static int apic_no;
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
     static bool mmio_registered;
 
     if (apic_no >= MAX_APICS) {
@@ -313,9 +315,12 @@ static void apic_common_realize(DeviceState *dev, Error **errp)
 
     info = APIC_COMMON_GET_CLASS(s);
     info->realize(dev, errp);
+
     if (!mmio_registered) {
-        ICCBus *b = ICC_BUS(qdev_get_parent_bus(dev));
-        memory_region_add_subregion(b->apic_address_space, 0, &s->io_memory);
+        memory_region_add_subregion_overlap(get_system_memory(),
+                                            APIC_DEFAULT_ADDRESS,
+                                            &pcms->apic_mmio,
+                                            0x1000);
         mmio_registered = true;
     }
 
@@ -433,13 +438,12 @@ static Property apic_properties_common[] = {
 
 static void apic_common_class_init(ObjectClass *klass, void *data)
 {
-    ICCDeviceClass *idc = ICC_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_apic_common;
     dc->reset = apic_reset_common;
     dc->props = apic_properties_common;
-    idc->realize = apic_common_realize;
+    dc->realize = apic_common_realize;
     /*
      * Reason: APIC and CPU need to be wired up by
      * x86_cpu_apic_create()
@@ -449,7 +453,7 @@ static void apic_common_class_init(ObjectClass *klass, void *data)
 
 static const TypeInfo apic_common_type = {
     .name = TYPE_APIC_COMMON,
-    .parent = TYPE_ICC_DEVICE,
+    .parent = TYPE_DEVICE,
     .instance_size = sizeof(APICCommonState),
     .class_size = sizeof(APICCommonClass),
     .class_init = apic_common_class_init,
include/hw/i386/apic_internal.h +2 -4
index dc7a89d..0421c20 100644
@@ -21,7 +21,6 @@
 #define QEMU_APIC_INTERNAL_H
 
 #include "exec/memory.h"
-#include "hw/cpu/icc_bus.h"
 #include "qemu/timer.h"
 
 /* APIC Local Vector Table */
@@ -78,7 +77,7 @@ typedef struct APICCommonState APICCommonState;
 
 typedef struct APICCommonClass
 {
-    ICCDeviceClass parent_class;
+    DeviceClass parent_class;
 
     DeviceRealize realize;
     void (*set_base)(APICCommonState *s, uint64_t val);
@@ -93,9 +92,8 @@ typedef struct APICCommonClass
 } APICCommonClass;
 
 struct APICCommonState {
-    ICCDevice busdev;
+    DeviceState parent;
 
-    MemoryRegion io_memory;
     X86CPU *cpu;
     uint32_t apicbase;
     uint8_t id;
include/hw/i386/pc.h +2 -1
index 69d9cf8..ce0143c 100644
@@ -34,6 +34,7 @@ struct PCMachineState {
     /* <public> */
     ram_addr_t hotplug_memory_base;
     MemoryRegion hotplug_memory;
+    MemoryRegion apic_mmio;
 
     HotplugHandler *acpi_dev;
     ISADevice *rtc;
@@ -177,7 +178,7 @@ extern int fd_bootchk;
 void pc_register_ferr_irq(qemu_irq irq);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
-void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge);
+void pc_cpus_init(const char *cpu_model);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);
 
target-i386/cpu.c +3 -16
index 3a9b32e..9e9f830 100644
@@ -43,7 +43,6 @@
 
 #include "sysemu/sysemu.h"
 #include "hw/qdev-properties.h"
-#include "hw/cpu/icc_bus.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/xen/xen.h"
 #include "hw/i386/apic_internal.h"
@@ -2091,8 +2090,7 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
 
 }
 
-X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
-                       Error **errp)
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
 {
     X86CPU *cpu = NULL;
     X86CPUClass *xcc;
@@ -2123,15 +2121,6 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
 
     cpu = X86_CPU(object_new(object_class_get_name(oc)));
 
-#ifndef CONFIG_USER_ONLY
-    if (icc_bridge == NULL) {
-        error_setg(&error, "Invalid icc-bridge value");
-        goto out;
-    }
-    qdev_set_parent_bus(DEVICE(cpu), qdev_get_child_bus(icc_bridge, "icc"));
-    object_unref(OBJECT(cpu));
-#endif
-
     x86_cpu_parse_featurestr(CPU(cpu), features, &error);
     if (error) {
         goto out;
@@ -2154,7 +2143,7 @@ X86CPU *cpu_x86_init(const char *cpu_model)
     Error *error = NULL;
     X86CPU *cpu;
 
-    cpu = cpu_x86_create(cpu_model, NULL, &error);
+    cpu = cpu_x86_create(cpu_model, &error);
     if (error) {
         goto out;
     }
@@ -2723,7 +2712,6 @@ static void mce_init(X86CPU *cpu)
 static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 {
     CPUX86State *env = &cpu->env;
-    DeviceState *dev = DEVICE(cpu);
     APICCommonState *apic;
     const char *apic_type = "apic";
 
@@ -2733,7 +2721,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
         apic_type = "xen-apic";
     }
 
-    cpu->apic_state = qdev_try_create(qdev_get_parent_bus(dev), apic_type);
+    cpu->apic_state = qdev_try_create(NULL, apic_type);
     if (cpu->apic_state == NULL) {
         error_setg(errp, "APIC device '%s' could not be created", apic_type);
         return;
@@ -3004,7 +2992,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 
     xcc->parent_realize = dc->realize;
     dc->realize = x86_cpu_realizefn;
-    dc->bus_type = TYPE_ICC_BUS;
     dc->props = x86_cpu_properties;
 
     xcc->parent_reset = cc->reset;
target-i386/cpu.h +1 -2
index 478450c..f4711ba 100644
@@ -983,8 +983,7 @@ typedef struct CPUX86State {
 #include "cpu-qom.h"
 
 X86CPU *cpu_x86_init(const char *cpu_model);
-X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
-                       Error **errp);
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp);
 int cpu_x86_exec(CPUX86State *s);
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 void x86_cpudef_setup(void);
Signature · 1 line
1.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH v4 01/10] cpu/apic: drop icc bus/bridge/

Quoted 11 lines · Zhu Guihua

From: Chen Fan <[email protected]>

ICC bus was invented only to provide hotplug capability to CPU and APIC because at the time being hotplug was available only for BUS attached devices.

Now this patch is to drop ICC bus impl, and switch to bus-less CPU+APIC hotplug, handling them in the same manner as pc-dimm.

Quoted 12 lines
---
 hw/i386/kvm/apic.c              | 10 ++++++++--
 hw/i386/pc.c                    | 21 +++++----------------
 hw/i386/pc_piix.c               |  9 +--------
 hw/i386/pc_q35.c                |  9 +--------
 hw/intc/apic.c                  | 16 +++++++++++-----
 hw/intc/apic_common.c           | 14 +++++++++-----
 include/hw/i386/apic_internal.h |  6 ++----
 include/hw/i386/pc.h            |  3 ++-
 target-i386/cpu.c               | 19 +++----------------
 target-i386/cpu.h               |  3 +--
 10 files changed, 43 insertions(+), 67 deletions(-)

What about hw/i386/xen/xen_apic.c:xen_apic_realize()?

  $ make
    CC    x86_64-softmmu/hw/i386/xen/xen_apic.o
  /home/ehabkost/rh/proj/virt/qemu/hw/i386/xen/xen_apic.c: In function ‘xen_apic_realize’:
  /home/ehabkost/rh/proj/virt/qemu/hw/i386/xen/xen_apic.c:44:29: error: ‘APICCommonState’ has no member named ‘io_memory’
       memory_region_init_io(&s->io_memory, OBJECT(s), &xen_apic_io_ops, s,
                               ^
  /home/ehabkost/rh/proj/virt/qemu/rules.mak:57: recipe for target 'hw/i386/xen/xen_apic.o' failed
  make[1]: *** [hw/i386/xen/xen_apic.o] Error 1
  Makefile:169: recipe for target 'subdir-x86_64-softmmu' failed
  make: *** [subdir-x86_64-softmmu] Error 2
Signature · 1 line
Eduardo
#3 lore raw

Re: [Qemu-devel] [PATCH v4 01/10] cpu/apic: drop icc bus/bridge/

Quoted 26 lines · Eduardo Habkost
Quoted 11 lines · Zhu Guihua

From: Chen Fan <[email protected]>

ICC bus was invented only to provide hotplug capability to CPU and APIC because at the time being hotplug was available only for BUS attached devices.

Now this patch is to drop ICC bus impl, and switch to bus-less CPU+APIC hotplug, handling them in the same manner as pc-dimm.

Quoted 12 lines
---
  hw/i386/kvm/apic.c              | 10 ++++++++--
  hw/i386/pc.c                    | 21 +++++----------------
  hw/i386/pc_piix.c               |  9 +--------
  hw/i386/pc_q35.c                |  9 +--------
  hw/intc/apic.c                  | 16 +++++++++++-----
  hw/intc/apic_common.c           | 14 +++++++++-----
  include/hw/i386/apic_internal.h |  6 ++----
  include/hw/i386/pc.h            |  3 ++-
  target-i386/cpu.c               | 19 +++----------------
  target-i386/cpu.h               |  3 +--
  10 files changed, 43 insertions(+), 67 deletions(-)

What about hw/i386/xen/xen_apic.c:xen_apic_realize()?

Quoted 10 lines
   $ make
     CC    x86_64-softmmu/hw/i386/xen/xen_apic.o
   /home/ehabkost/rh/proj/virt/qemu/hw/i386/xen/xen_apic.c: In function ‘xen_apic_realize’:
   /home/ehabkost/rh/proj/virt/qemu/hw/i386/xen/xen_apic.c:44:29: error: ‘APICCommonState’ has no member named ‘io_memory’
        memory_region_init_io(&s->io_memory, OBJECT(s), &xen_apic_io_ops, s,
                                ^
   /home/ehabkost/rh/proj/virt/qemu/rules.mak:57: recipe for target 'hw/i386/xen/xen_apic.o' failed
   make[1]: *** [hw/i386/xen/xen_apic.o] Error 1
   Makefile:169: recipe for target 'subdir-x86_64-softmmu' failed
   make: *** [subdir-x86_64-softmmu] Error 2

Oh, I'm sorry for that, because no xen platform environment. we forgot xen ;). so I want to fix it and rebase our patches under your x86 tree.

Thanks,
Chen

Quoted 1 line
#4 lore raw

Re: [Qemu-devel] [PATCH v4 01/10] cpu/apic: drop icc bus/bridge/

In reply to Zhu Guihua
Quoted 38 lines · On Fri, 13 Feb 2015 18:25:24 +0800 Zhu Guihua <[email protected]> wrote:

From: Chen Fan <[email protected]>

ICC bus was invented only to provide hotplug capability to CPU and APIC because at the time being hotplug was available only for BUS attached devices.

Now this patch is to drop ICC bus impl, and switch to bus-less CPU+APIC hotplug, handling them in the same manner as pc-dimm.

---
 hw/i386/kvm/apic.c              | 10 ++++++++--
 hw/i386/pc.c                    | 21 +++++----------------
 hw/i386/pc_piix.c               |  9 +--------
 hw/i386/pc_q35.c                |  9 +--------
 hw/intc/apic.c                  | 16 +++++++++++-----
 hw/intc/apic_common.c           | 14 +++++++++-----
 include/hw/i386/apic_internal.h |  6 ++----
 include/hw/i386/pc.h            |  3 ++-
 target-i386/cpu.c               | 19 +++----------------
 target-i386/cpu.h               |  3 +--
 10 files changed, 43 insertions(+), 67 deletions(-)
hw/i386/kvm/apic.c +1 -0
index 5b47056..4b7ce57 100644
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory.
  */
 #include "hw/i386/apic_internal.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/msi.h"
 #include "sysemu/kvm.h"
 
@@ -180,9 +181,14 @@ static void kvm_apic_reset(APICCommonState *s)
 static void kvm_apic_realize(DeviceState *dev, Error **errp)

hw/i386/kvm/apic.c static void kvm_apic_reset(APICCommonState *s) · line 189

Quoted 10 lines
hw/i386/kvm/apic.c +5 -2
 {
     APICCommonState *s = APIC_COMMON(dev);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    static bool mmio_registered;
 
-    memory_region_init_io(&s->io_memory, NULL, &kvm_apic_io_ops, s, "kvm-apic-msi",
-                          APIC_SPACE_SIZE);
+    if (!mmio_registered) {
+        memory_region_init_io(&pcms->apic_mmio, NULL, &kvm_apic_io_ops, s,
+                              "kvm-apic-msi", APIC_SPACE_SIZE);

APIC shouldn't access MachineState let alone modify it,
so keep io_memory in APICCommonState and export method something like:
apic_register_mmio(AddressSpace *as, hwaddr addr);

and use it in pc_machine_device_plug_cb()
but it would be better to use per CPU AddressSpace added by 09daed848c if it works with KVM. Then you could map APIC into it x86_cpu_realize().

author
#5 lore raw

PATCH v4 2/10 icc_bus: remove icc related files

In reply to Zhu Guihua

From: Chen Fan <[email protected]>

ICC bus impl has been droped, so all icc related files are not useful any more; delete them.

---
 MAINTAINERS                        |   6 --
 default-configs/i386-softmmu.mak   |   1 -
 default-configs/x86_64-softmmu.mak |   1 -
 hw/cpu/Makefile.objs               |   2 -
 hw/cpu/icc_bus.c                   | 118 -------------------------------------
 include/hw/cpu/icc_bus.h           |  82 --------------------------
 6 files changed, 210 deletions(-)
 delete mode 100644 hw/cpu/icc_bus.c
 delete mode 100644 include/hw/cpu/icc_bus.h
MAINTAINERS +0 -6
index 8c06739..8ad08d0 100644
@@ -795,12 +795,6 @@ F: qom/cpu.c
 F: include/qom/cpu.h
 F: target-i386/cpu.c
 
-ICC Bus
-M: Igor Mammedov <[email protected]>
-S: Supported
-F: include/hw/cpu/icc_bus.h
-F: hw/cpu/icc_bus.c
-
 Device Tree
 M: Peter Crosthwaite <[email protected]>
 M: Alexander Graf <[email protected]>
default-configs/i386-softmmu.mak +0 -1
index 8e08841..e433da5 100644
@@ -42,6 +42,5 @@ CONFIG_LPC_ICH9=y
 CONFIG_PCI_Q35=y
 CONFIG_APIC=y
 CONFIG_IOAPIC=y
-CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
default-configs/x86_64-softmmu.mak +0 -1
index 66557ac..4f76d41 100644
@@ -42,6 +42,5 @@ CONFIG_LPC_ICH9=y
 CONFIG_PCI_Q35=y
 CONFIG_APIC=y
 CONFIG_IOAPIC=y
-CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
hw/cpu/Makefile.objs +0 -2
index 6381238..193e489 100644
@@ -2,5 +2,3 @@ obj-$(CONFIG_ARM11MPCORE) += arm11mpcore.o
 obj-$(CONFIG_REALVIEW) += realview_mpcore.o
 obj-$(CONFIG_A9MPCORE) += a9mpcore.o
 obj-$(CONFIG_A15MPCORE) += a15mpcore.o
-obj-$(CONFIG_ICC_BUS) += icc_bus.o
-
hw/cpu/icc_bus.c deleted +0 -118

118 lines not on this page · raw message

include/hw/cpu/icc_bus.h deleted +0 -82

82 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#6 lore raw

PATCH v4 3/10 cpu: introduce CpuTopoInfo structure for argument simplification

In reply to Zhu Guihua

From: Chen Fan <[email protected]>

---
 target-i386/topology.h | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
target-i386/topology.h +17 -16
index 07a6c5f..e9ff89c 100644
@@ -47,6 +47,12 @@
  */
 typedef uint32_t apic_id_t;
 
+typedef struct X86CPUTopoInfo {
+    unsigned pkg_id;
+    unsigned core_id;
+    unsigned smt_id;
+} X86CPUTopoInfo;
+
 /* Return the bit width needed for 'count' IDs
  */
 static unsigned apicid_bitwidth_for_count(unsigned count)
@@ -92,13 +98,11 @@ static inline unsigned apicid_pkg_offset(unsigned nr_cores, unsigned nr_threads)
  */
 static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores,
                                              unsigned nr_threads,
-                                             unsigned pkg_id,
-                                             unsigned core_id,
-                                             unsigned smt_id)
+                                             const X86CPUTopoInfo *topo)
 {
-    return (pkg_id  << apicid_pkg_offset(nr_cores, nr_threads)) |
-           (core_id << apicid_core_offset(nr_cores, nr_threads)) |
-           smt_id;
+    return (topo->pkg_id  << apicid_pkg_offset(nr_cores, nr_threads)) |
+           (topo->core_id << apicid_core_offset(nr_cores, nr_threads)) |
+           topo->smt_id;
 }
 
 /* Calculate thread/core/package IDs for a specific topology,
@@ -107,14 +111,12 @@ static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores,
 static inline void x86_topo_ids_from_idx(unsigned nr_cores,
                                          unsigned nr_threads,
                                          unsigned cpu_index,
-                                         unsigned *pkg_id,
-                                         unsigned *core_id,
-                                         unsigned *smt_id)
+                                         X86CPUTopoInfo *topo)
 {
     unsigned core_index = cpu_index / nr_threads;
-    *smt_id = cpu_index % nr_threads;
-    *core_id = core_index % nr_cores;
-    *pkg_id = core_index / nr_cores;
+    topo->smt_id = cpu_index % nr_threads;
+    topo->core_id = core_index % nr_cores;
+    topo->pkg_id = core_index / nr_cores;
 }
 
 /* Make APIC ID for the CPU 'cpu_index'
@@ -125,10 +127,9 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_cores,
                                                 unsigned nr_threads,
                                                 unsigned cpu_index)
 {
-    unsigned pkg_id, core_id, smt_id;
-    x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index,
-                          &pkg_id, &core_id, &smt_id);
-    return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, core_id, smt_id);
+    X86CPUTopoInfo topo;
+    x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index, &topo);
+    return apicid_from_topo_ids(nr_cores, nr_threads, &topo);
 }
 
 #endif /* TARGET_I386_TOPOLOGY_H */
Signature · 1 line
1.9.3
author
#7 lore raw

PATCH v4 4/10 cpu: introduce get_compat_arch_id() method and override it for X86CPU

In reply to Zhu Guihua

get_compat_arch_id() is introduced to handle cross version migration issue, it is to convert new 'apic-id' to old 'cpu_index'.

---
 include/qom/cpu.h      |  3 +++
 qom/cpu.c              |  6 ++++++
 target-i386/cpu.c      | 10 ++++++++++
 target-i386/topology.h | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)
include/qom/cpu.h +3 -0
index 2098f1c..2e68dd2 100644
@@ -86,6 +86,8 @@ struct TranslationBlock;
  * @dump_state: Callback for dumping state.
  * @dump_statistics: Callback for dumping statistics.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
+ * @get_compat_arch_id: Callback for getting compatiable architecture-dependent
+ * CPU ID.
  * @get_paging_enabled: Callback for inquiring whether paging is enabled.
  * @get_memory_mapping: Callback for obtaining the memory mappings.
  * @set_pc: Callback for setting the Program Counter register.
@@ -130,6 +132,7 @@ typedef struct CPUClass {
     void (*dump_statistics)(CPUState *cpu, FILE *f,
                             fprintf_function cpu_fprintf, int flags);
     int64_t (*get_arch_id)(CPUState *cpu);
+    int64_t (*get_compat_arch_id)(CPUState *cpu);
     bool (*get_paging_enabled)(const CPUState *cpu);
     void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
                                Error **errp);
qom/cpu.c +6 -0
index 9c68fa4..83d7766 100644
@@ -321,6 +321,11 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu)
     return cpu->cpu_index;
 }
 
+static int64_t cpu_common_get_compat_arch_id(CPUState *cpu)
+{
+    return cpu->cpu_index;
+}
+
 static void cpu_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -330,6 +335,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
     k->parse_features = cpu_common_parse_features;
     k->reset = cpu_common_reset;
     k->get_arch_id = cpu_common_get_arch_id;
+    k->get_compat_arch_id = cpu_common_get_compat_arch_id;
     k->has_work = cpu_common_has_work;
     k->get_paging_enabled = cpu_common_get_paging_enabled;
     k->get_memory_mapping = cpu_common_get_memory_mapping;
target-i386/cpu.c +10 -0
index 9e9f830..25f4f54 100644
@@ -2931,6 +2931,15 @@ static int64_t x86_cpu_get_arch_id(CPUState *cs)
     return env->cpuid_apic_id;
 }
 
+static int64_t x86_cpu_get_compat_arch_id(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+
+    return x86_compat_index_from_apic_id(smp_cores, smp_threads,
+                                         env->cpuid_apic_id);
+}
+
 static bool x86_cpu_get_paging_enabled(const CPUState *cs)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -3009,6 +3018,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
     cc->get_arch_id = x86_cpu_get_arch_id;
+    cc->get_compat_arch_id = x86_cpu_get_compat_arch_id;
     cc->get_paging_enabled = x86_cpu_get_paging_enabled;
 #ifdef CONFIG_USER_ONLY
     cc->handle_mmu_fault = x86_cpu_handle_mmu_fault;
target-i386/topology.h +33 -0
index e9ff89c..6edd2c6 100644
@@ -132,4 +132,37 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_cores,
     return apicid_from_topo_ids(nr_cores, nr_threads, &topo);
 }
 
+/* Calculate CPU topology based on CPU APIC ID.
+ * + */
+static inline void x86_topo_ids_from_apic_id(unsigned nr_cores,
+                                             unsigned nr_threads,
+                                             apic_id_t apic_id,
+                                             X86CPUTopoInfo *topo)
+{
+    unsigned offset_mask;
+    topo->pkg_id = apic_id >> apicid_pkg_offset(nr_cores, nr_threads);
+
+    offset_mask = (1L << apicid_pkg_offset(nr_cores, nr_threads)) - 1;
+    topo->core_id = (apic_id & offset_mask)
+                     >> apicid_core_offset(nr_cores, nr_threads);
+
+    offset_mask = (1L << apicid_core_offset(nr_cores, nr_threads)) - 1;
+    topo->smt_id = apic_id & offset_mask;
+}
+
+/* Caculate CPU compat index based on CPU APIC ID.
+ */
+static inline unsigned x86_compat_index_from_apic_id(unsigned nr_cores,
+                                                     unsigned nr_threads,
+                                                     apic_id_t apic_id)
+{
+    X86CPUTopoInfo topo;
+
+    x86_topo_ids_from_apic_id(nr_cores, nr_threads, apic_id, &topo);
+
+    return topo.pkg_id * nr_cores * nr_threads +
+           topo.core_id * nr_threads +
+           topo.smt_id;
+}
+
 #endif /* TARGET_I386_TOPOLOGY_H */
Signature · 1 line
1.9.3
author
#8 lore raw

PATCH v4 5/10 qom/cpu: move register_vmstate to common CPUClass.realizefn

In reply to Zhu Guihua

From: Gu Zheng <[email protected]>

Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn, and use cc->get_arch_id as the instance id that suggested by Igor to fix the migration issue.

---
 exec.c            | 25 ++++++++++++++++++-------
 include/qom/cpu.h |  2 ++
 qom/cpu.c         |  4 ++++
 3 files changed, 24 insertions(+), 7 deletions(-)
exec.c +18 -7
index 6dff7bc..8361591 100644
@@ -513,10 +513,26 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
+void cpu_vmstate_register(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    int cpu_index = cc->get_arch_id(cpu) + max_cpus;
+    int compat_index = cc->get_compat_arch_id(cpu);
+
+    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common,
+                                       cpu, compat_index, 3);
+    }
+
+    if (cc->vmsd != NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, cc->vmsd,
+                                       cpu, compat_index, 3);
+    }
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUState *some_cpu;
     int cpu_index;
 
@@ -539,18 +555,13 @@ void cpu_exec_init(CPUArchState *env)
 #if defined(CONFIG_USER_ONLY)
     cpu_list_unlock();
 #endif
-    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-        vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
-    }
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
     assert(cc->vmsd == NULL);
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
 #endif
-    if (cc->vmsd != NULL) {
-        vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
-    }
 }
 
 #if defined(CONFIG_USER_ONLY)
include/qom/cpu.h +2 -0
index 2e68dd2..d0a50e2 100644
@@ -565,6 +565,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
 #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
 #ifdef CONFIG_SOFTMMU
 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
                                          bool is_write, bool is_exec,
qom/cpu.c +4 -0
index 83d7766..8e37045 100644
@@ -302,6 +302,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
 
+#if !defined(CONFIG_USER_ONLY)
+    cpu_vmstate_register(cpu);
+#endif
+
     if (dev->hotplugged) {
         cpu_synchronize_post_init(cpu);
         cpu_resume(cpu);
Signature · 1 line
1.9.3
#9 lore raw

Re: [Qemu-devel] [PATCH v4 05/10] qom/cpu: move register_vmstate to common CPUClass.realizefn

Quoted 5 lines · Zhu Guihua

From: Gu Zheng <[email protected]>

Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn, and use cc->get_arch_id as the instance id that suggested by Igor to fix the migration issue.

If you are implementing something new, please do that in a separate patch, either before or after moving the code. Makes it easier to review and easier to revert in case something goes wrong.

See two additional issues below:

Quoted 14 lines
---
 exec.c            | 25 ++++++++++++++++++-------
 include/qom/cpu.h |  2 ++
 qom/cpu.c         |  4 ++++
 3 files changed, 24 insertions(+), 7 deletions(-)
exec.c +0 -0
index 6dff7bc..8361591 100644

exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 519

Quoted 7 lines
exec.c +4 -0
@@ -513,10 +513,26 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
+void cpu_vmstate_register(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    int cpu_index = cc->get_arch_id(cpu) + max_cpus;

Breaks linux-user build:

LINK x86_64-linux-user/qemu-x86_64
exec.o: In function `cpu_vmstate_register':
/home/ehabkost/rh/proj/virt/qemu/exec.c:533: undefined reference to `max_cpus'
collect2: error: ld returned 1 exit status
Makefile:182: recipe for target 'qemu-x86_64' failed
make[1]: *** [qemu-x86_64] Error 1
Makefile:169: recipe for target 'subdir-x86_64-linux-user' failed
make: *** [subdir-x86_64-linux-user] Error 2

Quoted 58 lines
exec.c +14 -7
+    int compat_index = cc->get_compat_arch_id(cpu);
+
+    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common,
+                                       cpu, compat_index, 3);
+    }
+
+    if (cc->vmsd != NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, cc->vmsd,
+                                       cpu, compat_index, 3);
+    }
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUState *some_cpu;
     int cpu_index;
 
@@ -539,18 +555,13 @@ void cpu_exec_init(CPUArchState *env)
 #if defined(CONFIG_USER_ONLY)
     cpu_list_unlock();
 #endif
-    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-        vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
-    }
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
     assert(cc->vmsd == NULL);
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
 #endif
-    if (cc->vmsd != NULL) {
-        vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
-    }
 }
 
 #if defined(CONFIG_USER_ONLY)
include/qom/cpu.h +2 -0
index 2e68dd2..d0a50e2 100644
@@ -565,6 +565,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
 #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
 #ifdef CONFIG_SOFTMMU
 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
                                          bool is_write, bool is_exec,
qom/cpu.c +0 -0
index 83d7766..8e37045 100644

qom/cpu.c static void cpu_common_realizefn(DeviceState *dev, Error **errp) · line 307

Quoted 6 lines
qom/cpu.c +3 -0
@@ -302,6 +302,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
 
+#if !defined(CONFIG_USER_ONLY)
+    cpu_vmstate_register(cpu);
+#endif

CONFIG_USER_ONLY is never set on qom/cpu.c because it is target-independent code.

Good news is that we already have vmstate stubs, so you shouldn't need any CONFIG_USER_ONLY ifdefs around the vmstate code (but it looks like we will need a max_cpus stub).

Quoted 8 lines
qom/cpu.c +1 -0
+
     if (dev->hotplugged) {
         cpu_synchronize_post_init(cpu);
         cpu_resume(cpu);
Signature · 1 line
1.9.3
Signature · 1 line
Eduardo
#10 lore raw

Re: [Qemu-devel] [PATCH v4 05/10] qom/cpu: move register_vmstate to common CPUClass.realizefn

In reply to Zhu Guihua
Quoted 19 lines · On Fri, 13 Feb 2015 18:25:28 +0800 Zhu Guihua <[email protected]> wrote:

From: Gu Zheng <[email protected]>

Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn, and use cc->get_arch_id as the instance id that suggested by Igor to fix the migration issue.

---
 exec.c            | 25 ++++++++++++++++++-------
 include/qom/cpu.h |  2 ++
 qom/cpu.c         |  4 ++++
 3 files changed, 24 insertions(+), 7 deletions(-)
exec.c +0 -0
index 6dff7bc..8361591 100644

exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 519

Quoted 7 lines
exec.c +4 -0
@@ -513,10 +513,26 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
+void cpu_vmstate_register(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    int cpu_index = cc->get_arch_id(cpu) + max_cpus;

Why do you add max_cpus here?

Quoted 68 lines
exec.c +14 -7
+    int compat_index = cc->get_compat_arch_id(cpu);
+
+    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common,
+                                       cpu, compat_index, 3);
+    }
+
+    if (cc->vmsd != NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, cc->vmsd,
+                                       cpu, compat_index, 3);
+    }
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUState *some_cpu;
     int cpu_index;
 
@@ -539,18 +555,13 @@ void cpu_exec_init(CPUArchState *env)
 #if defined(CONFIG_USER_ONLY)
     cpu_list_unlock();
 #endif
-    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-        vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
-    }
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+    CPUClass *cc = CPU_GET_CLASS(cpu);
     register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
     assert(cc->vmsd == NULL);
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
 #endif
-    if (cc->vmsd != NULL) {
-        vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
-    }
 }
 
 #if defined(CONFIG_USER_ONLY)
include/qom/cpu.h +2 -0
index 2e68dd2..d0a50e2 100644
@@ -565,6 +565,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
 #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
 #ifdef CONFIG_SOFTMMU
 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
                                          bool is_write, bool is_exec,
qom/cpu.c +4 -0
index 83d7766..8e37045 100644
@@ -302,6 +302,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
 
+#if !defined(CONFIG_USER_ONLY)
+    cpu_vmstate_register(cpu);
+#endif
+
     if (dev->hotplugged) {
         cpu_synchronize_post_init(cpu);
         cpu_resume(cpu);
#11 lore raw

Re: [Qemu-devel] [PATCH v4 05/10] qom/cpu: move register_vmstate to common CPUClass.realizefn

Quoted 25 lines · Igor Mammedov
Quoted 22 lines · On Fri, 13 Feb 2015 18:25:28 +0800 Zhu Guihua <[email protected]> wrote:

From: Gu Zheng <[email protected]>

Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn, and use cc->get_arch_id as the instance id that suggested by Igor to fix the migration issue.

---
  exec.c            | 25 ++++++++++++++++++-------
  include/qom/cpu.h |  2 ++
  qom/cpu.c         |  4 ++++
  3 files changed, 24 insertions(+), 7 deletions(-)
exec.c +0 -0
index 6dff7bc..8361591 100644
@@ -513,10 +513,26 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
  }
  #endif
 
Quoted 5 lines

exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 519

Quoted 4 lines
exec.c +4 -0
+void cpu_vmstate_register(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    int cpu_index = cc->get_arch_id(cpu) + max_cpus;

Why do you add max_cpus here?

Adding max_cpus is to avoid cpu_index equals comat_index which would cause migration fails, this reason is that find_se() always compares instance_id with se->instance_id or se->alias_id when do migration.

Thanks,
Chen

Quoted 71 lines
Quoted 59 lines
exec.c +14 -7
+    int compat_index = cc->get_compat_arch_id(cpu);
+
+    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common,
+                                       cpu, compat_index, 3);
+    }
+
+    if (cc->vmsd != NULL) {
+        vmstate_register_with_alias_id(NULL, cpu_index, cc->vmsd,
+                                       cpu, compat_index, 3);
+    }
+}
+
  void cpu_exec_init(CPUArchState *env)
  {
      CPUState *cpu = ENV_GET_CPU(env);
-    CPUClass *cc = CPU_GET_CLASS(cpu);
      CPUState *some_cpu;
      int cpu_index;
 
@@ -539,18 +555,13 @@ void cpu_exec_init(CPUArchState *env)
  #if defined(CONFIG_USER_ONLY)
      cpu_list_unlock();
  #endif
-    if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-        vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
-    }
  #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+    CPUClass *cc = CPU_GET_CLASS(cpu);
      register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
                      cpu_save, cpu_load, env);
      assert(cc->vmsd == NULL);
      assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
  #endif
-    if (cc->vmsd != NULL) {
-        vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
-    }
  }
 
  #if defined(CONFIG_USER_ONLY)
include/qom/cpu.h +2 -0
index 2e68dd2..d0a50e2 100644
@@ -565,6 +565,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
  #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
  #ifdef CONFIG_SOFTMMU
  static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
                                           bool is_write, bool is_exec,
qom/cpu.c +0 -0
index 83d7766..8e37045 100644

qom/cpu.c static void cpu_common_realizefn(DeviceState *dev, Error **errp) · line 311

Quoted 10 lines
qom/cpu.c +4 -0
@@ -302,6 +302,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
  {
      CPUState *cpu = CPU(dev);
 
+#if !defined(CONFIG_USER_ONLY)
+    cpu_vmstate_register(cpu);
+#endif
+
      if (dev->hotplugged) {
          cpu_synchronize_post_init(cpu);
          cpu_resume(cpu);

.

author
#12 lore raw

PATCH v4 6/10 qom/cpu: move apic vmstate register into x86_cpu_apic_realize

In reply to Zhu Guihua

From: Gu Zheng <[email protected]>

move apic vmstate register into x86_cpu_apic_realize, and use cc->get_arch_id as the instance id to avoid using the auto-id which will break the migration if we add device not in order.

---
 hw/intc/apic_common.c           |  3 +--
 include/hw/i386/apic_internal.h |  3 +++
 target-i386/cpu.c               | 10 +++++++++-
 3 files changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic_common.c +1 -2
index bfaebe2..3b420a6 100644
@@ -387,7 +387,7 @@ static const VMStateDescription vmstate_apic_common_sipi = {
     }
 };
 
-static const VMStateDescription vmstate_apic_common = {
+const VMStateDescription vmstate_apic_common = {
     .name = "apic",
     .version_id = 3,
     .minimum_version_id = 3,
@@ -440,7 +440,6 @@ static void apic_common_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    dc->vmsd = &vmstate_apic_common;
     dc->reset = apic_reset_common;
     dc->props = apic_properties_common;
     dc->realize = apic_common_realize;
include/hw/i386/apic_internal.h +3 -0
index 0421c20..578a616 100644
@@ -22,6 +22,7 @@
 
 #include "exec/memory.h"
 #include "qemu/timer.h"
+#include "migration/vmstate.h"
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER                  0
@@ -136,6 +137,8 @@ typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
+extern const VMStateDescription vmstate_apic_common;
+
 void apic_report_irq_delivered(int delivered);
 bool apic_next_timer(APICCommonState *s, int64_t current_time);
 void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
target-i386/cpu.c +9 -1
index 25f4f54..028063c 100644
@@ -2737,10 +2737,18 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 {
-    if (cpu->apic_state == NULL) {
+    DeviceState *apic_state = cpu->apic_state;
+    CPUClass *cc = CPU_GET_CLASS(CPU(cpu));
+    int cpu_index = cc->get_arch_id(CPU(cpu)) + max_cpus;
+    int compat_index = cc->get_compat_arch_id(CPU(cpu));
+
+    if (apic_state == NULL) {
         return;
     }
 
+    vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_apic_common,
+                                   apic_state, compat_index, 3);
+
     if (qdev_init(cpu->apic_state)) {
         error_setg(errp, "APIC device '%s' could not be initialized",
                    object_get_typename(OBJECT(cpu->apic_state)));
Signature · 1 line
1.9.3
author
#13 lore raw

PATCH v4 7/10 monitor: use cc->get_arch_id as the cpu index

In reply to Zhu Guihua

From: Gu Zheng <[email protected]>

Use cc->get_arch_id as the cpu index to avoid the cpu index duplicated issue in the QMP/HMP command output.

---
 cpus.c    | 4 +++-
 monitor.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
cpus.c +3 -1
index 0cdd1d7..67d10a7 100644
@@ -1403,6 +1403,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
     CPU_FOREACH(cpu) {
         CpuInfoList *info;
+        CPUClass *cc;
 #if defined(TARGET_I386)
         X86CPU *x86_cpu = X86_CPU(cpu);
         CPUX86State *env = &x86_cpu->env;
@@ -1420,11 +1421,12 @@ CpuInfoList *qmp_query_cpus(Error **errp)
         CPUTriCoreState *env = &tricore_cpu->env;
 #endif
 
+        cc = CPU_GET_CLASS(cpu);
         cpu_synchronize_state(cpu);
 
         info = g_malloc0(sizeof(*info));
         info->value = g_malloc0(sizeof(*info->value));
-        info->value->CPU = cpu->cpu_index;
+        info->value->CPU = cc->get_arch_id(cpu);
         info->value->current = (cpu == first_cpu);
         info->value->halted = cpu->halted;
         info->value->thread_id = cpu->thread_id;
monitor.c +3 -1
index c3cc060..e57ae27 100644
@@ -1024,7 +1024,9 @@ static CPUArchState *mon_get_cpu(void)
 int monitor_get_cpu_index(void)
 {
     CPUState *cpu = ENV_GET_CPU(mon_get_cpu());
-    return cpu->cpu_index;
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+
+    return cc->get_arch_id(cpu);
 }
 
 static void do_info_registers(Monitor *mon, const QDict *qdict)
Signature · 1 line
1.9.3
author
#14 lore raw

PATCH v4 8/10 acpi: introduce acpi_send_gpe_event()

In reply to Zhu Guihua

acpi_send_gpe_event() is introduced to do a generic for acpi to send gpe event, and it can be reused by CPU and PCI hotplug.

---
 hw/acpi/core.c         | 7 +++++++
 include/hw/acpi/acpi.h | 3 +++
 2 files changed, 10 insertions(+)
hw/acpi/core.c +7 -0
index 51913d6..98ca994 100644
@@ -666,6 +666,13 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr)
     return val;
 }
 
+void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
+                         unsigned int hotplug_status)
+{
+    ar->gpe.sts[0] |= hotplug_status;
+    acpi_update_sci(ar, irq);
+}
+
 void acpi_update_sci(ACPIREGS *regs, qemu_irq irq)
 {
     int sci_level, pm1a_sts;
include/hw/acpi/acpi.h +3 -0
index 1f678b4..7a0a209 100644
@@ -172,6 +172,9 @@ void acpi_gpe_reset(ACPIREGS *ar);
 void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
 uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
 
+void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
+                         unsigned int hotplug_status);
+
 void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
 
 /* acpi.c */
Signature · 1 line
1.9.3
author
#15 lore raw

PATCH v4 9/10 cpu: add device_add foo-x86_64-cpu support

In reply to Zhu Guihua

From: Chen Fan <[email protected]>

Add support to device_add foo-x86_64-cpu, and additional checks of apic id are added into x86_cpuid_set_apic_id() to avoid duplicate. Besides, in order to support "device/device_add foo-x86_64-cpu" which without specified apic id, we assign cpuid_apic_id with a default broadcast value (0xFFFFFFFF) in initfn, and a new function get_free_apic_id() to provide a free apid id to cpuid_apic_id if it still has the default at realize time (e.g. hot add foo-cpu without a specified apic id) to avoid apic id duplicates.

Thanks very much for Igor's suggestion.

---
 hw/acpi/cpu_hotplug.c |  6 ++++--
 hw/i386/pc.c          |  6 ------
 target-i386/cpu.c     | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 11 deletions(-)
hw/acpi/cpu_hotplug.c +4 -2
index b8ebfad..8e4ed6e 100644
@@ -59,8 +59,10 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
         return;
     }
 
-    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
-    acpi_update_sci(ar, irq);
+    /* Only trigger sci if cpu is hotplugged */
+    if (dev->hotplugged) {
+        acpi_send_gpe_event(ar, irq, ACPI_CPU_HOTPLUG_STATUS);
+    }
 }
 
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/i386/pc.c +0 -6
index 500d369..1187e12 100644
@@ -1637,13 +1637,7 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 
-    if (!dev->hotplugged) {
-        goto out;
-    }
-
     if (!pcms->acpi_dev) {
-        error_setg(&local_err,
-                   "cpu hotplug is not enabled: missing acpi device");
         goto out;
     }
 
target-i386/cpu.c +45 -3

96 lines not on this page · raw message

Signature · 1 line
1.9.3
#16 lore raw
Quoted 118 lines · Zhu Guihua

From: Chen Fan <[email protected]>

Add support to device_add foo-x86_64-cpu, and additional checks of apic id are added into x86_cpuid_set_apic_id() to avoid duplicate. Besides, in order to support "device/device_add foo-x86_64-cpu" which without specified apic id, we assign cpuid_apic_id with a default broadcast value (0xFFFFFFFF) in initfn, and a new function get_free_apic_id() to provide a free apid id to cpuid_apic_id if it still has the default at realize time (e.g. hot add foo-cpu without a specified apic id) to avoid apic id duplicates.

Thanks very much for Igor's suggestion.

---
 hw/acpi/cpu_hotplug.c |  6 ++++--
 hw/i386/pc.c          |  6 ------
 target-i386/cpu.c     | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 11 deletions(-)
hw/acpi/cpu_hotplug.c +4 -2
index b8ebfad..8e4ed6e 100644
@@ -59,8 +59,10 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
         return;
     }
 
-    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
-    acpi_update_sci(ar, irq);
+    /* Only trigger sci if cpu is hotplugged */
+    if (dev->hotplugged) {
+        acpi_send_gpe_event(ar, irq, ACPI_CPU_HOTPLUG_STATUS);
+    }
 }
 
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/i386/pc.c +0 -6
index 500d369..1187e12 100644
@@ -1637,13 +1637,7 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 
-    if (!dev->hotplugged) {
-        goto out;
-    }
-
     if (!pcms->acpi_dev) {
-        error_setg(&local_err,
-                   "cpu hotplug is not enabled: missing acpi device");
         goto out;
     }
 
target-i386/cpu.c +23 -0
index 028063c..68a6aa4 100644
@@ -1703,6 +1703,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque,
     const int64_t max = UINT32_MAX;
     Error *error = NULL;
     int64_t value;
+    X86CPUTopoInfo topo;
 
     if (dev->realized) {
         error_setg(errp, "Attempt to set property '%s' on '%s' after "
@@ -1722,6 +1723,19 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
+    if (value > x86_cpu_apic_id_from_index(max_cpus - 1)) {
+        error_setg(errp, "CPU with APIC ID %" PRIi64
+                   " is more than MAX APIC ID limits", value);
+        return;
+    }
+
+    x86_topo_ids_from_apic_id(smp_cores, smp_threads, value, &topo);
+    if (topo.smt_id >= smp_threads || topo.core_id >= smp_cores) {
+        error_setg(errp, "CPU with APIC ID %" PRIi64 " does not match "
+                   "topology configuration.", value);
+        return;
+    }
+
     if ((value != cpu->env.cpuid_apic_id) && cpu_exists(value)) {
         error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value);
         return;
@@ -2166,8 +2180,10 @@ static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)
 {
     X86CPUDefinition *cpudef = data;
     X86CPUClass *xcc = X86_CPU_CLASS(oc);
+    DeviceClass *dc = DEVICE_CLASS(oc);
 
     xcc->cpu_def = cpudef;
+    dc->cannot_instantiate_with_device_add_yet = false;
 }
 
 static void x86_register_cpudef_type(X86CPUDefinition *def)
@@ -2176,6 +2192,7 @@ static void x86_register_cpudef_type(X86CPUDefinition *def)
     TypeInfo ti = {
         .name = typename,
         .parent = TYPE_X86_CPU,
+        .instance_size = sizeof(X86CPU),
         .class_init = x86_cpu_cpudef_class_init,
         .class_data = def,
     };
@@ -2709,11 +2726,28 @@ static void mce_init(X86CPU *cpu)
 }
 
 #ifndef CONFIG_USER_ONLY
+static uint32_t get_free_apic_id(void)
+{
+    int i;
+
+    for (i = 0; i < max_cpus; i++) {
+        uint32_t id = x86_cpu_apic_id_from_index(i);

target-i386/cpu.c static void mce_init(X86CPU *cpu) · line 2744

Quoted 10 lines
target-i386/cpu.c +10 -0
+
+        if (!cpu_exists(id)) {
+            return id;
+        }
+    }
+
+    return x86_cpu_apic_id_from_index(max_cpus);
+}
+
+#define APIC_ID_NOT_SET (~0U)

This is inside CONFIG_USER_ONLY...

Quoted 1 line
target-i386/cpu.c +1 -0
+

[...]

target-i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 2965

Quoted 6 lines
target-i386/cpu.c +1 -1
@@ -2920,7 +2962,7 @@ static void x86_cpu_initfn(Object *obj)
                         NULL, NULL, (void *)cpu->filtered_features, NULL);
 
     cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
-    env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
+    env->cpuid_apic_id = APIC_ID_NOT_SET;

...but this is not.

    CC    x86_64-linux-user/target-i386/cpu.o
  /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c: In function ‘x86_cpu_initfn’:
  /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:2964:26: error: ‘APIC_ID_NOT_SET’ undeclared (first use in this function)
       env->cpuid_apic_id = APIC_ID_NOT_SET;
                            ^

/home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:2964:26: note: each undeclared identifier is reported only once for each function it appears in /home/ehabkost/rh/proj/virt/qemu/rules.mak:57: recipe for target 'target-i386/cpu.o' failed
make[1]: *** [target-i386/cpu.o] Error 1
Makefile:169: recipe for target 'subdir-x86_64-linux-user' failed
make: *** [subdir-x86_64-linux-user] Error 2

Also, this will need to be rebased on top of the APIC ID cleanups from my x86 tree, located at:
https://github.com/ehabkost/qemu.git x86

Quoted 7 lines
target-i386/cpu.c +0 -0
     x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
 
Signature · 1 line
1.9.3
Signature · 1 line
Eduardo
author
#17 lore raw

PATCH v4 10/10 i386/cpu: add instance finalize callback

In reply to Zhu Guihua

From: Gu Zheng <[email protected]>

Add a func to finalize a cpu's instance. When cpu's device_add failed, and cpu's device_del executed, this func would be invoked.

---
 include/qom/cpu.h | 1 +
 target-i386/cpu.c | 8 ++++++++
 2 files changed, 9 insertions(+)
include/qom/cpu.h +1 -0
index d0a50e2..518f234 100644
@@ -308,6 +308,7 @@ struct CPUState {
 QTAILQ_HEAD(CPUTailQ, CPUState);
 extern struct CPUTailQ cpus;
 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
+#define CPU_REMOVE(cpu) QTAILQ_REMOVE(&cpus, cpu, node)
 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
     QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
target-i386/cpu.c +8 -0
index 68a6aa4..6df948f 100644
@@ -2973,6 +2973,13 @@ static void x86_cpu_initfn(Object *obj)
     }
 }
 
+static void x86_cpu_finalizefn(Object *obj)
+{
+    CPUState *cs = CPU(obj);
+
+    CPU_REMOVE(cs);
+}
+
 static int64_t x86_cpu_get_arch_id(CPUState *cs)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -3094,6 +3101,7 @@ static const TypeInfo x86_cpu_type_info = {
     .parent = TYPE_CPU,
     .instance_size = sizeof(X86CPU),
     .instance_init = x86_cpu_initfn,
+    .instance_finalize = x86_cpu_finalizefn,
     .abstract = true,
     .class_size = sizeof(X86CPUClass),
     .class_init = x86_cpu_common_class_init,
Signature · 1 line
1.9.3
#18 lore raw
In reply to Zhu Guihua

Hi Igor, Andreas,

The issues you commented in the previous version have been fixed in this one. Could you please help to review it?

Regards,
Gu

Quoted 85 lines · Zhu Guihua

This series is based on the previous patchset from Chen Fan:
https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html

We try to make cpu hotplug with device_add, and make "-device foo-x86_64-cpu" available, also we can set apic-id property with command line, if without setting apic-id property, we offer the first unoccupied apic id as the default new apic id. When hotplug cpu with device_add, additional check of APIC ID will be done after cpu object initialization which was different from 'cpu_add' command that check 'ids' at the beginning.

The is the first half of the previous series:
[RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support
https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html

---
Changelog since v3:
-fix cross version migration issue
-drop ICC bus impl
-do a generic for apic to send gpe event
-do not use migration code for CONFIG_USER_ONLY target

Changelog since v2:
-rebase on latest upstream.
-add cpu instance finalize.

Changelog since v1:
-rebased on latest upstream.
-introduce a help function to hide the access to icc_bus. -use a macro ACPI_ID_NOT_SET to replace the magic number(0xFFFFFFFF).

Changelog since RFC:
-split out APIC vmstate/QMP-monitor changes into separate patches. -add the handle of the startup cpus(-device foo).
-remove duplicated checking about env->cpuid_apic_id.
-do actual APIC ID allocation at realize time if it is not set before. -remove the unneeded x86_cpu_cpudef_instance_init().
-split off device_del support out here.
---

Chen Fan (4):
cpu/apic: drop icc bus/bridge/
icc_bus: remove icc related files
cpu: introduce CpuTopoInfo structure for argument simplification
cpu: add device_add foo-x86_64-cpu support

Gu Zheng (4):
qom/cpu: move register_vmstate to common CPUClass.realizefn qom/cpu: move apic vmstate register into x86_cpu_apic_realize
monitor: use cc->get_arch_id as the cpu index i386/cpu: add instance finalize callback

Zhu Guihua (2):
cpu: introduce get_compat_arch_id() method and override it for X86CPU
acpi: introduce acpi_send_gpe_event()

 MAINTAINERS                        |   6 --
 cpus.c                             |   4 +-
 default-configs/i386-softmmu.mak   |   1 -
 default-configs/x86_64-softmmu.mak |   1 -
 exec.c                             |  25 +++++---
 hw/acpi/core.c                     |   7 +++
 hw/acpi/cpu_hotplug.c              |   6 +-
 hw/cpu/Makefile.objs               |   2 -
 hw/cpu/icc_bus.c                   | 118 -------------------------------------
 hw/i386/kvm/apic.c                 |  10 +++-
 hw/i386/pc.c                       |  27 ++-------
 hw/i386/pc_piix.c                  |   9 +--
 hw/i386/pc_q35.c                   |   9 +--
 hw/intc/apic.c                     |  16 +++--
 hw/intc/apic_common.c              |  17 +++---
 include/hw/acpi/acpi.h             |   3 +
 include/hw/cpu/icc_bus.h           |  82 --------------------------
 include/hw/i386/apic_internal.h    |   9 +--
 include/hw/i386/pc.h               |   3 +-
 include/qom/cpu.h                  |   6 ++
 monitor.c                          |   4 +-
 qom/cpu.c                          |  10 ++++
 target-i386/cpu.c                  |  95 ++++++++++++++++++++++-------
 target-i386/cpu.h                  |   3 +-
 target-i386/topology.h             |  66 ++++++++++++++++-----
 25 files changed, 223 insertions(+), 316 deletions(-)
 delete mode 100644 hw/cpu/icc_bus.c
 delete mode 100644 include/hw/cpu/icc_bus.h
#19 lore raw

Hi Gu,

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 1 line

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

Quoted 1 line

Could you please help to review it?

Will get to it Friday earliest.

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#20 lore raw

Hi Andreas,

Quoted 9 lines · Andreas Färber

Hi Gu,

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 1 line

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

Quoted 5 lines

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

Can you explain all your thoughts about cpu hotplug feature with socket-based, or how goals do you want to see?

and what is the status of "device_add x86_64-cpu-socket" ?

after that, I think we can do somethings to help you to achieve your ideas.

Thanks,
Chen

Quoted 7 lines
Quoted 2 lines

Could you please help to review it?

Will get to it Friday earliest.

Regards,
Andreas

#21 lore raw

Hi,

Am 25.02.2015 um 10:58 schrieb Chen Fan:

Quoted 9 lines · Andreas Färber
Quoted 8 lines

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 2 lines

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

Quoted 8 lines
Quoted 5 lines

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

Can you explain all your thoughts about cpu hotplug feature with socket-based,
or how goals do you want to see?

Basically I am implementing Anthony's suggestion from a year or two back, that is moving towards using real building blocks such as Xeon-E5-4242 as shortcut for a 6-core, 2-HT device, ultimately replacing -cpu. Think of what can be plugged in real servers - a socket is atomic in reality, you can't add cores or hyperthreads dynamically. And the QOM realize model then forces me to use child<> properties inside the socket object for consistent recursive processing.

Regards,
Andreas

Quoted 16 lines

and what is the status of "device_add x86_64-cpu-socket" ?

after that, I think we can do somethings to help you to achieve your ideas.

Thanks,
Chen

Quoted 7 lines
Quoted 2 lines

Could you please help to review it?

Will get to it Friday earliest.

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#22 lore raw
Quoted 20 lines · Andreas Färber

Hi,

Am 25.02.2015 um 10:58 schrieb Chen Fan:

Quoted 9 lines · Andreas Färber
Quoted 8 lines

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 2 lines

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

Quoted 8 lines
Quoted 5 lines

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

Can you explain all your thoughts about cpu hotplug feature with socket-based,
or how goals do you want to see?

Quoted 7 lines

Basically I am implementing Anthony's suggestion from a year or two back, that is moving towards using real building blocks such as Xeon-E5-4242 as shortcut for a 6-core, 2-HT device, ultimately replacing -cpu. Think of what can be plugged in real servers - a socket is atomic in reality, you can't add cores or hyperthreads dynamically. And the QOM realize model then forces me to use child<> properties inside the socket object for consistent recursive processing.

yes, I agree with you.

but the existed command 'cpu-add' is adding one logic processor each time. it will cause compatibility with the socket-based cpu device. and what do you think to solve this problem ?

Thanks,
Chen

Quoted 18 lines

Regards,
Andreas

Quoted 13 lines

and what is the status of "device_add x86_64-cpu-socket" ?

after that, I think we can do somethings to help you to achieve your ideas.

Thanks,
Chen

Quoted 6 lines
Quoted 1 line

Could you please help to review it?

Will get to it Friday earliest.

Regards,
Andreas

#23 lore raw
In reply to Andreas Färber
Quoted 10 lines · Andreas Färber

Hi Gu,

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 1 line

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

Quoted 5 lines

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

If you have started a VM with -smp sockets=1,cores=4,threads=2, will you allow addition of a socket with just 2 cores like

device_add x86_64-cpu-socket,cores=2,id=sock2 ?

If so, will there be semantics to populate the remaining cores of that socket ? If so, would that look like below ?

device-add x86_64-cpu-core,sock=sock2

Regards,
Bharata.

#24 lore raw

Am 26.02.2015 um 05:42 schrieb Bharata B Rao:

Quoted 15 lines · Andreas Färber
Quoted 8 lines

Am 24.02.2015 um 02:25 schrieb Gu Zheng:

Quoted 1 line

The issues you commented in the previous version have been fixed in this one.

What I have repeatedly rejected is "device_add foo-x86_64-cpu". This is still in 00/10 and 09/10. Most of the actual changes however do look to be going in the right direction of making 'realize' work as expected for foo-x86_64-cpu.

Quoted 5 lines

As for the socket-based device_add I mentioned, I had pushed a work branch qom-cpu-x86 and had some off-list discussions for some of the other architectures but did not submit it as an RFC yet. What I am still working on is dynamic properties to allocate cores (threads TBD) for "device_add x86_64-cpu-socket,cores=n".

Quoted 4 lines

If you have started a VM with -smp sockets=1,cores=4,threads=2, will you allow addition of a socket with just 2 cores like

device_add x86_64-cpu-socket,cores=2,id=sock2 ?

In my implementation it is not yet working; with your patch it might, from a QEMU perspective. Whether that is sensible to do on x86 ACPI-/guest-wise is a different question. I didn't want to rule it out, as it seems possible in hardware when Intel/AMD socket types are compatible, and today cpu-add adds them one by one so it's possible.

On PowerPC the modeling could be done slightly differently, but as for x86 we'll have to keep in mind that there's not just sPAPR but also baremetal.

Quoted 4 lines

If so, will there be semantics to populate the remaining cores of that socket ? If so, would that look like below ?

device-add x86_64-cpu-core,sock=sock2

No, that is not possible with my modeling. Hotplug possibilities correspond to link<> properties, whereas my socket proposal uses child<> properties. This in turn has implications on CPU initialization functions, needing to not set realized=true. For non-x86 that will involve taking realized=true out of cpu_init() and moving it into call sites.

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
author
#25 lore raw
In reply to Zhu Guihua

Any other comments about this series?

cc Andreas,
Any progress about your socket model?

Thanks,
Zhu

Quoted 85 lines · Zhu Guihua

This series is based on the previous patchset from Chen Fan:
https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html

We try to make cpu hotplug with device_add, and make "-device foo-x86_64-cpu" available, also we can set apic-id property with command line, if without setting apic-id property, we offer the first unoccupied apic id as the default new apic id. When hotplug cpu with device_add, additional check of APIC ID will be done after cpu object initialization which was different from 'cpu_add' command that check 'ids' at the beginning.

The is the first half of the previous series:
[RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support
https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html

---
Changelog since v3:
-fix cross version migration issue
-drop ICC bus impl
-do a generic for apic to send gpe event
-do not use migration code for CONFIG_USER_ONLY target

Changelog since v2:
-rebase on latest upstream.
-add cpu instance finalize.

Changelog since v1:
-rebased on latest upstream.
-introduce a help function to hide the access to icc_bus. -use a macro ACPI_ID_NOT_SET to replace the magic number(0xFFFFFFFF).

Changelog since RFC:
-split out APIC vmstate/QMP-monitor changes into separate patches. -add the handle of the startup cpus(-device foo).
-remove duplicated checking about env->cpuid_apic_id.
-do actual APIC ID allocation at realize time if it is not set before. -remove the unneeded x86_cpu_cpudef_instance_init(). -split off device_del support out here.
---

Chen Fan (4):
cpu/apic: drop icc bus/bridge/
icc_bus: remove icc related files
cpu: introduce CpuTopoInfo structure for argument simplification
cpu: add device_add foo-x86_64-cpu support

Gu Zheng (4):
qom/cpu: move register_vmstate to common CPUClass.realizefn qom/cpu: move apic vmstate register into x86_cpu_apic_realize
monitor: use cc->get_arch_id as the cpu index i386/cpu: add instance finalize callback

Zhu Guihua (2):
cpu: introduce get_compat_arch_id() method and override it for X86CPU
acpi: introduce acpi_send_gpe_event()

  MAINTAINERS                        |   6 --
  cpus.c                             |   4 +-
  default-configs/i386-softmmu.mak   |   1 -
  default-configs/x86_64-softmmu.mak |   1 -
  exec.c                             |  25 +++++---
  hw/acpi/core.c                     |   7 +++
  hw/acpi/cpu_hotplug.c              |   6 +-
  hw/cpu/Makefile.objs               |   2 -
  hw/cpu/icc_bus.c                   | 118 -------------------------------------
  hw/i386/kvm/apic.c                 |  10 +++-
  hw/i386/pc.c                       |  27 ++-------
  hw/i386/pc_piix.c                  |   9 +--
  hw/i386/pc_q35.c                   |   9 +--
  hw/intc/apic.c                     |  16 +++--
  hw/intc/apic_common.c              |  17 +++---
  include/hw/acpi/acpi.h             |   3 +
  include/hw/cpu/icc_bus.h           |  82 --------------------------
  include/hw/i386/apic_internal.h    |   9 +--
  include/hw/i386/pc.h               |   3 +-
  include/qom/cpu.h                  |   6 ++
  monitor.c                          |   4 +-
  qom/cpu.c                          |  10 ++++
  target-i386/cpu.c                  |  95 ++++++++++++++++++++++-------
  target-i386/cpu.h                  |   3 +-
  target-i386/topology.h             |  66 ++++++++++++++++-----
  25 files changed, 223 insertions(+), 316 deletions(-)

delete mode 100644 hw/cpu/icc_bus.c
delete mode 100644 include/hw/cpu/icc_bus.h