Skip to content

soc: apple: sleep, mfd: macsmc: T6050: the wake's sources in macOS's order - #2611

Merged
DjDeveloperr merged 1 commit into
integration/aurorafrom
djdev/m5-t6050-wake-sources-macos-order
Nov 21, 2026
Merged

DjDeveloperr merged 1 commit into
integration/aurorafrom
djdev/m5-t6050-wake-sources-macos-order

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

On the J714s (M5 Pro), about 2 in 84 deep sleeps woke early: 0.5-13 s into a 60 s alarm, with MBSW 0 and the PMU's alarm not fired. Nothing named the source. This copies how macOS's wake handles its wake sources, taken from the macOS-HV rings of three docked sleeps (mxt4, dk1, dk2). Times are from the wake.

ms macOS
57 Each SPMI controller's handler (nub-spmi0, nub-spmi-a0, nub-spmi-a1) reads its latched sources (+0x600..+0x61c). It acks each set source that is enabled (+0x400..) and masks it until its driver has seen it: nub-spmi0 0x02 (the PMU), nub-spmi-a1 0x0B, and in dk1 nub-spmi-a0 0x3F. Set sources that aren't enabled stay set.
63 AP ON to the SMC (mxt4, dk1)
66-69 MBSE read (0x10650), MBSW read, MBSE = waka, then MSLD
95 PMU: RTC control read, boot stage 0xf801 = 0xfe, then the same reads as at entry

Its console logs system wake events: NUB.SPMI0Sw3IRQ nub-spmi0.0x02 nub-spmi-a1.0x0B rtc.

Linux acked only nub-spmi0's PMU sources. It wrote the PMU boot stage before AP ON and before the SMC's wake record, so MBSE read 0x106fe instead of macOS's 0x10650. It logged only the AP status bits.

Changes

  • t6050_spmi_src_ack() replaces t6050_spmi_pmu_ack(). At entry and at wake, it acks each latched and enabled source on nub-spmi0 and on every apple,spmi-buses controller, plus nub-spmi0's DT PMU sources. The enables are left alone.
  • macsmc gets a new saved op, .woken. Right after .end's AP ON at the platform wake, it reads MBSE and MBSW, writes waka and reads MSLD, all polled. The noirq resume keeps pmVC (58 ms floor after waka), the lid handling and the dark wakes. It takes the record itself when .woken didn't run or got no clean record; a failed first read logs no record line. Both wait for an ordinary command's in-flight reply through one helper, apple_smc_poll_in_flight(). A new scope's begin, and a resume that bails, clear what an earlier wake left (woken_done, saved_wake).
  • New sleep op .pmu_wake, run after the SMC's commands. For T6050 it reads the RTC control, writes the DT boot stage and does the DT reads.
  • One wake events: line per wake, in macOS's form: AP sources by ADT name, acked SPMI sources as <controller>.0x<source>, and rtc. The raw words go to the debug log.

The AP wake masks are unchanged: macOS arms the same 28 sources, ATC1/ATC2.PMGRUSBWakeup included. The J716c shares the T6050 ops and SMC policy, so it gets the same order; the traces are from the J714s. There is no switch: the new steps key on the DT (apple,spmi-buses, apple,spmi-pmu-sources, apple,pmu-wake-stage, apple,pmu-sleep-reads, the wake block), the controllers' own enables and the driver's state; no module parameter, no SoC or board check.

