cpufreq.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 __CPUPOWER_CPUFREQ_H__
  20. #define __CPUPOWER_CPUFREQ_H__
  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. /* determine current CPU frequency
  51. * - _kernel variant means kernel's opinion of CPU frequency
  52. * - _hardware variant means actual hardware CPU frequency,
  53. * which is only available to root.
  54. *
  55. * returns 0 on failure, else frequency in kHz.
  56. */
  57. unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
  58. unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
  59. #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
  60. /* determine CPU transition latency
  61. *
  62. * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds
  63. */
  64. unsigned long cpufreq_get_transition_latency(unsigned int cpu);
  65. /* determine hardware CPU frequency limits
  66. *
  67. * These may be limited further by thermal, energy or other
  68. * considerations by cpufreq policy notifiers in the kernel.
  69. */
  70. int cpufreq_get_hardware_limits(unsigned int cpu,
  71. unsigned long *min,
  72. unsigned long *max);
  73. /* determine CPUfreq driver used
  74. *
  75. * Remember to call cpufreq_put_driver when no longer needed
  76. * to avoid memory leakage, please.
  77. */
  78. char *cpufreq_get_driver(unsigned int cpu);
  79. void cpufreq_put_driver(char *ptr);
  80. /* determine CPUfreq policy currently used
  81. *
  82. * Remember to call cpufreq_put_policy when no longer needed
  83. * to avoid memory leakage, please.
  84. */
  85. struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);
  86. void cpufreq_put_policy(struct cpufreq_policy *policy);
  87. /* determine CPUfreq governors currently available
  88. *
  89. * may be modified by modprobe'ing or rmmod'ing other governors. Please
  90. * free allocated memory by calling cpufreq_put_available_governors
  91. * after use.
  92. */
  93. struct cpufreq_available_governors
  94. *cpufreq_get_available_governors(unsigned int cpu);
  95. void cpufreq_put_available_governors(
  96. struct cpufreq_available_governors *first);
  97. /* determine CPU frequency states available
  98. *
  99. * Only present on _some_ ->target() cpufreq drivers. For information purposes
  100. * only. Please free allocated memory by calling
  101. * cpufreq_put_available_frequencies after use.
  102. */
  103. struct cpufreq_available_frequencies
  104. *cpufreq_get_available_frequencies(unsigned int cpu);
  105. void cpufreq_put_available_frequencies(
  106. struct cpufreq_available_frequencies *first);
  107. /* determine affected CPUs
  108. *
  109. * Remember to call cpufreq_put_affected_cpus when no longer needed
  110. * to avoid memory leakage, please.
  111. */
  112. struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned
  113. int cpu);
  114. void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);
  115. /* determine related CPUs
  116. *
  117. * Remember to call cpufreq_put_related_cpus when no longer needed
  118. * to avoid memory leakage, please.
  119. */
  120. struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned
  121. int cpu);
  122. void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
  123. /* determine stats for cpufreq subsystem
  124. *
  125. * This is not available in all kernel versions or configurations.
  126. */
  127. struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
  128. unsigned long long *total_time);
  129. void cpufreq_put_stats(struct cpufreq_stats *stats);
  130. unsigned long cpufreq_get_transitions(unsigned int cpu);
  131. /* set new cpufreq policy
  132. *
  133. * Tries to set the passed policy as new policy as close as possible,
  134. * but results may differ depending e.g. on governors being available.
  135. */
  136. int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
  137. /* modify a policy by only changing min/max freq or governor
  138. *
  139. * Does not check whether result is what was intended.
  140. */
  141. int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
  142. int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
  143. int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
  144. /* set a specific frequency
  145. *
  146. * Does only work if userspace governor can be used and no external
  147. * interference (other calls to this function or to set/modify_policy)
  148. * occurs. Also does not work on ->range() cpufreq drivers.
  149. */
  150. int cpufreq_set_frequency(unsigned int cpu,
  151. unsigned long target_frequency);
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /* _CPUFREQ_H */