Skip to content

thunderbolt: tb: stop waiting for a CIO peer that is gone - #3959

Draft
themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:fix/tb-cio-partner-gone
Draft

themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:fix/tb-cio-partner-gone

Conversation

@themartiano

@themartiano themartiano commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: After a native CIO deep sleep the wake waits up to 30 rounds for each link that had a peer, inside the noirq phase of the system's resume. A peer that was unplugged during the sleep costs all 30: 34 s with a Thunderbolt display pulled from a J713 (older tree). Now the lane adapter decides. An adapter that reads unplugged at the end of two tb_wait_for_port() rounds in a row has no peer, and the wait for it ends after a little over 2 s. A peer whose link trains keeps its 30 rounds. Hosts with QUIRK_CIO_WAKE_GIVES_UP are unchanged.

Tested: Host side at the head, on main 30c1870. tools/asahi/tb-cio-sleep-tests.py: 47 cases, 32 negative controls pass (main: 42 and 29). The new cases fail against main's tb-cio-sleep.c (link_waits == gone[n].waits). run-host-tests.py --only cio 5/5, the same as main. arm64 W=1 LLVM 20 build of drivers/thunderbolt/: the same 208 kernel-doc warnings as main, none in tb-cio-sleep.c (it is built as part of tb.o). checkpatch --strict: clean. No KUnit suite covers these paths (apple-kunit.py plan picks none). Hardware, measured on an older tree, not at this head: 34 s lost to a display pulled from a J713 during a deep sleep; good docked wakes had the link back within about 0.5 s. This commit is in our 7.3.0 next4 test kernel (main ba12094 plus this and other open branches; the files it touches are the same on today's main). A row at this head is not yet run.

Risk: two-way · J713, the only host on main that sleeps with the router in place without QUIRK_CIO_WAKE_GIVES_UP. A dock that shows nothing on the lane for 2 s after the wake is now retired as unplugged instead of waited for, and rescanned at complete. Whether its PCIe comes back without a replug in that case is not known.

Other Macs: tb-cio-sleep.c runs only where apple_nhi_cio_bind() sets up a sleep in place: the J713 (T8132) and the J714s and J716c (T6050). The T6050 hosts set QUIRK_CIO_WAKE_GIVES_UP, so they already wait two rounds at most, and the new early end at two unplugged rounds changes nothing for them. T6020's deep sleep (#3569) powers the port off instead and does not reach this wait. Other Macs and the J715 do not run it. So only the J713 changes, and it only gets shorter in the unplugged case.

Not yet: J713 rows at this head: a display pulled during a deep sleep (expect link after wake: 0 after about 2.1 s, and the resume about 30 s shorter); 10 docked sleeps with the link back each time; 5 with a slow self-powered dock, and one with the dock switched off and on during the sleep.

Details
Evidence
  • Head 1386c7c, parent 30c1870 (main). Cherry-picked from our branch without conflict; the files it touches are unchanged on main since ba12094, the base of the test kernel.
  • python3 tools/asahi/tb-cio-sleep-tests.py: PASS 47 native tunnel replay cases, PASS 32 negative controls (main: 42 and 29).
  • Same test with drivers/thunderbolt/tb-cio-sleep.c taken from main and only the real variant run: fails, Assertion 'link_waits == gone[n].waits' failed.
  • tools/asahi/run-host-tests.py --only cio: 5/5 (atc-cio-sleep, cio-native, dart-cio-owner, dart-cio-power and this one), main 5/5.
  • Build: make O=<dir> LLVM=/usr/lib/llvm20/bin/ ARCH=arm64 olddefconfig from our J713 test kernel's config (7.3.0-0.next3), then W=1 drivers/thunderbolt/ (clang 20.1.8). 208 warnings, all kernel-doc in apple.c and other files this does not touch; the list is identical to main's.
  • scripts/checkpatch.pl --strict -g main..HEAD: 0 errors, 0 warnings, 0 checks.
  • scripts/ci/apple-kunit.py plan: no suite for these files.
  • git merge-tree with the other tb-cio-sleep.c branch (a router that leaves during the wake): no conflict.

After a native CIO deep sleep the wake waits up to 30 rounds for each
link that had a peer, inside the noirq phase of the system's resume. A
peer that was unplugged during the sleep costs all of them: 34 s with a
Thunderbolt display pulled from a J713 (measured on an older tree), with
every later resume waiting.

Only hosts with QUIRK_CIO_WAKE_GIVES_UP wait for two rounds, which
outlast a cold start's training. That quirk also bounds the wait for a
link that still trains and tolerates a router state that is not taken
back, neither of which is wanted here.

The lane adapter tells the two cases apart. A peer that is there trains,
and keeps its 30 rounds. An adapter that reads unplugged at the end of
two rounds in a row has no peer: the port is lost as before, after a
little over 2 s.

Hosts with the quirk are not affected. Of the others, only the J713
sleeps with a router in place.

Signed-off-by: Eduardo <git@martiano.me>

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