diff mbox

[v2] i386: keep cpu_model field in MachineState uptodate

Message ID 1440409329-22153-1-git-send-email-zhugh.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhu Guihua Aug. 24, 2015, 9:42 a.m. UTC
Update cpu_model in MachineState for i386, so that the field can be used
for cpu hotplug, instead of using a static variable.

Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
---
v2:
 -transfer MachineState from all pc_cpus_init() callers
---
 hw/i386/pc.c         | 16 +++++++---------
 hw/i386/pc_piix.c    |  2 +-
 hw/i386/pc_q35.c     |  2 +-
 include/hw/i386/pc.h |  2 +-
 4 files changed, 10 insertions(+), 12 deletions(-)

Comments

Eduardo Habkost Aug. 26, 2015, 3:11 p.m. UTC | #1
On Mon, Aug 24, 2015 at 05:42:09PM +0800, Zhu Guihua wrote:
> Update cpu_model in MachineState for i386, so that the field can be used
> for cpu hotplug, instead of using a static variable.
> 
> Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
[...]
> -void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
> +void pc_cpus_init(MachineState *machine, DeviceState *icc_bridge)

This is a PC initialization function, so a PCMachineState argument makes
more sense. See pc_cmos_init(), load_linux(), pc_guest_info_init(),
pc_memory_init(), etc.

The rest looks good.
Zhu Guihua Aug. 27, 2015, 3:17 a.m. UTC | #2
On 08/26/2015 11:11 PM, Eduardo Habkost wrote:
> On Mon, Aug 24, 2015 at 05:42:09PM +0800, Zhu Guihua wrote:
>> Update cpu_model in MachineState for i386, so that the field can be used
>> for cpu hotplug, instead of using a static variable.
>>
>> Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
> [...]
>> -void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
>> +void pc_cpus_init(MachineState *machine, DeviceState *icc_bridge)
> This is a PC initialization function, so a PCMachineState argument makes
> more sense. See pc_cmos_init(), load_linux(), pc_guest_info_init(),
> pc_memory_init(), etc.

Oh, I know how to do this. Thanks for your suggestion.

Thanks,
Zhu

>
> The rest looks good.
>
diff mbox

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9f2924e..46ea74a 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1081,11 +1081,10 @@  out:
     return cpu;
 }
 
-static const char *current_cpu_model;
-
 void pc_hot_add_cpu(const int64_t id, Error **errp)
 {
     DeviceState *icc_bridge;
+    MachineState *machine = MACHINE(qdev_get_machine());
     X86CPU *cpu;
     int64_t apic_id = x86_cpu_apic_id_from_index(id);
     Error *local_err = NULL;
@@ -1116,7 +1115,7 @@  void pc_hot_add_cpu(const int64_t id, Error **errp)
 
     icc_bridge = DEVICE(object_resolve_path_type("icc-bridge",
                                                  TYPE_ICC_BRIDGE, NULL));
-    cpu = pc_new_cpu(current_cpu_model, apic_id, icc_bridge, &local_err);
+    cpu = pc_new_cpu(machine->cpu_model, apic_id, icc_bridge, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
@@ -1124,7 +1123,7 @@  void pc_hot_add_cpu(const int64_t id, Error **errp)
     object_unref(OBJECT(cpu));
 }
 
-void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
+void pc_cpus_init(MachineState *machine, DeviceState *icc_bridge)
 {
     int i;
     X86CPU *cpu = NULL;
@@ -1132,14 +1131,13 @@  void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
     unsigned long apic_id_limit;
 
     /* init CPUs */
-    if (cpu_model == NULL) {
+    if (machine->cpu_model == NULL) {
 #ifdef TARGET_X86_64
-        cpu_model = "qemu64";
+        machine->cpu_model = "qemu64";
 #else
-        cpu_model = "qemu32";
+        machine->cpu_model = "qemu32";
 #endif
     }
-    current_cpu_model = cpu_model;
 
     apic_id_limit = pc_apic_id_limit(max_cpus);
     if (apic_id_limit > ACPI_CPU_HOTPLUG_ID_LIMIT) {
@@ -1149,7 +1147,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),
+        cpu = pc_new_cpu(machine->cpu_model, x86_cpu_apic_id_from_index(i),
                          icc_bridge, &error);
         if (error) {
             error_report_err(error);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 9558467..7e16665 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -145,7 +145,7 @@  static void pc_init1(MachineState *machine)
     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, icc_bridge);
 
     if (kvm_enabled() && kvmclock_enabled) {
         kvmclock_create();
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index c07d65b..e7249d2 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -136,7 +136,7 @@  static void pc_q35_init(MachineState *machine)
     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, icc_bridge);
     pc_acpi_init("q35-acpi-dsdt.aml");
 
     kvmclock_create();
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index d0cad87..ae0184d 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -161,7 +161,7 @@  bool pc_machine_is_smm_enabled(PCMachineState *pcms);
 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(MachineState *machine, DeviceState *icc_bridge);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);