1 /* SPDX-License-Identifier: GPL-2.0 */
7 * Alan Cox. <alan@redhat.com>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/list.h>
13 #include <linux/cpumask.h>
14 #include <linux/init.h>
15 #include <linux/llist.h>
17 typedef void (*smp_call_func_t)(void *info);
18 typedef bool (*smp_cond_func_t)(int cpu, void *info);
25 CSD_TYPE_ASYNC = 0x00,
27 CSD_TYPE_IRQ_WORK = 0x20,
28 CSD_FLAG_TYPE_MASK = 0xF0,
32 * structure shares (partial) layout with struct irq_work
34 struct __call_single_data {
35 struct llist_node llist;
41 /* Use __aligned() to avoid to use 2 cache lines for 1 csd */
42 typedef struct __call_single_data call_single_data_t
43 __aligned(sizeof(struct __call_single_data));
46 * Enqueue a llist_node on the call_single_queue; be very careful, read
47 * flush_smp_call_function_queue() in detail.
49 extern void __smp_call_single_queue(int cpu, struct llist_node *node);
51 /* total number of cpus in this system (may exceed NR_CPUS) */
52 extern unsigned int total_cpus;
54 int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
58 * Call a function on all processors
60 void on_each_cpu(smp_call_func_t func, void *info, int wait);
63 * Call a function on processors specified by mask, which might include
66 void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
67 void *info, bool wait);
70 * Call a function on each processor for which the supplied function
71 * cond_func returns a positive value. This may include the local
74 void on_each_cpu_cond(smp_cond_func_t cond_func, smp_call_func_t func,
75 void *info, bool wait);
77 void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
78 void *info, bool wait, const struct cpumask *mask);
80 int smp_call_function_single_async(int cpu, call_single_data_t *csd);
84 #include <linux/preempt.h>
85 #include <linux/kernel.h>
86 #include <linux/compiler.h>
87 #include <linux/thread_info.h>
91 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
92 * (defined in asm header):
96 * stops all CPUs but the current one:
98 extern void smp_send_stop(void);
101 * sends a 'reschedule' event to another CPU:
103 extern void smp_send_reschedule(int cpu);
107 * Prepare machine for booting other CPUs.
109 extern void smp_prepare_cpus(unsigned int max_cpus);
114 extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
117 * Final polishing of CPUs
119 extern void smp_cpus_done(unsigned int max_cpus);
122 * Call a function on all other processors
124 void smp_call_function(smp_call_func_t func, void *info, int wait);
125 void smp_call_function_many(const struct cpumask *mask,
126 smp_call_func_t func, void *info, bool wait);
128 int smp_call_function_any(const struct cpumask *mask,
129 smp_call_func_t func, void *info, int wait);
131 void kick_all_cpus_sync(void);
132 void wake_up_all_idle_cpus(void);
135 * Generic and arch helpers
137 void __init call_function_init(void);
138 void generic_smp_call_function_single_interrupt(void);
139 #define generic_smp_call_function_interrupt \
140 generic_smp_call_function_single_interrupt
143 * Mark the boot cpu "online" so that it can call console drivers in
144 * printk() and can access its per-cpu storage.
146 void smp_prepare_boot_cpu(void);
148 extern unsigned int setup_max_cpus;
149 extern void __init setup_nr_cpu_ids(void);
150 extern void __init smp_init(void);
152 extern int __boot_cpu_id;
154 static inline int get_boot_cpu_id(void)
156 return __boot_cpu_id;
161 static inline void smp_send_stop(void) { }
164 * These macros fold the SMP functionality into a single CPU system
166 #define raw_smp_processor_id() 0
167 static inline void up_smp_call_function(smp_call_func_t func, void *info)
170 #define smp_call_function(func, info, wait) \
171 (up_smp_call_function(func, info))
173 static inline void smp_send_reschedule(int cpu) { }
174 #define smp_prepare_boot_cpu() do {} while (0)
175 #define smp_call_function_many(mask, func, info, wait) \
176 (up_smp_call_function(func, info))
177 static inline void call_function_init(void) { }
180 smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
181 void *info, int wait)
183 return smp_call_function_single(0, func, info, wait);
186 static inline void kick_all_cpus_sync(void) { }
187 static inline void wake_up_all_idle_cpus(void) { }
189 #ifdef CONFIG_UP_LATE_INIT
190 extern void __init up_late_init(void);
191 static inline void smp_init(void) { up_late_init(); }
193 static inline void smp_init(void) { }
196 static inline int get_boot_cpu_id(void)
204 * raw_processor_id() - get the current (unstable) CPU id
206 * For then you know what you are doing and need an unstable
211 * smp_processor_id() - get the current (stable) CPU id
213 * This is the normal accessor to the CPU id and should be used
216 * The CPU id is stable when:
218 * - IRQs are disabled;
219 * - preemption is disabled;
220 * - the task is CPU affine.
222 * When CONFIG_DEBUG_PREEMPT; we verify these assumption and WARN
223 * when smp_processor_id() is used when the CPU id is not stable.
227 * Allow the architecture to differentiate between a stable and unstable read.
228 * For example, x86 uses an IRQ-safe asm-volatile read for the unstable but a
229 * regular asm read for the stable.
231 #ifndef __smp_processor_id
232 #define __smp_processor_id(x) raw_smp_processor_id(x)
235 #ifdef CONFIG_DEBUG_PREEMPT
236 extern unsigned int debug_smp_processor_id(void);
237 # define smp_processor_id() debug_smp_processor_id()
239 # define smp_processor_id() __smp_processor_id()
242 #define get_cpu() ({ preempt_disable(); __smp_processor_id(); })
243 #define put_cpu() preempt_enable()
246 * Callback to arch code if there's nosmp or maxcpus=0 on the
249 extern void arch_disable_smp_support(void);
251 extern void arch_enable_nonboot_cpus_begin(void);
252 extern void arch_enable_nonboot_cpus_end(void);
254 void smp_setup_processor_id(void);
256 int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
259 /* SMP core functions */
260 int smpcfd_prepare_cpu(unsigned int cpu);
261 int smpcfd_dead_cpu(unsigned int cpu);
262 int smpcfd_dying_cpu(unsigned int cpu);
264 #endif /* __LINUX_SMP_H */