cpu.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. * and system devices are handled in drivers/base/sys.c.
  10. *
  11. * CPUs are exported via sysfs in the class/cpu/devices/
  12. * directory.
  13. */
  14. #ifndef _LINUX_CPU_H_
  15. #define _LINUX_CPU_H_
  16. #include <linux/node.h>
  17. #include <linux/compiler.h>
  18. #include <linux/cpumask.h>
  19. struct device;
  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 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. extern int sched_create_sysfs_power_savings_entries(struct device *dev);
  33. #ifdef CONFIG_HOTPLUG_CPU
  34. extern void unregister_cpu(struct cpu *cpu);
  35. extern ssize_t arch_cpu_probe(const char *, size_t);
  36. extern ssize_t arch_cpu_release(const char *, size_t);
  37. #endif
  38. struct notifier_block;
  39. #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
  40. extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
  41. extern ssize_t arch_print_cpu_modalias(struct device *dev,
  42. struct device_attribute *attr,
  43. char *bufptr);
  44. #endif
  45. /*
  46. * CPU notifier priorities.
  47. */
  48. enum {
  49. /*
  50. * SCHED_ACTIVE marks a cpu which is coming up active during
  51. * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
  52. * notifier. CPUSET_ACTIVE adjusts cpuset according to
  53. * cpu_active mask right after SCHED_ACTIVE. During
  54. * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
  55. * ordered in the similar way.
  56. *
  57. * This ordering guarantees consistent cpu_active mask and
  58. * migration behavior to all cpu notifiers.
  59. */
  60. CPU_PRI_SCHED_ACTIVE = INT_MAX,
  61. CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
  62. CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
  63. CPU_PRI_CPUSET_INACTIVE = INT_MIN,
  64. /* migration should happen before other stuff but after perf */
  65. CPU_PRI_PERF = 20,
  66. CPU_PRI_MIGRATION = 10,
  67. /* bring up workqueues before normal notifiers and down after */
  68. CPU_PRI_WORKQUEUE_UP = 5,
  69. CPU_PRI_WORKQUEUE_DOWN = -5,
  70. };
  71. #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
  72. #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
  73. #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
  74. #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
  75. #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
  76. #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
  77. #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
  78. * not handling interrupts, soon dead.
  79. * Called on the dying cpu, interrupts
  80. * are already disabled. Must not
  81. * sleep, must not fail */
  82. #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
  83. * lock is dropped */
  84. #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
  85. * Called on the new cpu, just before
  86. * enabling interrupts. Must not sleep,
  87. * must not fail */
  88. /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
  89. * operation in progress
  90. */
  91. #define CPU_TASKS_FROZEN 0x0010
  92. #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
  93. #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
  94. #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
  95. #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
  96. #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
  97. #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
  98. #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
  99. #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
  100. #ifdef CONFIG_SMP
  101. /* Need to know about CPUs going up/down? */
  102. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  103. #define cpu_notifier(fn, pri) { \
  104. static struct notifier_block fn##_nb __cpuinitdata = \
  105. { .notifier_call = fn, .priority = pri }; \
  106. register_cpu_notifier(&fn##_nb); \
  107. }
  108. #define __cpu_notifier(fn, pri) { \
  109. static struct notifier_block fn##_nb __cpuinitdata = \
  110. { .notifier_call = fn, .priority = pri }; \
  111. __register_cpu_notifier(&fn##_nb); \
  112. }
  113. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  114. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  115. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  116. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  117. #ifdef CONFIG_HOTPLUG_CPU
  118. extern int register_cpu_notifier(struct notifier_block *nb);
  119. extern int __register_cpu_notifier(struct notifier_block *nb);
  120. extern void unregister_cpu_notifier(struct notifier_block *nb);
  121. extern void __unregister_cpu_notifier(struct notifier_block *nb);
  122. #else
  123. #ifndef MODULE
  124. extern int register_cpu_notifier(struct notifier_block *nb);
  125. extern int __register_cpu_notifier(struct notifier_block *nb);
  126. #else
  127. static inline int register_cpu_notifier(struct notifier_block *nb)
  128. {
  129. return 0;
  130. }
  131. static inline int __register_cpu_notifier(struct notifier_block *nb)
  132. {
  133. return 0;
  134. }
  135. #endif
  136. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  137. {
  138. }
  139. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  140. {
  141. }
  142. #endif
  143. int cpu_up(unsigned int cpu);
  144. void notify_cpu_starting(unsigned int cpu);
  145. extern void cpu_maps_update_begin(void);
  146. extern void cpu_maps_update_done(void);
  147. #define cpu_notifier_register_begin cpu_maps_update_begin
  148. #define cpu_notifier_register_done cpu_maps_update_done
  149. #else /* CONFIG_SMP */
  150. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  151. #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  152. static inline int register_cpu_notifier(struct notifier_block *nb)
  153. {
  154. return 0;
  155. }
  156. static inline int __register_cpu_notifier(struct notifier_block *nb)
  157. {
  158. return 0;
  159. }
  160. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  161. {
  162. }
  163. static inline void __unregister_cpu_notifier(struct notifier_block *nb)
  164. {
  165. }
  166. static inline void cpu_maps_update_begin(void)
  167. {
  168. }
  169. static inline void cpu_maps_update_done(void)
  170. {
  171. }
  172. static inline void cpu_notifier_register_begin(void)
  173. {
  174. }
  175. static inline void cpu_notifier_register_done(void)
  176. {
  177. }
  178. #endif /* CONFIG_SMP */
  179. extern struct bus_type cpu_subsys;
  180. #ifdef CONFIG_HOTPLUG_CPU
  181. /* Stop CPUs going up and down. */
  182. extern void get_online_cpus(void);
  183. extern void put_online_cpus(void);
  184. extern void cpu_hotplug_disable(void);
  185. extern void cpu_hotplug_enable(void);
  186. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  187. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  188. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  189. #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
  190. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  191. #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
  192. int cpu_down(unsigned int cpu);
  193. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  194. extern void cpu_hotplug_driver_lock(void);
  195. extern void cpu_hotplug_driver_unlock(void);
  196. #else
  197. static inline void cpu_hotplug_driver_lock(void)
  198. {
  199. }
  200. static inline void cpu_hotplug_driver_unlock(void)
  201. {
  202. }
  203. #endif
  204. #else /* CONFIG_HOTPLUG_CPU */
  205. #define get_online_cpus() do { } while (0)
  206. #define put_online_cpus() do { } while (0)
  207. #define cpu_hotplug_disable() do { } while (0)
  208. #define cpu_hotplug_enable() do { } while (0)
  209. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  210. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  211. /* These aren't inline functions due to a GCC bug. */
  212. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  213. #define __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  214. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  215. #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  216. #endif /* CONFIG_HOTPLUG_CPU */
  217. #ifdef CONFIG_PM_SLEEP_SMP
  218. extern int disable_nonboot_cpus(void);
  219. extern void enable_nonboot_cpus(void);
  220. #else /* !CONFIG_PM_SLEEP_SMP */
  221. static inline int disable_nonboot_cpus(void) { return 0; }
  222. static inline void enable_nonboot_cpus(void) {}
  223. #endif /* !CONFIG_PM_SLEEP_SMP */
  224. #define IDLE_START 1
  225. #define IDLE_END 2
  226. void idle_notifier_register(struct notifier_block *n);
  227. void idle_notifier_unregister(struct notifier_block *n);
  228. void idle_notifier_call_chain(unsigned long val);
  229. #endif /* _LINUX_CPU_H_ */