Skip to content

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

Open
DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
djdev/macsmc-wktp-full-wake
Open

DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
djdev/macsmc-wktp-full-wake

Conversation

@DjDeveloperr

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).

Assisted-by: LLM (Gemini:4 Neon)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants