rapl
zeus.device.cpu.rapl
RAPL CPUs.
-
RAPL (Running Average Power Limit): RAPL is a technology introduced by Intel that allows for power consumption monitoring and control at the processor and memory subsystem level. It provides mechanisms to enforce power limits and manage thermal conditions effectively.
-
Power Zone: A power zone in the context of RAPL refers to a logical grouping of components within the CPU or system that share a common power domain. Each power zone can be monitored and controlled independently. Typical power zones include the entire package, specific cores, and memory subsystems.
-
Package: The package refers to the physical CPU chip, which may contain multiple cores and integrated components. In RAPL, the package power domain encompasses the power consumption of all the cores and integrated units within the CPU package.
RaplWraparoundTracker
Monitor the wrapping around of RAPL counters.
This class acts as a lower level wrapper around a Python process that polls
the wrapping of RAPL counters. This is primarily used by
RAPLCPUs.
Warning
Since the monitor spawns a child process, it should not be instantiated as a global variable. Python puts a protection to prevent creating a process in global scope. Refer to the "Safe importing of main module" section in the Python documentation for more details.
Attributes:
| Name | Type | Description |
|---|---|---|
rapl_file_path |
str
|
File path of rapl file to track wraparounds for. |
max_energy_uj |
float
|
Max value of rapl counter for |
Source code in zeus/device/cpu/rapl.py
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 | |
__init__
__init__(rapl_file_path, max_energy_uj)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rapl_file_path
|
str
|
File path where the RAPL file is located |
required |
max_energy_uj
|
float
|
Max energy range uj value |
required |
Source code in zeus/device/cpu/rapl.py
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 | |
_stop
_stop()
Stop monitoring power usage.
Source code in zeus/device/cpu/rapl.py
102 103 104 105 106 107 108 | |
get_num_wraparounds
get_num_wraparounds()
Get the number of wraparounds detected by the polling process.
Source code in zeus/device/cpu/rapl.py
110 111 112 113 | |
ZeusRAPLNotSupportedError
Bases: ZeusBaseCPUError
Zeus CPU exception class wrapper for RAPL not supported on CPU.
Source code in zeus/device/cpu/rapl.py
157 158 159 160 161 162 | |
__init__
__init__(message)
Source code in zeus/device/cpu/rapl.py
160 161 162 | |
ZeusRAPLFileInitError
Bases: ZeusBaseCPUError
Zeus CPU exception class wrapper for RAPL file initialization error on CPU.
Source code in zeus/device/cpu/rapl.py
165 166 167 168 169 170 | |
__init__
__init__(message)
Source code in zeus/device/cpu/rapl.py
168 169 170 | |
ZeusRAPLPermissionError
Bases: ZeusBaseCPUError
Zeus GPU exception that wraps No Permission to perform GPU operation.
Source code in zeus/device/cpu/rapl.py
173 174 175 176 177 178 | |
__init__
__init__(message)
Source code in zeus/device/cpu/rapl.py
176 177 178 | |
RAPLFile
RAPL File class for each RAPL file.
This class defines the interface for interacting with a RAPL file for a package. A package can be a CPU or DRAM
Source code in zeus/device/cpu/rapl.py
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 | |
wraparound_tracker
property
wraparound_tracker
Return the RaplWraparoundTracker, creating it thread-safely on first access.
__init__
__init__(path)
Source code in zeus/device/cpu/rapl.py
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 | |
__str__
__str__()
Return a string representation of the RAPL file object.
Source code in zeus/device/cpu/rapl.py
296 297 298 299 | |
read
read()
Read the current energy value from the energy_uj file.
Returns:
| Type | Description |
|---|---|
float
|
The current energy value in millijoules. |
Source code in zeus/device/cpu/rapl.py
301 302 303 304 305 306 307 308 309 310 | |
RAPLCPU
Bases: CPU
Control a single CPU that supports RAPL.
Source code in zeus/device/cpu/rapl.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
__init__
__init__(cpu_index, rapl_dir)
Source code in zeus/device/cpu/rapl.py
360 361 362 363 364 | |
get_total_energy_consumption
get_total_energy_consumption()
Returns the total energy consumption of the specified powerzone. Units: mJ.
Source code in zeus/device/cpu/rapl.py
386 387 388 389 390 391 392 | |
supports_get_dram_energy_consumption
supports_get_dram_energy_consumption()
Returns True if the specified CPU powerzone supports retrieving the subpackage energy consumption.
Source code in zeus/device/cpu/rapl.py
394 395 396 | |
get_power_limits
get_power_limits()
Returns the power limits of the CPU package and DRAM zones.
Source code in zeus/device/cpu/rapl.py
398 399 400 401 402 403 | |
ZeusdRAPLCPU
Bases: RAPLCPU
A RAPLCPU that interfaces with RAPL via zeusd.
The parent RAPLCPU class requires root privileges to interface with RAPL. ZeusdRAPLCPU (this class) overrides RAPLCPU's methods so that they instead send requests to the Zeus daemon, which will interface with RAPL on behalf of ZeusdRAPLCPU. As a result, ZeusdRAPLCPU does not need root privileges to monitor CPU and DRAM energy consumption.
See here for details on system privileges required.
Source code in zeus/device/cpu/rapl.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
__init__
__init__(cpu_index, client)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cpu_index
|
int
|
Index of the CPU. |
required |
client
|
ZeusdClient
|
ZeusdClient connected to the daemon. |
required |
Source code in zeus/device/cpu/rapl.py
418 419 420 421 422 423 424 425 426 427 428 429 | |
get_total_energy_consumption
get_total_energy_consumption()
Returns the total energy consumption of the specified powerzone. Units: mJ.
Source code in zeus/device/cpu/rapl.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
supports_get_dram_energy_consumption
supports_get_dram_energy_consumption()
Returns True if the specified CPU powerzone supports retrieving the subpackage energy consumption.
Source code in zeus/device/cpu/rapl.py
448 449 450 | |
get_power_limits
get_power_limits()
Returns the power limits of the CPU package and DRAM zones.
Source code in zeus/device/cpu/rapl.py
452 453 454 | |
RAPLCPUs
Bases: CPUs
RAPL CPU Manager object, containing individual RAPLCPU objects, abstracting RAPL calls and handling related exceptions.
Source code in zeus/device/cpu/rapl.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
cpus
property
cpus
Returns a list of CPU objects being tracked.
__init__
__init__()
Source code in zeus/device/cpu/rapl.py
460 461 462 463 464 465 466 | |
_init_cpus
_init_cpus()
Initialize all Intel CPUs.
Source code in zeus/device/cpu/rapl.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
__del__
__del__()
Shuts down the Intel CPU monitoring.
Source code in zeus/device/cpu/rapl.py
498 499 500 | |
_polling_process
_polling_process(
rapl_file_path, max_energy_uj, wraparound_counter
)
Check for wraparounds in the specified rapl file.
Source code in zeus/device/cpu/rapl.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
rapl_is_available
cached
rapl_is_available()
Check if RAPL is available.
Source code in zeus/device/cpu/rapl.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
get_current_rapl_zone_id
get_current_rapl_zone_id(pid='current')
Return the RAPL package zone ID for the socket the given process runs on.
RAPL exposes one top-level power zone per CPU package (socket) under
/sys/class/powercap/intel-rapl:*. This helper maps a running process to the
RAPL zone ID of the package it is currently executing on, so that zone ID can
be passed as a cpu_indices entry to only measure that socket.
The physical package ID reported by sysfs topology is an arbitrary platform identifier and is not guaranteed to equal the RAPL zone ID, so the mapping is resolved via RAPL's own zone naming:
- Read the logical CPU the process last ran on from
/proc/{pid}/stat. - Read that CPU's physical package ID
Nfrom sysfs topology. - Read that CPU's die ID
Dfrom sysfs topology (if available). - Find the RAPL zone whose
namefile readspackage-Norpackage-N-die-Dand return its zone ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int | Literal['current']
|
The process ID to look up, or "current" for the current process. |
'current'
|
Note
Linux schedulers can preempt and reschedule processes to different CPUs. To
prevent this from happening during monitoring, use taskset to pin
processes to specific CPUs.
Source code in zeus/device/cpu/rapl.py
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 | |
_read_zone_power_limits
_read_zone_power_limits(zone_dir)
Read the power limit state of a RAPL powercap zone.
The kernel numbers constraints from zero without gaps, so reading stops at the first index without a constraint_K_name file.
A constraint attribute the kernel has no value for fails with ENODATA (e.g., the time window of peak_power) and is read as None.
Raises:
| Type | Description |
|---|---|
OSError
|
If a power limit file cannot be read. |
ValueError
|
If a power limit file has an unexpected value. |
Source code in zeus/device/cpu/rapl.py
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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |