-
Notifications
You must be signed in to change notification settings - Fork 9
/
raplcap.h
334 lines (303 loc) · 9.52 KB
/
raplcap.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
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
/**
* A power capping interface for Intel Running Average Power Limit (RAPL).
*
* If a NULL value is passed to functions for the raplcap (rc) parameter, a global default context is used.
* This global (NULL) context must be initialized/destroyed the same as an application-managed (non-NULL) context.
*
* It is the developer's responsibility to synchronize as needed when a context is accessed by multiple threads.
*
* RAPL "clamping" may be managed automatically as part of enabling, disabling, or setting power caps.
* It is implementation-specific if clamping is considered when getting or setting a zone's "enabled" status.
*
* The term "socket" is now deprecated in favor of "package".
* Historically, sockets always contained a single package, but some Intel architectures may now contain more than one.
*
* @author Connor Imes
* @date 2016-05-13
*/
#ifndef _RAPLCAP_H_
#define _RAPLCAP_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#if !defined(RAPLCAP_DEPRECATED)
#if defined(RAPLCAP_ALLOW_DEPRECATED)
#define RAPLCAP_DEPRECATED(x)
#elif defined(__GNUC__) || defined(__clang__)
#define RAPLCAP_DEPRECATED(x) __attribute__((deprecated(x)))
#elif defined(_MSC_VER)
#define RAPLCAP_DEPRECATED(x) __declspec(deprecated(x))
#else
#define RAPLCAP_DEPRECATED(x)
#endif
#endif
/**
* A RAPLCap context
*
* With the nsockets field deprecated, all that remains in the struct is a void pointer.
* For better forward compatibility, we chose not to expose new fields for packages and die, so that the ABI won't need
* to change as processor architectures continue to evolve in ways that impact RAPL management structure.
* It's easier to make functions backward compatible than it is to make structs backward compatible.
* In future releases, it might therefore be beneficial to just make the raplcap context struct opaque.
* If such a change is made, raplcap_init will also be changed to something like: `raplcap* raplcap_init(void)`
*/
typedef struct raplcap {
/**
* The nsockets field is now deprecated since it doesn't reflect the RAPL control structure anymore.
* Do not access the field directly - use functions 'raplcap_get_num_packages' and 'raplcap_get_num_die' instead.
*
* @deprecated
*/
RAPLCAP_DEPRECATED("Call functions raplcap_get_num_packages() and raplcap_get_num_die() instead")
uint32_t nsockets;
void* state;
} raplcap;
/**
* A RAPL power capping limit
*/
typedef struct raplcap_limit {
double seconds;
double watts;
} raplcap_limit;
/**
* Available RAPL zones (domains)
*/
typedef enum raplcap_zone {
RAPLCAP_ZONE_PACKAGE = 0,
RAPLCAP_ZONE_CORE,
RAPLCAP_ZONE_UNCORE,
RAPLCAP_ZONE_DRAM,
RAPLCAP_ZONE_PSYS,
} raplcap_zone;
/**
* Available RAPL constraints
*/
typedef enum raplcap_constraint {
RAPLCAP_CONSTRAINT_LONG_TERM,
RAPLCAP_CONSTRAINT_SHORT_TERM,
RAPLCAP_CONSTRAINT_PEAK_POWER,
} raplcap_constraint;
/**
* Initialize a RAPLCap context.
*
* @param rc
* @return 0 on success, a negative value on error
*/
int raplcap_init(raplcap* rc);
/**
* Destroy a RAPLCap context.
*
* @param rc
* @return 0 on success, a negative value on error
*/
int raplcap_destroy(raplcap* rc);
/**
* Get the number of available packages.
* If the raplcap context is not initialized, the function will attempt to discover the number of available packages.
*
* @param rc
* @return the number of packages, 0 on error
*/
uint32_t raplcap_get_num_packages(const raplcap* rc);
/**
* Deprecated, superseded by raplcap_get_num_packages.
*
* @param rc
* @return the number of packages, 0 on error
* @deprecated
*/
RAPLCAP_DEPRECATED("Call raplcap_get_num_packages() instead")
uint32_t raplcap_get_num_sockets(const raplcap* rc);
/**
* Get the number of available die in a package.
* If the raplcap context is not initialized, the function will attempt to discover the number of available die.
*
* @param rc
* @param pkg
* @return the number of die, 0 on error
*/
uint32_t raplcap_get_num_die(const raplcap* rc, uint32_t pkg);
/**
* Check if a zone is supported.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @return 0 if unsupported, 1 if supported, a negative value on error
*/
int raplcap_pd_is_zone_supported(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone);
/**
* Check if a zone constraint is supported.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param constraint
* @return 0 if unsupported, 1 if supported, a negative value on error
*/
int raplcap_pd_is_constraint_supported(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone,
raplcap_constraint constraint);
/**
* Check if a zone is enabled.
* Constraints can technically be enabled/disabled separately, but for simplicity and compatibility with lower-level
* RAPL interfaces, we define a zone to be enabled only if all of its constraints are enabled (disabled otherwise).
*
* @param rc
* @param pkg
* @param die
* @param zone
* @return 0 if disabled, 1 if enabled, a negative value on error
*/
int raplcap_pd_is_zone_enabled(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone);
/**
* Enable/disable a zone by enabling/disabling all of its constraints.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param enabled
* @return 0 on success, a negative value on error
*/
int raplcap_pd_set_zone_enabled(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone, int enabled);
/**
* Get the long and/or short term constraint limits for a zone, if it is supported.
* Not all zones use limit_short.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param limit_long
* @param limit_short
* @return 0 on success, a negative value on error
*/
int raplcap_pd_get_limits(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone,
raplcap_limit* limit_long, raplcap_limit* limit_short);
/**
* Set the long and/or short term constraint limits for a zone, if it is supported.
* Not all zones use limit_short.
* If the power or time window value is 0, it will not be written or the current value may be used.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param limit_long
* @param limit_short
* @return 0 on success, a negative value on error
*/
int raplcap_pd_set_limits(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone,
const raplcap_limit* limit_long, const raplcap_limit* limit_short);
/**
* Get a zone constraint's limit, if it is supported.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param constraint
* @param limit
* @return 0 on success, a negative value on error
*/
int raplcap_pd_get_limit(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone,
raplcap_constraint constraint, raplcap_limit* limit);
/**
* Set a zone constraint's limit, if it is supported.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @param constraint
* @param limit
* @return 0 on success, a negative value on error
*/
int raplcap_pd_set_limit(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone,
raplcap_constraint constraint, const raplcap_limit* limit);
/**
* Get the current energy counter value for a zone in Joules.
* Note that the counter rolls over - check the max value.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @return Joules on success, a negative value on error
*/
double raplcap_pd_get_energy_counter(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone);
/**
* Get the maximum energy counter value for a zone in Joules.
*
* @param rc
* @param pkg
* @param die
* @param zone
* @return Joules on success, a negative value on error
*/
double raplcap_pd_get_energy_counter_max(const raplcap* rc, uint32_t pkg, uint32_t die, raplcap_zone zone);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_is_zone_supported
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_is_zone_supported() instead")
int raplcap_is_zone_supported(const raplcap* rc, uint32_t pkg, raplcap_zone zone);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_is_zone_enabled
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_is_zone_enabled() instead")
int raplcap_is_zone_enabled(const raplcap* rc, uint32_t pkg, raplcap_zone zone);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_set_zone_enabled
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_set_zone_enabled() instead")
int raplcap_set_zone_enabled(const raplcap* rc, uint32_t pkg, raplcap_zone zone, int enabled);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_get_limits
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_get_limits() instead")
int raplcap_get_limits(const raplcap* rc, uint32_t pkg, raplcap_zone zone,
raplcap_limit* limit_long, raplcap_limit* limit_short);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_set_limits
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_set_limits() instead")
int raplcap_set_limits(const raplcap* rc, uint32_t pkg, raplcap_zone zone,
const raplcap_limit* limit_long, const raplcap_limit* limit_short);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_get_energy_counter
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_get_energy_counter() instead")
double raplcap_get_energy_counter(const raplcap* rc, uint32_t pkg, raplcap_zone zone);
/**
* Assumes die=0.
*
* @deprecated
* @see raplcap_pd_get_energy_counter_max
*/
RAPLCAP_DEPRECATED("Call raplcap_pd_get_energy_counter_max() instead")
double raplcap_get_energy_counter_max(const raplcap* rc, uint32_t pkg, raplcap_zone zone);
#ifdef __cplusplus
}
#endif
#endif