fix: deduplicate mirrored Linux RAPL counters - #1276
Conversation
|
Thanks for your contribution, that seems great! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1276 +/- ##
==========================================
+ Coverage 91.58% 91.68% +0.09%
==========================================
Files 49 49
Lines 5100 5136 +36
==========================================
+ Hits 4671 4709 +38
+ Misses 429 427 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hello, you have created more than 20 repository today, I suspect you are an OpenClaw agent. I'm not against AI contribution, but a human must be accountable and willing to contribute to our project. Please respect the PR submission template. We will merge EMI PR in a few days then look back at this PR. |
|
Updated the PR description to the complete repository template, including the required 🟠 AI-generated disclosure. I personally reviewed and tested every submitted line, understand the implementation, and can explain and support it through review and after merge. |
The Windows EMI backend (mlco2#1263) and the Linux RAPL backend (mlco2#1276) both need to detect channels that mirror the same hardware energy counter. Move the tolerance constant and the matching/detection helpers from windows_emi.py to rapl.py, next to RAPLFile, so both backends share one definition instead of duplicating the 1e-6 magic number. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The Windows EMI backend (mlco2#1263) and the Linux RAPL backend (mlco2#1276) both need to detect channels that mirror the same hardware energy counter. Move the tolerance constant and the matching/detection helpers from windows_emi.py to rapl.py, next to RAPLFile, so both backends share one definition instead of duplicating the 1e-6 magic number. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
start() used to permanently remove suspected mirrored counters from self._rapl_files based on a single instantaneous comparison. A file dropped by mistake (two independent packages coincidentally holding the same counter value) was gone for the life of the tracker, and each new start() of a task re-ran the destructive detection on whatever was left. Flag suspected mirrors in a candidate map instead, exactly like the EMI backend does: the files stay monitored, candidates are only left out of the reported details, and every start() re-evaluates the detection from the full set of files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ropping Port the second stage of the EMI mirrored-channel detection (mlco2#1263) that the Linux side was missing: a counter flagged at start() is only dropped for good once it has also accumulated the very same energy as its reference over a measurement interval. A candidate whose delta diverges is a real meter and is restored into the measurement; a candidate that has not accumulated anything stays pending until an interval is conclusive. This prevents a genuine second package from being silently discarded for the life of the run because it coincidentally held the same counter value at start. Unlike EMI, which snapshots a device's channels atomically, the powercap sysfs files are read one after the other, so two views of the same counter differ by the energy accrued between the reads. A relative tolerance alone misses true mirrors when the counters are small (right after a wrap-around, which happens every few minutes on packages with a small max_energy_range_uj). Matching therefore also allows an absolute 1 J difference, both when flagging candidates and when comparing deltas; a wrongly flagged independent package is restored by the confirmation stage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
503f7b8 to
77db9bb
Compare
|
Hello, sorry for the delay. |
Description
Drop mirrored nonzero Linux RAPL package counters at monitoring startup while preserving distinct package counters, zero counters, and DRAM domains. The documentation explains the multi-die mirrored-counter behavior.
Related Issue
Fixes #1274
Motivation and Context
Some Linux multi-die systems expose mirrored package-energy counters. Counting each mirror separately overstates CPU energy consumption, while indiscriminate deduplication could incorrectly remove distinct or zero-valued counters.
How Has This Been Tested?
uv run pytest tests/test_rapl_mmio_scanning.py -quv run pytest tests/test_cpu.py tests/test_rapl_mmio_scanning.py tests/test_rapl_parameters.py -quv run ruff check codecarbon/core/cpu.py tests/test_rapl_mmio_scanning.pyuv run ruff format --check codecarbon/core/cpu.py tests/test_rapl_mmio_scanning.pygit diff --checkScreenshots (if appropriate):
Not applicable.
Types of changes
AI Usage Disclosure
OpenAI Codex assisted with implementation, tests, and documentation preparation. I personally reviewed and tested every submitted line, understand the implementation, and can explain and maintain it.
Checklist: