2 * linux/arch/arm/kernel/smp.c
4 * Copyright (C) 2002 ARM Limited, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/config.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/sched.h>
15 #include <linux/interrupt.h>
16 #include <linux/cache.h>
17 #include <linux/profile.h>
18 #include <linux/errno.h>
20 #include <linux/cpu.h>
21 #include <linux/smp.h>
22 #include <linux/seq_file.h>
24 #include <asm/atomic.h>
25 #include <asm/cacheflush.h>
27 #include <asm/processor.h>
28 #include <asm/tlbflush.h>
29 #include <asm/ptrace.h>
32 * bitmask of present and online CPUs.
33 * The present bitmask indicates that the CPU is physically present.
34 * The online bitmask indicates that the CPU is up and running.
36 cpumask_t cpu_present_mask
;
37 cpumask_t cpu_online_map
;
40 * structures for inter-processor calls
41 * - A collection of single bit ipi messages.
45 unsigned long ipi_count
;
49 static DEFINE_PER_CPU(struct ipi_data
, ipi_data
) = {
50 .lock
= SPIN_LOCK_UNLOCKED
,
60 struct smp_call_struct
{
61 void (*func
)(void *info
);
68 static struct smp_call_struct
* volatile smp_call_function_data
;
69 static DEFINE_SPINLOCK(smp_call_function_lock
);
71 int __init
__cpu_up(unsigned int cpu
)
73 struct task_struct
*idle
;
77 * Spawn a new process manually. Grab a pointer to
78 * its task struct so we can mess with it
80 idle
= fork_idle(cpu
);
82 printk(KERN_ERR
"CPU%u: fork() failed\n", cpu
);
87 * Now bring the CPU into our world.
89 ret
= boot_secondary(cpu
, idle
);
91 printk(KERN_CRIT
"cpu_up: processor %d failed to boot\n", cpu
);
93 * FIXME: We need to clean up the new idle thread. --rmk
101 * Called by both boot and secondaries to move global data into
102 * per-processor storage.
104 void __init
smp_store_cpu_info(unsigned int cpuid
)
106 struct cpuinfo_arm
*cpu_info
= &per_cpu(cpu_data
, cpuid
);
108 cpu_info
->loops_per_jiffy
= loops_per_jiffy
;
111 void __init
smp_cpus_done(unsigned int max_cpus
)
114 unsigned long bogosum
= 0;
116 for_each_online_cpu(cpu
)
117 bogosum
+= per_cpu(cpu_data
, cpu
).loops_per_jiffy
;
119 printk(KERN_INFO
"SMP: Total of %d processors activated "
120 "(%lu.%02lu BogoMIPS).\n",
122 bogosum
/ (500000/HZ
),
123 (bogosum
/ (5000/HZ
)) % 100);
126 void __init
smp_prepare_boot_cpu(void)
128 unsigned int cpu
= smp_processor_id();
130 cpu_set(cpu
, cpu_present_mask
);
131 cpu_set(cpu
, cpu_online_map
);
134 static void send_ipi_message(cpumask_t callmap
, enum ipi_msg_type msg
)
139 local_irq_save(flags
);
141 for_each_cpu_mask(cpu
, callmap
) {
142 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
144 spin_lock(&ipi
->lock
);
145 ipi
->bits
|= 1 << msg
;
146 spin_unlock(&ipi
->lock
);
150 * Call the platform specific cross-CPU call function.
152 smp_cross_call(callmap
);
154 local_irq_restore(flags
);
158 * You must not call this function with disabled interrupts, from a
159 * hardware interrupt handler, nor from a bottom half handler.
161 int smp_call_function_on_cpu(void (*func
)(void *info
), void *info
, int retry
,
162 int wait
, cpumask_t callmap
)
164 struct smp_call_struct data
;
165 unsigned long timeout
;
172 cpu_clear(smp_processor_id(), callmap
);
173 if (cpus_empty(callmap
))
176 data
.pending
= callmap
;
178 data
.unfinished
= callmap
;
181 * try to get the mutex on smp_call_function_data
183 spin_lock(&smp_call_function_lock
);
184 smp_call_function_data
= &data
;
186 send_ipi_message(callmap
, IPI_CALL_FUNC
);
188 timeout
= jiffies
+ HZ
;
189 while (!cpus_empty(data
.pending
) && time_before(jiffies
, timeout
))
195 if (!cpus_empty(data
.pending
)) {
197 * this may be causing our panic - report it
200 "CPU%u: smp_call_function timeout for %p(%p)\n"
201 " callmap %lx pending %lx, %swait\n",
202 smp_processor_id(), func
, info
, callmap
, data
.pending
,
208 timeout
= jiffies
+ (5 * HZ
);
209 while (!cpus_empty(data
.pending
) && time_before(jiffies
, timeout
))
212 if (cpus_empty(data
.pending
))
213 printk(KERN_CRIT
" RESOLVED\n");
215 printk(KERN_CRIT
" STILL STUCK\n");
219 * whatever happened, we're done with the data, so release it
221 smp_call_function_data
= NULL
;
222 spin_unlock(&smp_call_function_lock
);
224 if (!cpus_empty(data
.pending
)) {
230 while (!cpus_empty(data
.unfinished
))
237 int smp_call_function(void (*func
)(void *info
), void *info
, int retry
,
240 return smp_call_function_on_cpu(func
, info
, retry
, wait
,
244 void show_ipi_list(struct seq_file
*p
)
250 for_each_online_cpu(cpu
)
251 seq_printf(p
, " %10lu", per_cpu(ipi_data
, cpu
).ipi_count
);
256 static void ipi_timer(struct pt_regs
*regs
)
258 int user
= user_mode(regs
);
261 profile_tick(CPU_PROFILING
, regs
);
262 update_process_times(user
);
267 * ipi_call_function - handle IPI from smp_call_function()
269 * Note that we copy data out of the cross-call structure and then
270 * let the caller know that we're here and have done with their data
272 static void ipi_call_function(unsigned int cpu
)
274 struct smp_call_struct
*data
= smp_call_function_data
;
275 void (*func
)(void *info
) = data
->func
;
276 void *info
= data
->info
;
277 int wait
= data
->wait
;
279 cpu_clear(cpu
, data
->pending
);
284 cpu_clear(cpu
, data
->unfinished
);
287 static DEFINE_SPINLOCK(stop_lock
);
290 * ipi_cpu_stop - handle IPI from smp_send_stop()
292 static void ipi_cpu_stop(unsigned int cpu
)
294 spin_lock(&stop_lock
);
295 printk(KERN_CRIT
"CPU%u: stopping\n", cpu
);
297 spin_unlock(&stop_lock
);
299 cpu_clear(cpu
, cpu_online_map
);
309 * Main handler for inter-processor interrupts
311 * For ARM, the ipimask now only identifies a single
312 * category of IPI (Bit 1 IPIs have been replaced by a
313 * different mechanism):
315 * Bit 0 - Inter-processor function call
317 void do_IPI(struct pt_regs
*regs
)
319 unsigned int cpu
= smp_processor_id();
320 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
327 spin_lock(&ipi
->lock
);
330 spin_unlock(&ipi
->lock
);
338 nextmsg
= msgs
& -msgs
;
340 nextmsg
= ffz(~nextmsg
);
349 * nothing more to do - eveything is
350 * done on the interrupt return path
355 ipi_call_function(cpu
);
363 printk(KERN_CRIT
"CPU%u: Unknown IPI message 0x%x\n",
371 void smp_send_reschedule(int cpu
)
373 send_ipi_message(cpumask_of_cpu(cpu
), IPI_RESCHEDULE
);
376 void smp_send_timer(void)
378 cpumask_t mask
= cpu_online_map
;
379 cpu_clear(smp_processor_id(), mask
);
380 send_ipi_message(mask
, IPI_TIMER
);
383 void smp_send_stop(void)
385 cpumask_t mask
= cpu_online_map
;
386 cpu_clear(smp_processor_id(), mask
);
387 send_ipi_message(mask
, IPI_CPU_STOP
);
393 int __init
setup_profiling_timer(unsigned int multiplier
)