Skip to contentSkip to conversation

fixes for rcu_offline_cpu, rcu_move_batch (2.6.8-rc2)

PATCH In review Nathan Lynch 5 participants 11 messages Jul 26, 2004 – Aug 15, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fixes for rcu_offline_cpu, rcu_move_batch (2.6.8-rc2)

Hi,

rcu_offline_cpu and rcu_move_batch have been broken since the list_head's in struct rcu_head and struct rcu_data were replaced with singly-linked lists:

CC kernel/rcupdate.o
kernel/rcupdate.c: In function `rcu_move_batch':
kernel/rcupdate.c:222: warning: passing arg 2 of `list_add_tail' from incompatible pointer type
kernel/rcupdate.c: In function `rcu_offline_cpu':
kernel/rcupdate.c:239: warning: passing arg 1 of `rcu_move_batch' from incompatible pointer type
kernel/rcupdate.c:240: warning: passing arg 1 of `rcu_move_batch' from incompatible pointer type
kernel/rcupdate.c:236: warning: label `unlock' defined but not used

Kernel crashes when you try to offline a cpu, not surprisingly.

It also looks like rcu_move_batch isn't preempt-safe so I touched that up, and got rid of an unused label in rcu_offline_cpu.

This fixes the crash for me; does it look ok?

kernel/rcupdate.c +11 -10
diff -prauNX /home/nathanl/working/dontdiff 2.6.8-rc2/kernel/rcupdate.c 2.6.8-rc2-ntl/kernel/rcupdate.c
@@ -210,16 +210,18 @@ static void rcu_check_quiescent_state(vo
  * locking requirements, the list it's pulling from has to belong to a cpu
  * which is dead and hence not processing interrupts.
  */
-static void rcu_move_batch(struct list_head *list)
+static void rcu_move_batch(struct rcu_head *list)
 {
-	struct list_head *entry;
-	int cpu = smp_processor_id();
+	int cpu;
 
 	local_irq_disable();
-	while (!list_empty(list)) {
-		entry = list->next;
-		list_del(entry);
-		list_add_tail(entry, &RCU_nxtlist(cpu));
+
+	cpu = smp_processor_id();
+
+	while (list != NULL) {
+		*RCU_nxttail(cpu) = list;
+		RCU_nxttail(cpu) = &list->next;
+		list = list->next;
 	}
 	local_irq_enable();
 }
@@ -233,11 +235,10 @@ static void rcu_offline_cpu(int cpu)
 	spin_lock_bh(&rcu_state.mutex);
 	if (rcu_ctrlblk.cur != rcu_ctrlblk.completed)
 		cpu_quiet(cpu);
-unlock:
 	spin_unlock_bh(&rcu_state.mutex);
 
-	rcu_move_batch(&RCU_curlist(cpu));
-	rcu_move_batch(&RCU_nxtlist(cpu));
+	rcu_move_batch(RCU_curlist(cpu));
+	rcu_move_batch(RCU_nxtlist(cpu));
 
 	tasklet_kill_immediate(&RCU_tasklet(cpu), cpu);
 }
#1 lore raw
Quoted 7 lines · Nathan Lynch

Hi,

rcu_offline_cpu and rcu_move_batch have been broken since the list_head's in struct rcu_head and struct rcu_data were replaced with singly-linked lists:

Quoted 10 lines

CC kernel/rcupdate.o
kernel/rcupdate.c: In function `rcu_move_batch':
kernel/rcupdate.c:222: warning: passing arg 2 of `list_add_tail' from incompatible pointer type
kernel/rcupdate.c: In function `rcu_offline_cpu':
kernel/rcupdate.c:239: warning: passing arg 1 of `rcu_move_batch' from incompatible pointer type
kernel/rcupdate.c:240: warning: passing arg 1 of `rcu_move_batch' from incompatible pointer type
kernel/rcupdate.c:236: warning: label `unlock' defined but not used

oop. We really should find some way to get more people to enable CPU hotplug. We have a coverage problem.

Quoted 7 lines

Kernel crashes when you try to offline a cpu, not surprisingly.

It also looks like rcu_move_batch isn't preempt-safe so I touched that up, and got rid of an unused label in rcu_offline_cpu.

This fixes the crash for me; does it look ok?

Looks good to me, thanks.

#2 lore raw
Quoted 2 lines · Andrew Morton

oop. We really should find some way to get more people to enable CPU hotplug. We have a coverage problem.

You'll have to suck it in when i send the i386 implementation then ;) It was on my queue including a bunch of fixes which needs testing before i send.

#3 lore raw

PATCH 1/1 i386 Hotplug CPU

Hi Andrew,
Could you consider taking the i386 arch support bits for cpu
hotplug? The main purpose is allowing for easier testing at each release.

Pulled from Rusty's previous changelog, plus a few additions (2,11,12)

1) Add CONFIG_HOTPLUG_CPU
2) disable local APIC timer on dead cpus.
3) Disable preempt around irq balancing to prevent CPUs going down.
4) Print irq stats for all possible cpus.
5) Debugging check for interrupts on offline cpus.
6) Hacky fixup_irqs() to redirect irqs when cpus go off/online.
7) play_dead() for offline cpus to spin inside.
8) Handle offline cpus set in flush_tlb_others().
9) Grab lock earlier in smp_call_function() to prevent CPUs going down.
10) Implement __cpu_disable() and __cpu_die().
11) Enable local interrupts in cpu_enable() after fixup_irqs()
12) Don't fiddle with NMI on dead cpu, but leave intact on other cpus.

 arch/i386/Kconfig          |    9 ++++
 arch/i386/kernel/apic.c    |    3 +
 arch/i386/kernel/io_apic.c |    2 +
 arch/i386/kernel/irq.c     |   81 ++++++++++++++++++++++++++++++++++++------
 arch/i386/kernel/msr.c     |    2 -
 arch/i386/kernel/process.c |   36 ++++++++++++++++++
 arch/i386/kernel/smp.c     |   25 ++++++++-----
 arch/i386/kernel/smpboot.c |   86 ++++++++++++++++++++++++++++++++++++++++++---
 arch/i386/kernel/traps.c   |    8 ++++
 include/asm-i386/cpu.h     |    2 +
 include/asm-i386/smp.h     |    3 +
 11 files changed, 229 insertions(+), 28 deletions(-)

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/Kconfig
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/Kconfig,v retrieving revision 1.1.1.1

