aboutsummaryrefslogtreecommitdiff
path: root/inc/powercap-rapl-sysfs.h
blob: 5b9f0b0d356863b244df0cba4a263cb782160821 (plain)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * SPDX-License-Identifier: BSD-3-Clause
 *
 * This interface is deprecated - use powercap-sysfs.h directly instead.
 * By limiting zone depth to 2, this interface will break if Intel RAPL extends its tree depth in the future.
 * The only other abstraction it provides is to mask the control type parameter, which doesn't add much value.
 * Intel also added the intel-rapl-mmio control type, so even the control type abstraction is not as useful as before.
 *
 * Read/write RAPL sysfs files.
 * This is a wrapper around powercap-sysfs.h.
 *
 * The control type is "intel-rapl" and zone depth is limited to 2.
 * The "zone" parameters below are for the top-level "zone", and the optional "sz" parameters are for other control
 * planes like "core", "uncore", and "dram".
 * The "is_sz" parameter must be non-zero when working with these control planes.
 *
 * For example, zone=0, sz=0, is_sz=1 is usually for the "core" power plane and is analogous to using powercap-sysfs.h
 * with zones[2]={0, 0}, depth=2.
 *
 * The "intel-rapl" control type implements a subset of the powercap interface.
 * The following functions are not currently supported by RAPL, but are implemented here in case RAPL adds support for
 * them in the future:
 * - rapl_sysfs_zone_reset_energy_uj
 * - rapl_sysfs_zone_get_max_power_range_uw
 * - rapl_sysfs_zone_get_power_uw
 * - rapl_sysfs_constraint_get_min_power_uw
 * - rapl_sysfs_constraint_get_max_time_window_us
 * - rapl_sysfs_constraint_get_min_time_window_us
 *
 * @author Connor Imes
 * @date 2017-08-24
 * @deprecated Use powercap-sysfs.h directly instead.
 */

#ifndef _RAPL_SYSFS_H
#define _RAPL_SYSFS_H

#ifdef __cplusplus
extern "C" {
#endif

#include <inttypes.h>
#include <unistd.h>

#if !defined(POWERCAP_DEPRECATED)
#if defined(POWERCAP_ALLOW_DEPRECATED)
#define POWERCAP_DEPRECATED(x)
#elif defined(__GNUC__) || defined(__clang__)
#define POWERCAP_DEPRECATED(x) __attribute__((deprecated(x)))
#elif defined(_MSC_VER)
#define POWERCAP_DEPRECATED(x) __declspec(deprecated(x))
#else
#define POWERCAP_DEPRECATED(x)
#endif
#endif

/**
 * Determine if a zone or subzone exist.
 * It is _not_ assumed that a zone maps one-to-one with an particular physical component like a socket or die.
 *
 * Originally, a zone mapped to a physical socket/package, but this assumed mapping did not hold.
 * As of 2019, a zone maps to a CPU die, but nothing prevents Intel from changing the scope again in the future.
 * Their backward compatibility _appears_ to be in a zone's name, but even this is not explicitly guaranteed, nor does
 * this sysfs binding interface make such an assumption - it is the user's responsibility to interpret what a zone is.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @return 0 if zone exists, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_exists() instead")
int rapl_sysfs_zone_exists(uint32_t zone, uint32_t sz, int is_sz);

/**
 * @deprecated Use rapl_sysfs_zone_exists() instead.
 *
 * This function's name no longer accurately describes its scope.
 * Prior to Cascade Lake CPUs (2019), RAPL top-level (parent) zones mapped one-to-one with physical sockets/packages.
 * Thus the term "pkg" made sense and was chosen over the more general term "zone".
 * Some systems now support multiple die on a physical socket/package, resulting in multiple top-level (parent) zones
 * per physical socket/package.
 * The scope of a zone could potentially change again in the future.
 *
 * This function checks if a top-level (parent) zone exists, where num(top-level zones) >= num(sockets).
 * For systems with a single die per physical socket, num(top-level zones) == num(sockets).
 * For systems with multiple die per physical socket, num(top-level zones) > num(sockets).
 *
 * @param zone
 * @return 0 if zone exists, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_exists() instead")
int rapl_sysfs_pkg_exists(uint32_t zone);

/**
 * @deprecated Use rapl_sysfs_zone_exists() instead.
 *
 * Determine if a subzone exists.
 *
 * @param zone
 * @param sz
 * @return 0 if subzone exists, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_exists() instead")
int rapl_sysfs_sz_exists(uint32_t zone, uint32_t sz);

/**
 * Determine if a constraint exists.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @return 0 if constraint exists, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_exists() instead")
int rapl_sysfs_constraint_exists(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint);

/**
 * Get max_energy_range_uj for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_max_energy_range_uj() instead")
int rapl_sysfs_zone_get_max_energy_range_uj(uint32_t zone, uint32_t sz, int is_sz, uint64_t* val);

/**
 * Reset energy_uj for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_reset_energy_uj() instead")
int rapl_sysfs_zone_reset_energy_uj(uint32_t zone, uint32_t sz, int is_sz);

/**
 * Get energy_uj for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_energy_uj() instead")
int rapl_sysfs_zone_get_energy_uj(uint32_t zone, uint32_t sz, int is_sz, uint64_t* val);

/**
 * Get max_power_range_uw for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_max_power_range_uw() instead")
int rapl_sysfs_zone_get_max_power_range_uw(uint32_t zone, uint32_t sz, int is_sz, uint64_t* val);

/**
 * Get power_uw for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_power_uw() instead")
int rapl_sysfs_zone_get_power_uw(uint32_t zone, uint32_t sz, int is_sz, uint64_t* val);

/**
 * Enable/disable a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_set_enabled() instead")
int rapl_sysfs_zone_set_enabled(uint32_t zone, uint32_t sz, int is_sz, uint32_t val);

/**
 * Get whether a zone is enabled or disabled.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_enabled() instead")
int rapl_sysfs_zone_get_enabled(uint32_t zone, uint32_t sz, int is_sz, uint32_t* val);

/**
 * Get name for a zone.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param buf
 * @param size
 * @return number of bytes read, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_zone_get_name() instead")
ssize_t rapl_sysfs_zone_get_name(uint32_t zone, uint32_t sz, int is_sz, char* buf, size_t size);

/**
 * Set power_limit_uw for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_set_power_limit_uw() instead")
int rapl_sysfs_constraint_set_power_limit_uw(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t val);

/**
 * Get power_limit_uw for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_power_limit_uw() instead")
int rapl_sysfs_constraint_get_power_limit_uw(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);

/**
 * Set time_window_us for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_set_time_window_us() instead")
int rapl_sysfs_constraint_set_time_window_us(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t val);

/**
 * Get time_window_us for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_time_window_us() instead")
int rapl_sysfs_constraint_get_time_window_us(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);

/**
 * Get max_power_uw for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_max_power_uw() instead")
int rapl_sysfs_constraint_get_max_power_uw(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);

/**
 * Get get_min_power_uw for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_min_power_uw() instead")
int rapl_sysfs_constraint_get_min_power_uw(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);

/**
 * Get max_time_window_us for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_max_time_window_us() instead")
int rapl_sysfs_constraint_get_max_time_window_us(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);

/**
 * Get min_time_window_us for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param val
 * @return 0 on success, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_min_time_window_us() instead")
int rapl_sysfs_constraint_get_min_time_window_us(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, uint64_t* val);


/**
 * Get name for a constraint.
 *
 * @param zone
 * @param sz
 * @param is_sz
 * @param constraint
 * @param buf
 * @param size
 * @return number of bytes read, a negative error code otherwise.
 */
POWERCAP_DEPRECATED("Call powercap_sysfs_constraint_get_name() instead")
ssize_t rapl_sysfs_constraint_get_name(uint32_t zone, uint32_t sz, int is_sz, uint32_t constraint, char* buf, size_t size);

#ifdef __cplusplus
}
#endif

#endif