cpufreq.h 5.3 KB

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