arch/i386/Kconfig +9 -0
diff -u -p -B -r1.1.1.1 Kconfig
@@ -1168,6 +1168,15 @@ config SCx200
 	  This support is also available as a module.  If compiled as a
 	  module, it will be called scx200.
 
+config HOTPLUG_CPU
+	bool "Support for hot-pluggable CPUs (EXPERIMENTAL)"
+	depends on SMP && HOTPLUG && EXPERIMENTAL
+	---help---
+	  Say Y here to experiment with turning CPUs off and on.  CPUs
+	  can be controlled through /sys/devices/system/cpu.
+
+	  Say N.
+
 source "drivers/pcmcia/Kconfig"
 
 source "drivers/pci/hotplug/Kconfig"

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/apic.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/apic.c,v retrieving revision 1.1.1.1

arch/i386/kernel/apic.c +2 -1
diff -u -p -B -r1.1.1.1 apic.c
@@ -26,6 +26,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/kernel_stat.h>
 #include <linux/sysdev.h>
+#include <linux/cpu.h>
 
 #include <asm/atomic.h>
 #include <asm/smp.h>
@@ -1007,7 +1008,7 @@ void __init setup_secondary_APIC_clock(v
 	local_irq_enable();
 }
 
-void __init disable_APIC_timer(void)
+void __devinit disable_APIC_timer(void)
 {
 	if (using_apic_timer) {
 		unsigned long v;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/io_apic.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/io_apic.c,v retrieving revision 1.1.1.1

arch/i386/kernel/io_apic.c +2 -0
diff -u -p -B -r1.1.1.1 io_apic.c
@@ -574,9 +574,11 @@ static int balanced_irq(void *unused)
 		time_remaining = schedule_timeout(time_remaining);
 		if (time_after(jiffies,
 				prev_balance_time+balanced_irq_interval)) {
+			preempt_disable();
 			do_irq_balance();
 			prev_balance_time = jiffies;
 			time_remaining = balanced_irq_interval;
+			preempt_enable();
 		}
 	}
 	return 0;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/irq.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/irq.c,v retrieving revision 1.1.1.1

arch/i386/kernel/irq.c +69 -12

127 lines not on this page · raw message

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/msr.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/msr.c,v retrieving revision 1.1.1.1

arch/i386/kernel/msr.c +1 -1
diff -u -p -B -r1.1.1.1 msr.c
@@ -260,7 +260,7 @@ static struct file_operations msr_fops =
 	.open = msr_open,
 };
 
-static int msr_class_simple_device_add(int i)
+static int __devinit msr_class_simple_device_add(int i)
 {
 	int err = 0;
 	struct class_device *class_err;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/process.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/process.c,v retrieving revision 1.1.1.1

arch/i386/kernel/process.c +36 -0
diff -u -p -B -r1.1.1.1 process.c
@@ -13,6 +13,7 @@
 
 #include <stdarg.h>
 
+#include <linux/cpu.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/fs.h>
@@ -54,6 +55,9 @@
 #include <linux/irq.h>
 #include <linux/err.h>
 
+#include <asm/tlbflush.h>
+#include <asm/cpu.h>
+
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
 int hlt_counter;
@@ -132,6 +136,36 @@ static void poll_idle (void)
 	}
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+#include <asm/nmi.h>
+/* We don't actually take CPU down, just spin without interrupts. */
+static inline void play_dead(void)
+{
+	disable_APIC_timer();
+
+	/* Ack it */
+	__get_cpu_var(cpu_state) = CPU_DEAD;
+
+	/* We shouldn't have to disable interrupts while dead, but
+	 * some interrupts just don't seem to go away, and this makes
+	 * it "work" for testing purposes. */
+	/* Death loop */
+	while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
+		cpu_relax();
+
+	local_irq_disable();
+	__flush_tlb_all();
+	cpu_set(smp_processor_id(), cpu_online_map);
+	enable_APIC_timer();
+	local_irq_enable();
+}
+#else
+static inline void play_dead(void)
+{
+	BUG();
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+
 /*
  * The idle thread. There's no useful work to be
  * done, so just try to conserve power and have a
@@ -148,6 +182,8 @@ void cpu_idle (void)
 			if (!idle)
 				idle = default_idle;
 
+			if (cpu_is_offline(smp_processor_id()))
+				play_dead();
 			irq_stat[smp_processor_id()].idle_timestamp = jiffies;
 			idle();
 		}

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/smp.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/smp.c,v retrieving revision 1.1.1.1

arch/i386/kernel/smp.c +16 -9
diff -u -p -B -r1.1.1.1 smp.c
@@ -19,6 +19,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/cache.h>
 #include <linux/interrupt.h>
+#include <linux/cpu.h>
 
 #include <asm/mtrr.h>
 #include <asm/tlbflush.h>
@@ -163,7 +164,7 @@ void send_IPI_mask_bitmask(cpumask_t cpu
 	unsigned long flags;
 
 	local_irq_save(flags);
-
+	WARN_ON(mask & ~cpus_addr(cpu_online_map)[0]);
 	/*
 	 * Wait for idle.
 	 */
@@ -345,21 +346,21 @@ out:
 static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
 						unsigned long va)
 {
-	cpumask_t tmp;
 	/*
 	 * A couple of (to be removed) sanity checks:
 	 *
-	 * - we do not send IPIs to not-yet booted CPUs.
 	 * - current CPU must not be in mask
 	 * - mask must exist :)
 	 */
 	BUG_ON(cpus_empty(cpumask));
-
-	cpus_and(tmp, cpumask, cpu_online_map);
-	BUG_ON(!cpus_equal(cpumask, tmp));
 	BUG_ON(cpu_isset(smp_processor_id(), cpumask));
 	BUG_ON(!mm);
 
+	/* If a CPU which we ran on has gone down, OK. */
+	cpus_and(cpumask, cpumask, cpu_online_map);
+	if (cpus_empty(cpumask))
+		return;
+
 	/*
 	 * i'm not happy about this global shared spinlock in the
 	 * MM hot path, but we'll see how contended it is.
@@ -484,6 +485,7 @@ void smp_send_nmi_allbutself(void)
  */
 void smp_send_reschedule(int cpu)
 {
+	WARN_ON(cpu_is_offline(cpu));
 	send_IPI_mask(cpumask_of_cpu(cpu), RESCHEDULE_VECTOR);
 }
 
@@ -524,10 +526,16 @@ int smp_call_function (void (*func) (voi
  */
 {
 	struct call_data_struct data;
-	int cpus = num_online_cpus()-1;
+	int cpus;
 
-	if (!cpus)
+	/* Holding any lock stops cpus from going down. */
+	spin_lock(&call_lock);
+	cpus = num_online_cpus()-1;
+
+	if (!cpus) {
+		spin_unlock(&call_lock);
 		return 0;
+	}
 
 	/* Can deadlock when called with interrupts disabled */
 	WARN_ON(irqs_disabled());
@@ -539,7 +547,6 @@ int smp_call_function (void (*func) (voi
 	if (wait)
 		atomic_set(&data.finished, 0);
 
-	spin_lock(&call_lock);
 	call_data = &data;
 	mb();
 

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/smpboot.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/smpboot.c,v retrieving revision 1.1.1.1

arch/i386/kernel/smpboot.c +81 -5

119 lines not on this page · raw message

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/traps.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/traps.c,v retrieving revision 1.1.1.1

arch/i386/kernel/traps.c +8 -0
diff -u -p -B -r1.1.1.1 traps.c
@@ -627,6 +627,14 @@ asmlinkage void do_nmi(struct pt_regs *
 	nmi_enter();
 
 	cpu = smp_processor_id();
+
+#ifdef CONFIG_HOTPLUG_CPU
+	if (!cpu_online(cpu)) {
+		nmi_exit();
+		return;
+	}
+#endif
+
 	++nmi_count(cpu);
 
 	if (!nmi_callback(regs, cpu))

Index: linux-2.6.8-rc2-mm1-lch/include/asm-i386/cpu.h
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/include/asm-i386/cpu.h,v retrieving revision 1.1.1.1

include/asm-i386/cpu.h +2 -0
diff -u -p -B -r1.1.1.1 cpu.h
@@ -5,6 +5,7 @@
 #include <linux/cpu.h>
 #include <linux/topology.h>
 #include <linux/nodemask.h>
+#include <linux/percpu.h>
 
 #include <asm/node.h>
 
@@ -26,4 +27,5 @@ static inline int arch_register_cpu(int
 	return register_cpu(&cpu_devices[num].cpu, num, parent);
 }
 
+DECLARE_PER_CPU(int, cpu_state);
 #endif /* _ASM_I386_CPU_H_ */

Index: linux-2.6.8-rc2-mm1-lch/include/asm-i386/smp.h
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/include/asm-i386/smp.h,v retrieving revision 1.1.1.1

include/asm-i386/smp.h +3 -0
diff -u -p -B -r1.1.1.1 smp.h
@@ -84,6 +84,9 @@ static __inline int logical_smp_processo
 }
 
 #endif
+
+extern int __cpu_disable(void);
+extern void __cpu_die(unsigned int cpu);
 #endif /* !__ASSEMBLY__ */
 
 #define NO_PROC_ID		0xFF		/* No processor magic marker */
#4 lore raw

Re: [PATCH][2.6-mm] i386 Hotplug CPU

Oops, bad patch, i'll resend shortly.

#5 lore raw

Re: [PATCH][2.6-mm] i386 Hotplug CPU

In reply to Zwane Mwaikambo
Quoted 6 lines · Zwane Mwaikambo

Hi Andrew,
Could you consider taking the i386 arch support bits for cpu
hotplug? The main purpose is allowing for easier testing at each release.

Pulled from Rusty's previous changelog, plus a few additions (2,11,12)

Quoted 12 lines

1) Add CONFIG_HOTPLUG_CPU
2) disable local APIC timer on dead cpus.
3) Disable preempt around irq balancing to prevent CPUs going down.
4) Print irq stats for all possible cpus.
5) Debugging check for interrupts on offline cpus.
6) Hacky fixup_irqs() to redirect irqs when cpus go off/online.
7) play_dead() for offline cpus to spin inside.
8) Handle offline cpus set in flush_tlb_others().
9) Grab lock earlier in smp_call_function() to prevent CPUs going down.
10) Implement __cpu_disable() and __cpu_die().
11) Enable local interrupts in cpu_enable() after fixup_irqs()
12) Don't fiddle with NMI on dead cpu, but leave intact on other cpus.

