Patchwork [RFC,07/12] target-i386/cpu: Introduce apic_id_for_cpu() function

login
register
mail settings
Submitter Eduardo Habkost
Date Jan. 9, 2013, 6:53 p.m.
Message ID <1357757632-1950-8-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/210825/
State New
Headers show

Comments

Eduardo Habkost - Jan. 9, 2013, 6:53 p.m.
This function will be used by both the CPU initialization code and the
fw_cfg table initialization code.

Later this function will be updated to generate APIC IDs according to
the CPU topology.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 17 ++++++++++++++++-
 target-i386/cpu.h |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)
Igor Mammedov - Jan. 10, 2013, 11:31 p.m.
On Wed,  9 Jan 2013 16:53:47 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> This function will be used by both the CPU initialization code and the
> fw_cfg table initialization code.
> 
> Later this function will be updated to generate APIC IDs according to
> the CPU topology.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c | 17 ++++++++++++++++-
>  target-i386/cpu.h |  2 ++
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 492656c..33787dc 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2192,6 +2192,21 @@ void x86_cpu_realize(Object *obj, Error **errp)
>      cpu_reset(CPU(cpu));
>  }
>  
> +/* Calculates initial APIC ID for a specific CPU index
> + *
> + * Currently we need to be able to calculate the APIC ID from the CPU index
> + * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
> + * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
> + * all CPUs up to max_cpus.
> + */
> +uint32_t apic_id_for_cpu(unsigned int cpu_index)
> +{
> +    /* right now APIC ID == CPU index. this will eventually change to use
> +     * the CPU topology configuration properly
> +     */
> +    return cpu_index;
> +}
> +
>  static void x86_cpu_initfn(Object *obj)
>  {
>      CPUState *cs = CPU(obj);
> @@ -2226,7 +2241,7 @@ static void x86_cpu_initfn(Object *obj)
>                          x86_cpuid_get_tsc_freq,
>                          x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
>  
> -    env->cpuid_apic_id = cs->cpu_index;
> +    env->cpuid_apic_id = apic_id_for_cpu(cs->cpu_index);
APIC ID is set by board so CPU shouldn't do it by itself.

Could you create static property for it and set it from board using property
instead?

>  
>      /* init various static tables used in TCG mode */
>      if (tcg_enabled() && !inited) {
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index f3c9df5..dbd9899 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -1238,4 +1238,6 @@ void disable_kvm_pv_eoi(void);
>  /* Return name of 32-bit register, from a R_* constant */
>  const char *get_register_name_32(unsigned int reg);
>  
> +uint32_t apic_id_for_cpu(unsigned int cpu_index);
> +
>  #endif /* CPU_I386_H */
> -- 
> 1.7.11.7
>
Eduardo Habkost - Jan. 10, 2013, 11:51 p.m.
On Fri, Jan 11, 2013 at 12:31:23AM +0100, Igor Mammedov wrote:
> On Wed,  9 Jan 2013 16:53:47 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > This function will be used by both the CPU initialization code and the
> > fw_cfg table initialization code.
> > 
> > Later this function will be updated to generate APIC IDs according to
> > the CPU topology.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target-i386/cpu.c | 17 ++++++++++++++++-
> >  target-i386/cpu.h |  2 ++
> >  2 files changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index 492656c..33787dc 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -2192,6 +2192,21 @@ void x86_cpu_realize(Object *obj, Error **errp)
> >      cpu_reset(CPU(cpu));
> >  }
> >  
> > +/* Calculates initial APIC ID for a specific CPU index
> > + *
> > + * Currently we need to be able to calculate the APIC ID from the CPU index
> > + * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
> > + * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
> > + * all CPUs up to max_cpus.
> > + */
> > +uint32_t apic_id_for_cpu(unsigned int cpu_index)
> > +{
> > +    /* right now APIC ID == CPU index. this will eventually change to use
> > +     * the CPU topology configuration properly
> > +     */
> > +    return cpu_index;
> > +}
> > +
> >  static void x86_cpu_initfn(Object *obj)
> >  {
> >      CPUState *cs = CPU(obj);
> > @@ -2226,7 +2241,7 @@ static void x86_cpu_initfn(Object *obj)
> >                          x86_cpuid_get_tsc_freq,
> >                          x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
> >  
> > -    env->cpuid_apic_id = cs->cpu_index;
> > +    env->cpuid_apic_id = apic_id_for_cpu(cs->cpu_index);
> APIC ID is set by board so CPU shouldn't do it by itself.
> 
> Could you create static property for it and set it from board using property
> instead?

I had a version that had the PC CPU creation code set the apic-id using
a apic-id property, but I am using this method to keep the bug fix
simpler and less intrusive, as I we don't have much time to remodel the
CPU creation code before soft freeze.

The previous version can be seen at:
  https://github.com/ehabkost/qemu-hacks/tree/apic-id-topology-using-apic-id-prop
The relevant apic-id-setting code is at:
  https://github.com/ehabkost/qemu-hacks/commit/a79156d0ad99ee89c0def535ce4cafcc4aa9a486

I believe the final solution for calculating the APIC IDs should instead
involve passing the package ID and bit width of core+thread IDs to a
package/socket object (so we don't need to expose the APIC IDs outside
QEMU). But whatever design we're going to choose to allow CPU hotplug, I
didn't want to introduce complexity that will get into our way when we
remodel the CPU creation/hotplug interfaces later.


> 
> >  
> >      /* init various static tables used in TCG mode */
> >      if (tcg_enabled() && !inited) {
> > diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> > index f3c9df5..dbd9899 100644
> > --- a/target-i386/cpu.h
> > +++ b/target-i386/cpu.h
> > @@ -1238,4 +1238,6 @@ void disable_kvm_pv_eoi(void);
> >  /* Return name of 32-bit register, from a R_* constant */
> >  const char *get_register_name_32(unsigned int reg);
> >  
> > +uint32_t apic_id_for_cpu(unsigned int cpu_index);
> > +
> >  #endif /* CPU_I386_H */
> > -- 
> > 1.7.11.7
> > 
> 
> 
> -- 
> Regards,
>   Igor
Eduardo Habkost - Jan. 10, 2013, 11:57 p.m.
On Fri, Jan 11, 2013 at 12:31:23AM +0100, Igor Mammedov wrote:
> On Wed,  9 Jan 2013 16:53:47 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > This function will be used by both the CPU initialization code and the
> > fw_cfg table initialization code.
> > 
> > Later this function will be updated to generate APIC IDs according to
> > the CPU topology.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target-i386/cpu.c | 17 ++++++++++++++++-
> >  target-i386/cpu.h |  2 ++
> >  2 files changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index 492656c..33787dc 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -2192,6 +2192,21 @@ void x86_cpu_realize(Object *obj, Error **errp)
> >      cpu_reset(CPU(cpu));
> >  }
> >  
> > +/* Calculates initial APIC ID for a specific CPU index
> > + *
> > + * Currently we need to be able to calculate the APIC ID from the CPU index
> > + * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
> > + * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
> > + * all CPUs up to max_cpus.
> > + */
> > +uint32_t apic_id_for_cpu(unsigned int cpu_index)
> > +{
> > +    /* right now APIC ID == CPU index. this will eventually change to use
> > +     * the CPU topology configuration properly
> > +     */
> > +    return cpu_index;
> > +}
> > +
> >  static void x86_cpu_initfn(Object *obj)
> >  {
> >      CPUState *cs = CPU(obj);
> > @@ -2226,7 +2241,7 @@ static void x86_cpu_initfn(Object *obj)
> >                          x86_cpuid_get_tsc_freq,
> >                          x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
> >  
> > -    env->cpuid_apic_id = cs->cpu_index;
> > +    env->cpuid_apic_id = apic_id_for_cpu(cs->cpu_index);
> APIC ID is set by board so CPU shouldn't do it by itself.
> 
> Could you create static property for it and set it from board using property
> instead?

I had a version that had the PC CPU creation code set the apic-id using
a apic-id property, but I am using this method to keep the bug fix
simpler and less intrusive, as I we don't have much time to remodel the
CPU creation code before soft freeze.

The previous version can be seen at:
  https://github.com/ehabkost/qemu-hacks/tree/apic-id-topology-using-apic-id-prop
The relevant apic-id-setting code is at:
  https://github.com/ehabkost/qemu-hacks/commit/a79156d0ad99ee89c0def535ce4cafcc4aa9a486

I believe the final solution for calculating the APIC IDs should instead
involve passing the package ID and bit width of core+thread IDs to a
package/socket object (so we don't need to expose the APIC IDs outside
QEMU). But whatever design we're going to choose to allow CPU hotplug, I
didn't want to introduce complexity that will get into our way when we
remodel the CPU creation/hotplug interfaces later.


> 
> >  
> >      /* init various static tables used in TCG mode */
> >      if (tcg_enabled() && !inited) {
> > diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> > index f3c9df5..dbd9899 100644
> > --- a/target-i386/cpu.h
> > +++ b/target-i386/cpu.h
> > @@ -1238,4 +1238,6 @@ void disable_kvm_pv_eoi(void);
> >  /* Return name of 32-bit register, from a R_* constant */
> >  const char *get_register_name_32(unsigned int reg);
> >  
> > +uint32_t apic_id_for_cpu(unsigned int cpu_index);
> > +
> >  #endif /* CPU_I386_H */
> > -- 
> > 1.7.11.7
> > 
> 
> 
> -- 
> Regards,
>   Igor

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 492656c..33787dc 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2192,6 +2192,21 @@  void x86_cpu_realize(Object *obj, Error **errp)
     cpu_reset(CPU(cpu));
 }
 
+/* Calculates initial APIC ID for a specific CPU index
+ *
+ * Currently we need to be able to calculate the APIC ID from the CPU index
+ * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
+ * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
+ * all CPUs up to max_cpus.
+ */
+uint32_t apic_id_for_cpu(unsigned int cpu_index)
+{
+    /* right now APIC ID == CPU index. this will eventually change to use
+     * the CPU topology configuration properly
+     */
+    return cpu_index;
+}
+
 static void x86_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
@@ -2226,7 +2241,7 @@  static void x86_cpu_initfn(Object *obj)
                         x86_cpuid_get_tsc_freq,
                         x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
 
-    env->cpuid_apic_id = cs->cpu_index;
+    env->cpuid_apic_id = apic_id_for_cpu(cs->cpu_index);
 
     /* init various static tables used in TCG mode */
     if (tcg_enabled() && !inited) {
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index f3c9df5..dbd9899 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1238,4 +1238,6 @@  void disable_kvm_pv_eoi(void);
 /* Return name of 32-bit register, from a R_* constant */
 const char *get_register_name_32(unsigned int reg);
 
+uint32_t apic_id_for_cpu(unsigned int cpu_index);
+
 #endif /* CPU_I386_H */