cpu.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Per-cpu interfaces can be implemented using a struct device_interface.
  15. * See the following for how to do this:
  16. * - drivers/base/intf.c
  17. * - Documentation/driver-model/interface.txt
  18. */
  19. #ifndef _LINUX_CPU_H_
  20. #define _LINUX_CPU_H_
  21. #include <linux/sysdev.h>
  22. #include <linux/node.h>
  23. #include <linux/compiler.h>
  24. #include <linux/cpumask.h>
  25. #include <asm/semaphore.h>
  26. struct cpu {
  27. int node_id; /* The node which contains the CPU */
  28. int no_control; /* Should the sysfs control file be created? */
  29. struct sys_device sysdev;
  30. };
  31. extern int register_cpu(struct cpu *, int, struct node *);
  32. extern struct sys_device *get_cpu_sysdev(int cpu);
  33. #ifdef CONFIG_HOTPLUG_CPU
  34. extern void unregister_cpu(struct cpu *, struct node *);
  35. #endif
  36. struct notifier_block;
  37. #ifdef CONFIG_SMP
  38. /* Need to know about CPUs going up/down? */
  39. extern int register_cpu_notifier(struct notifier_block *nb);
  40. extern void unregister_cpu_notifier(struct notifier_block *nb);
  41. extern int current_in_cpu_hotplug(void);
  42. int cpu_up(unsigned int cpu);
  43. #else
  44. static inline int register_cpu_notifier(struct notifier_block *nb)
  45. {
  46. return 0;
  47. }
  48. static inline void unregister_cpu_notifier(struct notifier_block *nb)
  49. {
  50. }
  51. static inline int current_in_cpu_hotplug(void)
  52. {
  53. return 0;
  54. }
  55. #endif /* CONFIG_SMP */
  56. extern struct sysdev_class cpu_sysdev_class;
  57. #ifdef CONFIG_HOTPLUG_CPU
  58. /* Stop CPUs going up and down. */
  59. extern void lock_cpu_hotplug(void);
  60. extern void unlock_cpu_hotplug(void);
  61. extern int lock_cpu_hotplug_interruptible(void);
  62. #define hotcpu_notifier(fn, pri) { \
  63. static struct notifier_block fn##_nb = \
  64. { .notifier_call = fn, .priority = pri }; \
  65. register_cpu_notifier(&fn##_nb); \
  66. }
  67. int cpu_down(unsigned int cpu);
  68. extern int __attribute__((weak)) smp_prepare_cpu(int cpu);
  69. #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
  70. #else
  71. #define lock_cpu_hotplug() do { } while (0)
  72. #define unlock_cpu_hotplug() do { } while (0)
  73. #define lock_cpu_hotplug_interruptible() 0
  74. #define hotcpu_notifier(fn, pri)
  75. /* CPUs don't go offline once they're online w/o CONFIG_HOTPLUG_CPU */
  76. static inline int cpu_is_offline(int cpu) { return 0; }
  77. #endif
  78. #endif /* _LINUX_CPU_H_ */