There was a race between the cpu being cleared from cpu_online_map and local APIC timer interrupts sneaking in, so i've moved the APIC timer interrupt disable earlier. Survived a couple of hours of stress testing.

 arch/i386/Kconfig          |    9 ++++
 arch/i386/kernel/apic.c    |    3 +
 arch/i386/kernel/io_apic.c |    2 +
 arch/i386/kernel/irq.c     |   81 ++++++++++++++++++++++++++++++++++------
 arch/i386/kernel/msr.c     |    2 -
 arch/i386/kernel/process.c |   34 +++++++++++++++++
 arch/i386/kernel/smp.c     |   25 ++++++++----
 arch/i386/kernel/smpboot.c |   89 ++++++++++++++++++++++++++++++++++++++++++---
 arch/i386/kernel/traps.c   |    8 ++++
 include/asm-i386/cpu.h     |    2 +
 include/asm-i386/smp.h     |    3 +
 11 files changed, 230 insertions(+), 28 deletions(-)

Index: linux-2.6.8-rc2-mm1-lch/include/asm-i386/cpu.h
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/include/asm-i386/cpu.h,v retrieving revision 1.1.1.1

include/asm-i386/cpu.h +2 -0
diff -u -p -B -r1.1.1.1 cpu.h
@@ -5,6 +5,7 @@
 #include <linux/cpu.h>
 #include <linux/topology.h>
 #include <linux/nodemask.h>
+#include <linux/percpu.h>
 
 #include <asm/node.h>
 
@@ -26,4 +27,5 @@ static inline int arch_register_cpu(int
 	return register_cpu(&cpu_devices[num].cpu, num, parent);
 }
 
+DECLARE_PER_CPU(int, cpu_state);
 #endif /* _ASM_I386_CPU_H_ */

Index: linux-2.6.8-rc2-mm1-lch/include/asm-i386/smp.h
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/include/asm-i386/smp.h,v retrieving revision 1.1.1.1

include/asm-i386/smp.h +3 -0
diff -u -p -B -r1.1.1.1 smp.h
@@ -84,6 +84,9 @@ static __inline int logical_smp_processo
 }
 
 #endif
+
+extern int __cpu_disable(void);
+extern void __cpu_die(unsigned int cpu);
 #endif /* !__ASSEMBLY__ */
 
 #define NO_PROC_ID		0xFF		/* No processor magic marker */

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/Kconfig
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/Kconfig,v retrieving revision 1.1.1.1

arch/i386/Kconfig +9 -0
diff -u -p -B -r1.1.1.1 Kconfig
@@ -1168,6 +1168,15 @@ config SCx200
 	  This support is also available as a module.  If compiled as a
 	  module, it will be called scx200.
 
+config HOTPLUG_CPU
+	bool "Support for hot-pluggable CPUs (EXPERIMENTAL)"
+	depends on SMP && HOTPLUG && EXPERIMENTAL
+	---help---
+	  Say Y here to experiment with turning CPUs off and on.  CPUs
+	  can be controlled through /sys/devices/system/cpu.
+
+	  Say N.
+
 source "drivers/pcmcia/Kconfig"
 
 source "drivers/pci/hotplug/Kconfig"

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/apic.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/apic.c,v retrieving revision 1.1.1.1

