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>
22 struct attribute_group;
25 int node_id; /* The node which contains the CPU */
26 int hotpluggable; /* creates sysfs control file if hotpluggable */
30 struct cpu_pstate_pwr {
35 struct cpu_pwr_stats {
38 struct cpu_pstate_pwr *ptable;
43 extern int register_cpu(struct cpu *cpu, int num);
44 extern struct device *get_cpu_device(unsigned cpu);
45 extern bool cpu_is_hotpluggable(unsigned cpu);
46 extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
47 extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
48 int cpu, unsigned int *thread);
50 extern int cpu_add_dev_attr(struct device_attribute *attr);
51 extern void cpu_remove_dev_attr(struct device_attribute *attr);
53 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
54 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
56 extern ssize_t cpu_show_meltdown(struct device *dev,
57 struct device_attribute *attr, char *buf);
58 extern ssize_t cpu_show_spectre_v1(struct device *dev,
59 struct device_attribute *attr, char *buf);
60 extern ssize_t cpu_show_spectre_v2(struct device *dev,
61 struct device_attribute *attr, char *buf);
62 extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
63 struct device_attribute *attr, char *buf);
64 extern ssize_t cpu_show_l1tf(struct device *dev,
65 struct device_attribute *attr, char *buf);
66 extern ssize_t cpu_show_mds(struct device *dev,
67 struct device_attribute *attr, char *buf);
70 struct device *cpu_device_create(struct device *parent, void *drvdata,
71 const struct attribute_group **groups,
72 const char *fmt, ...);
73 #ifdef CONFIG_HOTPLUG_CPU
74 extern void unregister_cpu(struct cpu *cpu);
75 extern ssize_t arch_cpu_probe(const char *, size_t);
76 extern ssize_t arch_cpu_release(const char *, size_t);
78 struct notifier_block;
81 * CPU notifier priorities.
85 * SCHED_ACTIVE marks a cpu which is coming up active during
86 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
87 * notifier. CPUSET_ACTIVE adjusts cpuset according to
88 * cpu_active mask right after SCHED_ACTIVE. During
89 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
90 * ordered in the similar way.
92 * This ordering guarantees consistent cpu_active mask and
93 * migration behavior to all cpu notifiers.
95 CPU_PRI_SCHED_ACTIVE = INT_MAX,
96 CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
97 CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
98 CPU_PRI_CPUSET_INACTIVE = INT_MIN,
100 /* migration should happen before other stuff but after perf */
102 CPU_PRI_MIGRATION = 10,
104 /* bring up workqueues before normal notifiers and down after */
105 CPU_PRI_WORKQUEUE_UP = 5,
106 CPU_PRI_WORKQUEUE_DOWN = -5,
109 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
110 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
111 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
112 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
113 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
114 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
115 #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
116 * not handling interrupts, soon dead.
117 * Called on the dying cpu, interrupts
118 * are already disabled. Must not
119 * sleep, must not fail */
120 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
122 #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
123 * Called on the new cpu, just before
124 * enabling interrupts. Must not sleep,
126 #define CPU_DYING_IDLE 0x000B /* CPU (unsigned)v dying, reached
128 #define CPU_BROKEN 0x000C /* CPU (unsigned)v did not die properly,
129 * perhaps due to preemption. */
131 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
132 * operation in progress
134 #define CPU_TASKS_FROZEN 0x0010
136 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
137 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
138 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
139 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
140 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
141 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
142 #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
143 #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
147 /* Need to know about CPUs going up/down? */
148 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
149 #define cpu_notifier(fn, pri) { \
150 static struct notifier_block fn##_nb = \
151 { .notifier_call = fn, .priority = pri }; \
152 register_cpu_notifier(&fn##_nb); \
155 #define __cpu_notifier(fn, pri) { \
156 static struct notifier_block fn##_nb = \
157 { .notifier_call = fn, .priority = pri }; \
158 __register_cpu_notifier(&fn##_nb); \
161 extern int register_cpu_notifier(struct notifier_block *nb);
162 extern int __register_cpu_notifier(struct notifier_block *nb);
163 extern void unregister_cpu_notifier(struct notifier_block *nb);
164 extern void __unregister_cpu_notifier(struct notifier_block *nb);
166 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
167 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
168 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
170 static inline int register_cpu_notifier(struct notifier_block *nb)
175 static inline int __register_cpu_notifier(struct notifier_block *nb)
180 static inline void unregister_cpu_notifier(struct notifier_block *nb)
184 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
189 void smpboot_thread_init(void);
190 int cpu_up(unsigned int cpu);
191 void notify_cpu_starting(unsigned int cpu);
192 extern void cpu_maps_update_begin(void);
193 extern void cpu_maps_update_done(void);
195 #define cpu_notifier_register_begin cpu_maps_update_begin
196 #define cpu_notifier_register_done cpu_maps_update_done
198 #else /* CONFIG_SMP */
200 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
201 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
203 static inline int register_cpu_notifier(struct notifier_block *nb)
208 static inline int __register_cpu_notifier(struct notifier_block *nb)
213 static inline void unregister_cpu_notifier(struct notifier_block *nb)
217 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
221 static inline void cpu_maps_update_begin(void)
225 static inline void cpu_maps_update_done(void)
229 static inline void cpu_notifier_register_begin(void)
233 static inline void cpu_notifier_register_done(void)
237 static inline void smpboot_thread_init(void)
241 #endif /* CONFIG_SMP */
242 extern struct bus_type cpu_subsys;
244 #ifdef CONFIG_HOTPLUG_CPU
245 /* Stop CPUs going up and down. */
247 extern void cpu_hotplug_begin(void);
248 extern void cpu_hotplug_done(void);
249 extern void get_online_cpus(void);
250 extern void cpu_hotplug_mutex_held(void);
251 extern void put_online_cpus(void);
252 extern void cpu_hotplug_disable(void);
253 extern void cpu_hotplug_enable(void);
254 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
255 #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
256 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
257 #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
258 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
259 #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
260 void clear_tasks_mm_cpumask(int cpu);
261 int cpu_down(unsigned int cpu);
263 #else /* CONFIG_HOTPLUG_CPU */
265 static inline void cpu_hotplug_begin(void) {}
266 static inline void cpu_hotplug_done(void) {}
267 #define get_online_cpus() do { } while (0)
268 #define put_online_cpus() do { } while (0)
269 #define cpu_hotplug_disable() do { } while (0)
270 #define cpu_hotplug_enable() do { } while (0)
271 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
272 #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
273 #define cpu_hotplug_mutex_held() do { } while (0)
274 /* These aren't inline functions due to a GCC bug. */
275 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
276 #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
277 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
278 #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
279 #endif /* CONFIG_HOTPLUG_CPU */
281 #ifdef CONFIG_PM_SLEEP_SMP
282 extern int disable_nonboot_cpus(void);
283 extern void enable_nonboot_cpus(void);
284 #else /* !CONFIG_PM_SLEEP_SMP */
285 static inline int disable_nonboot_cpus(void) { return 0; }
286 static inline void enable_nonboot_cpus(void) {}
287 #endif /* !CONFIG_PM_SLEEP_SMP */
289 struct cpu_pwr_stats *get_cpu_pwr_stats(void);
290 void trigger_cpu_pwr_stats_calc(void);
297 void cpu_startup_entry(enum cpuhp_state state);
299 void cpu_idle_poll_ctrl(bool enable);
301 void arch_cpu_idle(void);
302 void arch_cpu_idle_prepare(void);
303 void arch_cpu_idle_enter(void);
304 void arch_cpu_idle_exit(void);
305 void arch_cpu_idle_dead(void);
307 DECLARE_PER_CPU(bool, cpu_dead_idle);
309 int cpu_report_state(int cpu);
310 int cpu_check_up_prepare(int cpu);
311 void cpu_set_state_online(int cpu);
312 #ifdef CONFIG_HOTPLUG_CPU
313 bool cpu_wait_death(unsigned int cpu, int seconds);
314 bool cpu_report_death(void);
315 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
318 * These are used for a global "mitigations=" cmdline option for toggling
319 * optional CPU mitigations.
321 enum cpu_mitigations {
323 CPU_MITIGATIONS_AUTO,
326 extern enum cpu_mitigations cpu_mitigations;
328 /* mitigations=off */
329 static inline bool cpu_mitigations_off(void)
331 return cpu_mitigations == CPU_MITIGATIONS_OFF;
337 void idle_notifier_register(struct notifier_block *n);
338 void idle_notifier_unregister(struct notifier_block *n);
339 void idle_notifier_call_chain(unsigned long val);
341 #endif /* _LINUX_CPU_H_ */