Repository navigation
metal: synchronous pipeline calls always compile and return their result; completion handlers on workers (second version of #396) - #398
Conversation
…ult; completion handlers on workers (second version of #396) #396 timed the synchronous new*PipelineState calls out after 5 s and refused the pipeline while the compile went on. On phone 2 (19 Nov) a cold cache made backboardd's first render pipelines take longer than that; QuartzCore treats a refused render pipeline as fatal, backboardd aborted three times and launchd rebooted, twice. #397 reverted it. - metal2/CompileQueue.h (new, plain C++17): the rules. A synchronous call compiles on the calling thread, every time, and returns the pipeline or the compile's own error: no timeout, no worker slot, no negative cache. A completion-handler call returns at once; its compile runs on a worker (at most 3 at a time, FIFO list, no thread parked on a semaphore), the handler is called exactly once; an asynchronous compile that failed after more than 10 s is not started again for 10 minutes. Nothing is called with the lock held (handlers may ask for the next pipeline). - patches/frontend-async-compile.diff: the frontend on CompileQueue.h. The 3 pipeline makers go through gCompiler.sync, the 6 completion-handler methods through gCompiler.async (the handler gets the state, reflection and NSError the synchronous method made). The worker queue has no QoS of its own: a compile runs at the QoS of the thread that asked for it. STARBITE_M2V_COMPILE_TIMEOUT_MS is gone (a leftover mtl2-env line changes nothing). - mesa26-panvk-compile-budget.patch: the budget is the compiling thread's CPU time (CLOCK_THREAD_CPUTIME_ID), not wall time: a compile starved of a core is not a runaway, and a failed render pipeline is fatal to backboardd. - metal2/tests/compile-queue-test.cpp + tests/run.sh (and a CI step): sync waits for a slow compile even with the old timeout variable set; sync never waits behind busy async slots; 200 async requests on 3 slots each answered once; make() calling sync() and done() calling async() do not deadlock; a throwing handler keeps no slot; the negative cache is async-only. Under ThreadSanitizer too where the compiler has it. run.sh also checks the frontend diff: it fails on #396's version. - docs/ios27/METAL.md: why #396 was reverted, and what the timeout-0 boot's samples show (SpringBoard's main thread in a synchronous XPC to chronod; backboardd idle; no compile running). Per-user cache (hotmetal2-shared-cache.diff), the warm-cache step (81-m2v-cache.sh, harvest-m2v-cache.sh) unchanged from #396. Built, not phone-tested.
Phone test on phone 2, 22 Nov 2026 (19:44–20:02Z): not mergedSetup: BOOT L6c Cold-cache boot (log
|
| Check | Result |
|---|---|
| backboardd opens the device on the per-user cache | PASS: MTL2[57 backboardd]: device Mali-G72 MC18 in 5139 ms (cache /var/local/m2v-cache/u501) |
| cold compiles happened | PASS: 5 PANVK: lines at boot (compute shaders of 3224–7754 NIR; one compiled in 1099 ms), 11 by the end |
no refusal / still running after / abandoned after |
PASS. The only refused match is a sensor-hub line (shub: ... 0 refused), not Metal. |
| backboardd does not abort | PASS: no SWEET EXIT, CRASH or rebooting due to critical |
| frames continue past swap 8 | PASS: 2nd display on at 19:45:20, swap 22 by 19:45:31 |
| lock screen | PASS (shot v2cold-boot.png) |
| Settings open 1 (cold) | Settings was on screen in the first picture, taken 3–5 s after the tap. Two fragment shaders (3883 and 3991 NIR) compiled at the tap. The 24k-NIR compute shader did not come up. |
| Settings opens 2 and 3 | PASS: on screen in the picture taken 1–3 s after the tap; no new PANVK: lines |
| Display & Brightness ×3 | PASS: the page drew in each picture 1–3 s after the tap, with no new PANVK: lines and no freeze. iOS 27's page has no light/dark previews; the Appearance page has them, and they drew. |
| no Preferences exit, crash or refusal | PASS |
Warm-cache reboot (log con-xnu-boot-L6c-1122-1955.log)
| Check | Result |
|---|---|
PANVK: lines |
PASS: 0 for the whole run, which covered the boot, Settings ×3 and Display ×3 |
| backboardd device open | PASS: in 5135 ms (cold: 5139 ms) |
| swaps past 8, no refusal/abandon/exit/crash | PASS: display on 19:56:17, swap 8 at 19:56:41 |
| Settings opens 2 and 3 | PASS: on screen within 1–3 s |
| Display & Brightness ×3 | PASS: drawn within 1–3 s each time; three identical pictures |
| Settings open 1 within 3 s | NOT MEASURED: the first picture was at +8 s, with Settings on screen |
Why not merged
- Preferences never used the PR's code. Neither boot has a
MTL2[... Preferences]line, not evenplugin loaded, although Preferences getss.dylibthroughsweetinjectand is inmtl2-clients. SpringBoard and cameracaptured do printplugin loaded. On 18 Nov (con-xnu-boot-L4-1118-2103.log), Preferences printedplugin loadedonly about 10 minutes after it started. So the synchronous-compile-on-the-caller path in Preferences was not exercised: Settings' main list and the Display & Brightness page do not make Preferences open a Metal device. Every compile in these runs was backboardd's. - Warm-cache "Settings' first open within 3 s" was not measured: the first picture came at +8 s.
Everything that did run on the new frontend passed: backboardd on a cold cache, with sync compiles and no timeout refusal, then a warm cache with 0 compiles. #396's two failures did not come back: no backboardd crash loop, and frames continued after swap 6. To finish the test: find a Preferences page that makes it load MTL2, then open it cold and warm, and time the warm first open with a picture right after the tap.
Also seen: in the warm run, one tap hit the Accessibility row by mistake. The picture taken 1–3 s later is a mixed frame: the upper part is the Settings list, and the lower rows are the Accessibility page's, shifted sideways. The next picture showed the page complete. It is transient, not the frozen half-slid frame of 19 Nov, which stayed for 20 s. Not explained.
Temperature: big cores 61–66 °C while Settings was open. Preferences used about 127 % CPU continuously while open, on both boots.
|
Phone regression of current main, phone 2 (Galaxy S9, iOS 27.2.1), 28 Nov 2026 — PASS. Built: scion-kernel main
Home screen drawn on both (icons, widgets, dock, Wi-Fi + charging). Crash set = the earlier baselines' (locationd, chronod); no new crash loop. The S9's charger guard as before ( #421 ( |
Built, not phone-tested. No phone was reachable on 20 Nov; nothing here has run on a phone. Do not merge before the phone test below passes.
Second version of #396 (reverted by #397). It keeps what #396 got right (completion-handler compiles on worker threads, PanVK's compile budget for runaway compiles, one shader cache per user, the warm-cache step) and drops the part that broke the phone: a synchronous pipeline call now always gets its pipeline or the compile's own error, never a timeout refusal.
Why #396 failed on phone 2 (19 Nov)
5 s timeout → backboardd crash loop. On a cold cache, backboardd's first render pipelines took longer than
STARBITE_M2V_COMPILE_TIMEOUT_MS(5000 ms), so the frontend refused them ("still running … ask again"). QuartzCore treats a refused render pipeline as fatal, so backboardd aborted three times and launchd rebooted, on two boots in a row. A synchronous Metal call can't be told "ask again later".Timeout 0 → frames stop after the boot logo. The kernel's samples of that boot (
con-xnu-boot-L6-1119-0039.log, symbolized against the 24B156 cache) show:mach_msg. The only StarbiteMetal frames were the telemetrysleep()loops. No thread was compiling and there were no PANVK lines.-[CHSChronoServicesConnection _subscribeToExtensions]→xpc_connection_send_message_with_reply_sync). It made no new commits, so backboardd had nothing new to show.With the timeout at 0, metal: compiles off the UI thread (timeout + budget), per-user shader cache, warm-cache step #396's synchronous path compiled on the caller as before. Inferred: the stall was not caused by the frontend. It is not proven, because chronod wasn't sampled. The test image below samples it.
What changes
tools/ios27/metal2/CompileQueue.h(new, plain C++17). It holds the rules, and its header comment states them:patches/frontend-async-compile.diffgCompiler.syncand the 6 completion-handler methods throughgCompiler.async.STARBITE_M2V_COMPILE_TIMEOUT_MSis gone. A leftovermtl2-envline changes nothing.mesa26-panvk-compile-budget.patch. The budget now counts the compiling thread's CPU time (CLOCK_THREAD_CPUTIME_ID) instead of wall time. A compile that is only waiting for a core is not a runaway, and since synchronous callers now see this error, a wall-clock budget could fail backboardd's pipelines on a busy phone. The longest real compile seen took 25 s of CPU; the default budget stays at 90 s.Tests:
tools/ios27/metal2/tests/compile-queue-test.cpp+tests/run.sh, plus a CI step. Each test names the phone failure it would have caught:make()→sync()anddone()→async()re-entry doesn't deadlock;The tests also run under ThreadSanitizer where it can start (with
setarch -Ron Linux kernels with large mmap randomisation).run.shalso lints the frontend diff: no timed wait or timeout refusal, 3gCompiler.syncand 6gCompiler.async. It fails on metal: compiles off the UI thread (timeout + budget), per-user shader cache, warm-cache step #396's diff (checked) and passes on this one.docs/ios27/METAL.mdexplains why metal: compiles off the UI thread (timeout + budget), per-user shader cache, warm-cache step #396 was reverted and what the timeout-0 samples show.Unchanged from #396:
hotmetal2-shared-cache.diff,81-m2v-cache.shandharvest-m2v-cache.sh.The first commit re-applies #396 (reverting #397) so the second one reads as a change to it.
Trade-off, stated plainly
A synchronous caller on a UI thread still waits for its compile, as it did before #396. A cold first Settings open can take as long as its 24 522-NIR compute shader, about 25 s of one core. The fix for that is the warm cache (step 81), not a timer. Opens after the first should come from the per-user cache.
Built
Built on the Mac mini with
mk-panvk27.shandmk-bundle27.sh, using the same Xcode (iOS 18.5 SDK), host tools and bridge library (Nov 12) as #396's bundle:c1ba995d0a19f6af…(dSYM UUID 537181AC-2370-3012-861C-691F97A6FA4F)72136f02b948be76…The binaries contain no "still running after" string. These local checks pass:
tests/run.sh,provenance-check,arch-check --report,builds-test,build-lock-test. The talon preflight lane doesn't apply to this repository.Phone test (to do)
On phone 2, with BOOT L6 +
sweetsample=SpringBoard,backboardd,chronodand the root step "bundle + Preferences in mtl2-clients + step 81, cold cache":Cold-cache boot. Pass if:
PANVK:lines appear (the cache really was cold);refused,abandoned after,SWEET EXITorCRASH;If it stalls after swap 6, symbolize the main threads of SpringBoard, chronod and backboardd from the samples before rebooting.
Settings ×3. The first open may take as long as its compiles. Opens 2 and 3 should show Settings within 3 s with no new
PANVK:lines. No crash and no refusal on any open.Display & Brightness ×3. The page draws each time, with no freeze or crash; the 2nd and 3rd opens in under 2 s.
Warm-cache repeat. Reboot without a root step.
PANVK:lines should be 0 or very few, and Settings' first open within 3 s.The exact commands, images and hashes are in the test notes on the mini (prep-1120/TEST-ON-PHONE.md).
🤖 Generated with Claude Code