Skip to content

soc: apple: sleep: wait for the debug link's contract on a defined condition - #2402

Draft
RyanTheTide wants to merge 4 commits into
mainfrom
sweep/delays-soc
Draft

RyanTheTide wants to merge 4 commits into
mainfrom
sweep/delays-soc

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Two fixed waits in drivers/soc/apple read as delays standing in for a handshake.

  • sleep.c:3594/3611 (2a57a36, d9b438c): after the port controller's cold reset cuts the debug link, the sleep waited with mdelay(50) and then an mdelay(10) loop for the partner's contract. Whether the reset had been taken was guessed from seeing the contract gone. A contract never seen gone counted as back only after a 1 s floor, spun with interrupts off.
  • clpc.c:68 (51350a0): APPLE_CLPC_GPU_BACKOFF_MS, a 100 ms hold on the GPU floor after the PMP limits the DCS.

Change

  • sleep: the controller reports the boot loader's debug link in its MODE register ("DBMa"), and only the cold reset ends that mode. MODE is read before each reset. If it reads "DBMa", leaving that mode counts as the reset taken, so a quick reset no longer waits for the 1 s floor. A zero read from a controller that is still waking is ignored. If MODE reads anything else, the old test runs as before, floor included. The poll is now read_poll_timeout_atomic() over one function. That function enforces the 1.5 s limit in wall time, because the atomic poll counts only its own delays. The 50 ms stale-read window after the command is named (HPM_RESET_STALE_MS).
  • clpc: comment only. The PMP's limit is its vote in the PMC floor word. The PMP rewrites that register without an interrupt or a message to the AP, so no event exists to wait on. The hold is hysteresis on a sampled register.

Only boards whose DT has apple,debug-port reach the sleep change, and today that is t8140-j700.dts alone. SPMI gen 4 SoCs are refused in apple_sleep_map_debug_port(). The stale-read finding and the first-look timing are Diljit Singh's.

Testing

  • make W=1 drivers/soc/apple/sleep.o drivers/soc/apple/clpc.o with the release config: builds, no new warnings.

Still to run

  • Neo (T8140 J700), debug cable attached: echo deep > /sys/power/mem_sleep; rtcwake -d rtc0 -m mem -s 30, three times. Each time, dmesg must show debug link: contract back N ms after reset 1 (gone at M ms, mode), with no no contract with the partner warning, a clean resume, and a working debug link afterwards. Expect N to be at or below the old value; the old floor case was N >= 1000.
  • Neo, s2idle three times (rtcwake -d rtc0 -m freeze -s 20): no change expected, because this path runs only for deep.
  • J616s, M1 Pro, M2: not reached (no apple,debug-port). Their s2idle rows run against rtc1 in the combined kernel, unchanged.
Inventory of fixed delays in this area (our authors) and why the rest stay

Delays kept on purpose:

  • macsmc.c SMC_SLEEP_ARM_MS/SMC_SLEEP_IDLE_MS: both sides of each gap are already acknowledged commands (the MBSE write reply and the AP power ack). There is no known SMC status for "armed" to poll.
  • rtkit.c polled-mode loops and mailbox.c G17 TX: polled because the IRQ is off or missing.
  • sensor_shim.c: power-rail settle times.
  • SEP sbio.rs/sep.rs: shared-memory polls with no doorbell.

Sites that could be converted but are left alone here:

  • display-gate.c:2884: could use a bus notifier, but it runs on T6041 only.
  • sleep-t6050.h:2024: T6050 only.

The full table is in the evidence directory.

…ndition

After the port controller's cold reset cuts the debug link, the sleep
waits for the partner to renegotiate its contract. That wait was an
mdelay(50) and then an mdelay(10) loop for up to 1.5 s. Whether the
reset had been taken was inferred from seeing the contract gone (no
answer, or no contract); a contract that never seemed to go counted as
back only after a 1 s floor.

The controller names the boot loader's debug link in its MODE register
("DBMa"), and only the cold reset ends that mode. Read MODE before each
reset. Where it is the debug link's, the reset counts as taken once the
controller has left that mode, so a quick reset is no longer held to the
1 s floor. A controller still waking reads zeros, which say nothing of
its mode and are ignored. Where MODE reads anything else, the old test
is used as before, floor included.

One look at the controller is now a function polled with
read_poll_timeout_atomic(). The look itself bounds the wait in wall
time (1.5 s, as before): its SPMI commands take a while, and the atomic
poll counts only its own delays. The 50 ms after the reset command, in
which the controller still answers as before it, is named
HPM_RESET_STALE_MS.

The stale-read finding and the 50 ms first look are Diljit Singh's.

Fixes: 2a57a36 ("soc: apple: sleep: look for the debug link's contract from 50 ms after its cut")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
APPLE_CLPC_GPU_BACKOFF_MS keeps the GPU floor released for 100 ms after
the PMP last limited the DCS. It reads as a fixed delay standing in for
an event, so say why it is not one: the PMP's limit is its vote in the
PMC floor word, a register it rewrites with no interrupt or message to
the AP, and under heavy work that vote goes back to the top between
limits. Only sampling sees it; the hold is hysteresis on that sample.

