open-standards/jcp/jcp-rs
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Transaction Science 1108d507f9 jcp-energy: the per-process rung reads its own count only once the metering thread has left its core
SPEC §5.1 rung 3 already says it: the kernel adds a thread's energy to
its process's count (proc_pid_rusage ri_energy_nj) only when the thread
leaves a core, a process's read of its own count does not take the
reading thread off its core, and an implementation that relies on the
thread having left MUST check that it did. The reference meter did not.
Each end of a span was read from a thread still on its core, so a span
held up to a scheduling quantum of what the thread spent before it and
lacked its own tail, and was graded HwShunt.

Measured on an idle M3 Ultra (macOS 27.0.1) against the tests' own
reader, which sleeps before each read until the process's
context-switch count rose; 40 spans of each kind a run, six runs:
- 1 ms of the metering thread's CPU: all 40 showed no rise and were the
  default-power estimate, every run;
- a 2 ms sleep straight after 8 ms of CPU: 39 or 40 were graded HwShunt
  on the burn before them, about 41 mJ for a sleep.

Now ProcessEnergy::read, the read at each end of a Meter span and of a
FabricMeter span, sleeps (50 us, then 200 us, 1 ms, 5 ms) until the
metering thread's own energy count (proc_pidinfo PROC_PIDTHREADCOUNTS,
decoded only in the one layout known: 88 bytes, two performance levels
here) rose across a sleep, and only then reads the process. An end whose
thread was not seen to leave is not read: the Meter span is the
default-power estimate (process_span's existing path, Estimator, no
measured figure) and the FabricMeter span reports no CPU figure. The
rung opens only where the thread's count reads. The liveness probe still
samples with no sleep. The layout decoding and the rule are pure and
compiled on every platform.

With it, on that host, idle and under 40 busy loops (110 runs): every
span of both kinds was read, the work at 84% or more of the tests' own
window and the sleep at 6% or less of the window that held the burn. A
read costs about 80 us idle and 169 us at the median under the busy
loops, against under 1 us.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 20:50:52 -04:00
..
conformance/v1 jcp: JCR-1 receipts bind their payload — jcp/2 + version dispatch (SPEC §8, C23) 2026-07-18 03:04:19 -04:00
crates jcp-energy: the per-process rung reads its own count only once the metering thread has left its core 2026-10-12 20:50:52 -04:00
Cargo.lock jcp-x402: the settlement record carries its figure's grade; pay meters its compute 2026-10-10 18:05:48 -04:00
Cargo.toml jcp-action-receipt: AR-1, the composition envelope 2026-08-28 08:44:07 -04:00