arch/i386/kernel/apic.c +2 -1
diff -u -p -B -r1.1.1.1 apic.c
@@ -26,6 +26,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/kernel_stat.h>
 #include <linux/sysdev.h>
+#include <linux/cpu.h>
 
 #include <asm/atomic.h>
 #include <asm/smp.h>
@@ -1007,7 +1008,7 @@ void __init setup_secondary_APIC_clock(v
 	local_irq_enable();
 }
 
-void __init disable_APIC_timer(void)
+void __devinit disable_APIC_timer(void)
 {
 	if (using_apic_timer) {
 		unsigned long v;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/io_apic.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/io_apic.c,v retrieving revision 1.1.1.1

arch/i386/kernel/io_apic.c +2 -0
diff -u -p -B -r1.1.1.1 io_apic.c
@@ -574,9 +574,11 @@ static int balanced_irq(void *unused)
 		time_remaining = schedule_timeout(time_remaining);
 		if (time_after(jiffies,
 				prev_balance_time+balanced_irq_interval)) {
+			preempt_disable();
 			do_irq_balance();
 			prev_balance_time = jiffies;
 			time_remaining = balanced_irq_interval;
+			preempt_enable();
 		}
 	}
 	return 0;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/irq.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/irq.c,v retrieving revision 1.1.1.1

arch/i386/kernel/irq.c +69 -12

127 lines not on this page · raw message

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/msr.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/msr.c,v retrieving revision 1.1.1.1

arch/i386/kernel/msr.c +1 -1
diff -u -p -B -r1.1.1.1 msr.c
@@ -260,7 +260,7 @@ static struct file_operations msr_fops =
 	.open = msr_open,
 };
 
