Skip to content

FFM CPU temperature on Apple Silicon is nondeterministic and diverges from JNA #3529

Closed

Description

@dbwiddis

Found incidentally while smoke-testing #3528 on an M2 Max (macOS 15, JDK 25). Not caused by that PR — reproduced on unmodified master.

Symptom

hal.getSensors().getCpuTemperature() on the FFM provider returns one of two values across runs, from the same binary with no other change:

oshi.ffm.SystemInfo   6.699999809265137
oshi.ffm.SystemInfo  57.995201110839844   /  60.15781784057617  /  61.729740142822266

The JNA provider is stable and plausible on the same machine at the same moment:

oshi.SystemInfo      59.12498092651367

So the FFM path intermittently reports ~6.7 °C where JNA reports ~59 °C. It is not thermal variation — 6.7 is bit-for-bit identical every time it appears, and it alternates run to run rather than drifting.

Reproduction

Verified the flake is pre-existing by stashing the #3528 changes, rebuilding oshi-core-ffm from master, and re-running: master produced 6.699999809265137 on three consecutive runs and 57.995201110839844 on another. The #3528 branch produced both values too. Both branches show both values, so the variable is not the code under change.

Suspected cause

SmcUtilFFM.smcGetFirstFloat(conn, SMC_KEYS_CPU_TEMP_AS) returns the first key whose value is > 0, scanning Tp09, Tp0T, Tp01, Tp05, Tp0D. A key that intermittently yields a small bogus reading would be accepted and short-circuit the scan, which matches the exactly-repeating 6.7. Worth checking whether the SMC key-info cache (KEY_INFO_CACHE) is being populated with a stale or wrong dataSize/dataType on some open, since that would change how the same bytes are decoded.

A useful first diagnostic would be logging each key's raw bytes, dataSize and dataType per read and diffing a 6.7 run against a 59 run.

Scope

Apple Silicon path only. Not investigated on Intel Macs, and the non-_AS key (TC0P) was not exercised here.

Activity

  1. added
    bug?
    on Jul 26, 2026
  2. dbwiddis commented on Jul 26, 2026

    @dbwiddis
    MemberAuthor

    Investigated on the M2 Max. The premise of this issue is wrong — there is no FFM/JNA divergence, and no nondeterminism. Correcting the record, and re-scoping to the real bug underneath.

    There is no divergence

    Reading the raw SMC payload from both implementations at the same moment gives byte-identical results:

    key    rc   size   type   bytes          (JNA)        key    rc   size   type   bytes          (FFM)
    Tp09   0    4      flt    66 66 d6 40                 Tp09   0    4      flt    66 66 d6 40
    Tp0T   0    0                                         Tp0T   0    0
    Tp01   0    4      flt    66 66 d6 40                 Tp01   0    4      flt    66 66 d6 40
    Tp05   0    4      flt    89 41 94 40                 Tp05   0    4      flt    89 41 94 40
    Tp0D   0    4      flt    89 41 94 40                 Tp0D   0    4      flt    89 41 94 40
    

    66 66 d6 40 little-endian is exactly 6.7f. Interleaving the two implementations over repeated samples gave 0 disagreements in 12 rounds, and 7/7 agreement across a load transition. Both decode correctly; both see the same bytes.

    What is actually happening

    The value tracks CPU cluster activity, deterministically and reversibly:

    phase     JNA        FFM        agree
    QUIET     6.700      6.700      yes
    QUIET     6.700      6.700      yes
    LOADED    52.654     52.654     yes
    LOADED    53.274     53.274     yes
    LOADED    53.807     53.807     yes
    QUIET2    6.700      6.700      yes
    QUIET2    6.700      6.700      yes
    

    When the P-cores are idle, the SMC parks these sensors and returns a fixed sentinel — 6.700 for Tp09/Tp01 and 4.633 for Tp05/Tp0D. Two telltales that these are not readings:

    • In the parked state the sensors are pairwise exactly equal. Under load they differ (52.630 / 53.113 / 50.482 / 51.162), as independent sensors should.
    • 6.7 °C is below room ambient, so it cannot be a die temperature.

    Sustained load brings them live within ~1.6 s; they park again within ~1.5 s of the load stopping. What looked like run-to-run flakiness was just whether the machine happened to be busy.

    The real bug

    smcGetFirstFloat accepts any value > 0, so it returns the parked 6.700 as the CPU temperature whenever the machine is idle — which is most of the time. Both implementations share this, since the logic is duplicated in SmcUtil and SmcUtilFFM, so any fix belongs in both twins (and likely the GPU path, which uses the same helper).

    Sensors#getCpuTemperature documents 0 or NaN as "unavailable", so rejecting an implausible reading and returning 0 is contractually clean.

    Rejecting on a plausibility floor is more robust than matching the sentinel values, which are probably model-specific — I have only verified 6.700/4.633 on one M2 Max. A die below ~10 °C is not physical in any room someone is running a machine in, and idle Apple Silicon normally sits around 25-40 °C, so a floor in that gap discards the sentinel without ever rejecting a genuine reading.

    Retitling suggestion: "Apple Silicon idle CPU/GPU temperature reports an implausible parked sensor value".

  3. dbwiddis commented on Jul 27, 2026

    @dbwiddis
    MemberAuthor

    One more observation that firms up the diagnosis: the parked values split along cluster lines, not randomly.

    Tp09 = Tp01 = 6.700    <- both P-core sensors on M2
    Tp05 = Tp0D = 4.633    <- both E-core sensors on M2
    

    Within a cluster the readings are bit-identical; under load the same sensors diverge (52.630 / 53.113 / 50.482 / 51.162). One gated cluster reporting a single floor explains that; uninitialized memory or independent sensors would not produce two exact pairs that split on the P/E boundary.

    Two notes for whoever writes the fix, both pointing the same way:

    • Per exelban/stats#1703 the SMC firmware is inconsistent between devices even when they share an SoC, so 6.700/4.633 are likely specific to this M2 Max. Matching sentinel values would not travel.
    • Per exelban/stats#1012 the same key changes meaning across generations — Tp05 is a P-core on M1 Pro/Max but an E-core on M2 — so per-key special-casing would rot. Validity has to be judged from the value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug?

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions