cpu.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. /* bring up workqueues before normal notifiers and down after */
  64. CPU_PRI_WORKQUEUE_UP = 5,
  65. CPU_PRI_WORKQUEUE_DOWN = -5,
  66. };
  67. #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
  68. #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
  69. #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
  70. #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
  71. #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
  72. #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
  73. #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
  74. * not handling interrupts, soon dead.
  75. * Called on the dying cpu, interrupts
  76. * are already disabled. Must not
  77. * sleep, must not fail */
  78. #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
  79. * lock is dropped */
  80. #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
  81. * Called on the new cpu, just before
  82. * enabling interrupts. Must not sleep,
  83. * must not fail */
  84. /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
  85. * operation in progress
  86. */
  87. #define CPU_TASKS_FROZEN 0x0010
  88. #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
  89. #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
  90. #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
  91. #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
  92. #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
  93. #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
  94. #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
  95. #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
  96. #ifdef CONFIG_SMP
  97. /* Need to know about CPUs going up/down? */
  98. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  99. #define cpu_notifier(fn, pri) { \
  100. static struct notifier_block fn##_nb = \
  101. { .notifier_call = fn, .priority = pri }; \
  102. register_cpu_notifier(&fn##_nb); \
  103. }
  104. #define __cpu_notifier(fn, pri) { \
  105. static struct notifier_block fn##_nb = \
  106. { .notifier_call = fn, .priority = pri }; \
  107. __register_cpu_notifier(&fn##_nb); \
  108. }
  109. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  110. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  111. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  112. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  113. #ifdef CONFIG_HOTPLUG_CPU
  114. extern int register_cpu_notifier(struct notifier_block *nb);
  115. extern int __register_cpu_notifier(struct notifier_block *nb);
  116. extern void unregister_cpu_notifier(struct notifier_block *nb);
  117. extern void __unregister_cpu_notifier(struct notifier_block *nb);
  118. #else
  119. #ifndef MODULE
  120. extern int register_cpu_notifier(struct notifier_block *nb);
  121. extern int __register_cpu_notifier(struct notifier_block *nb);
  122. #else
  123. static inline int register_cpu_notifier(struct notifier_block *nb)
  124. {
  125. return 0;
  126. }
  127. static inline int __register_cpu_notifier(struct notifier_block *nb)
  128. {
  129. return 0;
  130. }
  131. #endif
  132. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  133. {
  134. }
  135. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  136. {
  137. }
  138. #endif
  139. int cpu_up(unsigned int cpu);
  140. void notify_cpu_starting(unsigned int cpu);
  141. extern void cpu_maps_update_begin(void);
  142. extern void cpu_maps_update_done(void);
  143. #define cpu_notifier_register_begin cpu_maps_update_begin
  144. #define cpu_notifier_register_done cpu_maps_update_done
  145. #else /* CONFIG_SMP */
  146. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  147. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  148. static inline int register_cpu_notifier(struct notifier_block *nb)
  149. {
  150. return 0;
  151. }
  152. static inline int __register_cpu_notifier(struct notifier_block *nb)
  153. {
  154. return 0;
  155. }
  156. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  157. {
  158. }
  159. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  160. {
  161. }
  162. static inline void cpu_maps_update_begin(void)
  163. {
  164. }
  165. static inline void cpu_maps_update_done(void)
  166. {
  167. }
  168. static inline void cpu_notifier_register_begin(void)
  169. {
  170. }
  171. static inline void cpu_notifier_register_done(void)
  172. {
  173. }
  174. #endif /* CONFIG_SMP */
  175. extern struct bus_type cpu_subsys;
  176. #ifdef CONFIG_HOTPLUG_CPU
  177. /* Stop CPUs going up and down. */
  178. extern void cpu_hotplug_begin(void);
  179. extern void cpu_hotplug_done(void);
  180. extern void get_online_cpus(void);
  181. extern bool try_get_online_cpus(void);
  182. extern void put_online_cpus(void);
  183. extern void cpu_hotplug_disable(void);
  184. extern void cpu_hotplug_enable(void);
  185. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  186. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  187. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  188. #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
  189. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  190. #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
  191. void clear_tasks_mm_cpumask(int cpu);
  192. int cpu_down(unsigned int cpu);
  193. #else /* CONFIG_HOTPLUG_CPU */
  194. static inline void cpu_hotplug_begin(void) {}
  195. static inline void cpu_hotplug_done(void) {}
  196. #define get_online_cpus() do { } while (0)
  197. #define try_get_online_cpus() true
  198. #define put_online_cpus() do { } while (0)
  199. #define cpu_hotplug_disable() do { } while (0)
  200. #define cpu_hotplug_enable() do { } while (0)
  201. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  202. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  203. /* These aren't inline functions due to a GCC bug. */
  204. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  205. #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  206. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  207. #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  208. #endif /* CONFIG_HOTPLUG_CPU */
  209. #ifdef CONFIG_PM_SLEEP_SMP
  210. extern int disable_nonboot_cpus(void);
  211. extern void enable_nonboot_cpus(void);
  212. #else /* !CONFIG_PM_SLEEP_SMP */
  213. static inline int disable_nonboot_cpus(void) { return 0; }
  214. static inline void enable_nonboot_cpus(void) {}
  215. #endif /* !CONFIG_PM_SLEEP_SMP */
  216. enum cpuhp_state {
  217. CPUHP_OFFLINE,
  218. CPUHP_ONLINE,
  219. };
  220. void cpu_startup_entry(enum cpuhp_state state);
  221. void cpu_idle_poll_ctrl(bool enable);
  222. void arch_cpu_idle(void);
  223. void arch_cpu_idle_prepare(void);
  224. void arch_cpu_idle_enter(void);
  225. void arch_cpu_idle_exit(void);
  226. void arch_cpu_idle_dead(void);
  227. #endif /* _LINUX_CPU_H_ */