cpu.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #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. /* prepare workqueues for other notifiers */
  67. CPU_PRI_WORKQUEUE = 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 __cpuinitdata = \
  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. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  151. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  152. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  153. void clear_tasks_mm_cpumask(int cpu);
  154. int cpu_down(unsigned int cpu);
  155. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  156. extern void cpu_hotplug_driver_lock(void);
  157. extern void cpu_hotplug_driver_unlock(void);
  158. #else
  159. static inline void cpu_hotplug_driver_lock(void)
  160. {
  161. }
  162. static inline void cpu_hotplug_driver_unlock(void)
  163. {
  164. }
  165. #endif
  166. #else /* CONFIG_HOTPLUG_CPU */
  167. #define get_online_cpus() do { } while (0)
  168. #define put_online_cpus() do { } while (0)
  169. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  170. /* These aren't inline functions due to a GCC bug. */
  171. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  172. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  173. #endif /* CONFIG_HOTPLUG_CPU */
  174. #ifdef CONFIG_PM_SLEEP_SMP
  175. extern int disable_nonboot_cpus(void);
  176. extern void enable_nonboot_cpus(void);
  177. #else /* !CONFIG_PM_SLEEP_SMP */
  178. static inline int disable_nonboot_cpus(void) { return 0; }
  179. static inline void enable_nonboot_cpus(void) {}
  180. #endif /* !CONFIG_PM_SLEEP_SMP */
  181. #endif /* _LINUX_CPU_H_ */