-static int msr_class_simple_device_add(int i)
+static int __devinit msr_class_simple_device_add(int i)
 {
 	int err = 0;
 	struct class_device *class_err;

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/process.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/process.c,v retrieving revision 1.1.1.1

arch/i386/kernel/process.c +34 -0
diff -u -p -B -r1.1.1.1 process.c
@@ -13,6 +13,7 @@
 
 #include <stdarg.h>
 
+#include <linux/cpu.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/fs.h>
@@ -54,6 +55,9 @@
 #include <linux/irq.h>
 #include <linux/err.h>
 
+#include <asm/tlbflush.h>
+#include <asm/cpu.h>
+
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
 int hlt_counter;
@@ -132,6 +136,34 @@ static void poll_idle (void)
 	}
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+#include <asm/nmi.h>
+/* We don't actually take CPU down, just spin without interrupts. */
+static inline void play_dead(void)
+{
+	/* Ack it */
+	__get_cpu_var(cpu_state) = CPU_DEAD;
+
+	/* We shouldn't have to disable interrupts while dead, but
+	 * some interrupts just don't seem to go away, and this makes
+	 * it "work" for testing purposes. */
+	/* Death loop */
+	while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
+		cpu_relax();
+
+	local_irq_disable();
+	__flush_tlb_all();
+	cpu_set(smp_processor_id(), cpu_online_map);
+	enable_APIC_timer();
+	local_irq_enable();
+}
+#else
+static inline void play_dead(void)
+{
+	BUG();
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+
 /*
  * The idle thread. There's no useful work to be
  * done, so just try to conserve power and have a
@@ -148,6 +180,8 @@ void cpu_idle (void)
 			if (!idle)
 				idle = default_idle;
 
+			if (cpu_is_offline(smp_processor_id()))
+				play_dead();
 			irq_stat[smp_processor_id()].idle_timestamp = jiffies;
 			idle();
 		}

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/smp.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/smp.c,v retrieving revision 1.1.1.1

arch/i386/kernel/smp.c +16 -9
diff -u -p -B -r1.1.1.1 smp.c
@@ -19,6 +19,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/cache.h>
 #include <linux/interrupt.h>
+#include <linux/cpu.h>
 
 #include <asm/mtrr.h>
 #include <asm/tlbflush.h>
@@ -163,7 +164,7 @@ void send_IPI_mask_bitmask(cpumask_t cpu
 	unsigned long flags;
 
 	local_irq_save(flags);
-
+	WARN_ON(mask & ~cpus_addr(cpu_online_map)[0]);
 	/*
 	 * Wait for idle.
 	 */
@@ -345,21 +346,21 @@ out:
 static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
 						unsigned long va)
 {
-	cpumask_t tmp;
 	/*
 	 * A couple of (to be removed) sanity checks:
 	 *
-	 * - we do not send IPIs to not-yet booted CPUs.
 	 * - current CPU must not be in mask
 	 * - mask must exist :)
 	 */
 	BUG_ON(cpus_empty(cpumask));
-
-	cpus_and(tmp, cpumask, cpu_online_map);
-	BUG_ON(!cpus_equal(cpumask, tmp));
 	BUG_ON(cpu_isset(smp_processor_id(), cpumask));
 	BUG_ON(!mm);
 
+	/* If a CPU which we ran on has gone down, OK. */
+	cpus_and(cpumask, cpumask, cpu_online_map);
+	if (cpus_empty(cpumask))
+		return;
+
 	/*
 	 * i'm not happy about this global shared spinlock in the
 	 * MM hot path, but we'll see how contended it is.
@@ -484,6 +485,7 @@ void smp_send_nmi_allbutself(void)
  */
 void smp_send_reschedule(int cpu)
 {
+	WARN_ON(cpu_is_offline(cpu));
 	send_IPI_mask(cpumask_of_cpu(cpu), RESCHEDULE_VECTOR);
 }
 
@@ -524,10 +526,16 @@ int smp_call_function (void (*func) (voi
  */
 {
 	struct call_data_struct data;
-	int cpus = num_online_cpus()-1;
+	int cpus;
 
-	if (!cpus)
+	/* Holding any lock stops cpus from going down. */
+	spin_lock(&call_lock);
+	cpus = num_online_cpus()-1;
+
+	if (!cpus) {
+		spin_unlock(&call_lock);
 		return 0;
+	}
 
 	/* Can deadlock when called with interrupts disabled */
 	WARN_ON(irqs_disabled());
@@ -539,7 +547,6 @@ int smp_call_function (void (*func) (voi
 	if (wait)
 		atomic_set(&data.finished, 0);
 
-	spin_lock(&call_lock);
 	call_data = &data;
 	mb();
 

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/smpboot.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/smpboot.c,v retrieving revision 1.1.1.1

arch/i386/kernel/smpboot.c +84 -5

122 lines not on this page · raw message

Index: linux-2.6.8-rc2-mm1-lch/arch/i386/kernel/traps.c
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/arch/i386/kernel/traps.c,v retrieving revision 1.1.1.1

arch/i386/kernel/traps.c +8 -0
diff -u -p -B -r1.1.1.1 traps.c
@@ -627,6 +627,14 @@ asmlinkage void do_nmi(struct pt_regs *
 	nmi_enter();
 
 	cpu = smp_processor_id();
+
+#ifdef CONFIG_HOTPLUG_CPU
+	if (!cpu_online(cpu)) {
+		nmi_exit();
+		return;
+	}
+#endif
+
 	++nmi_count(cpu);
 
 	if (!nmi_callback(regs, cpu))
#6 lore raw

Re: [PATCH][2.6-mm] i386 Hotplug CPU

In reply to Zwane Mwaikambo

Hi!

arch/i386/kernel/process.c static void poll_idle (void) · line 143

Quoted 5 lines
arch/i386/kernel/process.c +5 -0
+#ifdef CONFIG_HOTPLUG_CPU
+#include <asm/nmi.h>
+/* We don't actually take CPU down, just spin without interrupts. */
+static inline void play_dead(void)
+{

Well... if this can be fixed to really take cpu down, it will be immediately usefull for suspend-to-ram. If it is made to at least survive registers being overwritten, it will be usefull for suspend-to-disk...

Pavel

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         
#7 lore raw

Re: [lhcs-devel] Re: [PATCH][2.6-mm] i386 Hotplug CPU

Hi Pavel,

Quoted 10 lines · Pavel Machek

arch/i386/kernel/process.c static void poll_idle (void) · line 143

Quoted 5 lines
arch/i386/kernel/process.c +5 -0
+#ifdef CONFIG_HOTPLUG_CPU
+#include <asm/nmi.h>
+/* We don't actually take CPU down, just spin without interrupts. */
+static inline void play_dead(void)
+{

Well... if this can be fixed to really take cpu down, it will be immediately usefull for suspend-to-ram. If it is made to at least survive registers being overwritten, it will be usefull for suspend-to-disk...

Yeah i recall you mentioning this earlier, i'll look into adding the necessary bits so that you have enough state to resume from. Your mentioning this was one of the reasons i wanted this in.

Thanks,
Zwane

#8 lore raw

Re: [lhcs-devel] Re: [PATCH][2.6-mm] i386 Hotplug CPU

Quoted 3 lines · Zwane Mwaikambo

Yeah i recall you mentioning this earlier, i'll look into adding the necessary bits so that you have enough state to resume from. Your mentioning this was one of the reasons i wanted this in.

Pavel, considering that the processor is in a quiescent state when it's in the idle thread, can't we simply restart them all when we do the final sleep? So on the resume, we steer the APs straight into the offline cpu spin and manually bring them up again when the BSP has resumed? I reckon we don't have to save any state at all. I probably don't have the full picture yet so feel free to set me straight.

Thanks,
Zwane

#9 lore raw

Re: [lhcs-devel] Re: [PATCH][2.6-mm] i386 Hotplug CPU

Hi!

Quoted 9 lines
Quoted 3 lines

Yeah i recall you mentioning this earlier, i'll look into adding the necessary bits so that you have enough state to resume from. Your mentioning this was one of the reasons i wanted this in.

Pavel, considering that the processor is in a quiescent state when it's in the idle thread, can't we simply restart them all when we do the final sleep? So on the resume, we steer the APs straight into the offline cpu spin and manually bring them up again when the BSP has resumed? I reckon

Sorry, I do not understand what AP and BSP means in this context.

Quoted 2 lines

we don't have to save any state at all. I probably don't have the full picture yet so feel free to set me straight.

Yes, we can just shut those cpus down on suspend and completely boot them from real mode during resume... that should work. And we will need to do that during suspend-to-ram.

Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#10 lore raw

Re: [lhcs-devel] Re: [PATCH][2.6-mm] i386 Hotplug CPU

Quoted 11 lines · Pavel Machek
Quoted 9 lines
Quoted 3 lines

Yeah i recall you mentioning this earlier, i'll look into adding the necessary bits so that you have enough state to resume from. Your mentioning this was one of the reasons i wanted this in.

Pavel, considering that the processor is in a quiescent state when it's in the idle thread, can't we simply restart them all when we do the final sleep? So on the resume, we steer the APs straight into the offline cpu spin and manually bring them up again when the BSP has resumed? I reckon

Sorry, I do not understand what AP and BSP means in this context.

My mistake, Application and Bootstrap Processors.

Quoted 3 lines

Yes, we can just shut those cpus down on suspend and completely boot them from real mode during resume... that should work. And we will need to do that during suspend-to-ram.

Thanks i just wanted to run that by you first.