jouleclaw-energy: a Mac's whole-machine power from the SMC (EnergyDomain::System, ModelBased) #622
Loading…
Reference in a new issue
No description provided.
Delete branch "jouleclaw-energy/smc-system"
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?
On Apple Silicon under macOS 27, IOReport's CPU rails are frozen for an unprivileged reader, so
detect_meterfalls back to the load-average estimator, a guess gradedEstimator. Every Mac still publishes its total power in the SMC keyPSTR, and any process can read it through theAppleSMCKeysEndpointIOKit user client, with no root.What changes
EnergyDomain::System: the whole machine. It covers everything the machine's DC input feeds: the SoC, memory, storage, fans and the rest of the board. It does not cover the power supply's AC-to-DC loss. It containsSocTotaland every other domain.smc(macOS), moduleapple_smc.SmcSystemCounterintegratesPSTRover time and grades the resultModelBased. That is the grade NVML'spower.drawintegral already carries:PSTRis a power reading, not an energy counter, so no liveness probe can vouch for its integral.PSTRmust be a 4-byte float, and the sampler must see it refresh before the counter is available. The first construction in a process waits about a second for that.PSTRrefreshes about once a second (median gap 1.0 s on both Macs below), and it lags a step in load by about one refresh.detect_meterorder on macOS. A live IOReport counter comes first, then the SMC, then the load-average estimator. A figure from the SMC includes whatever else the machine powered, so it can read high for the work but never low.mesh-meter. Its exhaustivecovers_whole_requestmatch now treatsSystemas covering the whole request.ModelBasedrow now lists vendor power sampled and integrated over time (Apple SMCPSTR).MEASURED_ENERGY.mdgets a new section on this meter.energy_probeexample supports--features smcand integrates over at least the counter's minimum window.The feature is opt-in, so existing consumers behave as before until they enable
smc.Measured (macOS 27.2, unprivileged,
energy_probe, 2.5 s CPU churn)ModelBased,SystemModelBased,SystemPSTRequals the DC input (PDTR).Tests
apple-smc: measured. A new macOS CI step greps for that line under--features smcandioreport,smc. The clippy step lints both configurations.ModelBased) where it's built and live, and the estimator otherwise.Passing:
smc,ioreport,smcandioreport(both existing CI greps). Clippy clean in default,ioreport,smcandioreport,smc.mesh-meterwithhw-meter-apple.rapl,nvml, default clippy, andmesh-meterwithhw-meter-rapl.This PR is independent of #618 (RAPL MSR fallback); the two touch different lines.
🤖 Generated with Claude Code