cpuidle.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_state_kobj;
  49. struct cpuidle_driver_kobj;
  50. struct cpuidle_device {
  51. unsigned int registered:1;
  52. unsigned int enabled:1;
  53. unsigned int cpu;
  54. int last_residency;
  55. struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
  56. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  57. struct cpuidle_driver_kobj *kobj_driver;
  58. struct cpuidle_device_kobj *kobj_dev;
  59. struct list_head device_list;
  60. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  61. int safe_state_index;
  62. cpumask_t coupled_cpus;
  63. struct cpuidle_coupled *coupled;
  64. #endif
  65. };
  66. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  67. DECLARE_PER_CPU(struct cpuidle_device, cpuidle_dev);
  68. /**
  69. * cpuidle_get_last_residency - retrieves the last state's residency time
  70. * @dev: the target CPU
  71. *
  72. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  73. */
  74. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  75. {
  76. return dev->last_residency;
  77. }
  78. /****************************
  79. * CPUIDLE DRIVER INTERFACE *
  80. ****************************/
  81. struct cpuidle_driver {
  82. const char *name;
  83. struct module *owner;
  84. int refcnt;
  85. /* used by the cpuidle framework to setup the broadcast timer */
  86. unsigned int bctimer:1;
  87. /* states array must be ordered in decreasing power consumption */
  88. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  89. int state_count;
  90. int safe_state_index;
  91. /* the driver handles the cpus in cpumask */
  92. struct cpumask *cpumask;
  93. };
  94. #ifdef CONFIG_CPU_IDLE
  95. extern void disable_cpuidle(void);
  96. extern int cpuidle_select(struct cpuidle_driver *drv,
  97. struct cpuidle_device *dev);
  98. extern int cpuidle_enter(struct cpuidle_driver *drv,
  99. struct cpuidle_device *dev, int index);
  100. extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
  101. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  102. extern struct cpuidle_driver *cpuidle_get_driver(void);
  103. extern struct cpuidle_driver *cpuidle_driver_ref(void);
  104. extern void cpuidle_driver_unref(void);
  105. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  106. extern int cpuidle_register_device(struct cpuidle_device *dev);
  107. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  108. extern int cpuidle_register(struct cpuidle_driver *drv,
  109. const struct cpumask *const coupled_cpus);
  110. extern void cpuidle_unregister(struct cpuidle_driver *drv);
  111. extern void cpuidle_pause_and_lock(void);
  112. extern void cpuidle_resume_and_unlock(void);
  113. extern void cpuidle_pause(void);
  114. extern void cpuidle_resume(void);
  115. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  116. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  117. extern int cpuidle_play_dead(void);
  118. extern void cpuidle_use_deepest_state(bool enable);
  119. extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
  120. #else
  121. static inline void disable_cpuidle(void) { }
  122. static inline int cpuidle_select(struct cpuidle_driver *drv,
  123. struct cpuidle_device *dev)
  124. {return -ENODEV; }
  125. static inline int cpuidle_enter(struct cpuidle_driver *drv,
  126. struct cpuidle_device *dev, int index)
  127. {return -ENODEV; }
  128. static inline void cpuidle_reflect(struct cpuidle_device *dev, int index) { }
  129. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  130. {return -ENODEV; }
  131. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  132. static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
  133. static inline void cpuidle_driver_unref(void) {}
  134. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  135. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  136. {return -ENODEV; }
  137. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  138. static inline int cpuidle_register(struct cpuidle_driver *drv,
  139. const struct cpumask *const coupled_cpus)
  140. {return -ENODEV; }
  141. static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
  142. static inline void cpuidle_pause_and_lock(void) { }
  143. static inline void cpuidle_resume_and_unlock(void) { }
  144. static inline void cpuidle_pause(void) { }
  145. static inline void cpuidle_resume(void) { }
  146. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  147. {return -ENODEV; }
  148. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  149. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  150. static inline void cpuidle_use_deepest_state(bool enable) {}
  151. static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
  152. struct cpuidle_device *dev) {return NULL; }
  153. #endif
  154. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  155. void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
  156. #else
  157. static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
  158. {
  159. }
  160. #endif
  161. /******************************
  162. * CPUIDLE GOVERNOR INTERFACE *
  163. ******************************/
  164. struct cpuidle_governor {
  165. char name[CPUIDLE_NAME_LEN];
  166. struct list_head governor_list;
  167. unsigned int rating;
  168. int (*enable) (struct cpuidle_driver *drv,
  169. struct cpuidle_device *dev);
  170. void (*disable) (struct cpuidle_driver *drv,
  171. struct cpuidle_device *dev);
  172. int (*select) (struct cpuidle_driver *drv,
  173. struct cpuidle_device *dev);
  174. void (*reflect) (struct cpuidle_device *dev, int index);
  175. struct module *owner;
  176. };
  177. #ifdef CONFIG_CPU_IDLE
  178. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  179. #else
  180. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  181. {return 0;}
  182. #endif
  183. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  184. #define CPUIDLE_DRIVER_STATE_START 1
  185. #else
  186. #define CPUIDLE_DRIVER_STATE_START 0
  187. #endif
  188. #endif /* _LINUX_CPUIDLE_H */