2 * include/linux/cpu.h - generic cpu definition
4 * This is mainly for topological representation. We define the
5 * basic 'struct cpu' here, which can be embedded in per-arch
6 * definitions of processors.
8 * Basic handling of the devices is done in drivers/base/cpu.c
10 * CPUs are exported via sysfs in the devices/system/cpu
16 #include <linux/node.h>
17 #include <linux/compiler.h>
18 #include <linux/cpumask.h>
19 #include <linux/cpuhotplug.h>
23 struct attribute_group;
26 int node_id; /* The node which contains the CPU */
27 int hotpluggable; /* creates sysfs control file if hotpluggable */
31 extern void boot_cpu_init(void);
32 extern void boot_cpu_state_init(void);
34 extern int register_cpu(struct cpu *cpu, int num);
35 extern struct device *get_cpu_device(unsigned cpu);
36 extern bool cpu_is_hotpluggable(unsigned cpu);
37 extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
38 extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
39 int cpu, unsigned int *thread);
41 extern int cpu_add_dev_attr(struct device_attribute *attr);
42 extern void cpu_remove_dev_attr(struct device_attribute *attr);
44 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
45 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
48 struct device *cpu_device_create(struct device *parent, void *drvdata,
49 const struct attribute_group **groups,
50 const char *fmt, ...);
51 #ifdef CONFIG_HOTPLUG_CPU
52 extern void unregister_cpu(struct cpu *cpu);
53 extern ssize_t arch_cpu_probe(const char *, size_t);
54 extern ssize_t arch_cpu_release(const char *, size_t);
56 struct notifier_block;
59 * CPU notifier priorities.
62 /* migration should happen before other stuff but after perf */
64 CPU_PRI_MIGRATION = 10,
66 /* bring up workqueues before normal notifiers and down after */
67 CPU_PRI_WORKQUEUE_UP = 5,
68 CPU_PRI_WORKQUEUE_DOWN = -5,
71 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
72 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
73 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
74 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
75 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
76 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
77 #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
78 * not handling interrupts, soon dead.
79 * Called on the dying cpu, interrupts
80 * are already disabled. Must not
81 * sleep, must not fail */
82 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
84 #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
85 * Called on the new cpu, just before
86 * enabling interrupts. Must not sleep,
88 #define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly,
89 * perhaps due to preemption. */
91 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
92 * operation in progress
94 #define CPU_TASKS_FROZEN 0x0010
96 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
97 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
98 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
99 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
100 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
101 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
102 #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
103 #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
107 extern bool cpuhp_tasks_frozen;
108 /* Need to know about CPUs going up/down? */
109 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
110 #define cpu_notifier(fn, pri) { \
111 static struct notifier_block fn##_nb = \
112 { .notifier_call = fn, .priority = pri }; \
113 register_cpu_notifier(&fn##_nb); \
116 #define __cpu_notifier(fn, pri) { \
117 static struct notifier_block fn##_nb = \
118 { .notifier_call = fn, .priority = pri }; \
119 __register_cpu_notifier(&fn##_nb); \
121 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
122 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
123 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
124 #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
126 #ifdef CONFIG_HOTPLUG_CPU
127 extern int register_cpu_notifier(struct notifier_block *nb);
128 extern int __register_cpu_notifier(struct notifier_block *nb);
129 extern void unregister_cpu_notifier(struct notifier_block *nb);
130 extern void __unregister_cpu_notifier(struct notifier_block *nb);
134 extern int register_cpu_notifier(struct notifier_block *nb);
135 extern int __register_cpu_notifier(struct notifier_block *nb);
137 static inline int register_cpu_notifier(struct notifier_block *nb)
142 static inline int __register_cpu_notifier(struct notifier_block *nb)
148 static inline void unregister_cpu_notifier(struct notifier_block *nb)
152 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
157 int cpu_up(unsigned int cpu);
158 void notify_cpu_starting(unsigned int cpu);
159 extern void cpu_maps_update_begin(void);
160 extern void cpu_maps_update_done(void);
162 #define cpu_notifier_register_begin cpu_maps_update_begin
163 #define cpu_notifier_register_done cpu_maps_update_done
165 #else /* CONFIG_SMP */
166 #define cpuhp_tasks_frozen 0
168 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
169 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
171 static inline int register_cpu_notifier(struct notifier_block *nb)
176 static inline int __register_cpu_notifier(struct notifier_block *nb)
181 static inline void unregister_cpu_notifier(struct notifier_block *nb)
185 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
189 static inline void cpu_maps_update_begin(void)
193 static inline void cpu_maps_update_done(void)
197 static inline void cpu_notifier_register_begin(void)
201 static inline void cpu_notifier_register_done(void)
205 #endif /* CONFIG_SMP */
206 extern struct bus_type cpu_subsys;
208 #ifdef CONFIG_HOTPLUG_CPU
209 /* Stop CPUs going up and down. */
211 extern void cpu_hotplug_begin(void);
212 extern void cpu_hotplug_done(void);
213 extern void get_online_cpus(void);
214 extern void put_online_cpus(void);
215 extern void cpu_hotplug_disable(void);
216 extern void cpu_hotplug_enable(void);
217 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
218 #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
219 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
220 #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
221 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
222 #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
223 void clear_tasks_mm_cpumask(int cpu);
224 int cpu_down(unsigned int cpu);
226 #else /* CONFIG_HOTPLUG_CPU */
228 static inline void cpu_hotplug_begin(void) {}
229 static inline void cpu_hotplug_done(void) {}
230 #define get_online_cpus() do { } while (0)
231 #define put_online_cpus() do { } while (0)
232 #define cpu_hotplug_disable() do { } while (0)
233 #define cpu_hotplug_enable() do { } while (0)
234 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
235 #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
236 /* These aren't inline functions due to a GCC bug. */
237 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
238 #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
239 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
240 #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
241 #endif /* CONFIG_HOTPLUG_CPU */
243 #ifdef CONFIG_PM_SLEEP_SMP
244 extern int disable_nonboot_cpus(void);
245 extern void enable_nonboot_cpus(void);
246 #else /* !CONFIG_PM_SLEEP_SMP */
247 static inline int disable_nonboot_cpus(void) { return 0; }
248 static inline void enable_nonboot_cpus(void) {}
249 #endif /* !CONFIG_PM_SLEEP_SMP */
251 void cpu_startup_entry(enum cpuhp_state state);
253 void cpu_idle_poll_ctrl(bool enable);
255 void arch_cpu_idle(void);
256 void arch_cpu_idle_prepare(void);
257 void arch_cpu_idle_enter(void);
258 void arch_cpu_idle_exit(void);
259 void arch_cpu_idle_dead(void);
261 int cpu_report_state(int cpu);
262 int cpu_check_up_prepare(int cpu);
263 void cpu_set_state_online(int cpu);
264 #ifdef CONFIG_HOTPLUG_CPU
265 bool cpu_wait_death(unsigned int cpu, int seconds);
266 bool cpu_report_death(void);
267 void cpuhp_report_idle_dead(void);
269 static inline void cpuhp_report_idle_dead(void) { }
270 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
272 #endif /* _LINUX_CPU_H_ */