cpu.h 7.2 KB

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