You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/48-energy/README.md
+49-17Lines changed: 49 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -410,6 +410,46 @@ Performance Analysis:
410
410
- Traditional samples at fixed intervals (100ms)
411
411
```
412
412
413
+
### Hardware RAPL Energy Measurements
414
+
415
+
The energy monitor now includes **native support for Intel RAPL (Running Average Power Limit) hardware counters**, providing real-time energy measurements directly from CPU hardware instead of relying on software estimation. RAPL is available on Intel processors since Sandy Bridge (2011) and AMD processors since Zen+ (2019).
416
+
417
+
When RAPL is available, the tool automatically detects and uses hardware energy counters through the Linux `perf_event` interface. This provides several significant advantages over software estimation: it captures actual power consumption including dynamic frequency scaling (DVFS), CPU idle states (C-states), and voltage changes that simple time-based estimation cannot account for. RAPL measures multiple energy domains including the entire CPU package, individual cores, integrated graphics (uncore), and DRAM, giving you a complete picture of system energy consumption.
418
+
419
+
To use RAPL hardware measurements:
420
+
421
+
```bash
422
+
# Automatic RAPL detection (default behavior)
423
+
sudo ./energy_monitor -d 10
424
+
425
+
# Disable RAPL and use software estimation
426
+
sudo ./energy_monitor -d 10 --no-rapl -p 15.0
427
+
428
+
# Check RAPL availability on your system
429
+
ls /sys/bus/event_source/devices/power/events/
430
+
```
431
+
432
+
Example output with RAPL enabled:
433
+
434
+
```
435
+
RAPL initialized with 2 domains
436
+
Using hardware RAPL energy counters
437
+
Energy monitor started... Hit Ctrl-C to end.
438
+
439
+
=== Energy Usage Summary ===
440
+
PID COMM Runtime (ms) Energy (mJ)
441
+
...
442
+
443
+
=== RAPL Hardware Energy Measurements ===
444
+
pkg : 231.716422 J (231716.42 mJ)
445
+
cores : 159.937200 J (159937.20 mJ)
446
+
447
+
Total RAPL energy: 391.653622 J (391653.62 mJ)
448
+
Measurement method: Hardware RAPL counters
449
+
```
450
+
451
+
The RAPL measurements show total system energy consumption across all processes, while the per-process CPU time breakdown helps identify which applications consumed the most CPU cycles. For more information about RAPL and power capping, see the [Linux Powercap Framework documentation](https://docs.kernel.org/power/powercap/powercap.html).
452
+
413
453
## Understanding Energy Monitoring Trade-offs
414
454
415
455
While our energy monitor provides valuable insights, it's important to understand its limitations and trade-offs:
@@ -470,25 +510,17 @@ As a **teaching tool**, energy monitoring makes abstract concepts tangible by sh
470
510
471
511
## Extending the Energy Monitor
472
512
473
-
The current implementation provides a solid foundation for building more sophisticated energy monitoring capabilities. Several enhancement directions offer significant value for different deployment scenarios.
474
-
475
-
| Extension Area | Implementation Approach | Value Proposition |
|**Hardware Counter Integration**| Integrate RAPL counters via `PERF_TYPE_POWER` events | Replace estimation with actual hardware measurements |
478
-
|**Per-Core Power Modeling**| Track core assignment and model P-core vs E-core differences | Accurate attribution on heterogeneous processors |
479
-
|**Workload Classification**| Classify CPU-intensive, memory-bound, I/O-bound, and idle patterns | Enable workload-specific power optimization |
480
-
|**Container Runtime Integration**| Aggregate energy by container/pod for Kubernetes environments | Cloud-native energy attribution and billing |
481
-
|**Real-time Visualization**| Web dashboard with live energy consumption graphs | Immediate feedback for energy optimization |
513
+
The current implementation includes **native RAPL hardware counter support** for real-time energy measurements and provides a solid foundation for building more sophisticated energy monitoring capabilities. Several enhancement directions offer significant value for different deployment scenarios.
482
514
483
-
**Hardware counter integration** represents the most impactful enhancement, replacing our simplified estimation model with actual hardware measurements through RAPL (Running Average Power Limit) interfaces. Modern processors provide detailed energy counters that can be read via performance events, offering precise energy measurements down to individual CPU packages.
515
+
| Extension Area | Implementation Status | Value Proposition |
|**Hardware Counter Integration**| ✅ **Implemented** - RAPL counters via `perf_event_open()`| Actual hardware measurements with automatic fallback |
518
+
|**Per-Core Power Modeling**| Future enhancement | Accurate attribution on heterogeneous processors (P-cores vs E-cores) |
519
+
|**Workload Classification**| Future enhancement | Enable workload-specific power optimization |
520
+
|**Container Runtime Integration**| Future enhancement | Cloud-native energy attribution and billing |
521
+
|**Real-time Visualization**| Future enhancement | Immediate feedback for energy optimization |
484
522
485
-
```c
486
-
// Read RAPL counters for actual energy measurements
487
-
struct perf_event_attr attr = {
488
-
.type = PERF_TYPE_POWER,
489
-
.config = PERF_COUNT_HW_POWER_PKG,
490
-
};
491
-
```
523
+
**Hardware counter integration (✅ Implemented)**: The energy monitor now includes full RAPL support, reading actual hardware energy counters through the Linux `perf_event` interface. This provides precise energy measurements across multiple domains (package, cores, DRAM) and automatically falls back to software estimation when RAPL is unavailable. See the [Hardware RAPL Energy Measurements](#hardware-rapl-energy-measurements) section above for usage details.
492
524
493
525
**Per-core power modeling** becomes essential on heterogeneous processors where performance cores and efficiency cores have dramatically different power characteristics. Tracking which core each process runs on enables accurate energy attribution:
0 commit comments