fix: skip uncorrectable RAPL counter wraps - #1321
davidberenstein1957 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1321 +/- ##
==========================================
+ Coverage 91.43% 91.62% +0.18%
==========================================
Files 49 49
Lines 5057 5072 +15
==========================================
+ Hits 4624 4647 +23
+ Misses 433 425 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4e88977 to
d4a9959
Compare
When `max_energy_range_uj` is unreadable, `max_energy_reading` is 0, so the wrap-around branch still ran but corrected nothing, emitting a large negative energy delta straight into the CPU and total energy. Drop the sample instead, matching the EMI backend's behaviour. The same guard also covers driver resets and the transient read-error fallback. A failed read previously returned `Energy(0)`, which looked like a wrap-around and, with a readable `max_energy_range_uj`, injected a spurious positive delta of up to one counter range. `_get_value` now returns None, and the sample is skipped and re-baselined. The uncorrectable-wrap warning is emitted once per file instead of on every measurement cycle. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
d4a9959 to
f59ac22
Compare
Verdict: 🔧 Request changes (small)The bug is real, and worse than the description says:
Returning Must fix:
Should fix: Nit:
|
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Made the changes in b5aaca1: merged master, skipped unreadable (None) counters in the start() mirror detection with a test, and reworded the description (scope, plus the |
Description
RAPLFile.delta()now re-checks the wrap correction: if the corrected reading is still below the previous one, the sample is dropped (zero energy delta, zero power) with a warning, instead of emitting a negative energy delta.RAPLFile._get_value()now returnsNoneinstead of0when the counter can't be read, anddelta()re-baselines on the next readable value.IntelRAPL.start()skips unreadable counters in the mirror detection.Related Issue
Fixes #1309
Motivation and Context
max_energy_range_ujis set to0whenever it cannot be read (codecarbon/core/rapl.py:45). The comment claims wrap detection is then disabled, but only the correction was disabled; the wrap branch still ran and producedenergy_delta = energy - last_energy, a large negative value (up to -1.19e-3 kWh for a 2^32 uJ package domain). That flowed unchecked into_total_energy/_total_cpu_energy, and theabs()inPower.from_energies_and_delaymasked it in the power column. Dropping a sample loses at most one interval of genuine energy, which is strictly better than subtracting an hour's worth. This mirrors whatcodecarbon/core/windows_emi.py:566-574already does for EMI. Systems wheremax_energy_range_ujis readable are unaffected.Note from the author: with a readable max, a driver reset or suspend/resume still becomes
energy + max - last, a large positive delta; a plausibility bound (e.g. TDP x interval) is left for a follow-up. This PR should land before therapl_include_dramchange, since DRAM domains have smaller max ranges and wrap far more often.How Has This Been Tested?
tests/test_rapl_permissions.py:test_rapl_wraparound_without_max_skips_samplefails on master (energy_delta.kWhis about -1.11e-3), passes here.test_rapl_wraparound_with_max_is_correctedpins the existing wrap correction against regression.uv run pytest tests/test_rapl_permissions.py -q-> 2 passed, 2 skipped (the pre-existing Linux-only cases).black --checkclean;ruffreports only pre-existing findings in the touched files.Screenshots (if appropriate):
N/A
Types of changes
AI Usage Disclosure
Checklist: