Repository navigation
soc: apple: sleep: T8142: start the cores and write the cluster words as XNU (on #2192) - #2193
Conversation
|
Tested the head (8e270f6, on Eight real deep sleeps on one boot, woken by the PMU alarm (
Not covered: a lid wake. |
|
Lid wake too, on the same boot with the defaults (
|
|
Tested on my J813 (macOS 27.2 / 26B123 stub, EL2 aura Six real deep sleeps on one boot, Hyprland on the internal panel:
The machine was on AC for these, so there's no power number yet. A lid-closed night on battery with 🤖 Generated with Claude Code |
|
Blockers: 2. The burst and pen changes read correctly:
Nit: HW row: after the parameters are removed, J815 and J813 on the default command line (no Assisted-by: LLM (Claude:Opus 5.5) |
secondary_holding_pen_release is written with a CPU's MPIDR to let it out of the pen and never reset, so after boot it still names the last CPU released. secondary_data.task likewise keeps that CPU's idle task: __cpu_up() only clears it on failure. With the restartable spin table (aurora,rvbar-spin-table) a CPU comes back through the pen whenever the SoC restarts it at its reset vector: after a system sleep's commit, and at the wake. The CPU whose MPIDR is still in the pen walks straight through into secondary_startup, ahead of its own bring-up, and runs secondary_start_kernel() as that CPU with the stale task. The hotplug state machine has not started it, so no STARTING callback runs (no arch timer, no tick device), yet it marks itself online and completes cpu_running, so the real bring-up returns at once. It idles quietly while cpuidle is paused and faults at the first menu_select() after cpuidle_resume(): Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 CPU: 9 UID: 0 PID: 0 Comm: swapper/9 pc : tick_nohz_get_sleep_length+0x68/0xd4 Call trace: tick_nohz_get_sleep_length+0x68/0xd4 (P) menu_select+0x414/0x774 cpuidle_select+0x1c/0x28 do_idle+0x1e8/0x310 cpu_startup_entry+0x34/0x38 secondary_start_kernel+0x198/0x1bc Kernel panic - not syncing: Attempted to kill the idle task! Seen on a J815 (MacBook Air 15" M5) when every core was started at the end of the wake, as macOS does, instead of one by one at its bring-up. Reset the release to INVALID_HWID in the released CPU's cpu_postboot, which runs before complete(&cpu_running), so it can't race with the next bring-up; and again before a suspend's hold and after the wake, before any CPU is started. Clear secondary_data.task after a successful bring-up too, as kernels before 5.x did, so a core that still reaches __secondary_switched without a bring-up of its own waits in __secondary_too_slow instead of running as another CPU. Tested on J815: two real deep sleeps (256 s and 172 s) with all nine secondary cores started together at the wake, all back online, where the same kernel without this change panicked on the first wake. Signed-off-by: Nick <[email protected]>
8e270f6 to
ac12cac
Compare
|
@RyanTheTide done.
Rebase note: integration's dynamic-debug start trace landed in HW rows (J815 + J813, defaults, 3 alarm + 1 lid wake each) to follow. |
|
Re-review of ac12cac: No blockers. Earlier points: 1 resolved: The new code reads correctly. Nit: sleep.c:8307-8310: the block comment on the SoC/DCS perf-state words now has nothing under it, because the constants it described were removed. Delete it with them. HW row (still owed): J815 and J813 on this head with the default command line: 3+ alarm wakes and 1 lid wake each, "9 cores started in one burst" + 9 "Booted secondary processor" per wake, CPUs 0-9 online, Assisted-by: LLM (Claude:Opus 5.5) |
… as XNU
A traced macOS 27.2 sleep on a J813 (boot, a 40 s sleep, the wake and
three more entries) differs from ours in three places:
- The wake: 16.5 ms after it, right after the memory side and the WD2
stop, the boot core starts all nine other cores in one 0.23 ms burst,
three words each (+4 the core's bit, +8 the E core's bit or 0, +0xc
the P core's bit or 0). We started each core later, from its own
bring-up, with two words.
- The commit: the clusters' words are read-modify-written. The first
sleep after boot reads 0xf and writes 0; every commit after a wake
reads 0x2f and writes 0x20, keeping bit 5. We wrote 0 every time.
- The SoC/DCS perf-state page is never accessed.
Do the same:
- At the end of the wake, start the cores that were online when the
sleep began, in one burst with those three words. They come up
through the boot object into the kernel's holding pen and wait there;
each bring-up only releases its core. The per-core start stays for
runtime hotplug. T8142's data has no cpu_clusters, so the cluster
comes from the MPIDR.
- Clear only the clusters' on bits at the commit.
- Drop the SoC/DCS perf-state step (t8142_perf_down()) and the
apple_sleep.perf_down switch that chose it.
The burst depends on the holding pen being closed behind each released
CPU ("arm64: spin table: close the holding pen behind each released
CPU"); without it the last CPU booted runs ahead of its bring-up.
Tested on J815 (MacBook Air 15" M5): two real deep sleeps (256 s and
172 s), each with "9 cores started in one burst" and nine "Booted
secondary processor", all CPUs back, display, NVMe, Wi-Fi and Bluetooth
up; the read-modify-write and no perf-state step in a third sleep of
366 s before that. On two J813s (sithglan, gig3m) alarm and lid wakes
with the same behaviour. Reverting this commit is how to go back.
Signed-off-by: Nick <[email protected]>
ac12cac to
8be9e73
Compare
|
Re-review of 8be9e73: no blockers. The only change since ac12cac is the removal of the leftover perf-state block comment (old drivers/soc/apple/sleep.c:8307-8310), so the earlier points stay resolved. HW row (still owed, at 8be9e73, default command line): J815 and J813, 3+ alarm wakes and 1 lid wake each. Each wake should show "9 cores started in one burst" and 9 "Booted secondary processor", CPUs 0-9 online, Assisted-by: LLM (Claude:Opus 5.5) |
|
@RyanTheTide nit done in The J815/J813 rows on the default command line are still owed. |
|
Review at 8be9e73: no blockers. Since ac12cac only the orphaned perf-state comment block went away (range-diff: the #2192 commit is identical, the top commit loses four comment lines). I re-read the whole PR at this head anyway.
Merge order: this PR carries #2192's commit (c5daf57) as its first commit and #2192 is still open, so #2192 goes in first. Non-blocking:
Still owed, as before: J815 and J813 at 8be9e73 on the default command line (3+ alarm wakes and 1 lid wake each, one burst line and 9 "Booted secondary processor" per wake, CPUs 0-9 online, Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Formal §1–§6 review at 8be9e731e3137c498a7b7dc5b0f09cce3fcf4a2c against pre-pr-checklist.md (verified against live integration/aurora 70a00e583b03: not superseded).
0 code, policy, attribution, or CI blockers — holding only for §5 exact-head default-cmdline hardware & regression evidence (plus stack ordering with #2192).
Blocker
- §5 (Missing exact-head default-cmdline hardware & regression evidence on
8be9e731e313):- All reported J815 and J813 sleep runs were collected on the previous head (
8e270f62) with lab/non-default boot parameters (apple_sleep.deep=1,nvme_apple.sleep_untested=1,appledrm.s2r_untested=1,idle=nop,arm64.nowfxt,maxcpus=1) and before removing the three module parameters and updatingsleep_cpu_on(). - As already noted in the PR body ("Still owed"), please post exact-head (
8be9e731e313) default-cmdline hardware runs on J815 and J813: 3+ alarm wakes and 1 lid wake each, confirming"9 cores started in one burst"and 9"Booted secondary processor"per wake, CPUs 0–9 online,suspend_statsfail 0, and explicit regression counts (0 SELinux AVCs, 0 failed units, 0 new kernel errors).
- All reported J815 and J813 sleep runs were collected on the previous head (
Merge-Order Note
- This branch carries #2192's commit (
c5daf572c69c,"arm64: spin table: close the holding pen behind each released CPU") while #2192 is still open; #2192 should land first (or coordinate merge order).
Checklist Verification
- §1–§3 (Correctness / locking / memory / no hacks): Clean.
arch/arm64/kernel/smp.c:140-151: clearingsecondary_data.task+dcache_clean_inval_poc()aftercpu_online(cpu)is safe because the secondary reads it in__secondary_switchedbefore completingcpu_running.arch/arm64/kernel/smp_spin_table.c: closing the pen withwrite_pen_release(INVALID_HWID)inspin_table_hold_parked(),spin_table_stop_finished()(which runs beforeops->wake()), andsmp_rvbar_spin_table_postboot()prevents early wake-burst cores from racing ahead of their bring-up.drivers/soc/apple/sleep.c: all three A/B module parameters (cpu_burst,cluster_rmw,perf_down),t8142_perf_down()/t8142_perf_request(), and the orphaned perf-state comment block are cleanly removed with no dead references left behind;sleep_cpus_awakeis snapshotted in.beginbefore CPU offline; cluster words use RMW (~CLUSTER_ON); per-coresleep_cpu_on()remains intact for runtime hotplug.
- §4 & §6 (Attribution / clean-room / naming): Clean. Both commits carry human author/committer (
Nick <[email protected]>) and single humanSigned-off-by:only (zero AI commit trailers);Assisted-by:disclosed in PR body. - Live CI: All 7 checks green on
8be9e731e313(host-tests,source,rust-build,kunit,DWC3/ATC× 3).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 8be9e731e313: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: the J815 and J813 sleep runs used lab parameters (apple_sleep.deep=1, nvme_apple.sleep_untested=1, appledrm.s2r_untested=1, idle=nop). Needed: one J813 or J815 deep sleep at this head on the default command line. It's stacked on #2192, so it merges after that.
Checked: no Apple material, no gates: the cores are started and the cluster words written in the order the firmware expects. CI green.
Superseded by the review at 8be9e73
|
J815 (MacBook Air 15" M5) row at Candidate: The earlier J815 rows couldn't reach the commit (refused by DCP/SEP before it). With #2384, #3129 and #3130 in the same tree, one timed deep sleep and wake: No panic on the wake, no core retried. Regression on the same boot ( Not yet: more than one cycle per boot; J813. |
|
J815 (MacBook Air 15" M5) row at Candidate: One deep sleep with no timer, woken by a key on the built-in keyboard after about 10 minutes (boot Regression on the same boot, after the wake: 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors vs the previous boot, 0 WARN/BUG/Oops. |
|
J813 (MacBook Air 13" M5) row at
Assisted-by: LLM (Claude:Opus 5.5) |
The merge-base changed after approval.
DjDeveloperr
left a comment
There was a problem hiding this comment.
LGTM — re-approving at 8be9e731e313 after base retarget onto main following #2192's merge.
The merge-base changed after approval.
|
The exact J815 and J813 rows are recorded, and the prerequisite is on |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 8be9e731e313 once one non-T8142 regression row is posted (queued in our lab, on J713)
Blockers: none in the code.
Checked:
- The T8142 part: the burst starts only the cores that were online at
.begin, takes the cluster from the MPIDR (nocpu_clustersin the data), skips itself and any cluster above 1, and each later bring-up only releases its core from the pen. Runtime hotplug keeps the per-core start. The cluster words are now read-modify-written,perf_downand its module parameter are gone, and so are the Apple method names in comments. There's nothing to set on the command line any more. - Shared arm64 code: in
__cpu_up, clearingsecondary_data.taskaftercpu_online()makes a late core take the existingcbz … __secondary_too_slowpath, which is safe.write_pen_release(INVALID_HWID)insmp_rvbar_spin_table_postboot(),spin_table_hold_parked()andspin_table_stop_finished()closes the pen behind each core. arm64 brings CPUs up one at a time (__cpu_upwaits forcpu_running), so one CPU's postboot can't clear another's pending release. - Rows at this head: J815 (one deep sleep woken by a key; that run used extra command-line words) and gig3m's J813 on the default command line (3 alarm wakes + 1 lid wake, 9 cores in one burst each time,
suspend_stats5/0, 0 failed units).
Still needed before merge: the smp.c/smp_spin_table.c hunks run on every Mac that boots through the spin table, not only T8142. One row on another generation will cover it: CPU hotplug offline/online cycles plus a few s2idle wakes, 0 failed units and no __secondary_too_slow or tick warnings. I've queued that on J713 together with #1702. If it passes and nothing else changes, this can merge on that row. If you forward-merge main first and the changed files stay byte-identical, the rows carry over.
The merge-base changed after approval.
|
8be9e73 Neo (J700, T8140) + J616s (M4 Pro, T6040) + J615 (M3 Air 15", T8122) PASS: batched on main 7f00dc6 (0 merge-tree diffs), default cmdline; Neo 20/20 E+P CPU online/offline (0 errors, online 0-5) + 3/3 rtc0 s2idle wakes; J616s 3/3 rtc1 s2idle (0-13) + J615 3/3 rtc0 s2idle (0-7); 0 __secondary_too_slow / hotplug / tick warnings, 0 failed units, Enforcing, 0 new AVC, 0 new kernel errors; stock defaults restored. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Re-approving at 8be9e731e313. GitHub dismissed the earlier approval when the base moved, and the head is unchanged. The regression row this needed is posted: Neo 20/20 E+P CPU offline/online and 3/3 s2idle, J616s and J615 3/3 s2idle each, 0 spin-table or tick warnings.
The merge-base changed after approval.
|
Merged into main. Thank you! It merged on the hardware rows at this head and a non-author review. |
Stacked on #2192 (the pen fix, the first commit here). The burst below needs it.
In a traced macOS 27.2 sleep on J813 (boot, a 40 s sleep, the wake and three more entries), XNU differs from us in three places. This PR does the same as XNU:
.begin; they wait in the holding pen and each bring-up only releases its core. The per-core start insleep_cpu_on()stays for runtime hotplugt8142_perf_down()and its call are goneT8142's data has no
cpu_clusters, so the burst takes the cluster from the MPIDR.Changed on this head (review):
apple_sleep.cpu_burst,cluster_rmwandperf_downare removed. The defaults they had (burst Y, RMW Y, perf-down N) are now the only behaviour, which is what the J815 and both J813 rows ran. Reverting the commit is how to go back. The per-core "released from the pen" line is nowpr_debug, next to integration's dynamic-debug start trace. The "N cores started in one burst" line stays.t8142_cpu_burst()moved abovet8142_wake()'s comment. Rebased ontointegration/auroracc14570.Tested on J815 (MacBook Air 15" M5), on the previous head with the defaults:
J813: sithglan (alarm and lid wakes) and gig3m ran the defaults; their rows are in the comments.
Checks:
W=1adds no warnings indrivers/soc/apple/at either commit;checkpatch --strictis clean on this commit.Still owed (HW rows): J815 and J813 on this head with the default command line: 3+ alarm wakes and 1 lid wake each, "9 cores started in one burst" + 9 "Booted secondary processor" per wake, CPUs 0-9 online,
suspend_statsfail 0, 0 AVC, 0 failed units, 0 new kernel errors.Part of the J815 bring-up; board results are summarised in #135.