x86: Replace cpu_2_logical_apicid[] with early percpu variable
authorTejun Heo <tj@kernel.org>
Sun, 23 Jan 2011 13:37:30 +0000 (14:37 +0100)
committerIngo Molnar <mingo@elte.hu>
Fri, 28 Jan 2011 13:54:05 +0000 (14:54 +0100)
Unlike x86_64, on x86_32, the mapping from cpu to logical apicid
may vary depending on apic in use.  cpu_2_logical_apicid[] array
is used for this mapping.  Replace it with early percpu variable
x86_cpu_to_logical_apicid to make it better aligned with other
mappings.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: eric.dumazet@gmail.com
Cc: yinghai@kernel.org
Cc: brgerst@gmail.com
Cc: gorcunov@gmail.com
Cc: penberg@kernel.org
Cc: shaohui.zheng@intel.com
Cc: rientjes@google.com
LKML-Reference: <1295789862-25482-5-git-send-email-tj@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/apic.h
arch/x86/include/asm/smp.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/apic/es7000_32.c
arch/x86/kernel/apic/numaq_32.c
arch/x86/kernel/apic/summit_32.c
arch/x86/kernel/setup_percpu.c
arch/x86/kernel/smpboot.c

index 5e3969c36d7f62b87473f9a0b422beb5378e1737..eb139eced85041634613d4d0ce538f1bc3904a64 100644 (file)
@@ -595,8 +595,4 @@ extern int default_check_phys_apicid_present(int phys_apicid);
 
 #endif /* CONFIG_X86_LOCAL_APIC */
 
-#ifdef CONFIG_X86_32
-extern u8 cpu_2_logical_apicid[NR_CPUS];
-#endif
-
 #endif /* _ASM_X86_APIC_H */
index 4c2f63c7fc1b2ec071d3d32465f389a6d9df24dd..dc7c46a89db7eccae7aa6a0aa12bb7b22749d516 100644 (file)
@@ -38,6 +38,9 @@ static inline struct cpumask *cpu_core_mask(int cpu)
 
 DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
+#if defined(CONFIG_SMP) && defined(CONFIG_X86_32)
+DECLARE_EARLY_PER_CPU(int, x86_cpu_to_logical_apicid);
+#endif
 
 /* Static state in head.S used to set up a CPU */
 extern struct {
index 06c196d7e59c0e2f4300e3806ee8d2355e0496ec..126d5a3b00e9cdc8cdc3e5e25cc9ea82fb3e4cbf 100644 (file)
@@ -78,6 +78,17 @@ EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
 EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
 
 #ifdef CONFIG_X86_32
+
+#ifdef CONFIG_SMP
+/*
+ * On x86_32, the mapping between cpu and logical apicid may vary
+ * depending on apic in use.  The following early percpu variable is
+ * used for the mapping.  This is where the behaviors of x86_64 and 32
+ * actually diverge.  Let's keep it ugly for now.
+ */
+DEFINE_EARLY_PER_CPU(int, x86_cpu_to_logical_apicid, BAD_APICID);
+#endif
+
 /*
  * Knob to control our willingness to enable the local APIC.
  *
index 8593582d8022bed84972fe6bde245035778d7c80..7cb73e12f78459dbb35f4f1dcbf07df94c953b20 100644 (file)
@@ -534,7 +534,7 @@ static int es7000_cpu_to_logical_apicid(int cpu)
 #ifdef CONFIG_SMP
        if (cpu >= nr_cpu_ids)
                return BAD_APICID;
-       return cpu_2_logical_apicid[cpu];
+       return early_per_cpu(x86_cpu_to_logical_apicid, cpu);
 #else
        return logical_smp_processor_id();
 #endif
index 960f26ab5c9f24ed2f4587107faa2fcd457d782c..4ed90c4882e95ca987d521c61aa9fa96b3f6ed77 100644 (file)
@@ -377,7 +377,7 @@ static inline int numaq_cpu_to_logical_apicid(int cpu)
 {
        if (cpu >= nr_cpu_ids)
                return BAD_APICID;
-       return cpu_2_logical_apicid[cpu];
+       return early_per_cpu(x86_cpu_to_logical_apicid, cpu);
 }
 
 /*
index 9b419263d90df0e4b1ebc5c7d7ced5c7c36f038b..82cfc3ea70d1bf00b98e3281ec25e873b68cb025 100644 (file)
@@ -206,7 +206,7 @@ static void summit_init_apic_ldr(void)
 
        /* Create logical APIC IDs by counting CPUs already in cluster. */
        for (count = 0, i = nr_cpu_ids; --i >= 0; ) {
-               lid = cpu_2_logical_apicid[i];
+               lid = early_per_cpu(x86_cpu_to_logical_apicid, i);
                if (lid != BAD_APICID && APIC_CLUSTER(lid) == my_cluster)
                        ++count;
        }
@@ -247,7 +247,7 @@ static inline int summit_cpu_to_logical_apicid(int cpu)
 #ifdef CONFIG_SMP
        if (cpu >= nr_cpu_ids)
                return BAD_APICID;
-       return cpu_2_logical_apicid[cpu];
+       return early_per_cpu(x86_cpu_to_logical_apicid, cpu);
 #else
        return logical_smp_processor_id();
 #endif
index 002b79685f738014a8cf9127f804851459a6216b..b5147f00f0efe804fcedcc8ca729f4a5950c6f37 100644 (file)
@@ -225,6 +225,10 @@ void __init setup_per_cpu_areas(void)
                per_cpu(x86_bios_cpu_apicid, cpu) =
                        early_per_cpu_map(x86_bios_cpu_apicid, cpu);
 #endif
+#ifdef CONFIG_X86_32
+               per_cpu(x86_cpu_to_logical_apicid, cpu) =
+                       early_per_cpu_map(x86_cpu_to_logical_apicid, cpu);
+#endif
 #ifdef CONFIG_X86_64
                per_cpu(irq_stack_ptr, cpu) =
                        per_cpu(irq_stack_union.irq_stack, cpu) +
@@ -256,6 +260,9 @@ void __init setup_per_cpu_areas(void)
        early_per_cpu_ptr(x86_cpu_to_apicid) = NULL;
        early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL;
 #endif
+#ifdef CONFIG_X86_32
+       early_per_cpu_ptr(x86_cpu_to_logical_apicid) = NULL;
+#endif
 #if defined(CONFIG_X86_64) && defined(CONFIG_NUMA)
        early_per_cpu_ptr(x86_cpu_to_node_map) = NULL;
 #endif
index 53a85baaecca02187926b11f60310b50657855ad..df934e46bf5334645247effc657acf3f49a1e481 100644 (file)
@@ -165,9 +165,6 @@ static void unmap_cpu_to_node(int cpu)
 #endif
 
 #ifdef CONFIG_X86_32
-u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly =
-                                       { [0 ... NR_CPUS-1] = BAD_APICID };
-
 static void map_cpu_to_logical_apicid(void)
 {
        int cpu = smp_processor_id();
@@ -177,13 +174,13 @@ static void map_cpu_to_logical_apicid(void)
        if (!node_online(node))
                node = first_online_node;
 
-       cpu_2_logical_apicid[cpu] = apicid;
+       early_per_cpu(x86_cpu_to_logical_apicid, cpu) = apicid;
        map_cpu_to_node(cpu, node);
 }
 
 void numa_remove_cpu(int cpu)
 {
-       cpu_2_logical_apicid[cpu] = BAD_APICID;
+       early_per_cpu(x86_cpu_to_logical_apicid, cpu) = BAD_APICID;
        unmap_cpu_to_node(cpu);
 }
 #else