diff mbox

[5/5] apic: create apic as a child of cpu, not system_bus any longer

Message ID 1341900967-4344-6-git-send-email-qemulist@gmail.com
State New
Headers show

Commit Message

pingfan liu July 10, 2012, 6:16 a.m. UTC
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 hw/pc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

Comments

Paolo Bonzini July 10, 2012, 8:45 a.m. UTC | #1
Il 10/07/2012 08:16, Liu Ping Fan ha scritto:
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  hw/pc.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/pc.c b/hw/pc.c
> index c7e9ab3..8df58c9 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
>      }
>  }
>  
> -static DeviceState *apic_init(void *env, uint8_t apic_id)
> +static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
>  {
>      DeviceState *dev;
>      static int apic_mapped;
>  
>      if (kvm_irqchip_in_kernel()) {
> -        dev = qdev_create(NULL, "kvm-apic");
> +        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
>      } else if (xen_enabled()) {
> -        dev = qdev_create(NULL, "xen-apic");
> +        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
>      } else {
> -        dev = qdev_create(NULL, "apic");
> +        dev = qdev_create_kid(OBJECT(cpu), "apic");
>      }

Does it make sense instead to do this in the realize method of the CPU?

Paolo

>  
>      qdev_prop_set_uint8(dev, "id", apic_id);
> @@ -945,7 +945,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)
>      }
>      env = &cpu->env;
>      if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
> -        env->apic_state = apic_init(env, env->cpuid_apic_id);
> +        env->apic_state = apic_init(cpu, env, env->cpuid_apic_id);
>      }
>      qemu_register_reset(pc_cpu_reset, cpu);
>      pc_cpu_reset(cpu);
>
Andreas Färber July 10, 2012, 10:41 a.m. UTC | #2
Am 10.07.2012 10:45, schrieb Paolo Bonzini:
> Il 10/07/2012 08:16, Liu Ping Fan ha scritto:
>> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>> ---
>>  hw/pc.c |   10 +++++-----
>>  1 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/pc.c b/hw/pc.c
>> index c7e9ab3..8df58c9 100644
>> --- a/hw/pc.c
>> +++ b/hw/pc.c
>> @@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
>>      }
>>  }
>>  
>> -static DeviceState *apic_init(void *env, uint8_t apic_id)
>> +static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
>>  {
>>      DeviceState *dev;
>>      static int apic_mapped;
>>  
>>      if (kvm_irqchip_in_kernel()) {
>> -        dev = qdev_create(NULL, "kvm-apic");
>> +        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
>>      } else if (xen_enabled()) {
>> -        dev = qdev_create(NULL, "xen-apic");
>> +        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
>>      } else {
>> -        dev = qdev_create(NULL, "apic");
>> +        dev = qdev_create_kid(OBJECT(cpu), "apic");
>>      }
> 
> Does it make sense instead to do this in the realize method of the CPU?

Igor was working on patches to do that. We ran into other design issues
on that road, yesterday I made a proposal how we might proceed with his
approach:

http://lists.nongnu.org/archive/html/qemu-devel/2012-07/msg00992.html

Andreas
Igor Mammedov July 11, 2012, 8:41 a.m. UTC | #3
On 07/10/2012 12:41 PM, Andreas Färber wrote:
> Am 10.07.2012 10:45, schrieb Paolo Bonzini:
>> Il 10/07/2012 08:16, Liu Ping Fan ha scritto:
>>> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>>> ---
>>>   hw/pc.c |   10 +++++-----
>>>   1 files changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/hw/pc.c b/hw/pc.c
>>> index c7e9ab3..8df58c9 100644
>>> --- a/hw/pc.c
>>> +++ b/hw/pc.c
>>> @@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
>>>       }
>>>   }
>>>
>>> -static DeviceState *apic_init(void *env, uint8_t apic_id)
>>> +static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
>>>   {
>>>       DeviceState *dev;
>>>       static int apic_mapped;
>>>
>>>       if (kvm_irqchip_in_kernel()) {
>>> -        dev = qdev_create(NULL, "kvm-apic");
>>> +        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
>>>       } else if (xen_enabled()) {
>>> -        dev = qdev_create(NULL, "xen-apic");
>>> +        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
>>>       } else {
>>> -        dev = qdev_create(NULL, "apic");
>>> +        dev = qdev_create_kid(OBJECT(cpu), "apic");
>>>       }
>>
>> Does it make sense instead to do this in the realize method of the CPU?
>
> Igor was working on patches to do that. We ran into other design issues
> on that road, yesterday I made a proposal how we might proceed with his
> approach:
>
> http://lists.nongnu.org/archive/html/qemu-devel/2012-07/msg00992.html
>
> Andreas


I was trying to put APIC by-value inside of X86_CPU and do in-place initialization
in x86_cpu_initfn(), but that has it's own drawbacks:
   1. currently all apic flavors have common instance sizeof(APICCommonState) that
      could be used as a way to reserve space in CPUX86State. But they could diverge
      and create problems later when nobody remembers that sizeof(whatever apic) must
      be equal to sizeof(APICCommonState)
   2. it won't solve OOM anyway because of a initfn could fail due to OOM in any
      object_property_add() call

So if not-inplace apic creation in realize() is acceptable alternative then I'd like to
respin apic patches with this change.
diff mbox

Patch

diff --git a/hw/pc.c b/hw/pc.c
index c7e9ab3..8df58c9 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -886,17 +886,17 @@  DeviceState *cpu_get_current_apic(void)
     }
 }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
+static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
 {
     DeviceState *dev;
     static int apic_mapped;
 
     if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
     } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
     } else {
-        dev = qdev_create(NULL, "apic");
+        dev = qdev_create_kid(OBJECT(cpu), "apic");
     }
 
     qdev_prop_set_uint8(dev, "id", apic_id);
@@ -945,7 +945,7 @@  static X86CPU *pc_new_cpu(const char *cpu_model)
     }
     env = &cpu->env;
     if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
-        env->apic_state = apic_init(env, env->cpuid_apic_id);
+        env->apic_state = apic_init(cpu, env, env->cpuid_apic_id);
     }
     qemu_register_reset(pc_cpu_reset, cpu);
     pc_cpu_reset(cpu);