[patch 102/198] x86_64: Switch SMP bootup over to new CPU hotplug state machine

2005-04-12 Thread akpm

From: "Andi Kleen" <[EMAIL PROTECTED]>

This will allow hotplug CPU in the future and in general cleans up a lot of
crufty code.  It also should plug some races that the old hackish way
introduces.  Remove one old race workaround in NMI watchdog setup that is not
needed anymore.

I removed the old total sum of bogomips reporting code.  The brag value of
BogoMips has been greatly devalued in the last years on the open market.

Real CPU hotplug will need some more work, but the infrastructure for it is
there now.

One drawback: the new TSC sync algorithm is less accurate than before.  The
old way of zeroing TSCs is too intrusive to do later.  Instead the TSC of the
BP is duplicated now, which is less accurate.

akpm:

- sync_tsc_bp_init seems to have the sense of `init' inverted.

- SPIN_LOCK_UNLOCKED is deprecated - use DEFINE_SPINLOCK.

Cc: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Signed-off-by: Andi Kleen <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 25-akpm/arch/x86_64/kernel/nmi.c |6 
 25-akpm/arch/x86_64/kernel/smp.c |   25 +
 25-akpm/arch/x86_64/kernel/smpboot.c |  684 ---
 25-akpm/arch/x86_64/kernel/time.c|9 
 25-akpm/include/asm-x86_64/msr.h |1 
 25-akpm/include/asm-x86_64/proto.h   |2 
 25-akpm/include/asm-x86_64/smp.h |   29 -
 7 files changed, 369 insertions(+), 387 deletions(-)

diff -puN 
arch/x86_64/kernel/nmi.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state 
arch/x86_64/kernel/nmi.c
--- 
25/arch/x86_64/kernel/nmi.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
  2005-04-12 03:21:27.384973752 -0700
+++ 25-akpm/arch/x86_64/kernel/nmi.c2005-04-12 03:21:27.396971928 -0700
@@ -130,12 +130,6 @@ int __init check_nmi_watchdog (void)
mdelay((10*1000)/nmi_hz); // wait 10 ticks
 
for (cpu = 0; cpu < NR_CPUS; cpu++) {
-#ifdef CONFIG_SMP
-   /* Check cpu_callin_map here because that is set
-  after the timer is started. */
-   if (!cpu_isset(cpu, cpu_callin_map))
-   continue;
-#endif
if (cpu_pda[cpu].__nmi_count - counts[cpu] <= 5) {
printk("CPU#%d: NMI appears to be stuck (%d)!\n", 
   cpu,
diff -puN 
arch/x86_64/kernel/smpboot.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
 arch/x86_64/kernel/smpboot.c
--- 
25/arch/x86_64/kernel/smpboot.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
  2005-04-12 03:21:27.386973448 -0700
+++ 25-akpm/arch/x86_64/kernel/smpboot.c2005-04-12 03:21:27.401971168 
-0700
@@ -12,8 +12,7 @@
  * Pentium Pro and Pentium-II/Xeon MP machines.
  * Original development of Linux SMP code supported by Caldera.
  *
- * This code is released under the GNU General Public License version 2 or
- * later.
+ * This code is released under the GNU General Public License version 2
  *
  * Fixes
  * Felix Koop  :   NR_CPUS used properly
@@ -31,9 +30,13 @@
  * Tigran Aivazian :   fixed "0.00 in /proc/uptime on SMP" bug.
  * Maciej W. Rozycki   :   Bits for genuine 82489DX APICs
  * Andi Kleen  :   Changed for SMP boot into long mode.
- * Rusty Russell   :   Hacked into shape for new "hotplug" 
boot process. 
+ * Rusty Russell   :   Hacked into shape for new "hotplug" 
boot process.
+ *  Andi Kleen  :   Converted to new state machine.
+ * Various cleanups.
+ * Probably mostly hotplug CPU ready now.
  */
 
+
 #include 
 #include 
 
@@ -54,11 +57,15 @@
 #include 
 #include 
 
+/* Change for real CPU hotplug. Note other files need to be fixed
+   first too. */
+#define __cpuinit __init
+#define __cpuinitdata __initdata
+
 /* Number of siblings per CPU package */
 int smp_num_siblings = 1;
 /* Package ID of each logical CPU */
 u8 phys_proc_id[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
-/* Core ID of each logical CPU */
 u8 cpu_core_id[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
 EXPORT_SYMBOL(phys_proc_id);
 EXPORT_SYMBOL(cpu_core_id);
@@ -66,13 +73,24 @@ EXPORT_SYMBOL(cpu_core_id);
 /* Bitmask of currently online CPUs */
 cpumask_t cpu_online_map;
 
+EXPORT_SYMBOL(cpu_online_map);
+
+/*
+ * Private maps to synchronize booting between AP and BP.
+ * Probably not needed anymore, but it makes for easier debugging. -AK
+ */
 cpumask_t cpu_callin_map;
 cpumask_t cpu_callout_map;
-static cpumask_t smp_commenced_mask;
+
+cpumask_t cpu_possible_map;
+EXPORT_SYMBOL(cpu_possible_map);
 
 /* Per CPU bogomips and other parameters */
 struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
 
+/* Set when the idlers are all forked */
+int smp_threads_ready;
+
 cpumask_t cpu_sibling_map[NR_CPUS] __cacheline_aligned;
 cpumask_t cpu_core_map[NR_CPUS] __cacheline_aligned;
 
@@ -80,8 +98,8 @@ cpumask_t 

[patch 102/198] x86_64: Switch SMP bootup over to new CPU hotplug state machine

2005-04-12 Thread akpm

From: Andi Kleen [EMAIL PROTECTED]

This will allow hotplug CPU in the future and in general cleans up a lot of
crufty code.  It also should plug some races that the old hackish way
introduces.  Remove one old race workaround in NMI watchdog setup that is not
needed anymore.

I removed the old total sum of bogomips reporting code.  The brag value of
BogoMips has been greatly devalued in the last years on the open market.

Real CPU hotplug will need some more work, but the infrastructure for it is
there now.

One drawback: the new TSC sync algorithm is less accurate than before.  The
old way of zeroing TSCs is too intrusive to do later.  Instead the TSC of the
BP is duplicated now, which is less accurate.

akpm:

- sync_tsc_bp_init seems to have the sense of `init' inverted.

