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,
29 CSD_FLAG_TYPE_MASK
= 0xF0,
33 * structure shares (partial) layout with struct irq_work
35 struct __call_single_data
{
36 struct llist_node llist
;
42 /* Use __aligned() to avoid to use 2 cache lines for 1 csd */
43 typedef struct __call_single_data call_single_data_t
44 __aligned(sizeof(struct __call_single_data
));
47 * Enqueue a llist_node on the call_single_queue; be very careful, read
48 * flush_smp_call_function_queue() in detail.
50 extern void __smp_call_single_queue(int cpu
, struct llist_node
*node
);
52 /* total number of cpus in this system (may exceed NR_CPUS) */
53 extern unsigned int total_cpus
;
55 int smp_call_function_single(int cpuid
, smp_call_func_t func
, void *info
,
59 * Call a function on all processors
61 void on_each_cpu(smp_call_func_t func
, void *info
, int wait
);
64 * Call a function on processors specified by mask, which might include
67 void on_each_cpu_mask(const struct cpumask
*mask
, smp_call_func_t func
,
68 void *info
, bool wait
);
71 * Call a function on each processor for which the supplied function
72 * cond_func returns a positive value. This may include the local
75 void on_each_cpu_cond(smp_cond_func_t cond_func
, smp_call_func_t func
,
76 void *info
, bool wait
);
78 void on_each_cpu_cond_mask(smp_cond_func_t cond_func
, smp_call_func_t func
,
79 void *info
, bool wait
, const struct cpumask
*mask
);
81 int smp_call_function_single_async(int cpu
, call_single_data_t
*csd
);
85 #include <linux/preempt.h>
86 #include <linux/kernel.h>
87 #include <linux/compiler.h>
88 #include <linux/thread_info.h>
92 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
93 * (defined in asm header):
97 * stops all CPUs but the current one:
99 extern void smp_send_stop(void);
102 * sends a 'reschedule' event to another CPU:
104 extern void smp_send_reschedule(int cpu
);
108 * Prepare machine for booting other CPUs.
110 extern void smp_prepare_cpus(unsigned int max_cpus
);
115 extern int __cpu_up(unsigned int cpunum
, struct task_struct
*tidle
);
118 * Final polishing of CPUs
120 extern void smp_cpus_done(unsigned int max_cpus
);
123 * Call a function on all other processors
125 void smp_call_function(smp_call_func_t func
, void *info
, int wait
);
126 void smp_call_function_many(const struct cpumask
*mask
,
127 smp_call_func_t func
, void *info
, bool wait
);
129 int smp_call_function_any(const struct cpumask
*mask
,
130 smp_call_func_t func
, void *info
, int wait
);
132 void kick_all_cpus_sync(void);
133 void wake_up_all_idle_cpus(void);
136 * Generic and arch helpers
138 void __init
call_function_init(void);
139 void generic_smp_call_function_single_interrupt(void);
140 #define generic_smp_call_function_interrupt \
141 generic_smp_call_function_single_interrupt
144 * Mark the boot cpu "online" so that it can call console drivers in
145 * printk() and can access its per-cpu storage.
147 void smp_prepare_boot_cpu(void);
149 extern unsigned int setup_max_cpus
;
150 extern void __init
setup_nr_cpu_ids(void);
151 extern void __init
smp_init(void);
153 extern int __boot_cpu_id
;
155 static inline int get_boot_cpu_id(void)
157 return __boot_cpu_id
;
162 static inline void smp_send_stop(void) { }
165 * These macros fold the SMP functionality into a single CPU system
167 #define raw_smp_processor_id() 0
168 static inline void up_smp_call_function(smp_call_func_t func
, void *info
)
171 #define smp_call_function(func, info, wait) \
172 (up_smp_call_function(func, info))
174 static inline void smp_send_reschedule(int cpu
) { }
175 #define smp_prepare_boot_cpu() do {} while (0)
176 #define smp_call_function_many(mask, func, info, wait) \
177 (up_smp_call_function(func, info))
178 static inline void call_function_init(void) { }
181 smp_call_function_any(const struct cpumask
*mask
, smp_call_func_t func
,
182 void *info
, int wait
)
184 return smp_call_function_single(0, func
, info
, wait
);
187 static inline void kick_all_cpus_sync(void) { }
188 static inline void wake_up_all_idle_cpus(void) { }
190 #ifdef CONFIG_UP_LATE_INIT
191 extern void __init
up_late_init(void);
192 static inline void smp_init(void) { up_late_init(); }
194 static inline void smp_init(void) { }
197 static inline int get_boot_cpu_id(void)
205 * raw_processor_id() - get the current (unstable) CPU id
207 * For then you know what you are doing and need an unstable
212 * smp_processor_id() - get the current (stable) CPU id
214 * This is the normal accessor to the CPU id and should be used
217 * The CPU id is stable when:
219 * - IRQs are disabled;
220 * - preemption is disabled;
221 * - the task is CPU affine.
223 * When CONFIG_DEBUG_PREEMPT; we verify these assumption and WARN
224 * when smp_processor_id() is used when the CPU id is not stable.
228 * Allow the architecture to differentiate between a stable and unstable read.
229 * For example, x86 uses an IRQ-safe asm-volatile read for the unstable but a
230 * regular asm read for the stable.
232 #ifndef __smp_processor_id
233 #define __smp_processor_id(x) raw_smp_processor_id(x)
236 #ifdef CONFIG_DEBUG_PREEMPT
237 extern unsigned int debug_smp_processor_id(void);
238 # define smp_processor_id() debug_smp_processor_id()
240 # define smp_processor_id() __smp_processor_id()
243 #define get_cpu() ({ preempt_disable(); __smp_processor_id(); })
244 #define put_cpu() preempt_enable()
247 * Callback to arch code if there's nosmp or maxcpus=0 on the
250 extern void arch_disable_smp_support(void);
252 extern void arch_thaw_secondary_cpus_begin(void);
253 extern void arch_thaw_secondary_cpus_end(void);
255 void smp_setup_processor_id(void);
257 int smp_call_on_cpu(unsigned int cpu
, int (*func
)(void *), void *par
,
260 /* SMP core functions */
261 int smpcfd_prepare_cpu(unsigned int cpu
);
262 int smpcfd_dead_cpu(unsigned int cpu
);
263 int smpcfd_dying_cpu(unsigned int cpu
);
265 #endif /* __LINUX_SMP_H */