cpu.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
  56. * lock is dropped */
  57. #define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly,
  58. * perhaps due to preemption. */
  59. /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
  60. * operation in progress
  61. */
  62. #define CPU_TASKS_FROZEN 0x0010
  63. #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
  64. #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
  65. #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
  66. #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
  67. #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
  68. #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
  69. #ifdef CONFIG_SMP
  70. extern bool cpuhp_tasks_frozen;
  71. /* Need to know about CPUs going up/down? */
  72. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  73. #define cpu_notifier(fn, pri) { \
  74. static struct notifier_block fn##_nb = \
  75. { .notifier_call = fn, .priority = pri }; \
  76. register_cpu_notifier(&fn##_nb); \
  77. }
  78. #define __cpu_notifier(fn, pri) { \
  79. static struct notifier_block fn##_nb = \
  80. { .notifier_call = fn, .priority = pri }; \
  81. __register_cpu_notifier(&fn##_nb); \
  82. }
  83. extern int register_cpu_notifier(struct notifier_block *nb);
  84. extern int __register_cpu_notifier(struct notifier_block *nb);
  85. extern void unregister_cpu_notifier(struct notifier_block *nb);
  86. extern void __unregister_cpu_notifier(struct notifier_block *nb);
  87. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  88. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  89. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  90. static inline int register_cpu_notifier(struct notifier_block *nb)
  91. {
  92. return 0;
  93. }
  94. static inline int __register_cpu_notifier(struct notifier_block *nb)
  95. {
  96. return 0;
  97. }
  98. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  99. {
  100. }
  101. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  102. {
  103. }
  104. #endif
  105. int cpu_up(unsigned int cpu);
  106. void notify_cpu_starting(unsigned int cpu);
  107. extern void cpu_maps_update_begin(void);
  108. extern void cpu_maps_update_done(void);
  109. #define cpu_notifier_register_begin cpu_maps_update_begin
  110. #define cpu_notifier_register_done cpu_maps_update_done
  111. #else /* CONFIG_SMP */
  112. #define cpuhp_tasks_frozen 0
  113. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  114. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  115. static inline int register_cpu_notifier(struct notifier_block *nb)
  116. {
  117. return 0;
  118. }
  119. static inline int __register_cpu_notifier(struct notifier_block *nb)
  120. {
  121. return 0;
  122. }
  123. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  124. {
  125. }
  126. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  127. {
  128. }
  129. static inline void cpu_maps_update_begin(void)
  130. {
  131. }
  132. static inline void cpu_maps_update_done(void)
  133. {
  134. }
  135. static inline void cpu_notifier_register_begin(void)
  136. {
  137. }
  138. static inline void cpu_notifier_register_done(void)
  139. {
  140. }
  141. #endif /* CONFIG_SMP */
  142. extern struct bus_type cpu_subsys;
  143. #ifdef CONFIG_HOTPLUG_CPU
  144. /* Stop CPUs going up and down. */
  145. extern void cpu_hotplug_begin(void);
  146. extern void cpu_hotplug_done(void);
  147. extern void get_online_cpus(void);
  148. extern void put_online_cpus(void);
  149. extern void cpu_hotplug_disable(void);
  150. extern void cpu_hotplug_enable(void);
  151. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  152. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  153. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  154. #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
  155. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  156. #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
  157. void clear_tasks_mm_cpumask(int cpu);
  158. int cpu_down(unsigned int cpu);
  159. #else /* CONFIG_HOTPLUG_CPU */
  160. static inline void cpu_hotplug_begin(void) {}
  161. static inline void cpu_hotplug_done(void) {}
  162. #define get_online_cpus() do { } while (0)
  163. #define put_online_cpus() do { } while (0)
  164. #define cpu_hotplug_disable() do { } while (0)
  165. #define cpu_hotplug_enable() do { } while (0)
  166. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  167. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  168. /* These aren't inline functions due to a GCC bug. */
  169. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  170. #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  171. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  172. #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  173. #endif /* CONFIG_HOTPLUG_CPU */
  174. #ifdef CONFIG_PM_SLEEP_SMP
  175. extern int freeze_secondary_cpus(int primary);
  176. static inline int disable_nonboot_cpus(void)
  177. {
  178. return freeze_secondary_cpus(0);
  179. }
  180. extern void enable_nonboot_cpus(void);
  181. #else /* !CONFIG_PM_SLEEP_SMP */
  182. static inline int disable_nonboot_cpus(void) { return 0; }
  183. static inline void enable_nonboot_cpus(void) {}
  184. #endif /* !CONFIG_PM_SLEEP_SMP */
  185. void cpu_startup_entry(enum cpuhp_state state);
  186. void cpu_idle_poll_ctrl(bool enable);
  187. /* Attach to any functions which should be considered cpuidle. */
  188. #define __cpuidle __attribute__((__section__(".cpuidle.text")))
  189. bool cpu_in_idle(unsigned long pc);
  190. void arch_cpu_idle(void);
  191. void arch_cpu_idle_prepare(void);
  192. void arch_cpu_idle_enter(void);
  193. void arch_cpu_idle_exit(void);
  194. void arch_cpu_idle_dead(void);
  195. int cpu_report_state(int cpu);
  196. int cpu_check_up_prepare(int cpu);
  197. void cpu_set_state_online(int cpu);
  198. #ifdef CONFIG_HOTPLUG_CPU
  199. bool cpu_wait_death(unsigned int cpu, int seconds);
  200. bool cpu_report_death(void);
  201. void cpuhp_report_idle_dead(void);
  202. #else
  203. static inline void cpuhp_report_idle_dead(void) { }
  204. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  205. #endif /* _LINUX_CPU_H_ */