Skip to content

drm/asahi: m3: support firmware-driven deep sleep on T8122 - #3504

Open
satchlj wants to merge 2 commits into
aurora-silicon:mainfrom
satchlj:feat/m3-gpu-deep-sleep
Open

satchlj wants to merge 2 commits into
aurora-silicon:mainfrom
satchlj:feat/m3-gpu-deep-sleep

Conversation

@satchlj

@satchlj satchlj commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

What: Add firmware-driven deep sleep (mem/deep) suspend/resume support for the Apple M3 (G15G / T8122) GPU driver (aurora), draining in-flight work, lowering PS_GFX and releasing the PMP GPU vote on suspend, and warm-restarting RTKit on resume without tearing down DRM/userspace state.
Tested: J613 M3 Air 13" at 8e6a5b8: 3/3 consecutive real mem/deep cycles (boot object resumes 0 -> 1 -> 2 -> 3), GPU firmware warm-restarted in 827–1353 µs (real=true), healthy=1, live Borealis Vulkan and 911 FPS glmark2-es2-drm, 0 failed units.
Risk: two-way · M3 (T8122)
Not yet: M3 Pro / M3 Max (T603x) deep sleep (tested on T8122 J613).

Details
  • Suspend: Drain in-flight GPU work, idle RTKit, release the PMP GPU device power vote, and lower PS_GFX via apple-sleep so the T8122 sleep controller can commit deep sleep.
  • Resume: Restore the PMP GPU power vote and PS_GFX domain, perform an RTKit warm restart of the GPU coprocessor without tearing down DRM/userspace state, and resume command submission.
  • Safety: Avoid sleeping inside RCU read-side critical sections along the suspend/resume path.
Evidence

Verified on MacBook Air 13" M3 (J613, T8122, macOS 26.6.2 / 25G83 firmware) at 8e6a5b81 across 3 consecutive real mem/deep (pm_test=none) cycles:

  • boot object resumes: 0 -> 1 -> 2 -> 3
  • GPU firmware wake latency: 1209 us, 1353 us, 827 us (real=true)
  • /sys/kernel/debug/asahi-m3/progress: healthy=1, completed 311 -> 393 -> 456 -> 529 -> 2353
  • vulkaninfo --summary: Apple M3 (G15G C0), Borealis (Mesa 26.3.0-devel)
  • glmark2-es2-drm --off-screen -b build:duration=2.0: 911 FPS (glmark2 Score: 910)
  • Zero RTKit, IOMMU, or RCU warnings in dmesg; systemctl --failed = 0.

Add system suspend/resume support for the Apple M3 (G15G / T8122) GPU driver across firmware-driven deep sleep:

- Drain in-flight work, idle RTKit, release the PMP GPU power vote, and lower PS_GFX via apple-sleep on suspend so the sleep controller can commit deep sleep cleanly.
- On resume, restore the PMP GPU power vote and PS_GFX domain, perform an RTKit warm restart of the GPU coprocessor without tearing down user DRM state, and resume command submission.
- Avoid sleeping under RCU read locks during the suspend/resume teardown and restart path.

Tested across 3 consecutive real deep sleep cycles (mem/deep, pm_test=none) on MacBook Air 13" M3 (J613, T8122) with live Borealis Vulkan and OpenGL ES (glmark2-es2-drm) rendering after every wake.

Signed-off-by: Satya Benson <[email protected]>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners November 28, 2026 08:56
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at 87596f8a: not ready yet

Check Detail
CI at head no failing: host-tests, host-tests
Review no approved by RyanTheTide, but GitHub does not count it yet (code owner from Core or Omarchy Mac needed, or approval went stale)
Requested changes no requested by DjDeveloperr
Hardware row at head ok comment at 87596f8a
Conflicts ok none
PR text ok Risk: two-way · M3 (T8122)

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 8e6a5b81

Blockers:

  1. pr-text CI failure (runs/46128162271): add the required Tested: line (exact head SHA + Mac + result) and Risk: line (two-way or one-way + affected Macs) to the PR description so pr-text passes.
  2. Wait for the remaining queued KUnit CI jobs to finish green.

Checked:

  • M3 (T8122/G15G) firmware-driven deep sleep suspend/resume path (drain GPU work, idle RTKit, release PMP GPU power vote, lower PS_GFX; restore vote + PS_GFX and warm-restart RTKit on resume) is clean and proven across 3 consecutive real mem/deep cycles on J613 (boot object resumes 0 -> 3).
  • Checked for Apple material, tool attribution, private serials, and board gating: clean; MERGEABLE on main; human Signed-off-by present.
