4 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
5 * Copyright (C) 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
7 * Lots of stuff stolen from arch/alpha/kernel/smp.c
9 * 01/05/16 Rohit Seth <rohit.seth@intel.com> IA64-SMP functions. Reorganized
10 * the existing code (on the lines of x86 port).
11 * 00/09/11 David Mosberger <davidm@hpl.hp.com> Do loops_per_jiffy
12 * calibration on each CPU.
13 * 00/08/23 Asit Mallick <asit.k.mallick@intel.com> fixed logical processor id
14 * 00/03/31 Rohit Seth <rohit.seth@intel.com> Fixes for Bootstrap Processor
15 * & cpu_online_map now gets done here (instead of setup.c)
16 * 99/10/05 davidm Update to bring it in sync with new command-line processing
18 * 10/13/00 Goutham Rao <goutham.rao@intel.com> Updated smp_call_function and
19 * smp_call_function_single to resend IPI on timeouts
21 #define __KERNEL_SYSCALLS__
23 #include <linux/config.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/smp.h>
30 #include <linux/kernel_stat.h>
32 #include <linux/delay.h>
33 #include <linux/cache.h>
34 #include <linux/efi.h>
36 #include <asm/atomic.h>
37 #include <asm/bitops.h>
38 #include <asm/current.h>
39 #include <asm/delay.h>
40 #include <asm/machvec.h>
45 #include <asm/pgalloc.h>
46 #include <asm/pgtable.h>
47 #include <asm/processor.h>
48 #include <asm/ptrace.h>
50 #include <asm/system.h>
51 #include <asm/unistd.h>
54 /* The 'big kernel lock' */
55 spinlock_t kernel_flag __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
58 * Structure and data for smp_call_function(). This is designed to minimise static memory
59 * requirements. It also looks cleaner.
61 static spinlock_t call_lock = SPIN_LOCK_UNLOCKED;
63 struct call_data_struct {
64 void (*func) (void *info);
71 static volatile struct call_data_struct *call_data;
73 #define IPI_CALL_FUNC 0
74 #define IPI_CPU_STOP 1
79 extern void cpu_halt (void);
83 clear_bit(smp_processor_id(), &cpu_online_map);
90 handle_IPI (int irq, void *dev_id, struct pt_regs *regs)
92 int this_cpu = smp_processor_id();
93 unsigned long *pending_ipis = &local_cpu_data->ipi.operation;
96 /* Count this now; we may make a call that never returns. */
97 local_cpu_data->ipi_count++;
99 mb(); /* Order interrupt and bit testing. */
100 while ((ops = xchg(pending_ipis, 0)) != 0) {
101 mb(); /* Order bit clearing and data access. */
106 ops &= ~(1 << which);
111 struct call_data_struct *data;
112 void (*func)(void *info);
116 /* release the 'pointer lock' */
117 data = (struct call_data_struct *) call_data;
123 atomic_inc(&data->started);
125 /* At this point the structure may be gone unless wait is true. */
128 /* Notify the sending CPU that the task is done. */
131 atomic_inc(&data->finished);
140 printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which);
145 mb(); /* Order data access and bit testing. */
150 send_IPI_single (int dest_cpu, int op)
152 set_bit(op, &cpu_data(dest_cpu)->ipi.operation);
153 platform_send_ipi(dest_cpu, IA64_IPI_VECTOR, IA64_IPI_DM_INT, 0);
157 send_IPI_allbutself (int op)
161 for (i = 0; i < smp_num_cpus; i++) {
162 if (i != smp_processor_id())
163 send_IPI_single(i, op);
168 send_IPI_all (int op)
172 for (i = 0; i < smp_num_cpus; i++)
173 send_IPI_single(i, op);
177 send_IPI_self (int op)
179 send_IPI_single(smp_processor_id(), op);
183 smp_send_reschedule (int cpu)
185 platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
189 smp_flush_tlb_all (void)
191 smp_call_function((void (*)(void *))local_flush_tlb_all, 0, 1, 1);
192 local_flush_tlb_all();
196 smp_flush_tlb_mm (struct mm_struct *mm)
198 local_flush_tlb_mm(mm);
200 /* this happens for the common case of a single-threaded fork(): */
201 if (likely(mm == current->active_mm && atomic_read(&mm->mm_users) == 1))
204 smp_call_function((void (*)(void *))local_flush_tlb_mm, mm, 1, 1);
208 * Run a function on another CPU
209 * <func> The function to run. This must be fast and non-blocking.
210 * <info> An arbitrary pointer to pass to the function.
211 * <nonatomic> Currently unused.
212 * <wait> If true, wait until function has completed on other CPUs.
213 * [RETURNS] 0 on success, else a negative status code.
215 * Does not return until the remote CPU is nearly ready to execute <func>
216 * or is or has executed.
220 smp_call_function_single (int cpuid, void (*func) (void *info), void *info, int nonatomic,
223 struct call_data_struct data;
226 if (cpuid == smp_processor_id()) {
227 printk("%s: trying to call self\n", __FUNCTION__);
233 atomic_set(&data.started, 0);
236 atomic_set(&data.finished, 0);
238 spin_lock_bh(&call_lock);
241 mb(); /* ensure store to call_data precedes setting of IPI_CALL_FUNC */
242 send_IPI_single(cpuid, IPI_CALL_FUNC);
244 /* Wait for response */
245 while (atomic_read(&data.started) != cpus)
249 while (atomic_read(&data.finished) != cpus)
253 spin_unlock_bh(&call_lock);
258 * this function sends a 'generic call function' IPI to all other CPUs
263 * [SUMMARY] Run a function on all other CPUs.
264 * <func> The function to run. This must be fast and non-blocking.
265 * <info> An arbitrary pointer to pass to the function.
266 * <nonatomic> currently unused.
267 * <wait> If true, wait (atomically) until function has completed on other CPUs.
268 * [RETURNS] 0 on success, else a negative status code.
270 * Does not return until remote CPUs are nearly ready to execute <func> or are or have
273 * You must not call this function with disabled interrupts or from a hardware interrupt
274 * handler, you may call it from a bottom half handler.
277 smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wait)
279 struct call_data_struct data;
280 int cpus = smp_num_cpus-1;
287 atomic_set(&data.started, 0);
290 atomic_set(&data.finished, 0);
292 spin_lock_bh(&call_lock);
295 mb(); /* ensure store to call_data precedes setting of IPI_CALL_FUNC */
296 send_IPI_allbutself(IPI_CALL_FUNC);
298 /* Wait for response */
299 while (atomic_read(&data.started) != cpus)
303 while (atomic_read(&data.finished) != cpus)
307 spin_unlock_bh(&call_lock);
312 smp_do_timer (struct pt_regs *regs)
314 int user = user_mode(regs);
316 if (--local_cpu_data->prof_counter <= 0) {
317 local_cpu_data->prof_counter = local_cpu_data->prof_multiplier;
318 update_process_times(user);
323 * this function calls the 'stop' function on all other CPUs in the system.
328 send_IPI_allbutself(IPI_CPU_STOP);
333 setup_profiling_timer (unsigned int multiplier)