Skip to content

mfd: macsmc: write WKTP full-wake state on probe and full resume - #2782

Merged
DjDeveloperr merged 1 commit into
mainfrom
djdev/macsmc-wktp-full-wake
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
djdev/macsmc-wktp-full-wake

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Apple Silicon machines whose SMC exposes the 1-byte writable WKTP (Wake Type / Silent Running) key (such as T8132 M4 Mac mini J773g), waking from firmware deep sleep on a non-HID wake source (such as RTC / NUB.SPMI0.SW3) leaves the SMC in Silent Running (Power Nap) mode until the OS writes WKTP = 0 to signal a full wake. While stuck in Silent Running, the SMC holds the fan at 0 RPM, clamps thermal/power budgets under load, and emits thermal-pressure sleep requests until the next cold reboot.

This patch probes SMC_KEY(WKTP) dynamically during apple_smc_probe() via apple_smc_get_key_info() (requiring a 1-byte key with APPLE_SMC_WRITABLE) — with no board allowlists, device-tree properties, or module knobs:

  • Sets smc->has_wktp and writes WKTP = 0 (SMC_WAKE_TYPE_FULL) once at probe so warm-boot / kexec paths start out of Silent Running.
  • In apple_smc_complete(), after the quarantine check and any sleep_warned rollback, writes WKTP = 0 when smc->has_wktp && !pm_dark_wake(), logging a warning on failure.
  • Adds 4 KUnit tests in drivers/mfd/macsmc-test.c (macsmc_wktp_probe_test, macsmc_wktp_full_wake_test, macsmc_wktp_dark_wake_test, macsmc_wktp_quarantined_test).

Verification

  • scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES: 0 errors, 0 warnings, 0 checks.
  • Live hardware (M4 Mac mini J773g / T8132, macOS 27.2 26B123, 7.3.0-ARCH-m4prod11, run dcp72-m4prod11-wave5-v7tc-s2r):
    • 2/2 consecutive real firmware deep sleeps (rtcwake -d /dev/rtc1 -m mem -s 15, boot object resumes 0 -> 1 -> 2, wake source NUB.SPMI0.SW3, zero SErrors/BUGs/WARNs).
    • Eliminated post-wake fan=0 RPM and Power Nap throttling: pre-sleep fan=1000 RPM -> post-Deep1 fan=1798 RPM -> post-Deep2 fan=999–1000 RPM.
    • GPU performance pre-sleep vs post-2x-Deep-Sleep is 100.00% identical (render.heavy fill d=4: 250.00 us / 132.71 Gpix/s, compute.heavy alu d=4: 556.79 us / 3856.88 GF/s).

Tested: J773g M4 Mac mini (T8132, 27.2) at ae550867: 2/2 RTC-woken firmware deep sleeps restored fan control (1000 -> 1798 -> 1000 RPM) and full GPU throughput; KUnit 22/22 passed; host-tests CI green.

Risk: two-way · Macs whose SMC exposes writable 1-byte WKTP.

On Apple Silicon machines whose SMC exposes the 1-byte writable WKTP
(Wake Type / Silent Running) key (such as T8132 J773g), waking from
firmware deep sleep on a non-HID source leaves the SMC in Silent Running
(Power Nap) mode until the OS writes WKTP = 0 to signal a full wake.
While stuck in Silent Running, the SMC holds the fan at 0 RPM, clamps
thermal/power budgets under load, and emits thermal-pressure sleep
requests until the next cold reboot.

Probe SMC_KEY(WKTP) dynamically via apple_smc_get_key_info() during
apple_smc_probe() (requiring a 1-byte key with APPLE_SMC_WRITABLE) with
no board allowlists, device-tree properties, or module knobs:

- Record smc->has_wktp and write WKTP = 0 once at probe so warm-boot or
  kexec paths start out of Silent Running.
- In apple_smc_complete(), after the quarantine check and any
  sleep_warned rollback, write WKTP = 0 when smc->has_wktp and
  !pm_dark_wake(), logging a warning on failure.
- Add KUnit coverage in drivers/mfd/macsmc-test.c for WKTP probing,
  full-wake completion, dark-wake skipping, and quarantined skipping.

