cpuidle.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. int state_count;
  56. struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
  57. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  58. struct cpuidle_driver_kobj *kobj_driver;
  59. struct cpuidle_device_kobj *kobj_dev;
  60. struct list_head device_list;
  61. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  62. int safe_state_index;
  63. cpumask_t coupled_cpus;
  64. struct cpuidle_coupled *coupled;
  65. #endif
  66. };
  67. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  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_idle_call(void);
  97. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  98. extern struct cpuidle_driver *cpuidle_get_driver(void);
  99. extern struct cpuidle_driver *cpuidle_driver_ref(void);
  100. extern void cpuidle_driver_unref(void);
  101. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  102. extern int cpuidle_register_device(struct cpuidle_device *dev);
  103. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  104. extern int cpuidle_register(struct cpuidle_driver *drv,
  105. const struct cpumask *const coupled_cpus);
  106. extern void cpuidle_unregister(struct cpuidle_driver *drv);
  107. extern void cpuidle_pause_and_lock(void);
  108. extern void cpuidle_resume_and_unlock(void);
  109. extern void cpuidle_pause(void);
  110. extern void cpuidle_resume(void);
  111. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  112. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  113. extern int cpuidle_play_dead(void);
  114. extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
  115. #else
  116. static inline void disable_cpuidle(void) { }
  117. static inline int cpuidle_idle_call(void) { return -ENODEV; }
  118. static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
  119. {return -ENODEV; }
  120. static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
  121. static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
  122. static inline void cpuidle_driver_unref(void) {}
  123. static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  124. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  125. {return -ENODEV; }
  126. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  127. static inline int cpuidle_register(struct cpuidle_driver *drv,
  128. const struct cpumask *const coupled_cpus)
  129. {return -ENODEV; }
  130. static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
  131. static inline void cpuidle_pause_and_lock(void) { }
  132. static inline void cpuidle_resume_and_unlock(void) { }
  133. static inline void cpuidle_pause(void) { }
  134. static inline void cpuidle_resume(void) { }
  135. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  136. {return -ENODEV; }
  137. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  138. static inline int cpuidle_play_dead(void) {return -ENODEV; }
  139. #endif
  140. #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
  141. void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
  142. #else
  143. static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
  144. {
  145. }
  146. #endif
  147. /******************************
  148. * CPUIDLE GOVERNOR INTERFACE *
  149. ******************************/
  150. struct cpuidle_governor {
  151. char name[CPUIDLE_NAME_LEN];
  152. struct list_head governor_list;
  153. unsigned int rating;
  154. int (*enable) (struct cpuidle_driver *drv,
  155. struct cpuidle_device *dev);
  156. void (*disable) (struct cpuidle_driver *drv,
  157. struct cpuidle_device *dev);
  158. int (*select) (struct cpuidle_driver *drv,
  159. struct cpuidle_device *dev);
  160. void (*reflect) (struct cpuidle_device *dev, int index);
  161. struct module *owner;
  162. };
  163. #ifdef CONFIG_CPU_IDLE
  164. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  165. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  166. #else
  167. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  168. {return 0;}
  169. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  170. #endif
  171. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  172. #define CPUIDLE_DRIVER_STATE_START 1
  173. #else
  174. #define CPUIDLE_DRIVER_STATE_START 0
  175. #endif
  176. #endif /* _LINUX_CPUIDLE_H */