cpu.h 8.6 KB

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