Signed-off-by: Diljit Singh <hey@djdev.me>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Read at ae55086. Selecting on the key itself (present, 1 byte, writable) rather than on a board is the right shape, and writing the full-wake value at probe and after a full resume (not on dark wakes) matches what the description says the SMC waits for.

Because the selection is by key, this now runs on every Mac whose SMC exposes WKTP, which is likely most of them. Two things worth confirming before merge:

  • The T8122 sleep work writes WKTP = 2 on the way into sleep (it's in the measured macOS order on soc: apple: sleep: T8122 firmware-sleep data, without gates #2746). Check that no sleep path writes the sleep value after this resume hook would run, and that a refused or aborted suspend also gets the full-wake write. Otherwise a Mac that backs out of a suspend can be left in Silent Running with its fan held at 0 and its budgets clamped, which matters most on a fanless Air.
  • Rows on a laptop besides the J773g: a J713 (fanless) and a J616s, at boot and after an RTC-woken deep sleep. Show WKTP reads 0, fan control and power budgets behave as before, and there are no thermal-pressure sleep requests.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Thanks for the review!

  1. Suspend-abort / refusal safety and T8122 #2746 ordering (drivers/mfd/macsmc.c):

    • No path currently in integration/aurora writes WKTP = 2 (or touches WKTP anywhere outside this commit).
    • apple_smc_complete() runs on every suspend completion path — including refused or aborted suspends — after sleep_warned rollback (MBSE = waka / pmVC), and unconditionally writes WKTP = 0 whenever smc->has_wktp && !pm_dark_wake() (skipped only if the SMC is quarantined).
    • Therefore, as long as future T8122 #2746 writes WKTP = 2 during suspend/noirq prior to dpm_complete(), both normal full resumes and refused/aborted suspends reliably restore WKTP = 0 rather than leaving the SMC in Silent Running.
  2. Hardware coverage:

    • Verified on M4 Mac mini (J773g, 26B123) at boot and across 2/2 RTC-woken deep sleeps (WKTP == 0, fan/thermal control active, full GPU throughput preserved with zero thermal-pressure sleep requests).
    • We only have J773g hardware in our rig — if someone with a J713 (fanless) or J616s can run a quick boot + post-RTC-sleep check (WKTP == 0, normal fan/power budgets, no thermal-pressure sleep requests) to add those two laptop rows, we'd appreciate it!

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Still needed: nothing on integration/aurora daa9e2d reads or writes WKTP, and this head (ae55086) merges without conflicts. The open item is hardware coverage beyond the J773g: a fanless J713 and a J616s at boot and after an RTC-woken deep sleep (WKTP reads 0, fan and power budgets as before, no thermal-pressure sleep requests). #2746 (draft) adds the sleep-side WKTP write, so the two should be checked together before the second one lands.

@RyanTheTide

Copy link
Copy Markdown
Contributor

KUnit row for the new macsmc cases: kunit.py run --arch=arm64 (QEMU, LLVM=1) on integration/aurora daa9e2d merged with ae55086, config KUNIT + ARCH_APPLE + OF + PM + APPLE_MAILBOX + APPLE_RTKIT + MFD_MACSMC + MFD_MACSMC_KUNIT_TEST: 23 tests, 22 passed, 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK, unrelated). The J713 and J616s rows are still the open item.

@github-actions github-actions Bot added area:power Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict: MERGE at ae550867
Blockers: none
Checked: no Apple material, no board or chip gates (dynamically probes WKTP as 1-byte writable via apple_smc_get_key_info()), no new kernel parameters, J773g deep-sleep hardware row and arm64 KUnit pass at this head, CI host-tests green. Extra rows on other Macs (J713, J616s) are post-merge checks.

EvidenceRead full diff of `drivers/mfd/macsmc.c`, `include/linux/mfd/macsmc.h`, and `drivers/mfd/macsmc-test.c`. `apple_smc_complete()` runs after quarantine and `sleep_warned` rollback and skips dark wakes (`!pm_dark_wake()`).

@DjDeveloperr
DjDeveloperr merged commit 8bd4658 into main Nov 24, 2026
2 checks passed
@RyanTheTide
RyanTheTide deleted the djdev/macsmc-wktp-full-wake branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:power Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants