cpuidle.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/module.h>
  15. #include <linux/kobject.h>
  16. #include <linux/completion.h>
  17. #define CPUIDLE_STATE_MAX 8
  18. #define CPUIDLE_NAME_LEN 16
  19. #define CPUIDLE_DESC_LEN 32
  20. struct cpuidle_device;
  21. /****************************
  22. * CPUIDLE DEVICE INTERFACE *
  23. ****************************/
  24. struct cpuidle_state {
  25. char name[CPUIDLE_NAME_LEN];
  26. char desc[CPUIDLE_DESC_LEN];
  27. void *driver_data;
  28. unsigned int flags;
  29. unsigned int exit_latency; /* in US */
  30. unsigned int power_usage; /* in mW */
  31. unsigned int target_residency; /* in US */
  32. unsigned long long usage;
  33. unsigned long long time; /* in US */
  34. int (*enter) (struct cpuidle_device *dev,
  35. struct cpuidle_state *state);
  36. };
  37. /* Idle State Flags */
  38. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  39. #define CPUIDLE_FLAG_CHECK_BM (0x02) /* BM activity will exit state */
  40. #define CPUIDLE_FLAG_POLL (0x10) /* no latency, no savings */
  41. #define CPUIDLE_FLAG_SHALLOW (0x20) /* low latency, minimal savings */
  42. #define CPUIDLE_FLAG_BALANCED (0x40) /* medium latency, moderate savings */
  43. #define CPUIDLE_FLAG_DEEP (0x80) /* high latency, large savings */
  44. #define CPUIDLE_FLAG_IGNORE (0x100) /* ignore during this idle period */
  45. #define CPUIDLE_FLAG_TLB_FLUSHED (0x200) /* tlb will be flushed */
  46. #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
  47. /**
  48. * cpuidle_get_statedata - retrieves private driver state data
  49. * @state: the state
  50. */
  51. static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  52. {
  53. return state->driver_data;
  54. }
  55. /**
  56. * cpuidle_set_statedata - stores private driver state data
  57. * @state: the state
  58. * @data: the private data
  59. */
  60. static inline void
  61. cpuidle_set_statedata(struct cpuidle_state *state, void *data)
  62. {
  63. state->driver_data = data;
  64. }
  65. struct cpuidle_state_kobj {
  66. struct cpuidle_state *state;
  67. struct completion kobj_unregister;
  68. struct kobject kobj;
  69. };
  70. struct cpuidle_device {
  71. unsigned int registered:1;
  72. unsigned int enabled:1;
  73. unsigned int power_specified:1;
  74. unsigned int cpu;
  75. int last_residency;
  76. int state_count;
  77. struct cpuidle_state states[CPUIDLE_STATE_MAX];
  78. struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
  79. struct cpuidle_state *last_state;
  80. struct list_head device_list;
  81. struct kobject kobj;
  82. struct completion kobj_unregister;
  83. void *governor_data;
  84. struct cpuidle_state *safe_state;
  85. int (*prepare) (struct cpuidle_device *dev);
  86. };
  87. DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  88. /**
  89. * cpuidle_get_last_residency - retrieves the last state's residency time
  90. * @dev: the target CPU
  91. *
  92. * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  93. */
  94. static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
  95. {
  96. return dev->last_residency;
  97. }
  98. /****************************
  99. * CPUIDLE DRIVER INTERFACE *
  100. ****************************/
  101. struct cpuidle_driver {
  102. char name[CPUIDLE_NAME_LEN];
  103. struct module *owner;
  104. };
  105. #ifdef CONFIG_CPU_IDLE
  106. extern int cpuidle_register_driver(struct cpuidle_driver *drv);
  107. struct cpuidle_driver *cpuidle_get_driver(void);
  108. extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
  109. extern int cpuidle_register_device(struct cpuidle_device *dev);
  110. extern void cpuidle_unregister_device(struct cpuidle_device *dev);
  111. extern void cpuidle_pause_and_lock(void);
  112. extern void cpuidle_resume_and_unlock(void);
  113. extern int cpuidle_enable_device(struct cpuidle_device *dev);
  114. extern void cpuidle_disable_device(struct cpuidle_device *dev);
  115. #else
  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 void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
  120. static inline int cpuidle_register_device(struct cpuidle_device *dev)
  121. {return -ENODEV; }
  122. static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
  123. static inline void cpuidle_pause_and_lock(void) { }
  124. static inline void cpuidle_resume_and_unlock(void) { }
  125. static inline int cpuidle_enable_device(struct cpuidle_device *dev)
  126. {return -ENODEV; }
  127. static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
  128. #endif
  129. /******************************
  130. * CPUIDLE GOVERNOR INTERFACE *
  131. ******************************/
  132. struct cpuidle_governor {
  133. char name[CPUIDLE_NAME_LEN];
  134. struct list_head governor_list;
  135. unsigned int rating;
  136. int (*enable) (struct cpuidle_device *dev);
  137. void (*disable) (struct cpuidle_device *dev);
  138. int (*select) (struct cpuidle_device *dev);
  139. void (*reflect) (struct cpuidle_device *dev);
  140. struct module *owner;
  141. };
  142. #ifdef CONFIG_CPU_IDLE
  143. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  144. extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
  145. #else
  146. static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  147. {return 0;}
  148. static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
  149. #endif
  150. #ifdef CONFIG_ARCH_HAS_CPU_RELAX
  151. #define CPUIDLE_DRIVER_STATE_START 1
  152. #else
  153. #define CPUIDLE_DRIVER_STATE_START 0
  154. #endif
  155. #endif /* _LINUX_CPUIDLE_H */