-
Notifications
You must be signed in to change notification settings - Fork 2
/
cpufreq-bindings.h
256 lines (230 loc) · 7.28 KB
/
cpufreq-bindings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/**
* Bindings to cpufreq in Linux sysfs.
* Linux does not guarantee that all files will be present, e.g. "bios_limit" or "scaling_setspeed".
*
* No function parameters are allowed to be NULL.
* If the "fd" (file descriptor) parameter is > 0, it will be used, otherwise the file is opened and closed locally.
*
* Frequency values are in KHz.
* See: https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
*
* @author Connor Imes
* @date 2017-03-16
*/
#ifndef _CPUFREQ_BINDINGS_H_
#define _CPUFREQ_BINDINGS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <unistd.h>
typedef enum cpufreq_bindings_file {
CPUFREQ_BINDINGS_FILE_AFFECTED_CPUS,
CPUFREQ_BINDINGS_FILE_BIOS_LIMIT,
CPUFREQ_BINDINGS_FILE_CPUINFO_CUR_FREQ,
CPUFREQ_BINDINGS_FILE_CPUINFO_MAX_FREQ,
CPUFREQ_BINDINGS_FILE_CPUINFO_MIN_FREQ,
CPUFREQ_BINDINGS_FILE_CPUINFO_TRANSITION_LATENCY,
CPUFREQ_BINDINGS_FILE_RELATED_CPUS,
CPUFREQ_BINDINGS_FILE_SCALING_AVAILABLE_FREQUENCIES,
CPUFREQ_BINDINGS_FILE_SCALING_AVAILABLE_GOVERNORS,
CPUFREQ_BINDINGS_FILE_SCALING_CUR_FREQ,
CPUFREQ_BINDINGS_FILE_SCALING_DRIVER,
CPUFREQ_BINDINGS_FILE_SCALING_GOVERNOR,
CPUFREQ_BINDINGS_FILE_SCALING_MAX_FREQ,
CPUFREQ_BINDINGS_FILE_SCALING_MIN_FREQ,
CPUFREQ_BINDINGS_FILE_SCALING_SETSPEED
} cpufreq_bindings_file;
/**
* Open a file (presumably so the file descriptor can be cached/reused).
*
* @param core
* @param file
* @param flags
* Usually O_RDONLY or O_RDWR; if < 0, open flags are chosen automatically
* @return the file descriptor, or -1 on error (errno will be set)
*/
int cpufreq_bindings_file_open(uint32_t core, cpufreq_bindings_file file, int flags);
/**
* Close a file descriptor.
*
* @param fd
* @return 0 on success, or -1 on error (errno will be set)
*/
int cpufreq_bindings_file_close(int fd);
/**
* Get the affected cores specified by "affected_cpus".
*
* @param fd
* @param core
* @param affected
* The array to be written to - should be as large as the number of cores in the system
* @param len
* The length of the array
* @return the number of affected cpus, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_affected_cpus(int fd, uint32_t core, uint32_t* affected, uint32_t len);
/**
* Get the frequency specified by "bios_limit".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_bios_limit(int fd, uint32_t core);
/**
* Get the frequency specified by "cpuinfo_cur_freq".
*
* @param fd
* @param core
* @return the frequency on success, 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_cpuinfo_cur_freq(int fd, uint32_t core);
/**
* Get the frequency specified by "cpuinfo_max_freq".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_cpuinfo_max_freq(int fd, uint32_t core);
/**
* Get the frequency specified by "cpuinfo_min_freq".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_cpuinfo_min_freq(int fd, uint32_t core);
/**
* Get frequency switching latency specified by "cpuinfo_transition_latency".
* Note that the kernel documentation appears outdated - instead of returning -1, UINT32_MAX may be returned.
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_cpuinfo_transition_latency(int fd, uint32_t core);
/**
* Get the related cpus specified by "related_cpus".
*
* @param fd
* @param core
* @param related
* The array to be written to - should be as large as the number of cores in the system
* @param len
* The length of the array
* @return the number of related cpus, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_related_cpus(int fd, uint32_t core, uint32_t* related, uint32_t len);
/**
* Get the available frequencies specified by "scaling_available_frequencies".
*
* @param fd
* @param core
* @param freqs
* An array of frequencies to be written to
* @param len
* The length of the "freqs" array
* @return the number of frequencies found, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_scaling_available_frequencies(int fd, uint32_t core, uint32_t* freqs, uint32_t len);
/**
* Get the available governors specified by "scaling_available_governors".
*
* @param fd
* @param core
* @param governors
* A character buffer to be written to (treated as a 2D char array) - should be len * width in size
* @param len
* The number of entries in the "governors" buffer array
* @param width
* the width of each entry in the "governors" buffer array
* @return the number of frequencies found, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_scaling_available_governors(int fd, uint32_t core, char* governors, size_t len, size_t width);
/**
* Get the frequency specified by "scaling_cur_freq".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_scaling_cur_freq(int fd, uint32_t core);
/**
* Get the scaling driver specified by "scaling_driver".
*
* @param fd
* @param core
* @param driver
* @param len
* @return the number of bytes read, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_get_scaling_driver(int fd, uint32_t core, char* driver, size_t len);
/**
* Get the scaling governor specified by "scaling_governor".
*
* @param fd
* @param core
* @param governor
* @param len
* @return the number of bytes read, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_get_scaling_governor(int fd, uint32_t core, char* governor, size_t len);
/**
* Get the scaling governor on "scaling_governor".
*
* @param fd
* @param core
* @param governor
* @param len
* @return the number of bytes written, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_set_scaling_governor(int fd, uint32_t core, const char* governor, size_t len);
/**
* Get the frequency specified by "scaling_max_freq".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_scaling_max_freq(int fd, uint32_t core);
/**
* Set the frequency on "scaling_max_freq".
*
* @param fd
* @param core
* @param freq
* @return the number of bytes written, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_set_scaling_max_freq(int fd, uint32_t core, uint32_t freq);
/**
* Get the frequency specified by "scaling_min_freq".
*
* @param fd
* @param core
* @return the frequency on success, or 0 on failure (errno will be set)
*/
uint32_t cpufreq_bindings_get_scaling_min_freq(int fd, uint32_t core);
/**
* Set the frequency on "scaling_min_freq".
*
* @param fd
* @param core
* @param freq
* @return the number of bytes written, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_set_scaling_min_freq(int fd, uint32_t core, uint32_t freq);
/**
* Set the frequency on "scaling_setspeed".
*
* @param fd
* @param core
* @param freq
* @return the number of bytes written, or -1 on failure (errno will be set)
*/
ssize_t cpufreq_bindings_set_scaling_setspeed(int fd, uint32_t core, uint32_t freq);
#ifdef __cplusplus
}
#endif
#endif