1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _LINUX_CPU_H_
15#define _LINUX_CPU_H_
16
17#include <linux/node.h>
18#include <linux/compiler.h>
19#include <linux/cpumask.h>
20
21struct device;
22
23struct cpu {
24 int node_id;
25 int hotpluggable;
26 struct device dev;
27};
28
29extern int register_cpu(struct cpu *cpu, int num);
30extern struct device *get_cpu_device(unsigned cpu);
31extern bool cpu_is_hotpluggable(unsigned cpu);
32
33extern int cpu_add_dev_attr(struct device_attribute *attr);
34extern void cpu_remove_dev_attr(struct device_attribute *attr);
35
36extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
37extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
38
39extern ssize_t cpu_show_meltdown(struct device *dev,
40 struct device_attribute *attr, char *buf);
41extern ssize_t cpu_show_spectre_v1(struct device *dev,
42 struct device_attribute *attr, char *buf);
43extern ssize_t cpu_show_spectre_v2(struct device *dev,
44 struct device_attribute *attr, char *buf);
45
46#ifdef CONFIG_HOTPLUG_CPU
47extern void unregister_cpu(struct cpu *cpu);
48extern ssize_t arch_cpu_probe(const char *, size_t);
49extern ssize_t arch_cpu_release(const char *, size_t);
50#endif
51struct notifier_block;
52
53#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
54extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
55extern ssize_t arch_print_cpu_modalias(struct device *dev,
56 struct device_attribute *attr,
57 char *bufptr);
58#endif
59
60
61
62
63enum {
64
65
66
67
68
69
70
71
72
73
74
75 CPU_PRI_SCHED_ACTIVE = INT_MAX,
76 CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
77 CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
78 CPU_PRI_CPUSET_INACTIVE = INT_MIN,
79
80
81 CPU_PRI_PERF = 20,
82 CPU_PRI_MIGRATION = 10,
83
84 CPU_PRI_WORKQUEUE_UP = 5,
85 CPU_PRI_WORKQUEUE_DOWN = -5,
86};
87
88#define CPU_ONLINE 0x0002
89#define CPU_UP_PREPARE 0x0003
90#define CPU_UP_CANCELED 0x0004
91#define CPU_DOWN_PREPARE 0x0005
92#define CPU_DOWN_FAILED 0x0006
93#define CPU_DEAD 0x0007
94#define CPU_DYING 0x0008
95
96
97
98
99#define CPU_POST_DEAD 0x0009
100
101#define CPU_STARTING 0x000A
102
103
104
105#define CPU_BROKEN 0x000C
106
107
108
109
110
111#define CPU_TASKS_FROZEN 0x0010
112
113#define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
114#define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
115#define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
116#define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
117#define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
118#define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
119#define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
120#define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
121
122
123#ifdef CONFIG_SMP
124
125#if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
126#define cpu_notifier(fn, pri) { \
127 static struct notifier_block fn##_nb = \
128 { .notifier_call = fn, .priority = pri }; \
129 register_cpu_notifier(&fn##_nb); \
130}
131
132#define __cpu_notifier(fn, pri) { \
133 static struct notifier_block fn##_nb = \
134 { .notifier_call = fn, .priority = pri }; \
135 __register_cpu_notifier(&fn##_nb); \
136}
137#else
138#define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
139#define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
140#endif
141
142#ifdef CONFIG_HOTPLUG_CPU
143extern int register_cpu_notifier(struct notifier_block *nb);
144extern int __register_cpu_notifier(struct notifier_block *nb);
145extern void unregister_cpu_notifier(struct notifier_block *nb);
146extern void __unregister_cpu_notifier(struct notifier_block *nb);
147#else
148
149#ifndef MODULE
150extern int register_cpu_notifier(struct notifier_block *nb);
151extern int __register_cpu_notifier(struct notifier_block *nb);
152#else
153static inline int register_cpu_notifier(struct notifier_block *nb)
154{
155 return 0;
156}
157
158static inline int __register_cpu_notifier(struct notifier_block *nb)
159{
160 return 0;
161}
162#endif
163
164static inline void unregister_cpu_notifier(struct notifier_block *nb)
165{
166}
167
168static inline void __unregister_cpu_notifier(struct notifier_block *nb)
169{
170}
171#endif
172
173int cpu_up(unsigned int cpu);
174void notify_cpu_starting(unsigned int cpu);
175extern void cpu_maps_update_begin(void);
176extern void cpu_maps_update_done(void);
177
178#define cpu_notifier_register_begin cpu_maps_update_begin
179#define cpu_notifier_register_done cpu_maps_update_done
180
181#else
182
183#define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
184#define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
185
186static inline int register_cpu_notifier(struct notifier_block *nb)
187{
188 return 0;
189}
190
191static inline int __register_cpu_notifier(struct notifier_block *nb)
192{
193 return 0;
194}
195
196static inline void unregister_cpu_notifier(struct notifier_block *nb)
197{
198}
199
200static inline void __unregister_cpu_notifier(struct notifier_block *nb)
201{
202}
203
204static inline void cpu_maps_update_begin(void)
205{
206}
207
208static inline void cpu_maps_update_done(void)
209{
210}
211
212static inline void cpu_notifier_register_begin(void)
213{
214}
215
216static inline void cpu_notifier_register_done(void)
217{
218}
219
220#endif
221extern struct bus_type cpu_subsys;
222
223#ifdef CONFIG_HOTPLUG_CPU
224
225
226extern void get_online_cpus(void);
227extern bool try_get_online_cpus(void);
228extern void put_online_cpus(void);
229extern void cpu_hotplug_disable(void);
230extern void cpu_hotplug_enable(void);
231#define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
232#define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
233#define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
234#define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
235#define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
236#define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
237void clear_tasks_mm_cpumask(int cpu);
238int cpu_down(unsigned int cpu);
239
240#else
241
242#define get_online_cpus() do { } while (0)
243#define try_get_online_cpus() true
244#define put_online_cpus() do { } while (0)
245#define cpu_hotplug_disable() do { } while (0)
246#define cpu_hotplug_enable() do { } while (0)
247#define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
248#define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
249
250#define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
251#define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
252#define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
253#define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
254#endif
255
256#ifdef CONFIG_PM_SLEEP_SMP
257extern int disable_nonboot_cpus(void);
258extern void enable_nonboot_cpus(void);
259#else
260static inline int disable_nonboot_cpus(void) { return 0; }
261static inline void enable_nonboot_cpus(void) {}
262#endif
263
264enum cpuhp_state {
265 CPUHP_OFFLINE,
266 CPUHP_ONLINE,
267};
268
269void cpu_startup_entry(enum cpuhp_state state);
270void cpu_idle(void);
271
272void cpu_idle_poll_ctrl(bool enable);
273
274
275#define __cpuidle __attribute__((__section__(".cpuidle.text")))
276
277bool cpu_in_idle(unsigned long pc);
278
279void arch_cpu_idle(void);
280void arch_cpu_idle_prepare(void);
281void arch_cpu_idle_enter(void);
282void arch_cpu_idle_exit(void);
283void arch_cpu_idle_dead(void);
284
285DECLARE_PER_CPU(bool, cpu_dead_idle);
286
287int cpu_report_state(int cpu);
288int cpu_check_up_prepare(int cpu);
289void cpu_set_state_online(int cpu);
290#ifdef CONFIG_HOTPLUG_CPU
291bool cpu_wait_death(unsigned int cpu, int seconds);
292bool cpu_report_death(void);
293#endif
294
295#endif
296