1 /* SPDX-License-Identifier: GPL-2.0 */
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/smp_types.h>
17 typedef void (*smp_call_func_t)(void *info);
18 typedef bool (*smp_cond_func_t)(int cpu, void *info);
21 * structure shares (partial) layout with struct irq_work
23 struct __call_single_data {
25 struct __call_single_node node;
27 struct llist_node llist;
35 /* Use __aligned() to avoid to use 2 cache lines for 1 csd */
36 typedef struct __call_single_data call_single_data_t
37 __aligned(sizeof(struct __call_single_data));
40 * Enqueue a llist_node on the call_single_queue; be very careful, read
41 * flush_smp_call_function_queue() in detail.
43 extern void __smp_call_single_queue(int cpu, struct llist_node *node);
45 /* total number of cpus in this system (may exceed NR_CPUS) */
46 extern unsigned int total_cpus;
48 int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
52 * Call a function on all processors
54 void on_each_cpu(smp_call_func_t func, void *info, int wait);
57 * Call a function on processors specified by mask, which might include
60 void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
61 void *info, bool wait);
64 * Call a function on each processor for which the supplied function
65 * cond_func returns a positive value. This may include the local
68 void on_each_cpu_cond(smp_cond_func_t cond_func, smp_call_func_t func,
69 void *info, bool wait);
71 void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
72 void *info, bool wait, const struct cpumask *mask);
74 int smp_call_function_single_async(int cpu, call_single_data_t *csd);
78 #include <linux/preempt.h>
79 #include <linux/kernel.h>
80 #include <linux/compiler.h>
81 #include <linux/thread_info.h>
85 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
86 * (defined in asm header):
90 * stops all CPUs but the current one:
92 extern void smp_send_stop(void);
95 * sends a 'reschedule' event to another CPU:
97 extern void smp_send_reschedule(int cpu);
101 * Prepare machine for booting other CPUs.
103 extern void smp_prepare_cpus(unsigned int max_cpus);
108 extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
111 * Final polishing of CPUs
113 extern void smp_cpus_done(unsigned int max_cpus);
116 * Call a function on all other processors
118 void smp_call_function(smp_call_func_t func, void *info, int wait);
119 void smp_call_function_many(const struct cpumask *mask,
120 smp_call_func_t func, void *info, bool wait);
122 int smp_call_function_any(const struct cpumask *mask,
123 smp_call_func_t func, void *info, int wait);
125 void kick_all_cpus_sync(void);
126 void wake_up_all_idle_cpus(void);
129 * Generic and arch helpers
131 void __init call_function_init(void);
132 void generic_smp_call_function_single_interrupt(void);
133 #define generic_smp_call_function_interrupt \
134 generic_smp_call_function_single_interrupt
137 * Mark the boot cpu "online" so that it can call console drivers in
138 * printk() and can access its per-cpu storage.
140 void smp_prepare_boot_cpu(void);
142 extern unsigned int setup_max_cpus;
143 extern void __init setup_nr_cpu_ids(void);
144 extern void __init smp_init(void);
146 extern int __boot_cpu_id;
148 static inline int get_boot_cpu_id(void)
150 return __boot_cpu_id;
155 static inline void smp_send_stop(void) { }
158 * These macros fold the SMP functionality into a single CPU system
160 #define raw_smp_processor_id() 0
161 static inline void up_smp_call_function(smp_call_func_t func, void *info)
164 #define smp_call_function(func, info, wait) \
165 (up_smp_call_function(func, info))
167 static inline void smp_send_reschedule(int cpu) { }
168 #define smp_prepare_boot_cpu() do {} while (0)
169 #define smp_call_function_many(mask, func, info, wait) \
170 (up_smp_call_function(func, info))
171 static inline void call_function_init(void) { }
174 smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
175 void *info, int wait)
177 return smp_call_function_single(0, func, info, wait);
180 static inline void kick_all_cpus_sync(void) { }
181 static inline void wake_up_all_idle_cpus(void) { }
183 #ifdef CONFIG_UP_LATE_INIT
184 extern void __init up_late_init(void);
185 static inline void smp_init(void) { up_late_init(); }
187 static inline void smp_init(void) { }
190 static inline int get_boot_cpu_id(void)
198 * raw_processor_id() - get the current (unstable) CPU id
200 * For then you know what you are doing and need an unstable
205 * smp_processor_id() - get the current (stable) CPU id
207 * This is the normal accessor to the CPU id and should be used
210 * The CPU id is stable when:
212 * - IRQs are disabled;
213 * - preemption is disabled;
214 * - the task is CPU affine.
216 * When CONFIG_DEBUG_PREEMPT; we verify these assumption and WARN
217 * when smp_processor_id() is used when the CPU id is not stable.
221 * Allow the architecture to differentiate between a stable and unstable read.
222 * For example, x86 uses an IRQ-safe asm-volatile read for the unstable but a
223 * regular asm read for the stable.
225 #ifndef __smp_processor_id
226 #define __smp_processor_id(x) raw_smp_processor_id(x)
229 #ifdef CONFIG_DEBUG_PREEMPT
230 extern unsigned int debug_smp_processor_id(void);
231 # define smp_processor_id() debug_smp_processor_id()
233 # define smp_processor_id() __smp_processor_id()
236 #define get_cpu() ({ preempt_disable(); __smp_processor_id(); })
237 #define put_cpu() preempt_enable()
240 * Callback to arch code if there's nosmp or maxcpus=0 on the
243 extern void arch_disable_smp_support(void);
245 extern void arch_thaw_secondary_cpus_begin(void);
246 extern void arch_thaw_secondary_cpus_end(void);
248 void smp_setup_processor_id(void);
250 int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
253 /* SMP core functions */
254 int smpcfd_prepare_cpu(unsigned int cpu);
255 int smpcfd_dead_cpu(unsigned int cpu);
256 int smpcfd_dying_cpu(unsigned int cpu);
258 #endif /* __LINUX_SMP_H */