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