- SPIN_LOCK_UNLOCKED is deprecated - use DEFINE_SPINLOCK.

Cc: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Signed-off-by: Andi Kleen [EMAIL PROTECTED]
Signed-off-by: Andrew Morton [EMAIL PROTECTED]
---

 25-akpm/arch/x86_64/kernel/nmi.c |6 
 25-akpm/arch/x86_64/kernel/smp.c |   25 +
 25-akpm/arch/x86_64/kernel/smpboot.c |  684 ---
 25-akpm/arch/x86_64/kernel/time.c|9 
 25-akpm/include/asm-x86_64/msr.h |1 
 25-akpm/include/asm-x86_64/proto.h   |2 
 25-akpm/include/asm-x86_64/smp.h |   29 -
 7 files changed, 369 insertions(+), 387 deletions(-)

diff -puN 
arch/x86_64/kernel/nmi.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state 
arch/x86_64/kernel/nmi.c
--- 
25/arch/x86_64/kernel/nmi.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
  2005-04-12 03:21:27.384973752 -0700
+++ 25-akpm/arch/x86_64/kernel/nmi.c2005-04-12 03:21:27.396971928 -0700
@@ -130,12 +130,6 @@ int __init check_nmi_watchdog (void)
mdelay((10*1000)/nmi_hz); // wait 10 ticks
 
for (cpu = 0; cpu  NR_CPUS; cpu++) {
-#ifdef CONFIG_SMP
-   /* Check cpu_callin_map here because that is set
-  after the timer is started. */
-   if (!cpu_isset(cpu, cpu_callin_map))
-   continue;
-#endif
if (cpu_pda[cpu].__nmi_count - counts[cpu] = 5) {
printk(CPU#%d: NMI appears to be stuck (%d)!\n, 
   cpu,
diff -puN 
arch/x86_64/kernel/smpboot.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
 arch/x86_64/kernel/smpboot.c
--- 
25/arch/x86_64/kernel/smpboot.c~x86_64-switch-smp-bootup-over-to-new-cpu-hotplug-state
  2005-04-12 03:21:27.386973448 -0700
+++ 25-akpm/arch/x86_64/kernel/smpboot.c2005-04-12 03:21:27.401971168 
-0700
@@ -12,8 +12,7 @@
  * Pentium Pro and Pentium-II/Xeon MP machines.
  * Original development of Linux SMP code supported by Caldera.
  *
- * This code is released under the GNU General Public License version 2 or
- * later.
+ * This code is released under the GNU General Public License version 2
  *
  * Fixes
  * Felix Koop  :   NR_CPUS used properly
@@ -31,9 +30,13 @@
  * Tigran Aivazian :   fixed 0.00 in /proc/uptime on SMP bug.
  * Maciej W. Rozycki   :   Bits for genuine 82489DX APICs
  * Andi Kleen  :   Changed for SMP boot into long mode.
- * Rusty Russell   :   Hacked into shape for new hotplug 
boot process. 
+ * Rusty Russell   :   Hacked into shape for new hotplug 
boot process.
+ *  Andi Kleen  :   Converted to new state machine.
+ * Various cleanups.
+ * Probably mostly hotplug CPU ready now.
  */
 
+
 #include linux/config.h
 #include linux/init.h
 
@@ -54,11 +57,15 @@
 #include asm/tlbflush.h
 #include asm/proto.h
 
+/* Change for real CPU hotplug. Note other files need to be fixed
+   first too. */
+#define __cpuinit __init
+#define __cpuinitdata __initdata
+
 /* Number of siblings per CPU package */
 int smp_num_siblings = 1;
 /* Package ID of each logical CPU */
 u8 phys_proc_id[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
-/* Core ID of each logical CPU */
 u8 cpu_core_id[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
 EXPORT_SYMBOL(phys_proc_id);
 EXPORT_SYMBOL(cpu_core_id);
@@ -66,13 +73,24 @@ EXPORT_SYMBOL(cpu_core_id);
 /* Bitmask of currently online CPUs */
 cpumask_t cpu_online_map;
 
+EXPORT_SYMBOL(cpu_online_map);
+
+/*
+ * Private maps to synchronize booting between AP and BP.
+ * Probably not needed anymore, but it makes for easier debugging. -AK
+ */
 cpumask_t cpu_callin_map;
 cpumask_t cpu_callout_map;
-static cpumask_t smp_commenced_mask;
+
+cpumask_t cpu_possible_map;
+EXPORT_SYMBOL(cpu_possible_map);
 
 /* Per CPU bogomips and other parameters */
 struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
 
+/* Set when the idlers are all forked */
+int smp_threads_ready;
+
 cpumask_t cpu_sibling_map[NR_CPUS] __cacheline_aligned;
 cpumask_t cpu_core_map[NR_CPUS] __cacheline_aligned;
 
@@