cpu.h 7.0 KB

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