No functional change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the Neo deep row below is on 86fea1a.

I checked sleep_hpm_contract_back() and its callers:

  • The poll is bounded. With timeout_us = 0, the -ETIMEDOUT from the look's own wall-time check (drivers/soc/apple/sleep.c:3613) makes cond true, and the caller returns it.
  • A MODE read that fails leaves ret set, so the look counts as not up / taken, as the old code did.
  • mode starts at the debug-link value when the look does not read it (sleep.c:3611), and mode is zero-initialised in apple_sleep_usb_down().
  • A retry after a failed reset re-reads MODE and falls back to the old test once the mode has gone.
  • The 10 ms step goes through udelay below the constant limit.
  • Only DTs with apple,debug-port reach this code, and the MODE value is the controller's documented mode tag.
  • The clpc commit changes a comment only. Both commits are clean.
  1. The debug-mode path now ends the wait at the first look that sees the mode left plus a PD contract (sleep.c:3625, 3631). That shortcut is the one the 1 s floor guarded against: a contract that reads as before the reset. Nothing in the code shows that the controller only reports HPM_POWER_CONNECTED + PD after it has left DBMa once it has renegotiated, not from a cached status. Only the hardware row below can settle that. It must show N well under 1000 with a working debug link after resume, not just the log line.
  2. Optional, sleep.c:3645: in debug mode the MODE test already rejects the stale window, since stale reads still show DBMa. The mdelay(HPM_RESET_STALE_MS) is then needed only on the fallback path. Skipping it when debug_mode is set would remove the last fixed wait from the path this PR converts.

HW row: Neo J700 with the debug cable, on a fleet kernel plus this head, default command line. Run echo deep > /sys/power/mem_sleep; rtcwake -d rtc0 -m mem -s 30 five times. Each wake must show contract back N ms after reset 1 (gone at M ms, mode), no no contract with the partner, a clean resume, and a VDM/serial round trip over the debug link afterwards. Then three s2idle cycles unchanged, 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Forward-merged main f02bd68 as d3b238f. Conflict in sleep.c: main (b43e2b0, T8122 deep sleep) moved the contract wait onto the raw counter because the late cut now runs with timekeeping suspended, and made the per-reset log conditional on debug_cut_after_stops. The resolution keeps this PR's MODE-based look and read_poll_timeout_atomic() (which only counts its own udelays, no ktime), but times it on cntvct_el0 through a small sleep_hpm_ms_since() helper instead of ktime_get(), and keeps main's condition on the log line (with this PR's ", mode" suffix). Local: arm64 LLVM W=1 sleep.o and clpc.o build with no warnings.

Still needed: the Neo deep row on this head (debug cable attached, echo deep > /sys/power/mem_sleep; rtcwake -d rtc1 -m mem -s 30 x3, the contract-back line with ", mode" each time and a normal resume). Since main's change, a T8122 deep row (J615) is worth adding too, as the late-cut path now runs there.

The previous merge of main recorded 7b10eb1 as its parent but kept
the tree of the merge with the main before it, which dropped #4379 (T6031
fixed refresh rates) from dcp.c, iomfb.c and dcp-firmware-test.c. Take
those three files as main has them; nothing else changes.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

RyanTheTide commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Follow-up: the merge above took main's tip as its parent while main moved under it, so its tree missed #4379 (dcp.c, iomfb.c, dcp-firmware-test.c). 0766096 restores those three files exactly as main has them; the PR diff against main is back to sleep.c and clpc.c only.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware row at exact head 076609612dcb on the Neo (J700): PARTIAL (debug link not active).

  • mem_sleep deep, 3x rtcwake -m mem -s 15 on the apple-pmu RTC: 3/3 clean resumes (suspend success +1 each), Wi-Fi, BT and the panel back.
  • But no debug link: line in any cycle: no debug link was active on this boot (no debug cable session), so the new contract wait was not exercised. mem_sleep restored after.
  • Still needed: the same with the debug link up, and the J615 row.

How: one combined test kernel for eight PRs, not this PR alone. Kernel 7.3.0-aurora-ci = main d0684a06 + merge commits of linux#2712 b6887f88, #2300 c1d351d2, #1990 83ef8b0f, #3742 798c2cde, #2350 5f18911e, #2398 75b30c6c, #1814 775f31d2, #2402 07660961 (all merged clean, test commit 03a571ef, cloud build https://github.com/aurora-silicon/linux/actions/runs/47474056726). Booted as a one-shot on the lab Neo (J700, T8140, 26.6.2 stub) with this kernel's own t8140-j700.dtb in a trial Stage 2 (live aura 1.0.0b19 + U-Boot, only the DTB swapped), default cmdline, silent (no audio playback). Boot health on the test kernel: 0 error-level kernel lines, 0 AVC, 0 failed units. Saved default restored after.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant