cpu.h 6.6 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/device.h>
  17. #include <linux/node.h>
  18. #include <linux/compiler.h>
  19. #include <linux/cpumask.h>
  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. /* prepare workqueues for other notifiers */
  68. CPU_PRI_WORKQUEUE = 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 __cpuinitdata = \
  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 get_online_cpus(void);
  150. extern void put_online_cpus(void);
  151. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  152. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  153. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  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_ */