cpu.h 6.3 KB

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