Evidence
  • Head: 8e6a5b81 (base: main, mergeable: MERGEABLE, +674/-20 across 9 files).

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 28, 2026
satchlj added a commit to satchlj/linux that referenced this pull request Nov 28, 2026
Keep .untested = true and .display_no_restart = true on t8122_sleep_soc
so /sys/power/mem_sleep remains [s2idle] by default until all T8122
deep-sleep prerequisites (aurora-silicon#3425, aurora-silicon#3504, aurora-silicon#3445, aurora-silicon#3452) have landed and
27.2-firmware T8122 boards (J615) have a matching display sleep path.

With .untested and .display_no_restart preserved, default s2idle and
apple_sleep.deep=1 dry runs stay intact on both 26.6.2 (J613) and 27.2
(J615), while committed J613 deep sleep runs via apple_sleep.deep=1
apple_sleep.untested_commit=1.

Signed-off-by: Satya Benson <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Second T8122 row, on a J615 (M3 Air 15", 27.2 firmware). Kernel: main 965d4a7 + this PR (8e6a5b8) + #3505 (263ce82), one-shot boot with apple_sleep.deep=1.

  • Boot: clean, 0 failed units, no new kernel errors compared with the same Mac on its normal kernel.
  • s2idle x2 (default path): PASS, same boot, display/Wi-Fi/BT/NVMe back after each.
  • deep: refused at device prepare by the GPU: aurora-g16 292400000.gpu: PM: device_prepare(): genpd_prepare returns -16. On 27.2 the T8122 GPU is taken by the shared G16 backend (g16::claims() in driver.rs), not by the m3 path this PR changes, and G16's T8122 row has deep_sleep: false (g16/hw.rs), so sleep_prepare() returns EBUSY. Clean refusal, same boot, nothing broken.

So on 27.2 boards this PR changes nothing. No regression from the J615, but its deep sleep isn't covered either. That needs the G16 T8122 row to gain deep sleep, which is separate from this PR.

@satchlj

satchlj commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Hardware row at this head on J613 (MacBook Air 13" M3, T8122): 3/3 mem/deep cycles completed with the GPU powered down through this PR.

Setup: main 972a5665 merged with this PR at 8e6a5b81735d, #3590 0f755337, #2163 2115ca6e and #1490 16915f57. Daily command line plus apple_sleep.deep=1 apple_sleep.untested_commit=1. 8 s RTC wakes.

Results:

Not yet: a GPU workload across a deep sleep. The desktop was idle, and this row did not render after each wake.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 8e6a5b81735d

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - M3 (T8122/G15G) firmware-driven deep sleep suspend/resume path (drain GPU work, idle RTKit, release PMP GPU power vote, lower PS_GFX; restore vote + PS_GFX and warm-restart RTKit on resume) is clean and proven across 3 consecutive real mem/deep cycles on J613 (boot object resumes 0 -> 3).

  • Checked for Apple material, tool attribution, private serials, and board gating: clean; MERGEABLE on main; human Signed-off-by present.

Follow-ups (not blocking): add Tested/Risk lines so pr-text passes; queued KUnit

@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Hardware rows at this head (8e6a5b81) on J613 (MacBook Air 13" M3, T8122, 26.6.2 / 25G83 firmware).

Kernel: main 7ccd92ac with #3605 222e0e6b, #3607 40936f13, #3608 87830763, this PR 8e6a5b81 and #3590 0f755337 merged unchanged. linux-aurora packaging and config, non-debug (no BRCMDBG). Booted once on a read-only root with a tmpfs overlay. Each cycle is rtcwake -m mem -s 15 with mem_sleep set to deep, pm_test=none.

Row Cmdline addition Cycles Result
A apple_sleep.deep=1 5 Every suspend stopped before the commit. That is the sleep driver's dry run for T8122 without apple_sleep.untested_commit=1. No hang; the GPU checks passed after each one
A2 apple_sleep.deep=1 apple_sleep.untested_commit=1 5 5/5 deep. boot object resumes 0 → 5; suspend_stats success 0 → 5
B same as A2 10 10/10 deep. boot object resumes 0 → 10; no reset

After every wake, in A2 and B (15 wakes):

  • GPU firmware came back with real=true in 788–1626 µs. Each wake logged PS_GFX lowered via apple-sleep, stopped and released PMP GPU device 5 and GPU domain after the wake: 0x1f0023ff.
  • asahi-m3/progress: healthy=1, with completed climbing (320 → 11257 in A2).
  • vulkaninfo --summary: Apple M3 (G15G C0), Borealis.
  • glmark2-es2-drm --off-screen -b build:duration=2.0: scores from 962 to 1016 (1001 before the first sleep).
  • After each row: 0 failed units, and no new EDAC reports.

Not covered: M3 Pro and M3 Max. Deep sleep still needs apple_sleep.untested_commit=1 on T8122, which is the sleep driver's gate, not this PR's. Wake sources other than the RTC, and sleeps longer than 15 s, were not tested.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aborted deep suspend can leave the GPU offline. In m3_runtime.rs:1619–1624, sleep_suspend detaches the RTKit mailbox and stops the ASC before releasing the PMP vote. If the release returns an error, m3_drm.rs returns before setting sleep_stopped. On PM unwind, sleep_complete sees neither sleep_stopped nor a commit descriptor and reopens submission without restarting the firmware. Track each completed suspend step and recover it on abort. Please test a PMP release failure after ASC stop and verify the GPU still completes work.

The firmware stop in .suspend() detaches the RTKit mailbox, stops the
ASC, then releases the PMP GPU power vote. If the release failed, the
error returned before sleep_stopped was set; on the PM core's unwind,
.complete() saw neither sleep_stopped nor a commit descriptor and
reopened submission on stopped firmware, leaving the GPU offline.

Record each step as it completes (mailbox detached, ASC stopped, PMP
vote released, PS_GFX lowered) in m3_sleep_steps::Steps. .complete()
undoes exactly the recorded steps, in reverse order: raise PS_GFX only
if it was lowered, take the PMP vote again only if it was released,
then warm-restart the coprocessor whenever any step ran, before
submission reopens. A stop that never started leaves firmware alone, as
before. If the undo itself fails, the runtime is marked failed and
pending work is failed, as for a failed wake.

The step sequence and the undo plan live in a module with no kernel
dependencies, so the production code runs in host tests
(tools/asahi/m3-sleep-steps-tests.py). They inject a PMP release
failure after the ASC stop and an ASC stop failure after the mailbox
detach, and check that firmware is restarted, without re-acquiring a
vote that was never released, before submission may reopen. Two
negative controls (restart only after a full stop; record the ASC stop
only after the PMP release) are both killed.

Signed-off-by: Satya Benson <[email protected]>
@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@DjDeveloperr Thanks, you're right: that abort path reopened submission on stopped firmware. Head 8e6a5b81 → 87596f8a (one commit appended, no rebase).

What changed (87596f8a, "drm/asahi: m3: track each deep-sleep stop step and undo it on abort")

  • New m3/m3_sleep_steps.rs records each suspend step as it completes: MAILBOX_OFF, ASC_STOPPED, PMP_RELEASED, PS_LOWERED. Runtime::sleep_suspend() runs the stop through m3_sleep_steps::stop(), so a failure at the PMP release leaves MAILBOX_OFF | ASC_STOPPED recorded. Backend::sleep_suspend() records PS_LOWERED where it used to set sleep_stopped, which this commit removes.
  • Backend::sleep_complete() takes the recorded steps and undoes exactly those, in reverse order (m3_sleep_steps::complete()):
    • raise PS_GFX and hand it back from apple-sleep, only if it was lowered;
    • take the PMP vote again, only if it was released;
    • then warm-restart the coprocessor and RTKit whenever any step ran.
      Submission reopens (sleep_unhold()) only after the restart succeeds. If the undo fails, the runtime is marked failed and pending work is failed (sleep_fail()), as for a failed wake. When no step ran (a stop that never started, or the commit-descriptor path), the firmware is left alone, as before.
  • In your case (the PMP release fails after the ASC stop), .complete() now warm-restarts the firmware without re-acquiring a vote that was never released, then reopens submission.

Tests

  • Host test tools/asahi/m3-sleep-steps-tests.py, registered in run-host-tests.py. It builds the production module with rustc --test against a GPU model whose firmware runs only with the mailbox attached, the ASC running and the vote held:
    • pmp_release_failure_after_asc_stop_restarts_firmware: injects the release failure after the ASC stop and asserts the recorded steps, the plan (restart, no PMP acquire, no PS raise), the call order and that firmware is running again before submission reopens.
    • Also: an ASC stop failure after the mailbox detach; a full stop, which restores power before the restart; no step, which leaves firmware alone; and a failed re-acquire, which reports the error and does not restart.
    • Negative controls --mutate restart-only-full-stop (the old behaviour) and --mutate late-asc-mark are both killed.
  • Results: 3/3 runs pass (5/5 tests; both mutants killed). drivers/gpu/drm/asahi/ builds (arm64, LLVM, CONFIG_DRM_ASAHI_M3_T8122=y) with no warnings in the touched files.

Untested on hardware. "The GPU still completes work after an aborted suspend" has not run on a Mac at 87596f8a, and the original 3-cycle deep row was at 8e6a5b81. Rows owed on J613, default command line, mem_sleep=deep:

  1. Aborted suspend after the ASC stop. Make the PMP release fail once after stop_asc(), using a one-shot debug fault-injection build of this head (not part of the PR), then run echo mem > /sys/power/state. Pass: the suspend is refused, dmesg shows sleep stop failed ... after steps 0x3 then firmware back in ... plan=Plan { raise_ps: false, acquire_pmp: false, restart: true }, healthy=1, and vkcube --c 300 plus glmark2-es2-drm complete afterwards.
  2. Regression of the normal path. 3 consecutive real deep cycles at 87596f8a: boot object resumes increment, firmware back with plan showing all three set, live Borealis Vulkan and glmark2-es2-drm after each wake, 0 failed units, 0 new kernel errors.

Our J613's recovery path is down right now, so these wait until it is back. I'll post them as a regression request.

@satchlj
satchlj requested a review from DjDeveloperr December 1, 2026 14:07
@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) and removed ci-failing A check failed at the PR head (bot) labels Dec 1, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the reported abort. A failed PMP release after ASC stop now leaves enough state for completion to restart the firmware before reopening submissions. It reacquires the vote only when the release succeeded. The focused fault-injection test covers the reported ordering.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 2026
@satchlj satchlj closed this Dec 1, 2026
@satchlj satchlj reopened this Dec 1, 2026
@satchlj satchlj closed this Dec 1, 2026
@satchlj satchlj reopened this Dec 1, 2026
@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Hardware row (Row 2) on MacBook Air 13" M3 (J613, T8122, 26.6.2 / 25G83 stub), exact head 87596f8a merged onto main 645b086d, non-debug kernel, apple_sleep.deep=1 apple_sleep.untested_commit=1, mem_sleep=deep:

  • 3/3 deep sleep cycles (rtcwake -m mem -s 15), no reset, 0 failed units, EDAC delta 0:
    • apple-sleep: back from sleep, boot object resumes 0 -> 1 -> 2 -> 3 (suspend_stats/success 0 -> 3).
    • GPU suspend/resume per cycle:
      • Cycle 1: M3 GPU: stopped and released PMP GPU device 5 in 430 us, PS_GFX lowered via apple-sleep (saved=0x1f0023ff, auto_off=0, lower=0), firmware back in 1875 us (real=true plan=Plan { raise_ps: true, acquire_pmp: true, restart: true })
      • Cycle 2: stopped in 418 us, firmware back in 1214 us (real=true plan=Plan { raise_ps: true, acquire_pmp: true, restart: true })
      • Cycle 3: stopped in 342 us, firmware back in 1141 us (real=true plan=Plan { raise_ps: true, acquire_pmp: true, restart: true })
    • Post-wake GPU checks (baseline and after wakes 1–3): asahi-m3 progress healthy=1 (completed 284 -> 2418 -> 4622 -> 6813), vulkaninfo --summary lists Apple M3 (G15G C0) with Borealis, glmark2-es2-drm --off-screen -b build:duration=2.0 scores 985 -> 989 -> 1004 -> 985.
    • Timed 4 s audio capture (48000 / 44100 Hz) stayed at 4010–4017 ms after every wake; Wi-Fi rejoined on every wake.

Not yet tested on hardware at 87596f8a:

  • Row 1 (injected one-shot PMP-release failure after ASC stop on a debug build — currently building, will post once run).
  • T603x hardware; wakes other than 15 s RTC; deep sleep without apple_sleep.untested_commit=1 (sleep-driver T8122 gate).

This branch has not been deployed

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

Labels

area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants