a process reads its own energy only once the reading thread has left its core #229
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/in-process-self-read-fold"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
The kernel adds a thread's CPU energy to its process's count (
ri_energy_nj) only when that thread leaves its core. So a process reading its own count from a running thread does not see that thread's latest energy:#214 measured this and fixed it in sandbox-meter. Four other crates carry their own in-process counter and read it with no check, and they meter short spans: proof attempts, cascade lookups, flow scans, served requests.
Measured on an idle M3 Ultra, before the fix. In every one of the four crates:
An idle host is the worst case, because nothing takes the reading thread off its core but its own quantum. A loaded M5 Max showed 60–78%.
What
Each crate keeps its own code, since the standards do not depend on each other. The rule is the same in all four.
The rule. Before a self-read, sleep (50 µs, then 200 µs, 1 ms, 5 ms) until the reading thread's own energy count has moved across a sleep. That count is
proc_pidinfoflavour 34, a private-header flavour, used only where it reads in the expected layout. A read that is not seen to fold is no reading: the span takes the crate's existing estimate path. It is never a zero, and never a short figure under a hardware label. Reads of another process (a child, a tree) are not folded.Per crate:
ProcessCpuCounter, and through itProcessSpanMeter's CPU half, mesh'sProcessMeterand the fabric calibration. AddsEnergyError::NotFolded.ProcessEnergyrung. An unverified end falls to the default-power estimate.measure_marginal. That measurement was already one span around a batch.Docs: each crate's module docs,
jouleclaw/SPEC.md§1.3, and the eoc SCI annex. The annex's "accrues in lumps" observation now carries its mechanism and the remedy; its measured figures stand.Evidence (M3 Ultra, idle unless stated)
HwShunt, ≥985/1000 of the oracleHwShunton the burn → 40/40, ≤4/1000ri_energy_njfrom a raw buffer. It shares no code with the meter.ioreport: 129;fabric-meterpass;jcp-conformanceandproof-conformancepass;gen-vectorsoutput is byte-identical toproof/conformance/v1;Not covered
🤖 Generated with Claude Code