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);
68 extern ssize_t cpu_show_tsx_async_abort(struct device *dev,
69 struct device_attribute *attr,
71 extern ssize_t cpu_show_itlb_multihit(struct device *dev,
72 struct device_attribute *attr, char *buf);
75 struct device *cpu_device_create(struct device *parent, void *drvdata,
76 const struct attribute_group **groups,
77 const char *fmt, ...);
78 #ifdef CONFIG_HOTPLUG_CPU
79 extern void unregister_cpu(struct cpu *cpu);
80 extern ssize_t arch_cpu_probe(const char *, size_t);
81 extern ssize_t arch_cpu_release(const char *, size_t);
83 struct notifier_block;
86 * CPU notifier priorities.
90 * SCHED_ACTIVE marks a cpu which is coming up active during
91 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
92 * notifier. CPUSET_ACTIVE adjusts cpuset according to
93 * cpu_active mask right after SCHED_ACTIVE. During
94 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
95 * ordered in the similar way.
97 * This ordering guarantees consistent cpu_active mask and
98 * migration behavior to all cpu notifiers.
100 CPU_PRI_SCHED_ACTIVE = INT_MAX,
101 CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
102 CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
103 CPU_PRI_CPUSET_INACTIVE = INT_MIN,
105 /* migration should happen before other stuff but after perf */
107 CPU_PRI_MIGRATION = 10,
109 /* bring up workqueues before normal notifiers and down after */
110 CPU_PRI_WORKQUEUE_UP = 5,
111 CPU_PRI_WORKQUEUE_DOWN = -5,
114 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
115 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
116 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
117 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
118 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
119 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
120 #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
121 * not handling interrupts, soon dead.
122 * Called on the dying cpu, interrupts
123 * are already disabled. Must not
124 * sleep, must not fail */
125 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
127 #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
128 * Called on the new cpu, just before
129 * enabling interrupts. Must not sleep,
131 #define CPU_DYING_IDLE 0x000B /* CPU (unsigned)v dying, reached
133 #define CPU_BROKEN 0x000C /* CPU (unsigned)v did not die properly,
134 * perhaps due to preemption. */
136 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
137 * operation in progress
139 #define CPU_TASKS_FROZEN 0x0010
141 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
142 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
143 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
144 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
145 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
146 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
147 #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
148 #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
152 /* Need to know about CPUs going up/down? */
153 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
154 #define cpu_notifier(fn, pri) { \
155 static struct notifier_block fn##_nb = \
156 { .notifier_call = fn, .priority = pri }; \
157 register_cpu_notifier(&fn##_nb); \
160 #define __cpu_notifier(fn, pri) { \
161 static struct notifier_block fn##_nb = \
162 { .notifier_call = fn, .priority = pri }; \
163 __register_cpu_notifier(&fn##_nb); \
166 extern int register_cpu_notifier(struct notifier_block *nb);
167 extern int __register_cpu_notifier(struct notifier_block *nb);
168 extern void unregister_cpu_notifier(struct notifier_block *nb);
169 extern void __unregister_cpu_notifier(struct notifier_block *nb);
171 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
172 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
173 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
175 static inline int register_cpu_notifier(struct notifier_block *nb)
180 static inline int __register_cpu_notifier(struct notifier_block *nb)
185 static inline void unregister_cpu_notifier(struct notifier_block *nb)
189 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
194 void smpboot_thread_init(void);
195 int cpu_up(unsigned int cpu);
196 void notify_cpu_starting(unsigned int cpu);
197 extern void cpu_maps_update_begin(void);
198 extern void cpu_maps_update_done(void);
200 #define cpu_notifier_register_begin cpu_maps_update_begin
201 #define cpu_notifier_register_done cpu_maps_update_done
203 #else /* CONFIG_SMP */
205 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
206 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
208 static inline int register_cpu_notifier(struct notifier_block *nb)
213 static inline int __register_cpu_notifier(struct notifier_block *nb)
218 static inline void unregister_cpu_notifier(struct notifier_block *nb)
222 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
226 static inline void cpu_maps_update_begin(void)
230 static inline void cpu_maps_update_done(void)
234 static inline void cpu_notifier_register_begin(void)
238 static inline void cpu_notifier_register_done(void)
242 static inline void smpboot_thread_init(void)
246 #endif /* CONFIG_SMP */
247 extern struct bus_type cpu_subsys;
249 #ifdef CONFIG_HOTPLUG_CPU
250 /* Stop CPUs going up and down. */
252 extern void cpu_hotplug_begin(void);
253 extern void cpu_hotplug_done(void);
254 extern void get_online_cpus(void);
255 extern void cpu_hotplug_mutex_held(void);
256 extern void put_online_cpus(void);
257 extern void cpu_hotplug_disable(void);
258 extern void cpu_hotplug_enable(void);
259 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
260 #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
261 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
262 #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
263 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
264 #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
265 void clear_tasks_mm_cpumask(int cpu);
266 int cpu_down(unsigned int cpu);
268 #else /* CONFIG_HOTPLUG_CPU */
270 static inline void cpu_hotplug_begin(void) {}
271 static inline void cpu_hotplug_done(void) {}
272 #define get_online_cpus() do { } while (0)
273 #define put_online_cpus() do { } while (0)
274 #define cpu_hotplug_disable() do { } while (0)
275 #define cpu_hotplug_enable() do { } while (0)
276 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
277 #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
278 #define cpu_hotplug_mutex_held() do { } while (0)
279 /* These aren't inline functions due to a GCC bug. */
280 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
281 #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
282 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
283 #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
284 #endif /* CONFIG_HOTPLUG_CPU */
286 #ifdef CONFIG_PM_SLEEP_SMP
287 extern int disable_nonboot_cpus(void);
288 extern void enable_nonboot_cpus(void);
289 #else /* !CONFIG_PM_SLEEP_SMP */
290 static inline int disable_nonboot_cpus(void) { return 0; }
291 static inline void enable_nonboot_cpus(void) {}
292 #endif /* !CONFIG_PM_SLEEP_SMP */
294 struct cpu_pwr_stats *get_cpu_pwr_stats(void);
295 void trigger_cpu_pwr_stats_calc(void);
302 void cpu_startup_entry(enum cpuhp_state state);
304 void cpu_idle_poll_ctrl(bool enable);
306 void arch_cpu_idle(void);
307 void arch_cpu_idle_prepare(void);
308 void arch_cpu_idle_enter(void);
309 void arch_cpu_idle_exit(void);
310 void arch_cpu_idle_dead(void);
312 DECLARE_PER_CPU(bool, cpu_dead_idle);
314 int cpu_report_state(int cpu);
315 int cpu_check_up_prepare(int cpu);
316 void cpu_set_state_online(int cpu);
317 #ifdef CONFIG_HOTPLUG_CPU
318 bool cpu_wait_death(unsigned int cpu, int seconds);
319 bool cpu_report_death(void);
320 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
323 * These are used for a global "mitigations=" cmdline option for toggling
324 * optional CPU mitigations.
326 enum cpu_mitigations {
328 CPU_MITIGATIONS_AUTO,
331 extern enum cpu_mitigations cpu_mitigations;
333 /* mitigations=off */
334 static inline bool cpu_mitigations_off(void)
336 return cpu_mitigations == CPU_MITIGATIONS_OFF;
342 void idle_notifier_register(struct notifier_block *n);
343 void idle_notifier_unregister(struct notifier_block *n);
344 void idle_notifier_call_chain(unsigned long val);
346 #endif /* _LINUX_CPU_H_ */