Testing

  • Host compile checks (asahi profile, W=1): clean, also with CONFIG_KUNIT=y and CONFIG_MFD_MACSMC_KUNIT_TEST=y.
  • Independent reviews: v1 FAIL (a BUILD_BUG_ON array size), v2 FAIL (KUnit build break in macsmc-test.c), v3, v4 and v5 PASS-WITH-NITS. Every finding is fixed in this head or listed as a follow-up. This head's own review is on the PR.
  • J714s hardware, kit m5-test/kitN3-20261120 (this change's code on the kitI1 stack; later revisions changed only the failure paths, the wording and the shared wait helper): 5 deep sleeps on 60 s alarms, 0 early wakes, all 5 wake reasons named.
    • Every wake: wake record: MBSE 0x10650, MBSW 0, macOS's value (Linux read 0x106fe before), and wake events: NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc, macOS's form.
    • One of the five woke on time, but the harness gave up waiting for SSH: Wi-Fi took about 270 s to reconnect after the N1's re-probe. That is a separate Wi-Fi bug with its own lane; the kernel was up throughout.
  • The rest of the count toward 40 sleeps comes after the merge, from the new default's sleeps and the soaks.

🤖 Generated with Claude Code

@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-t6050-wake-sources-macos-order branch 3 times, most recently from 448120a to 8aa11d7 Compare November 20, 2026 23:33
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the trace table. The ordering change reads cleanly, and .woken only takes effect where a T6050 smc_policy exists, so the J813 and T8132 macsmc paths are untouched. A few points:

  • sleep-t6050.h, comment above t6050_spmi_src_ack(): "Linux takes no SPMI interrupt" holds for today's T6050 DT, but spmi-apple-controller.c:418-503 already provides an irq_domain for the 256 peripheral sources (edge handler, acks in the same 0x600 words). Once a driver maps one of them, the blanket write-1-to-clear at entry and at wake will swallow its edge. Could the ack skip sources that have a mapping in the controller's domain, or could the comment at least name this limit?
  • t6050_sleep_after_ans(): the entry ack now clears every latched and enabled source on all eight controllers, not only the PMU's, so an event that latches during suspend no longer stops the sleep. spmi_src_valid is cleared straight afterwards, so nothing records what was dropped. A dev_dbg of the entry's acks would make a missed wake traceable later.
  • apple_smc_sleep_saved_woken(): the in-flight reply wait can now spin for up to 200 ms inside the platform wake, under the SMC's device lock. A note on why that bound is acceptable there would help.
  • Testing: the J716c gets the same order through the shared ops but has no trace and no row. Please mention it alongside the J714s counts, or keep it on the old order until it has a row.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-t6050-wake-sources-macos-order branch from 8aa11d7 to f796159 Compare November 21, 2026 03:27
…order

About 2 in 84 of the J714s's deep sleeps end early (0.5-13 s into a
60 s alarm, MBSW 0, the PMU's alarm not fired) with nothing that names
the source. macOS's wake handles its wake sources in a fixed order. From
the macOS-HV rings of three docked sleeps (mxt4, dk1, dk2; dk2 hooked
the SPMI controllers only), with times from the wake:

- 57 ms: each SPMI controller's handler (nub-spmi0, nub-spmi-a0,
  nub-spmi-a1) reads its eight latched-source words (+0x600..+0x61c).
  It acknowledges each set source that is enabled (+0x400..), and masks
  it until its driver has seen it. Those were nub-spmi0's 0x02 (the
  PMU), nub-spmi-a1's 0x0b, and in dk1 also nub-spmi-a0's 0x3f. Set
  sources that aren't enabled stay set. At run time the handler takes
  each source as it comes, so none is pending at a sleep's entry.
- 63 ms (mxt4, dk1): AP ON to the SMC. At 66-68 ms MBSE is read
  (0x10650), MBSW is read, and MBSE = waka; at 68.6-69.0 ms MSLD.
- 95 ms: the PMU. Its RTC control is read, the boot stage
  0xf801 = 0xfe is written, and then 0xf801, 0xf808, 0xf802, 0xf818,
  0xf819, 0xf800 and 0xa7dc are read (the DT's apple,pmu-sleep-reads,
  as at the entry).
- Its console logs "system wake events: NUB.SPMI0Sw3IRQ nub-spmi0.0x02
  nub-spmi-a1.0x0B rtc" (wm2), and pmset the same names.

Linux acknowledged only nub-spmi0's PMU sources. It wrote the PMU's
boot stage before AP ON and before the SMC's wake record, so MBSE read
0x106fe. It logged only the AP status bits.

Do as macOS does:

- t6050_spmi_src_ack() replaces t6050_spmi_pmu_ack(). At the entry,
  before the sleep's masks, and at the wake, before the run-time masks,
  it acknowledges each set and enabled source, and nub-spmi0's DT PMU
  sources, on nub-spmi0 and on every apple,spmi-buses controller. The
  enables are left alone. A set source that is enabled holds the
  controller's output up, and nub-spmi0's outputs are AP wake sources.
