aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/kernel
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2010-04-26 06:08:55 -0400
committerPaul Mundt <lethal@linux-sh.org>2010-04-26 06:08:55 -0400
commit763142d1efb56effe614d71185781796c4b83c78 (patch)
treef886c239786fd4be028e3a45006c5cc5c1b3a3f2 /arch/sh/kernel
parent8db2bc4559639680a94d4492ae4b7ce71298a74f (diff)
sh: CPU hotplug support.
This adds preliminary support for CPU hotplug for SH SMP systems. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/kernel')
-rw-r--r--arch/sh/kernel/idle.c6
-rw-r--r--arch/sh/kernel/irq.c42
-rw-r--r--arch/sh/kernel/localtimer.c4
-rw-r--r--arch/sh/kernel/smp.c103
4 files changed, 152 insertions, 3 deletions
diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 204005329fe1..425d604e3a28 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -19,6 +19,7 @@
19#include <asm/pgalloc.h> 19#include <asm/pgalloc.h>
20#include <asm/system.h> 20#include <asm/system.h>
21#include <asm/atomic.h> 21#include <asm/atomic.h>
22#include <asm/smp.h>
22 23
23void (*pm_idle)(void) = NULL; 24void (*pm_idle)(void) = NULL;
24 25
@@ -89,10 +90,13 @@ void cpu_idle(void)
89 while (1) { 90 while (1) {
90 tick_nohz_stop_sched_tick(1); 91 tick_nohz_stop_sched_tick(1);
91 92
92 while (!need_resched() && cpu_online(cpu)) { 93 while (!need_resched()) {
93 check_pgt_cache(); 94 check_pgt_cache();
94 rmb(); 95 rmb();
95 96
97 if (cpu_is_offline(cpu))
98 play_dead();
99
96 local_irq_disable(); 100 local_irq_disable();
97 /* Don't trace irqs off for idle */ 101 /* Don't trace irqs off for idle */
98 stop_critical_timings(); 102 stop_critical_timings();
diff --git a/arch/sh/kernel/irq.c b/arch/sh/kernel/irq.c
index f6a9319c28e2..257de1f0692b 100644
--- a/arch/sh/kernel/irq.c
+++ b/arch/sh/kernel/irq.c
@@ -12,6 +12,7 @@
12#include <linux/kernel_stat.h> 12#include <linux/kernel_stat.h>
13#include <linux/seq_file.h> 13#include <linux/seq_file.h>
14#include <linux/ftrace.h> 14#include <linux/ftrace.h>
15#include <linux/delay.h>
15#include <asm/processor.h> 16#include <asm/processor.h>
16#include <asm/machvec.h> 17#include <asm/machvec.h>
17#include <asm/uaccess.h> 18#include <asm/uaccess.h>
@@ -292,3 +293,44 @@ int __init arch_probe_nr_irqs(void)
292 return 0; 293 return 0;
293} 294}
294#endif 295#endif
296
297#ifdef CONFIG_HOTPLUG_CPU
298static void route_irq(struct irq_desc *desc, unsigned int irq, unsigned int cpu)
299{
300 printk(KERN_INFO "IRQ%u: moving from cpu%u to cpu%u\n",
301 irq, desc->node, cpu);
302
303 raw_spin_lock_irq(&desc->lock);
304 desc->chip->set_affinity(irq, cpumask_of(cpu));
305 raw_spin_unlock_irq(&desc->lock);
306}
307
308/*
309 * The CPU has been marked offline. Migrate IRQs off this CPU. If
310 * the affinity settings do not allow other CPUs, force them onto any
311 * available CPU.
312 */
313void migrate_irqs(void)
314{
315 struct irq_desc *desc;
316 unsigned int irq, cpu = smp_processor_id();
317
318 for_each_irq_desc(irq, desc) {
319 if (desc->node == cpu) {
320 unsigned int newcpu = cpumask_any_and(desc->affinity,
321 cpu_online_mask);
322 if (newcpu >= nr_cpu_ids) {
323 if (printk_ratelimit())
324 printk(KERN_INFO "IRQ%u no longer affine to CPU%u\n",
325 irq, cpu);
326
327 cpumask_setall(desc->affinity);
328 newcpu = cpumask_any_and(desc->affinity,
329 cpu_online_mask);
330 }
331
332 route_irq(desc, irq, newcpu);
333 }
334 }
335}
336#endif
diff --git a/arch/sh/kernel/localtimer.c b/arch/sh/kernel/localtimer.c
index 865a2f1029b1..8bfc6dfa8b94 100644
--- a/arch/sh/kernel/localtimer.c
+++ b/arch/sh/kernel/localtimer.c
@@ -60,3 +60,7 @@ void local_timer_setup(unsigned int cpu)
60 60
61 clockevents_register_device(clk); 61 clockevents_register_device(clk);
62} 62}
63
64void local_timer_stop(unsigned int cpu)
65{
66}
diff --git a/arch/sh/kernel/smp.c b/arch/sh/kernel/smp.c
index 21e7f8a9f3e4..86cd6f94b53b 100644
--- a/arch/sh/kernel/smp.c
+++ b/arch/sh/kernel/smp.c
@@ -79,6 +79,105 @@ void __init smp_prepare_boot_cpu(void)
79 per_cpu(cpu_state, cpu) = CPU_ONLINE; 79 per_cpu(cpu_state, cpu) = CPU_ONLINE;
80} 80}
81 81
82#ifdef CONFIG_HOTPLUG_CPU
83void native_cpu_die(unsigned int cpu)
84{
85 unsigned int i;
86
87 for (i = 0; i < 10; i++) {
88 smp_rmb();
89 if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
90 if (system_state == SYSTEM_RUNNING)
91 pr_info("CPU %u is now offline\n", cpu);
92
93 return;
94 }
95
96 msleep(100);
97 }
98
99 pr_err("CPU %u didn't die...\n", cpu);
100}
101
102int native_cpu_disable(unsigned int cpu)
103{
104 return cpu == 0 ? -EPERM : 0;
105}
106
107void play_dead_common(void)
108{
109 idle_task_exit();
110 irq_ctx_exit(raw_smp_processor_id());
111 mb();
112
113 __get_cpu_var(cpu_state) = CPU_DEAD;
114 local_irq_disable();
115}
116
117void native_play_dead(void)
118{
119 play_dead_common();
120}
121
122int __cpu_disable(void)
123{
124 unsigned int cpu = smp_processor_id();
125 struct task_struct *p;
126 int ret;
127
128 ret = mp_ops->cpu_disable(cpu);
129 if (ret)
130 return ret;
131
132 /*
133 * Take this CPU offline. Once we clear this, we can't return,
134 * and we must not schedule until we're ready to give up the cpu.
135 */
136 set_cpu_online(cpu, false);
137
138 /*
139 * OK - migrate IRQs away from this CPU
140 */
141 migrate_irqs();
142
143 /*
144 * Stop the local timer for this CPU.
145 */
146 local_timer_stop(cpu);
147
148 /*
149 * Flush user cache and TLB mappings, and then remove this CPU
150 * from the vm mask set of all processes.
151 */
152 flush_cache_all();
153 local_flush_tlb_all();
154
155 read_lock(&tasklist_lock);
156 for_each_process(p)
157 if (p->mm)
158 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
159 read_unlock(&tasklist_lock);
160
161 return 0;
162}
163#else /* ... !CONFIG_HOTPLUG_CPU */
164int native_cpu_disable(void)
165{
166 return -ENOSYS;
167}
168
169void native_cpu_die(unsigned int cpu)
170{
171 /* We said "no" in __cpu_disable */
172 BUG();
173}
174
175void native_play_dead(void)
176{
177 BUG();
178}
179#endif
180
82asmlinkage void __cpuinit start_secondary(void) 181asmlinkage void __cpuinit start_secondary(void)
83{ 182{
84 unsigned int cpu = smp_processor_id(); 183 unsigned int cpu = smp_processor_id();
@@ -88,8 +187,8 @@ asmlinkage void __cpuinit start_secondary(void)
88 atomic_inc(&mm->mm_count); 187 atomic_inc(&mm->mm_count);
89 atomic_inc(&mm->mm_users); 188 atomic_inc(&mm->mm_users);
90 current->active_mm = mm; 189 current->active_mm = mm;
91 BUG_ON(current->mm);
92 enter_lazy_tlb(mm, current); 190 enter_lazy_tlb(mm, current);
191 local_flush_tlb_all();
93 192
94 per_cpu_trap_init(); 193 per_cpu_trap_init();
95 194
@@ -156,6 +255,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
156 break; 255 break;
157 256
158 udelay(10); 257 udelay(10);
258 barrier();
159 } 259 }
160 260
161 if (cpu_online(cpu)) 261 if (cpu_online(cpu))
@@ -270,7 +370,6 @@ static void flush_tlb_mm_ipi(void *mm)
270 * behalf of debugees, kswapd stealing pages from another process etc). 370 * behalf of debugees, kswapd stealing pages from another process etc).
271 * Kanoj 07/00. 371 * Kanoj 07/00.
272 */ 372 */
273
274void flush_tlb_mm(struct mm_struct *mm) 373void flush_tlb_mm(struct mm_struct *mm)
275{ 374{
276 preempt_disable(); 375 preempt_disable();