cpufreq.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * cpufreq.h - definitions for libcpufreq
  3. *
  4. * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef _CPUFREQ_H
  20. #define _CPUFREQ_H 1
  21. struct cpufreq_policy {
  22. unsigned long min;
  23. unsigned long max;
  24. char *governor;
  25. };
  26. struct cpufreq_available_governors {
  27. char *governor;
  28. struct cpufreq_available_governors *next;
  29. struct cpufreq_available_governors *first;
  30. };
  31. struct cpufreq_available_frequencies {
  32. unsigned long frequency;
  33. struct cpufreq_available_frequencies *next;
  34. struct cpufreq_available_frequencies *first;
  35. };
  36. struct cpufreq_affected_cpus {
  37. unsigned int cpu;
  38. struct cpufreq_affected_cpus *next;
  39. struct cpufreq_affected_cpus *first;
  40. };
  41. struct cpufreq_stats {
  42. unsigned long frequency;
  43. unsigned long long time_in_state;
  44. struct cpufreq_stats *next;
  45. struct cpufreq_stats *first;
  46. };
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /*
  51. * returns 0 if the specified CPU is present (it doesn't say
  52. * whether it is online!), and an error value if not.
  53. */
  54. extern int cpufreq_cpu_exists(unsigned int cpu);
  55. /* determine current CPU frequency
  56. * - _kernel variant means kernel's opinion of CPU frequency
  57. * - _hardware variant means actual hardware CPU frequency,
  58. * which is only available to root.
  59. *
  60. * returns 0 on failure, else frequency in kHz.
  61. */
  62. extern unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
  63. extern unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
  64. #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
  65. /* determine CPU transition latency
  66. *
  67. * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds
  68. */
  69. extern unsigned long cpufreq_get_transition_latency(unsigned int cpu);
  70. /* determine hardware CPU frequency limits
  71. *
  72. * These may be limited further by thermal, energy or other
  73. * considerations by cpufreq policy notifiers in the kernel.
  74. */
  75. extern int cpufreq_get_hardware_limits(unsigned int cpu,
  76. unsigned long *min,
  77. unsigned long *max);
  78. /* determine CPUfreq driver used
  79. *
  80. * Remember to call cpufreq_put_driver when no longer needed
  81. * to avoid memory leakage, please.
  82. */
  83. extern char *cpufreq_get_driver(unsigned int cpu);
  84. extern void cpufreq_put_driver(char *ptr);
  85. /* determine CPUfreq policy currently used
  86. *
  87. * Remember to call cpufreq_put_policy when no longer needed
  88. * to avoid memory leakage, please.
  89. */
  90. extern struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);
  91. extern void cpufreq_put_policy(struct cpufreq_policy *policy);
  92. /* determine CPUfreq governors currently available
  93. *
  94. * may be modified by modprobe'ing or rmmod'ing other governors. Please
  95. * free allocated memory by calling cpufreq_put_available_governors
  96. * after use.
  97. */
  98. extern struct cpufreq_available_governors
  99. *cpufreq_get_available_governors(unsigned int cpu);
  100. extern void cpufreq_put_available_governors(
  101. struct cpufreq_available_governors *first);
  102. /* determine CPU frequency states available
  103. *
  104. * Only present on _some_ ->target() cpufreq drivers. For information purposes
  105. * only. Please free allocated memory by calling
  106. * cpufreq_put_available_frequencies after use.
  107. */
  108. extern struct cpufreq_available_frequencies
  109. *cpufreq_get_available_frequencies(unsigned int cpu);
  110. extern void cpufreq_put_available_frequencies(
  111. struct cpufreq_available_frequencies *first);
  112. /* determine affected CPUs
  113. *
  114. * Remember to call cpufreq_put_affected_cpus when no longer needed
  115. * to avoid memory leakage, please.
  116. */
  117. extern struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned
  118. int cpu);
  119. extern void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);
  120. /* determine related CPUs
  121. *
  122. * Remember to call cpufreq_put_related_cpus when no longer needed
  123. * to avoid memory leakage, please.
  124. */
  125. extern struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned
  126. int cpu);
  127. extern void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
  128. /* determine stats for cpufreq subsystem
  129. *
  130. * This is not available in all kernel versions or configurations.
  131. */
  132. extern struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
  133. unsigned long long *total_time);
  134. extern void cpufreq_put_stats(struct cpufreq_stats *stats);
  135. extern unsigned long cpufreq_get_transitions(unsigned int cpu);
  136. /* set new cpufreq policy
  137. *
  138. * Tries to set the passed policy as new policy as close as possible,
  139. * but results may differ depending e.g. on governors being available.
  140. */
  141. extern int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
  142. /* modify a policy by only changing min/max freq or governor
  143. *
  144. * Does not check whether result is what was intended.
  145. */
  146. extern int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
  147. extern int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
  148. extern int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
  149. /* set a specific frequency
  150. *
  151. * Does only work if userspace governor can be used and no external
  152. * interference (other calls to this function or to set/modify_policy)
  153. * occurs. Also does not work on ->range() cpufreq drivers.
  154. */
  155. extern int cpufreq_set_frequency(unsigned int cpu,
  156. unsigned long target_frequency);
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif /* _CPUFREQ_H */