cpufreq.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 * cpufreq_get_available_governors(unsigned int cpu);
  99. extern void cpufreq_put_available_governors(struct cpufreq_available_governors *first);
  100. /* determine CPU frequency states available
  101. *
  102. * only present on _some_ ->target() cpufreq drivers. For information purposes
  103. * only. Please free allocated memory by calling cpufreq_put_available_frequencies
  104. * after use.
  105. */
  106. extern struct cpufreq_available_frequencies * cpufreq_get_available_frequencies(unsigned int cpu);
  107. extern void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *first);
  108. /* determine affected CPUs
  109. *
  110. * Remember to call cpufreq_put_affected_cpus when no longer needed
  111. * to avoid memory leakage, please.
  112. */
  113. extern struct cpufreq_affected_cpus * cpufreq_get_affected_cpus(unsigned int cpu);
  114. extern 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. extern struct cpufreq_affected_cpus * cpufreq_get_related_cpus(unsigned int cpu);
  121. extern void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
  122. /* determine stats for cpufreq subsystem
  123. *
  124. * This is not available in all kernel versions or configurations.
  125. */
  126. extern struct cpufreq_stats * cpufreq_get_stats(unsigned int cpu, unsigned long long *total_time);
  127. extern void cpufreq_put_stats(struct cpufreq_stats *stats);
  128. extern unsigned long cpufreq_get_transitions(unsigned int cpu);
  129. /* set new cpufreq policy
  130. *
  131. * Tries to set the passed policy as new policy as close as possible,
  132. * but results may differ depending e.g. on governors being available.
  133. */
  134. extern int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
  135. /* modify a policy by only changing min/max freq or governor
  136. *
  137. * Does not check whether result is what was intended.
  138. */
  139. extern int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
  140. extern int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
  141. extern int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
  142. /* set a specific frequency
  143. *
  144. * Does only work if userspace governor can be used and no external
  145. * interference (other calls to this function or to set/modify_policy)
  146. * occurs. Also does not work on ->range() cpufreq drivers.
  147. */
  148. extern int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* _CPUFREQ_H */