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
9 * and system devices are handled in drivers/base/sys.c.
11 * CPUs are exported via sysfs in the class/cpu/devices/
17 #include <linux/node.h>
18 #include <linux/compiler.h>
19 #include <linux/cpumask.h>
21 /*******************************************************************************
22 * 20131225 marc.huang *
23 * CPU Hotplug and idle integration *
24 *******************************************************************************/
25 extern atomic_t is_in_hotplug
;
26 /******************************************************************************/
31 int node_id
; /* The node which contains the CPU */
32 int hotpluggable
; /* creates sysfs control file if hotpluggable */
36 extern int register_cpu(struct cpu
*cpu
, int num
);
37 extern struct device
*get_cpu_device(unsigned cpu
);
38 extern bool cpu_is_hotpluggable(unsigned cpu
);
40 extern int cpu_add_dev_attr(struct device_attribute
*attr
);
41 extern void cpu_remove_dev_attr(struct device_attribute
*attr
);
43 extern int cpu_add_dev_attr_group(struct attribute_group
*attrs
);
44 extern void cpu_remove_dev_attr_group(struct attribute_group
*attrs
);
46 #ifdef CONFIG_HOTPLUG_CPU
47 extern void unregister_cpu(struct cpu
*cpu
);
48 extern ssize_t
arch_cpu_probe(const char *, size_t);
49 extern ssize_t
arch_cpu_release(const char *, size_t);
51 struct notifier_block
;
53 #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
54 extern int arch_cpu_uevent(struct device
*dev
, struct kobj_uevent_env
*env
);
55 extern ssize_t
arch_print_cpu_modalias(struct device
*dev
,
56 struct device_attribute
*attr
,
61 * CPU notifier priorities.
65 * SCHED_ACTIVE marks a cpu which is coming up active during
66 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
67 * notifier. CPUSET_ACTIVE adjusts cpuset according to
68 * cpu_active mask right after SCHED_ACTIVE. During
69 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
70 * ordered in the similar way.
72 * This ordering guarantees consistent cpu_active mask and
73 * migration behavior to all cpu notifiers.
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
,
80 /* migration should happen before other stuff but after perf */
82 CPU_PRI_MIGRATION
= 10,
83 /* bring up workqueues before normal notifiers and down after */
84 CPU_PRI_WORKQUEUE_UP
= 5,
85 CPU_PRI_WORKQUEUE_DOWN
= -5,
88 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
89 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
90 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
91 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
92 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
93 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
94 #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
95 * not handling interrupts, soon dead.
96 * Called on the dying cpu, interrupts
97 * are already disabled. Must not
98 * sleep, must not fail */
99 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
101 #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
102 * Called on the new cpu, just before
103 * enabling interrupts. Must not sleep,
106 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
107 * operation in progress
109 #define CPU_TASKS_FROZEN 0x0010
111 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
112 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
113 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
114 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
115 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
116 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
117 #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
118 #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
122 /* Need to know about CPUs going up/down? */
123 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
124 #define cpu_notifier(fn, pri) { \
125 static struct notifier_block fn##_nb __cpuinitdata = \
126 { .notifier_call = fn, .priority = pri }; \
127 register_cpu_notifier(&fn##_nb); \
129 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
130 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
131 #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
132 #ifdef CONFIG_HOTPLUG_CPU
133 extern int register_cpu_notifier(struct notifier_block
*nb
);
134 extern void unregister_cpu_notifier(struct notifier_block
*nb
);
138 extern int register_cpu_notifier(struct notifier_block
*nb
);
140 static inline int register_cpu_notifier(struct notifier_block
*nb
)
146 static inline void unregister_cpu_notifier(struct notifier_block
*nb
)
151 int cpu_up(unsigned int cpu
);
152 void notify_cpu_starting(unsigned int cpu
);
153 extern void cpu_maps_update_begin(void);
154 extern void cpu_maps_update_done(void);
156 #else /* CONFIG_SMP */
158 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
160 static inline int register_cpu_notifier(struct notifier_block
*nb
)
165 static inline void unregister_cpu_notifier(struct notifier_block
*nb
)
169 static inline void cpu_maps_update_begin(void)
173 static inline void cpu_maps_update_done(void)
177 #endif /* CONFIG_SMP */
178 extern struct bus_type cpu_subsys
;
180 #ifdef CONFIG_HOTPLUG_CPU
181 /* Stop CPUs going up and down. */
183 extern void get_online_cpus(void);
184 extern void put_online_cpus(void);
185 extern void cpu_hotplug_disable(void);
186 extern void cpu_hotplug_enable(void);
187 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
188 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
189 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
190 void clear_tasks_mm_cpumask(int cpu
);
191 int cpu_down(unsigned int cpu
);
193 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
194 extern void cpu_hotplug_driver_lock(void);
195 extern void cpu_hotplug_driver_unlock(void);
197 static inline void cpu_hotplug_driver_lock(void)
201 static inline void cpu_hotplug_driver_unlock(void)
206 #else /* CONFIG_HOTPLUG_CPU */
208 #define get_online_cpus() do { } while (0)
209 #define put_online_cpus() do { } while (0)
210 #define cpu_hotplug_disable() do { } while (0)
211 #define cpu_hotplug_enable() do { } while (0)
212 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
213 /* These aren't inline functions due to a GCC bug. */
214 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
215 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
216 #endif /* CONFIG_HOTPLUG_CPU */
218 #ifdef CONFIG_PM_SLEEP_SMP
219 extern int disable_nonboot_cpus(void);
220 extern void enable_nonboot_cpus(void);
221 #else /* !CONFIG_PM_SLEEP_SMP */
222 static inline int disable_nonboot_cpus(void) { return 0; }
223 static inline void enable_nonboot_cpus(void) {}
224 #endif /* !CONFIG_PM_SLEEP_SMP */
231 void cpu_startup_entry(enum cpuhp_state state
);
234 void cpu_idle_poll_ctrl(bool enable
);
236 void arch_cpu_idle(void);
237 void arch_cpu_idle_prepare(void);
238 void arch_cpu_idle_enter(void);
239 void arch_cpu_idle_exit(void);
240 void arch_cpu_idle_dead(void);
245 void idle_notifier_register(struct notifier_block
*n
);
246 void idle_notifier_unregister(struct notifier_block
*n
);
247 void idle_notifier_call_chain(unsigned long val
);
249 #endif /* _LINUX_CPU_H_ */