cpuidle.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * cpuidle.h - a generic framework for CPU idle power management
  3. *
  4. * (C) 2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  5. * Shaohua Li <shaohua.li@intel.com>
  6. * Adam Belay <abelay@novell.com>
  7. *
  8. * This code is licenced under the GPL.
  9. */
  10. #ifndef _LINUX_CPUIDLE_H
  11. #define _LINUX_CPUIDLE_H
  12. #include <linux/percpu.h>
  13. #include <linux/list.h>
  14. #include <linux/hrtimer.h>
  15. #define CPUIDLE_STATE_MAX 10
  16. #define CPUIDLE_NAME_LEN 16
  17. #define CPUIDLE_DESC_LEN 32
  18. struct module;
  19. struct cpuidle_device;
  20. struct cpuidle_driver;
  21. /****************************
  22. * CPUIDLE DEVICE INTERFACE *
  23. ****************************/
  24. struct cpuidle_state_usage {
  25. unsigned long long disable;
  26. unsigned long long usage;
  27. unsigned long long time; /* in US */
  28. };
  29. struct cpuidle_state {
  30. char name[CPUIDLE_NAME_LEN];
  31. char desc[CPUIDLE_DESC_LEN];
  32. unsigned int flags;
  33. unsigned int exit_latency; /* in US */
  34. int power_usage; /* in mW */
  35. unsigned int target_residency; /* in US */
  36. bool disabled; /* disabled on all CPUs */
  37. int (*enter) (struct cpuidle_device *dev,
  38. struct cpuidle_driver *drv,
  39. int index);
  40. int (*enter_dead) (struct cpuidle_device *dev, int index);
  41. };
  42. /* Idle State Flags */
  43. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  44. #define CPUIDLE_FLAG_COUPLED (0x02) /* state applies to multiple cpus */
  45. #define CPUIDLE_FLAG_TIMER_STOP (0x04) /* timer is stopped on this state */
  46. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  47. struct cpuidle_device_kobj;
  48. struct cpuidle_device {
  49. unsigned int registered:1;
  50. unsigned int enabled:1;
  51. unsigned int cpu;
  52. int last_residency;
  53. int state_count;
  54. struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
  55. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  56. struct cpuidle_driver_kobj *kobj_driver;
  57. struct cpuidle_device_kobj *kobj_dev;
  58. struct list_head device_list;
  59. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  60. int safe_state_index;
  61. cpumask_t coupled_cpus;
  62. struct cpuidle_coupled *coupled;
  63. #endif
  64. };
  65. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  66. /**
  67. * cpuidle_get_last_residency - retrieves the last state's residency time
  68. * @dev: the target CPU
  69. *
  70. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  71. */
  72. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  73. {
  74. return dev->last_residency;
  75. }
  76. /****************************
  77. * CPUIDLE DRIVER INTERFACE *
  78. ****************************/
  79. struct cpuidle_driver {
  80. const char *name;
  81. struct module *owner;
  82. int refcnt;
  83. /* used by the cpuidle framework to setup the broadcast timer */
  84. unsigned int bctimer:1;
  85. /* states array must be ordered in decreasing power consumption */
  86. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  87. int state_count;
  88. int safe_state_index;
  89. /* the driver handles the cpus in cpumask */
  90. struct cpumask *cpumask;
  91. };
  92. #ifdef CONFIG_CPU_IDLE
  93. extern void disable_cpuidle(void);
  94. extern int cpuidle_idle_call(void);
  95. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  96. extern struct cpuidle_driver *cpuidle_get_driver(void);
  97. extern struct cpuidle_driver *cpuidle_driver_ref(void);
  98. extern void cpuidle_driver_unref(void);
  99. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  100. extern int cpuidle_register_device(struct cpuidle_device *dev);
  101. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  102. extern int cpuidle_register(struct cpuidle_driver *drv,
  103. const struct cpumask *const coupled_cpus);
  104. extern void cpuidle_unregister(struct cpuidle_driver *drv);
  105. extern void cpuidle_pause_and_lock(void);
  106. extern void cpuidle_resume_and_unlock(void);
  107. extern void cpuidle_pause(void);
  108. extern void cpuidle_resume(void);
  109. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  110. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  111. extern int cpuidle_play_dead(void);
  112. extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
  113. #else
  114. static inline void disable_cpuidle(void) { }
  115. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  116. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  117. {return -ENODEV; }
  118. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  119. static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
  120. static inline void cpuidle_driver_unref(void) {}
  121. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  122. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  123. {return -ENODEV; }
  124. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  125. static inline int cpuidle_register(struct cpuidle_driver *drv,
  126. const struct cpumask *const coupled_cpus)
  127. {return -ENODEV; }
  128. static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
  129. static inline void cpuidle_pause_and_lock(void) { }
  130. static inline void cpuidle_resume_and_unlock(void) { }
  131. static inline void cpuidle_pause(void) { }
  132. static inline void cpuidle_resume(void) { }
  133. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  134. {return -ENODEV; }
  135. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  136. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  137. #endif
  138. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  139. void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
  140. #else
  141. static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
  142. {
  143. }
  144. #endif
  145. /******************************
  146. * CPUIDLE GOVERNOR INTERFACE *
  147. ******************************/
  148. struct cpuidle_governor {
  149. char name[CPUIDLE_NAME_LEN];
  150. struct list_head governor_list;
  151. unsigned int rating;
  152. int (*enable) (struct cpuidle_driver *drv,
  153. struct cpuidle_device *dev);
  154. void (*disable) (struct cpuidle_driver *drv,
  155. struct cpuidle_device *dev);
  156. int (*select) (struct cpuidle_driver *drv,
  157. struct cpuidle_device *dev);
  158. void (*reflect) (struct cpuidle_device *dev, int index);
  159. struct module *owner;
  160. };
  161. #ifdef CONFIG_CPU_IDLE
  162. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  163. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  164. #else
  165. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  166. {return 0;}
  167. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  168. #endif
  169. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  170. #define CPUIDLE_DRIVER_STATE_START 1
  171. #else
  172. #define CPUIDLE_DRIVER_STATE_START 0
  173. #endif
  174. #endif /* _LINUX_CPUIDLE_H */