cpu.h 8.9 KB

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