cpu.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. *
  10. * CPUs are exported via sysfs in the devices/system/cpu
  11. * directory.
  12. */
  13. #ifndef _LINUX_CPU_H_
  14. #define _LINUX_CPU_H_
  15. #include <linux/node.h>
  16. #include <linux/compiler.h>
  17. #include <linux/cpumask.h>
  18. struct device;
  19. struct device_node;
  20. struct attribute_group;
  21. struct cpu {
  22. int node_id; /* The node which contains the CPU */
  23. int hotpluggable; /* creates sysfs control file if hotpluggable */
  24. struct device dev;
  25. };
  26. extern int register_cpu(struct cpu *cpu, int num);
  27. extern struct device *get_cpu_device(unsigned cpu);
  28. extern bool cpu_is_hotpluggable(unsigned cpu);
  29. extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
  30. extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
  31. int cpu, unsigned int *thread);
  32. extern int cpu_add_dev_attr(struct device_attribute *attr);
  33. extern void cpu_remove_dev_attr(struct device_attribute *attr);
  34. extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
  35. extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
  36. extern __printf(4, 5)
  37. struct device *cpu_device_create(struct device *parent, void *drvdata,
  38. const struct attribute_group **groups,
  39. const char *fmt, ...);
  40. #ifdef CONFIG_HOTPLUG_CPU
  41. extern void unregister_cpu(struct cpu *cpu);
  42. extern ssize_t arch_cpu_probe(const char *, size_t);
  43. extern ssize_t arch_cpu_release(const char *, size_t);
  44. #endif
  45. struct notifier_block;
  46. /*
  47. * CPU notifier priorities.
  48. */
  49. enum {
  50. /*
  51. * SCHED_ACTIVE marks a cpu which is coming up active during
  52. * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
  53. * notifier. CPUSET_ACTIVE adjusts cpuset according to
  54. * cpu_active mask right after SCHED_ACTIVE. During
  55. * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
  56. * ordered in the similar way.
  57. *
  58. * This ordering guarantees consistent cpu_active mask and
  59. * migration behavior to all cpu notifiers.
  60. */
  61. CPU_PRI_SCHED_ACTIVE = INT_MAX,
  62. CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
  63. CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
  64. CPU_PRI_CPUSET_INACTIVE = INT_MIN,
  65. /* migration should happen before other stuff but after perf */
  66. CPU_PRI_PERF = 20,
  67. CPU_PRI_MIGRATION = 10,
  68. CPU_PRI_SMPBOOT = 9,
  69. /* bring up workqueues before normal notifiers and down after */
  70. CPU_PRI_WORKQUEUE_UP = 5,
  71. CPU_PRI_WORKQUEUE_DOWN = -5,
  72. };
  73. #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
  74. #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
  75. #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
  76. #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
  77. #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
  78. #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
  79. #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
  80. * not handling interrupts, soon dead.
  81. * Called on the dying cpu, interrupts
  82. * are already disabled. Must not
  83. * sleep, must not fail */
  84. #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
  85. * lock is dropped */
  86. #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
  87. * Called on the new cpu, just before
  88. * enabling interrupts. Must not sleep,
  89. * must not fail */
  90. #define CPU_DYING_IDLE 0x000B /* CPU (unsigned)v dying, reached
  91. * idle loop. */
  92. #define CPU_BROKEN 0x000C /* CPU (unsigned)v did not die properly,
  93. * perhaps due to preemption. */
  94. /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
  95. * operation in progress
  96. */
  97. #define CPU_TASKS_FROZEN 0x0010
  98. #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
  99. #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
  100. #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
  101. #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
  102. #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
  103. #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
  104. #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
  105. #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
  106. #ifdef CONFIG_SMP
  107. /* Need to know about CPUs going up/down? */
  108. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  109. #define cpu_notifier(fn, pri) { \
  110. static struct notifier_block fn##_nb = \
  111. { .notifier_call = fn, .priority = pri }; \
  112. register_cpu_notifier(&fn##_nb); \
  113. }
  114. #define __cpu_notifier(fn, pri) { \
  115. static struct notifier_block fn##_nb = \
  116. { .notifier_call = fn, .priority = pri }; \
  117. __register_cpu_notifier(&fn##_nb); \
  118. }
  119. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  120. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  121. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  122. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  123. #ifdef CONFIG_HOTPLUG_CPU
  124. extern int register_cpu_notifier(struct notifier_block *nb);
  125. extern int __register_cpu_notifier(struct notifier_block *nb);
  126. extern void unregister_cpu_notifier(struct notifier_block *nb);
  127. extern void __unregister_cpu_notifier(struct notifier_block *nb);
  128. #else
  129. #ifndef MODULE
  130. extern int register_cpu_notifier(struct notifier_block *nb);
  131. extern int __register_cpu_notifier(struct notifier_block *nb);
  132. #else
  133. static inline int register_cpu_notifier(struct notifier_block *nb)
  134. {
  135. return 0;
  136. }
  137. static inline int __register_cpu_notifier(struct notifier_block *nb)
  138. {
  139. return 0;
  140. }
  141. #endif
  142. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  143. {
  144. }
  145. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  146. {
  147. }
  148. #endif
  149. void smpboot_thread_init(void);
  150. int cpu_up(unsigned int cpu);
  151. void notify_cpu_starting(unsigned int cpu);
  152. extern void cpu_maps_update_begin(void);
  153. extern void cpu_maps_update_done(void);
  154. #define cpu_notifier_register_begin cpu_maps_update_begin
  155. #define cpu_notifier_register_done cpu_maps_update_done
  156. #else /* CONFIG_SMP */
  157. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  158. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  159. static inline int register_cpu_notifier(struct notifier_block *nb)
  160. {
  161. return 0;
  162. }
  163. static inline int __register_cpu_notifier(struct notifier_block *nb)
  164. {
  165. return 0;
  166. }
  167. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  168. {
  169. }
  170. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  171. {
  172. }
  173. static inline void cpu_maps_update_begin(void)
  174. {
  175. }
  176. static inline void cpu_maps_update_done(void)
  177. {
  178. }
  179. static inline void cpu_notifier_register_begin(void)
  180. {
  181. }
  182. static inline void cpu_notifier_register_done(void)
  183. {
  184. }
  185. static inline void smpboot_thread_init(void)
  186. {
  187. }
  188. #endif /* CONFIG_SMP */
  189. extern struct bus_type cpu_subsys;
  190. #ifdef CONFIG_HOTPLUG_CPU
  191. /* Stop CPUs going up and down. */
  192. extern void cpu_hotplug_begin(void);
  193. extern void cpu_hotplug_done(void);
  194. extern void get_online_cpus(void);
  195. extern void put_online_cpus(void);
  196. extern void cpu_hotplug_disable(void);
  197. extern void cpu_hotplug_enable(void);
  198. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  199. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  200. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  201. #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
  202. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  203. #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
  204. void clear_tasks_mm_cpumask(int cpu);
  205. int cpu_down(unsigned int cpu);
  206. #else /* CONFIG_HOTPLUG_CPU */
  207. static inline void cpu_hotplug_begin(void) {}
  208. static inline void cpu_hotplug_done(void) {}
  209. #define get_online_cpus() do { } while (0)
  210. #define put_online_cpus() do { } while (0)
  211. #define cpu_hotplug_disable() do { } while (0)
  212. #define cpu_hotplug_enable() do { } while (0)
  213. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  214. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  215. /* These aren't inline functions due to a GCC bug. */
  216. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  217. #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  218. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  219. #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  220. #endif /* CONFIG_HOTPLUG_CPU */
  221. #ifdef CONFIG_PM_SLEEP_SMP
  222. extern int disable_nonboot_cpus(void);
  223. extern void enable_nonboot_cpus(void);
  224. #else /* !CONFIG_PM_SLEEP_SMP */
  225. static inline int disable_nonboot_cpus(void) { return 0; }
  226. static inline void enable_nonboot_cpus(void) {}
  227. #endif /* !CONFIG_PM_SLEEP_SMP */
  228. enum cpuhp_state {
  229. CPUHP_OFFLINE,
  230. CPUHP_ONLINE,
  231. };
  232. void cpu_startup_entry(enum cpuhp_state state);
  233. void cpu_idle_poll_ctrl(bool enable);
  234. void arch_cpu_idle(void);
  235. void arch_cpu_idle_prepare(void);
  236. void arch_cpu_idle_enter(void);
  237. void arch_cpu_idle_exit(void);
  238. void arch_cpu_idle_dead(void);
  239. DECLARE_PER_CPU(bool, cpu_dead_idle);
  240. int cpu_report_state(int cpu);
  241. int cpu_check_up_prepare(int cpu);
  242. void cpu_set_state_online(int cpu);
  243. #ifdef CONFIG_HOTPLUG_CPU
  244. bool cpu_wait_death(unsigned int cpu, int seconds);
  245. bool cpu_report_death(void);
  246. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  247. #endif /* _LINUX_CPU_H_ */