cpu.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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/sysdev.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 sys_device sysdev;
  24. };
  25. extern int register_cpu(struct cpu *cpu, int num);
  26. extern struct sys_device *get_cpu_sysdev(unsigned cpu);
  27. extern int cpu_add_sysdev_attr(struct sysdev_attribute *attr);
  28. extern void cpu_remove_sysdev_attr(struct sysdev_attribute *attr);
  29. extern int cpu_add_sysdev_attr_group(struct attribute_group *attrs);
  30. extern void cpu_remove_sysdev_attr_group(struct attribute_group *attrs);
  31. extern int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls);
  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. /*
  39. * CPU notifier priorities.
  40. */
  41. enum {
  42. /*
  43. * SCHED_ACTIVE marks a cpu which is coming up active during
  44. * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
  45. * notifier. CPUSET_ACTIVE adjusts cpuset according to
  46. * cpu_active mask right after SCHED_ACTIVE. During
  47. * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
  48. * ordered in the similar way.
  49. *
  50. * This ordering guarantees consistent cpu_active mask and
  51. * migration behavior to all cpu notifiers.
  52. */
  53. CPU_PRI_SCHED_ACTIVE = INT_MAX,
  54. CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
  55. CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
  56. CPU_PRI_CPUSET_INACTIVE = INT_MIN,
  57. /* migration should happen before other stuff but after perf */
  58. CPU_PRI_PERF = 20,
  59. CPU_PRI_MIGRATION = 10,
  60. /* prepare workqueues for other notifiers */
  61. CPU_PRI_WORKQUEUE = 5,
  62. };
  63. #ifdef CONFIG_SMP
  64. /* Need to know about CPUs going up/down? */
  65. #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
  66. #define cpu_notifier(fn, pri) { \
  67. static struct notifier_block fn##_nb __cpuinitdata = \
  68. { .notifier_call = fn, .priority = pri }; \
  69. register_cpu_notifier(&fn##_nb); \
  70. }
  71. #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  72. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  73. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
  74. #ifdef CONFIG_HOTPLUG_CPU
  75. extern int register_cpu_notifier(struct notifier_block *nb);
  76. extern void unregister_cpu_notifier(struct notifier_block *nb);
  77. #else
  78. #ifndef MODULE
  79. extern int register_cpu_notifier(struct notifier_block *nb);
  80. #else
  81. static inline int register_cpu_notifier(struct notifier_block *nb)
  82. {
  83. return 0;
  84. }
  85. #endif
  86. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  87. {
  88. }
  89. #endif
  90. int cpu_up(unsigned int cpu);
  91. void notify_cpu_starting(unsigned int cpu);
  92. extern void cpu_maps_update_begin(void);
  93. extern void cpu_maps_update_done(void);
  94. #else /* CONFIG_SMP */
  95. #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
  96. static inline int register_cpu_notifier(struct notifier_block *nb)
  97. {
  98. return 0;
  99. }
  100. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  101. {
  102. }
  103. static inline void cpu_maps_update_begin(void)
  104. {
  105. }
  106. static inline void cpu_maps_update_done(void)
  107. {
  108. }
  109. #endif /* CONFIG_SMP */
  110. extern struct sysdev_class cpu_sysdev_class;
  111. #ifdef CONFIG_HOTPLUG_CPU
  112. /* Stop CPUs going up and down. */
  113. extern void get_online_cpus(void);
  114. extern void put_online_cpus(void);
  115. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  116. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  117. #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
  118. int cpu_down(unsigned int cpu);
  119. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  120. extern void cpu_hotplug_driver_lock(void);
  121. extern void cpu_hotplug_driver_unlock(void);
  122. #else
  123. static inline void cpu_hotplug_driver_lock(void)
  124. {
  125. }
  126. static inline void cpu_hotplug_driver_unlock(void)
  127. {
  128. }
  129. #endif
  130. #else /* CONFIG_HOTPLUG_CPU */
  131. #define get_online_cpus() do { } while (0)
  132. #define put_online_cpus() do { } while (0)
  133. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  134. /* These aren't inline functions due to a GCC bug. */
  135. #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
  136. #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
  137. #endif /* CONFIG_HOTPLUG_CPU */
  138. #ifdef CONFIG_PM_SLEEP_SMP
  139. extern int suspend_cpu_hotplug;
  140. extern int disable_nonboot_cpus(void);
  141. extern void enable_nonboot_cpus(void);
  142. #else /* !CONFIG_PM_SLEEP_SMP */
  143. #define suspend_cpu_hotplug 0
  144. static inline int disable_nonboot_cpus(void) { return 0; }
  145. static inline void enable_nonboot_cpus(void) {}
  146. #endif /* !CONFIG_PM_SLEEP_SMP */
  147. #endif /* _LINUX_CPU_H_ */