1 /*
2  * include/linux/cpu.h - generic cpu definition
3  *
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.
7  *
8  * Basic handling of the devices is done in drivers/base/cpu.c
9  * and system devices are handled in drivers/base/sys.c.
10  *
11  * CPUs are exported via sysfs in the class/cpu/devices/
12  * directory.
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 
21 struct device;
22 
23 struct cpu {
24 	int node_id;		/* The node which contains the CPU */
25 	int hotpluggable;	/* creates sysfs control file if hotpluggable */
26 	struct device dev;
27 };
28 
29 extern int register_cpu(struct cpu *cpu, int num);
30 extern struct device *get_cpu_device(unsigned cpu);
31 extern bool cpu_is_hotpluggable(unsigned cpu);
32 
33 extern int cpu_add_dev_attr(struct device_attribute *attr);
34 extern void cpu_remove_dev_attr(struct device_attribute *attr);
35 
36 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
37 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
38 
39 extern int sched_create_sysfs_power_savings_entries(struct device *dev);
40 
41 #ifdef CONFIG_HOTPLUG_CPU
42 extern void unregister_cpu(struct cpu *cpu);
43 extern ssize_t arch_cpu_probe(const char *, size_t);
44 extern ssize_t arch_cpu_release(const char *, size_t);
45 #endif
46 struct notifier_block;
47 
48 #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
49 extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
50 extern ssize_t arch_print_cpu_modalias(struct device *dev,
51 				       struct device_attribute *attr,
52 				       char *bufptr);
53 #endif
54 
55 /*
56  * CPU notifier priorities.
57  */
58 enum {
59 	/*
60 	 * SCHED_ACTIVE marks a cpu which is coming up active during
61 	 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
62 	 * notifier.  CPUSET_ACTIVE adjusts cpuset according to
63 	 * cpu_active mask right after SCHED_ACTIVE.  During
64 	 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
65 	 * ordered in the similar way.
66 	 *
67 	 * This ordering guarantees consistent cpu_active mask and
68 	 * migration behavior to all cpu notifiers.
69 	 */
70 	CPU_PRI_SCHED_ACTIVE	= INT_MAX,
71 	CPU_PRI_CPUSET_ACTIVE	= INT_MAX - 1,
72 	CPU_PRI_SCHED_INACTIVE	= INT_MIN + 1,
73 	CPU_PRI_CPUSET_INACTIVE	= INT_MIN,
74 
75 	/* migration should happen before other stuff but after perf */
76 	CPU_PRI_PERF		= 20,
77 	CPU_PRI_MIGRATION	= 10,
78 	/* bring up workqueues before normal notifiers and down after */
79 	CPU_PRI_WORKQUEUE_UP	= 5,
80 	CPU_PRI_WORKQUEUE_DOWN	= -5,
81 };
82 
83 #define CPU_ONLINE		0x0002 /* CPU (unsigned)v is up */
84 #define CPU_UP_PREPARE		0x0003 /* CPU (unsigned)v coming up */
85 #define CPU_UP_CANCELED		0x0004 /* CPU (unsigned)v NOT coming up */
86 #define CPU_DOWN_PREPARE	0x0005 /* CPU (unsigned)v going down */
87 #define CPU_DOWN_FAILED		0x0006 /* CPU (unsigned)v NOT going down */
88 #define CPU_DEAD		0x0007 /* CPU (unsigned)v dead */
89 #define CPU_DYING		0x0008 /* CPU (unsigned)v not running any task,
90 					* not handling interrupts, soon dead.
91 					* Called on the dying cpu, interrupts
92 					* are already disabled. Must not
93 					* sleep, must not fail */
94 #define CPU_POST_DEAD		0x0009 /* CPU (unsigned)v dead, cpu_hotplug
95 					* lock is dropped */
96 #define CPU_STARTING		0x000A /* CPU (unsigned)v soon running.
97 					* Called on the new cpu, just before
98 					* enabling interrupts. Must not sleep,
99 					* must not fail */
100 
101 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
102  * operation in progress
103  */
104 #define CPU_TASKS_FROZEN	0x0010
105 
106 #define CPU_ONLINE_FROZEN	(CPU_ONLINE | CPU_TASKS_FROZEN)
107 #define CPU_UP_PREPARE_FROZEN	(CPU_UP_PREPARE | CPU_TASKS_FROZEN)
108 #define CPU_UP_CANCELED_FROZEN	(CPU_UP_CANCELED | CPU_TASKS_FROZEN)
109 #define CPU_DOWN_PREPARE_FROZEN	(CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
110 #define CPU_DOWN_FAILED_FROZEN	(CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
111 #define CPU_DEAD_FROZEN		(CPU_DEAD | CPU_TASKS_FROZEN)
112 #define CPU_DYING_FROZEN	(CPU_DYING | CPU_TASKS_FROZEN)
113 #define CPU_STARTING_FROZEN	(CPU_STARTING | CPU_TASKS_FROZEN)
114 
115 
116 #ifdef CONFIG_SMP
117 /* Need to know about CPUs going up/down? */
118 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
119 #define cpu_notifier(fn, pri) {					\
120 	static struct notifier_block fn##_nb __cpuinitdata =	\
121 		{ .notifier_call = fn, .priority = pri };	\
122 	register_cpu_notifier(&fn##_nb);			\
123 }
124 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
125 #define cpu_notifier(fn, pri)	do { (void)(fn); } while (0)
126 #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
127 #ifdef CONFIG_HOTPLUG_CPU
128 extern int register_cpu_notifier(struct notifier_block *nb);
129 extern void unregister_cpu_notifier(struct notifier_block *nb);
130 #else
131 
132 #ifndef MODULE
133 extern int register_cpu_notifier(struct notifier_block *nb);
134 #else
register_cpu_notifier(struct notifier_block * nb)135 static inline int register_cpu_notifier(struct notifier_block *nb)
136 {
137 	return 0;
138 }
139 #endif
140 
unregister_cpu_notifier(struct notifier_block * nb)141 static inline void unregister_cpu_notifier(struct notifier_block *nb)
142 {
143 }
144 #endif
145 
146 int cpu_up(unsigned int cpu);
147 void notify_cpu_starting(unsigned int cpu);
148 extern void cpu_maps_update_begin(void);
149 extern void cpu_maps_update_done(void);
150 
151 #else	/* CONFIG_SMP */
152 
153 #define cpu_notifier(fn, pri)	do { (void)(fn); } while (0)
154 
register_cpu_notifier(struct notifier_block * nb)155 static inline int register_cpu_notifier(struct notifier_block *nb)
156 {
157 	return 0;
158 }
159 
unregister_cpu_notifier(struct notifier_block * nb)160 static inline void unregister_cpu_notifier(struct notifier_block *nb)
161 {
162 }
163 
cpu_maps_update_begin(void)164 static inline void cpu_maps_update_begin(void)
165 {
166 }
167 
cpu_maps_update_done(void)168 static inline void cpu_maps_update_done(void)
169 {
170 }
171 
172 #endif /* CONFIG_SMP */
173 extern struct bus_type cpu_subsys;
174 
175 #ifdef CONFIG_HOTPLUG_CPU
176 /* Stop CPUs going up and down. */
177 
178 extern void get_online_cpus(void);
179 extern void put_online_cpus(void);
180 extern void cpu_hotplug_disable(void);
181 extern void cpu_hotplug_enable(void);
182 #define hotcpu_notifier(fn, pri)	cpu_notifier(fn, pri)
183 #define register_hotcpu_notifier(nb)	register_cpu_notifier(nb)
184 #define unregister_hotcpu_notifier(nb)	unregister_cpu_notifier(nb)
185 int cpu_down(unsigned int cpu);
186 
187 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
188 extern void cpu_hotplug_driver_lock(void);
189 extern void cpu_hotplug_driver_unlock(void);
190 #else
cpu_hotplug_driver_lock(void)191 static inline void cpu_hotplug_driver_lock(void)
192 {
193 }
194 
cpu_hotplug_driver_unlock(void)195 static inline void cpu_hotplug_driver_unlock(void)
196 {
197 }
198 #endif
199 
200 #else		/* CONFIG_HOTPLUG_CPU */
201 
202 #define get_online_cpus()	do { } while (0)
203 #define put_online_cpus()	do { } while (0)
204 #define cpu_hotplug_disable()	do { } while (0)
205 #define cpu_hotplug_enable()	do { } while (0)
206 #define hotcpu_notifier(fn, pri)	do { (void)(fn); } while (0)
207 /* These aren't inline functions due to a GCC bug. */
208 #define register_hotcpu_notifier(nb)	({ (void)(nb); 0; })
209 #define unregister_hotcpu_notifier(nb)	({ (void)(nb); })
210 #endif		/* CONFIG_HOTPLUG_CPU */
211 
212 #ifdef CONFIG_PM_SLEEP_SMP
213 extern int disable_nonboot_cpus(void);
214 extern void enable_nonboot_cpus(void);
215 #else /* !CONFIG_PM_SLEEP_SMP */
disable_nonboot_cpus(void)216 static inline int disable_nonboot_cpus(void) { return 0; }
enable_nonboot_cpus(void)217 static inline void enable_nonboot_cpus(void) {}
218 #endif /* !CONFIG_PM_SLEEP_SMP */
219 
220 #endif /* _LINUX_CPU_H_ */
221