Skip to content

fix(sensors): handle RAPL energy counter wraparound - #445

Open
manunicholasjacob wants to merge 1 commit into
hubblo-org:devfrom
manunicholasjacob:fix/rapl-counter-wraparound
Open

manunicholasjacob wants to merge 1 commit into
hubblo-org:devfrom
manunicholasjacob:fix/rapl-counter-wraparound

Conversation

@manunicholasjacob

Copy link
Copy Markdown

Fixes #280

What: powercap energy_uj counters wrap to 0 after max_energy_range_uj, which scaphandre never read. On a wrap, socket power showed 0 W and domain and host power returned nothing.

How: generate_topology stores each zone's max_energy_range_uj (socket, domain, psys). A pure counter_delta(prev, last, max) returns (max - prev) + last on a wrap and None if the range is unknown; it is used in the three get_records_diff_power_microwatts and Topology::get_records_diff. A host sum of PKG + DRAM has no single range, so it still returns None on a drop; that sum is also what scaph_host_energy_microjoules exports, maybe related to #324 (unchanged).

Tests: 5 new unit tests, including a fake powercap tree via SCAPHANDRE_POWERCAP_PATH (--vm). fmt and the CI clippy command pass. In WSL2 (no powercap), the same 5 hardware tests fail on dev and on this branch. No real RAPL wrap reproduced.

AI-assisted: written with Claude (Anthropic); tests run locally.

powercap energy_uj counters wrap to 0 after max_energy_range_uj. Read
that range for socket, domain and psys zones in generate_topology, and
use a counter_delta helper in the power and energy diff functions so a
wrap gives the real delta. When the range is unknown, the socket path
now returns None instead of reporting 0 W.

Fixes hubblo-org#280

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: manunicholasjacob <manunicholasjacob@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant