Skip to contentSkip to conversation

target-i386: initialize APIC at CPU level

PATCH Superseded Igor Mammedov 3 participants 5 messages Oct 9, 2012 – Oct 10, 2012

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 target-i386: initialize APIC at CPU level

(L)APIC is a part of cpu [1] so move APIC initialization inside of x86_cpu object. Since cpu_model and override flags currently specify whether APIC should be created or not, APIC creation&initialization is moved into x86_cpu_apic_init() which is called from x86_cpu_realize().

[1] - all x86 cpus have integrated APIC if we overlook existence of i486, and it's more convenient to model after majority of them.

---
v2:
* init APIC mapping at cpu level, due to Peter's objection to putting it into APIC's initfn and Jan's suggestion to do it inside cpu.
v3:
* create APIC at realize time
* rebased on top of current qemu tree
* whitespace fix
* ifdef only body of x86_cpu_apic_init()
v4:
* put hw/xen.h under #ifndef CONFIG_USER_ONLY
* check for error after x86_cpu_apic_init()
* remove unneeded 'return'
v5:
* use qdev_try_create() instead of qdev_create() to avoid abort at realize time. spotted-by: Andreas Färber <[email protected]>

---
 hw/pc.c           | 56 +++++-----------------------------------------------
 target-i386/cpu.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 51 deletions(-)
hw/pc.c +5 -51
index 6c0722d..aa5abe0 100644
@@ -70,8 +70,6 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
-#define MSI_ADDR_BASE 0xfee00000
-
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
@@ -845,35 +843,6 @@ DeviceState *cpu_get_current_apic(void)
     }
 }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
-{
-    DeviceState *dev;
-    static int apic_mapped;
-
-    if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
-    } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
-    } else {
-        dev = qdev_create(NULL, "apic");
-    }
-
-    qdev_prop_set_uint8(dev, "id", apic_id);
-    qdev_prop_set_ptr(dev, "cpu_env", env);
-    qdev_init_nofail(dev);
-
-    /* XXX: mapping more APICs at the same memory location */
-    if (apic_mapped == 0) {
-        /* NOTE: the APIC is directly connected to the CPU - it is not
-           on the global memory bus. */
-        /* XXX: what if the base changes? */
-        sysbus_mmio_map(sysbus_from_qdev(dev), 0, MSI_ADDR_BASE);
-        apic_mapped = 1;
-    }
-
-    return dev;
-}
-
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
 {
     CPUX86State *s = opaque;
@@ -883,24 +852,6 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
     }
 }
 
-static X86CPU *pc_new_cpu(const char *cpu_model)
-{
-    X86CPU *cpu;
-    CPUX86State *env;
-
-    cpu = cpu_x86_init(cpu_model);
-    if (cpu == NULL) {
-        fprintf(stderr, "Unable to find x86 CPU definition\n");
-        exit(1);
-    }
-    env = &cpu->env;
-    if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
-        env->apic_state = apic_init(env, env->cpuid_apic_id);
-    }
-    cpu_reset(CPU(cpu));
-    return cpu;
-}
-
 void pc_cpus_init(const char *cpu_model)
 {
     int i;
@@ -914,8 +865,11 @@ void pc_cpus_init(const char *cpu_model)
 #endif
     }
 
-    for(i = 0; i < smp_cpus; i++) {
-        pc_new_cpu(cpu_model);
+    for (i = 0; i < smp_cpus; i++) {
+        if (!cpu_x86_init(cpu_model)) {
+            fprintf(stderr, "Unable to find x86 CPU definition\n");
+            exit(1);
+        }
     }
 }
 
target-i386/cpu.c +59 -0

79 lines not on this page · raw message

Signature · 1 line
1.7.11.4
#1 lore raw

Am 09.10.2012 19:17, schrieb Igor Mammedov:

Quoted 9 lines

(L)APIC is a part of cpu [1] so move APIC initialization inside of x86_cpu object. Since cpu_model and override flags currently specify whether APIC should be created or not, APIC creation&initialization is moved into x86_cpu_apic_init() which is called from x86_cpu_realize().

[1] - all x86 cpus have integrated APIC if we overlook existence of i486, and it's more convenient to model after majority of them.

I am happy with this latest round of fixes to ad-hoc feedback from my CPU remodeling perspective (as an interim solution), and I depend on this for my APIC changes (code is being moved around here).

Quoted 4 lines
target-i386/cpu.c +4 -0
+    if (env->apic_state == NULL) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED, apic_type);
+        return;
+    }

[...]

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

Quoted 5 lines
target-i386/cpu.c +5 -0
+    if (qdev_init(env->apic_state)) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED,
+                  object_get_typename(OBJECT(env->apic_state)));
+        return;
+    }

Luiz, could you please take a look whether I can apply this to my qom-cpu tree now or whether error_set() should be replaced by error_setg() or something? Contents-wise these are error-checking creation and initialization of a child (APIC) device/object.

Thanks,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 6 lines · On Wed, 10 Oct 2012 12:01:29 +0200 Andreas Färber <[email protected]> wrote:

Am 09.10.2012 19:17, schrieb Igor Mammedov:

Quoted 5 lines

(L)APIC is a part of cpu [1] so move APIC initialization inside of x86_cpu object. Since cpu_model and override flags currently specify whether APIC should be created or not, APIC creation&initialization is moved into x86_cpu_apic_init() which is called from x86_cpu_realize().

Quoted 11 lines
Quoted 4 lines

[1] - all x86 cpus have integrated APIC if we overlook existence of i486, and it's more convenient to model after majority of them.

I am happy with this latest round of fixes to ad-hoc feedback from my CPU remodeling perspective (as an interim solution), and I depend on this for my APIC changes (code is being moved around here).

Quoted 2 lines
target-i386/cpu.c +2 -0
+    if (env->apic_state == NULL) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED, apic_type);

This is equivalent to error_setg(errp, "Device '%s' could not be initialized",...). I'm not sure if repeating the same string in many places is a better than using an existing macro.

Quoted 18 lines
Quoted 2 lines
(quoted diff) +2 -0
+        return;
+    }

[...]

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

Quoted 5 lines
target-i386/cpu.c +5 -0
+    if (qdev_init(env->apic_state)) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED,u
+                  object_get_typename(OBJECT(env->apic_state)));
+        return;
+    }

Luiz, could you please take a look whether I can apply this to my qom-cpu tree now or whether error_set() should be replaced by error_setg() or something? Contents-wise these are error-checking creation and initialization of a child (APIC) device/object.

Thanks,
Andreas

#3 lore raw

Am 10.10.2012 14:49, schrieb Igor Mammedov:

Quoted 18 lines
Quoted 15 lines · On Wed, 10 Oct 2012 12:01:29 +0200 Andreas Färber <[email protected]> wrote:

Am 09.10.2012 19:17, schrieb Igor Mammedov:

Quoted 9 lines

(L)APIC is a part of cpu [1] so move APIC initialization inside of x86_cpu object. Since cpu_model and override flags currently specify whether APIC should be created or not, APIC creation&initialization is moved into x86_cpu_apic_init() which is called from x86_cpu_realize().

[1] - all x86 cpus have integrated APIC if we overlook existence of i486, and it's more convenient to model after majority of them.

I am happy with this latest round of fixes to ad-hoc feedback from my CPU remodeling perspective (as an interim solution), and I depend on this for my APIC changes (code is being moved around here).

Quoted 5 lines
Quoted 2 lines

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

Quoted 2 lines
target-i386/cpu.c +2 -0
+    if (env->apic_state == NULL) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED, apic_type);

This is equivalent to error_setg(errp, "Device '%s' could not be initialized",...). I'm not sure if repeating the same string in many places is a better than using an existing macro.

I thought their intention was to have specialized rather than standard messages, so maybe "An APIC of type '%s' could not be created." and "The APIC of type '%s' could not be initialized."?

Andreas

Quoted 20 lines
Quoted 19 lines
Quoted 3 lines
(quoted diff) +2 -0
+        return;
+    }

[...]

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

Quoted 5 lines
target-i386/cpu.c +5 -0
+    if (qdev_init(env->apic_state)) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED,u
+                  object_get_typename(OBJECT(env->apic_state)));
+        return;
+    }

Luiz, could you please take a look whether I can apply this to my qom-cpu tree now or whether error_set() should be replaced by error_setg() or something? Contents-wise these are error-checking creation and initialization of a child (APIC) device/object.

Thanks,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw
In reply to Andreas Färber
Quoted 26 lines · On Wed, 10 Oct 2012 12:01:29 +0200 Andreas Färber <[email protected]> wrote:

Am 09.10.2012 19:17, schrieb Igor Mammedov:

Quoted 9 lines

(L)APIC is a part of cpu [1] so move APIC initialization inside of x86_cpu object. Since cpu_model and override flags currently specify whether APIC should be created or not, APIC creation&initialization is moved into x86_cpu_apic_init() which is called from x86_cpu_realize().

[1] - all x86 cpus have integrated APIC if we overlook existence of i486, and it's more convenient to model after majority of them.

I am happy with this latest round of fixes to ad-hoc feedback from my CPU remodeling perspective (as an interim solution), and I depend on this for my APIC changes (code is being moved around here).

Quoted 4 lines
target-i386/cpu.c +4 -0
+    if (env->apic_state == NULL) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED, apic_type);
+        return;
+    }

[...]

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

Quoted 5 lines
target-i386/cpu.c +5 -0
+    if (qdev_init(env->apic_state)) {
+        error_set(errp, QERR_DEVICE_INIT_FAILED,
+                  object_get_typename(OBJECT(env->apic_state)));
+        return;
+    }
Quoted 4 lines

Luiz, could you please take a look whether I can apply this to my qom-cpu tree now or whether error_set() should be replaced by error_setg() or something? Contents-wise these are error-checking creation and initialization of a child (APIC) device/object.

I only saw this after I replied to the last email I was copied in this thread.

Is there anything else I should clarify?

Basically, we should not use QERR_* macros in new code. The only exception are the ErrorClass errors, defined in qapi-schema.json (except GenericError).

If you call qdev_init() or whatever function several times and use the same error message in all calls, then you should change qdev_init() to take an Error argument.