- macsmc gets a new saved op, .woken. Right after .end's AP ON at the
  platform wake, it reads MBSE and MBSW, writes waka and reads MSLD,
  polled, after any ordinary command in flight has had its reply polled
  in, as the noirq resume does (one helper, apple_smc_poll_in_flight(),
  now does that wait for both). The noirq resume keeps pmVC (the
  policy's 58 ms floor after waka; macOS's came 55-62 ms after), the
  lid's handling and the dark wakes. It takes the record itself if
  .woken didn't run for this wake or didn't get both a clean record and
  waka (an ordinary command released with the scope can make one fail
  for the moment). A failed read in that first try logs no record line,
  so it never leaves an all-zero one; the noirq resume logs the record
  it reads. After a clean read and a failed waka, both record lines are
  real ones. A
  new scope's begin, and a resume that bails, clear what an earlier wake
  left (woken_done, saved_wake).
  The KUnit tests' calls take the path without a policy (woken false).
- The sleep core gets a new op, .pmu_wake, run after the SMC's commands.
  For T6050 it reads the PMU's RTC control, writes the DT's boot stage
  and does the DT's reads. .finish writes the stage itself only for an
  attempt that never committed.
- After each wake, one line in macOS's form: "wake events:" with the
  set AP sources by their ADT names, the acknowledged SPMI sources as
  <controller>.0x<source>, and "rtc" if the PMU's alarm fired. The raw
  words go to the debug log.

The AP wake masks are unchanged: macOS arms the same 28 sources,
ATC1/ATC2.PMGRUSBWakeup among them. The J716c shares the T6050 ops and
the SMC policy and gets the same order; the traces are J714s ones.

Signed-off-by: Diljit Singh <hey@djdev.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-t6050-wake-sources-macos-order branch from f796159 to f197658 Compare November 21, 2026 03:35
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Independent review (Opus 5.5, xhigh) on the exact head f1976580de5d2293ac44d61a0b8834db8a8dde94: PASS.

  • On f79615964d86: PASS-WITH-NITS. apple_smc_poll_in_flight() is exactly equivalent to both earlier loops: same bound, same delay, same acquire loads, and each caller then acts as before. No new runtime switch, magic constant, or SoC or board gate. macsmc-test.c matches every changed signature.
  • Its three nits are fixed in this head:
    • a 101-column comment in macsmc.h;
    • the commit text now says ".woken didn't get both a clean record and waka";
    • the bound is now SMC_IN_FLIGHT_US / SMC_SAVED_STEP_US, still 20000 polls of 10 us, with the acquire/release pairing commented.
  • The re-check of that delta found nothing else changed.

The only checkpatch warnings left are cosmetic: "memory barrier without comment", which the rest of the file's saved_pending accesses also give, and the attribution line's form.

🤖 Generated with Claude Code

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Merging on the exact head f1976580de5d: the independent review passed on this head, and CI is green on it.

Hardware gate on the J714s (kit m5-test/kitN3-20261120): 5 deep sleeps on 60 s alarms, 0 early wakes, every wake reason named. Each wake logged MBSE 0x10650, macOS's value, and wake events: NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc.

A separate class stays possible after the merge: the AOP crashing at a sleep's entry. Its crash message wakes the AP 0.5-0.6 s in, with MBSE 0x107fe and AOP.Outbox0_NotEmpty (dd2 w401 on the current default; ki2 w1 was one too). This change names that wake (wake events: AOP.Outbox0_NotEmpty ...) but doesn't prevent it. That is the AOP-crash item's (#2606). So the target for this change is 0 unexplained early wakes.

The rest of the count toward 40 sleeps, with 0 unexplained early wakes, comes after the merge. It will come from the new default's sleeps (sw4 / sship4) and the soaks, as with #2609.

🤖 Generated with Claude Code

@DjDeveloperr
DjDeveloperr merged commit ab9352c into integration/aurora Nov 21, 2026
7 checks passed
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