cpu.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #include <linux/cpuhotplug.h>
  19. struct device;
  20. struct device_node;
  21. struct attribute_group;
  22. struct cpu {
  23. int node_id; /* The node which contains the CPU */
  24. int hotpluggable; /* creates sysfs control file if hotpluggable */
  25. struct device dev;
  26. };
  27. extern void boot_cpu_init(void);
  28. extern void boot_cpu_state_init(void);
  29. extern int register_cpu(struct cpu *cpu, int num);
  30. extern struct device *get_cpu_device(unsigned cpu);
  31. extern bool cpu_is_hotpluggable(unsigned cpu);
  32. extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
  33. extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
  34. int cpu, unsigned int *thread);
  35. extern int cpu_add_dev_attr(struct device_attribute *attr);
  36. extern void cpu_remove_dev_attr(struct device_attribute *attr);
  37. extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
  38. extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
  39. extern __printf(4, 5)
  40. struct device *cpu_device_create(struct device *parent, void *drvdata,
  41. const struct attribute_group **groups,
  42. const char *fmt, ...);
  43. #ifdef CONFIG_HOTPLUG_CPU
  44. extern void unregister_cpu(struct cpu *cpu);
  45. extern ssize_t arch_cpu_probe(const char *, size_t);
  46. extern ssize_t arch_cpu_release(const char *, size_t);
  47. #endif
  48. struct notifier_block;
  49. #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
  50. #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
  51. #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
  52. #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
  53. #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
  54. #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
  55. #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
  56. * not handling interrupts, soon dead.
  57. * Called on the dying cpu, interrupts
  58. * are already disabled. Must not
  59. * sleep, must not fail */
  60. #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
  61. * lock is dropped */
  62. #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
  63. * Called on the new cpu, just before
  64. * enabling interrupts. Must not sleep,
  65. * must not fail */
  66. #define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly,
  67. * perhaps due to preemption. */
  68. /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
  69. * operation in progress
  70. */
  71. #define CPU_TASKS_FROZEN 0x0010
  72. #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
  73. #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
  74. #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
  75. #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
  76. #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
  77. #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
  78. #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
  79. #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
  80. #ifdef CONFIG_SMP
  81. extern bool cpuhp_tasks_frozen;
  82. /* Need to know about CPUs going up/down? */
  83. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  84. #define cpu_notifier(fn, pri) { \
  85. static struct notifier_block fn##_nb = \
  86. { .notifier_call = fn, .priority = pri }; \
  87. register_cpu_notifier(&fn##_nb); \
  88. }
  89. #define __cpu_notifier(fn, pri) { \
  90. static struct notifier_block fn##_nb = \
  91. { .notifier_call = fn, .priority = pri }; \
  92. __register_cpu_notifier(&fn##_nb); \
  93. }
  94. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  95. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  96. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  97. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  98. #ifdef CONFIG_HOTPLUG_CPU
  99. extern int register_cpu_notifier(struct notifier_block *nb);
  100. extern int __register_cpu_notifier(struct notifier_block *nb);
  101. extern void unregister_cpu_notifier(struct notifier_block *nb);
  102. extern void __unregister_cpu_notifier(struct notifier_block *nb);
  103. #else
  104. #ifndef MODULE
  105. extern int register_cpu_notifier(struct notifier_block *nb);
  106. extern int __register_cpu_notifier(struct notifier_block *nb);
  107. #else
  108. static inline int register_cpu_notifier(struct notifier_block *nb)
  109. {
  110. return 0;
  111. }
  112. static inline int __register_cpu_notifier(struct notifier_block *nb)
  113. {
  114. return 0;
  115. }
  116. #endif
  117. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  118. {
  119. }
  120. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  121. {
  122. }
  123. #endif
  124. int cpu_up(unsigned int cpu);
  125. void notify_cpu_starting(unsigned int cpu);
  126. extern void cpu_maps_update_begin(void);
  127. extern void cpu_maps_update_done(void);
  128. #define cpu_notifier_register_begin cpu_maps_update_begin
  129. #define cpu_notifier_register_done cpu_maps_update_done
  130. #else /* CONFIG_SMP */
  131. #define cpuhp_tasks_frozen 0
  132. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  133. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  134. static inline int register_cpu_notifier(struct notifier_block *nb)
  135. {
  136. return 0;
  137. }
  138. static inline int __register_cpu_notifier(struct notifier_block *nb)
  139. {
  140. return 0;
  141. }
  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. static inline void cpu_maps_update_begin(void)
  149. {
  150. }
  151. static inline void cpu_maps_update_done(void)
  152. {
  153. }
  154. static inline void cpu_notifier_register_begin(void)
  155. {
  156. }
  157. static inline void cpu_notifier_register_done(void)
  158. {
  159. }
  160. #endif /* CONFIG_SMP */
  161. extern struct bus_type cpu_subsys;
  162. #ifdef CONFIG_HOTPLUG_CPU
  163. /* Stop CPUs going up and down. */
  164. extern void cpu_hotplug_begin(void);
  165. extern void cpu_hotplug_done(void);
  166. extern void get_online_cpus(void);
  167. extern void put_online_cpus(void);
  168. extern void cpu_hotplug_disable(void);
  169. extern void cpu_hotplug_enable(void);
  170. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  171. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  172. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  173. #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
  174. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  175. #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
  176. void clear_tasks_mm_cpumask(int cpu);
  177. int cpu_down(unsigned int cpu);
  178. #else /* CONFIG_HOTPLUG_CPU */
  179. static inline void cpu_hotplug_begin(void) {}
  180. static inline void cpu_hotplug_done(void) {}
  181. #define get_online_cpus() do { } while (0)
  182. #define put_online_cpus() do { } while (0)
  183. #define cpu_hotplug_disable() do { } while (0)
  184. #define cpu_hotplug_enable() do { } while (0)
  185. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  186. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  187. /* These aren't inline functions due to a GCC bug. */
  188. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  189. #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  190. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  191. #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  192. #endif /* CONFIG_HOTPLUG_CPU */
  193. #ifdef CONFIG_PM_SLEEP_SMP
  194. extern int disable_nonboot_cpus(void);
  195. extern void enable_nonboot_cpus(void);
  196. #else /* !CONFIG_PM_SLEEP_SMP */
  197. static inline int disable_nonboot_cpus(void) { return 0; }
  198. static inline void enable_nonboot_cpus(void) {}
  199. #endif /* !CONFIG_PM_SLEEP_SMP */
  200. void cpu_startup_entry(enum cpuhp_state state);
  201. void cpu_idle_poll_ctrl(bool enable);
  202. void arch_cpu_idle(void);
  203. void arch_cpu_idle_prepare(void);
  204. void arch_cpu_idle_enter(void);
  205. void arch_cpu_idle_exit(void);
  206. void arch_cpu_idle_dead(void);
  207. int cpu_report_state(int cpu);
  208. int cpu_check_up_prepare(int cpu);
  209. void cpu_set_state_online(int cpu);
  210. #ifdef CONFIG_HOTPLUG_CPU
  211. bool cpu_wait_death(unsigned int cpu, int seconds);
  212. bool cpu_report_death(void);
  213. void cpuhp_report_idle_dead(void);
  214. #else
  215. static inline void cpuhp_report_idle_dead(void) { }
  216. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  217. #endif /* _LINUX_CPU_H_ */