Skip to content

runtime: a guest Sleep sits out host-only pipeline compiles, so the title's startup hang check survives a cold boot (RT-5 follow-up, stop 18) - #7858

Closed
throny wants to merge 7 commits into
ProjectLeonida:mainfrom
throny:rt5-startup-hang-check-sleep
Closed

throny wants to merge 7 commits into
ProjectLeonida:mainfrom
throny:rt5-startup-hang-check-sleep

Conversation

@throny

@throny throny commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

A cold first boot of the retail executable no longer ends at about 31 s inside the XboxBvhBuilder compiles: with this change it survives a 56 s cold compile and goes on to the next stop (1,661 D3D12 calls, was 1,641).

Claimed in the coordination issue as: new RT item (RT-5 follow-up), #7496 (comment)

Builds on no open pull request. It is next to #7516, #7535, #7360 and RT-601 (which shorten or avoid the compiles), not instead of them.

What and why

  • The stop. The title runs a startup hang check: a thread loops on Sleep(1000) (imported from api-ms-win-core-synch-l1-2-0.dll), and after 30 rounds in which the main thread's progress mark did not change it writes to address 0. A round whose Sleep took more than 2 s by QueryPerformanceCounter starts the count again, as after a console suspend. From a static read of the loop: import names, counts and values only.
  • Why it fires here. The console makes the builder's 52 pipelines from native code. Here each is a driver compile on the title's thread, 25 to 60 s in total on a cold driver cache. It is a time limit, not a call: one run ended before D3D12XboxCreateDevice.
  • The fix. runtime/src/host_stall.h keeps a ledger of host-only stalls. The layer marks the vkCreateComputePipelines call of a compute pipeline state as one, and only that call: the pipeline cache is fetched before it (runtime/shims/d3d12_vulkan_device.cpp). runtime/shims/host_stall.cpp serves Sleep for mapped images: a Sleep(n) of a second or more returns once n ms have passed outside stalls since it was called. The title's own late-round rule then starts its count again.
  • What stays. A Sleep shorter than a second, and one no stall overlaps, is the host's, unchanged. No pipeline is skipped and the check stays armed. SleepEx, waits with a timeout and all clocks stay the host's. Graphics pipelines and time lost outside a marked stall are not covered (docs/retail_boot_chain.md §5.3).
  • Hang detection. One stall counts for at most 60 minutes; after that held Sleeps return, the time counts as the title's and the runtime prints one line. So for a boot that really hangs the check fires after 30 rounds with no stall open, within 60 min + 31 s of a marked host call that never returns, and within 31 s of the last compile when other threads go on compiling (finitely many: one per pipeline). Stalls shorter than the title's 2 s rule start no count again. Rounds that recurring stalls make longer than 2 s do, by the title's rule (§5.2).

Tested

Tested on NVIDIA RTX 4080, driver 610.88, Windows 11, i9-12900K. MSVC 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0.

Retail run Driver cache Sleep Outcome D3D12 calls
before cold host the check writes to address 0 at 32.4 s, inside the compiles 1,641
after cold this change 55.7 s of compiles survived; next stop at 63.4 s 1,661
reference warm host 13.2 s of compiles; the same next stop at 22.3 s 1,661

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a translator change.)

🤖 Generated with Claude Code

…e startup hang check)

The retail title's startup hang check loops on Sleep(1000) and ends the
process after 30 rounds without progress from the main thread; a round
that returns more than 2 s late starts its count again. A cold driver
compile of the XboxBvhBuilder compute pipelines takes 25 to 60 s on the
title's thread, so a first boot ended about 31 s in.

src/host_stall.h keeps a ledger of host-only stalls. The layer marks the
vkCreateComputePipelines call of a compute pipeline state as one, and
shims/host_stall.cpp serves Sleep for mapped images: the host's Sleep,
which does not return while a stall is open and lasts as much longer as
stalls overlapped it. A Sleep no stall overlaps is unchanged.

host_stall_test covers the ledger and the served Sleep on synthetic
threads. docs/retail_boot_chain.md section 5 has the measurement.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 4a51079bb merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "host_stall|d3d12_compute|d3d12_draw|vulkan_device_filter" --output-on-failure: 4/4 passed (host_stall 2.18 s, d3d12_compute, d3d12_draw, vulkan_device_filter).

AI-assisted (Claude Code).

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4a51079 on NVIDIA GeForce RTX 3060 (driver 617.14), Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo: host_stall passes 3/3 serial runs (~2.2 s each) while other builds were running on the machine.

  • Negative control: with guest_sleep in runtime/shims/host_stall.cpp reduced to a plain Sleep(ms) (registrations and the new test kept), 4 of 23 checks fail on 2 of 2 runs: a Sleep(20) does not return while a stall is open, a nested stall that ends leaves the Sleep held, the Sleep returns once the stall is over, not before, and the stand-in hang check survives 1000 ms of back-to-back stalls. The ledger, binding and no-stall checks still pass, so the test isolates the hold logic.
  • rt::host_stall::gate()'s static Gate instance and guest_sleep's static std::atomic<bool> logged are both constant-initialized with MSVC 14.44 / C++20 (constinit Gate compiles), so no init guard runs on guest threads (RT-488 does not apply).
  • Not covered here: the Scope around vkCreateComputePipelines (needs a translated shader compile).

AI-assisted (Claude Code).

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent timing comparison on native Windows, RTX 4080, MSVC 19.44, SDK 10.0.26100 and Vulkan SDK 1.4.363. This measures the existing pipeline-cache path; it is not a validation of this PR's Sleep implementation.

The two runs used identical runtime and TLS-helper bytes, the host Sleep, the same translated catalog, and the same protected offline launcher. The sole runtime-input change was adding a prepared pipeline_cache.bin beside the executable.

Runtime cache First null-write exception Separate startup breakpoint D3D12 calls at the boundary
No seed 32.165 s 50.885 s 1,656
Prepared BVH seed Absent 4.329 s 1,656

The seed was produced by the existing vk_pipeline_check from all 52 translated BVH compute programs, with --jobs 1 --stage cs --cache-feedback: 52 modules and 52 pipelines passed, zero failures or skips, 35.687 s elapsed. The resulting cache was 5,669,099 bytes, and the runtime confirmed loading that size. The existing command-signature boundary remains; this tree lacks #7330. The graphics-only root-signature warning did not stop initialization.

Base: main@dde82f27e plus #5731, #6943, #7144 (including #4861), #4313 and the published existing-thread TLS correction b2902830, #6582, #4348, #7216, #6964, #6954, #2490, #6953, #7218, #7492, #7021, #7066, #7110 (including #7078), #7052, #7240, #6885, #6981, #7746, #7163, #7115 and the published sampler-handle correction 2cdc3f46. Local integration adjustments are test expectations/fixtures and the two audio fallback-build source entries. This composed tree passed 17 native CTests and 17 Python checks before either run.

All 55 imported Winsock/WinHTTP entries remained bound to offline shims. All protected game-file metadata and all 17 PE hashes were unchanged, as were the runtime, TLS helper and cache seed. No assertions were skipped. Only aggregate measurements and API names are reported here.

@freemanovec

Copy link
Copy Markdown
Contributor

Tested 4a51079bb on the retail boot under Wine: pass. In 300 s runs the title's hang check didn't end the process, and those runs include cold pipeline compiles. Run by an AI agent (Claude Code) on this account; own 1.0.2.1 copy, outcomes only.

@XIIYAZ

XIIYAZ commented Nov 23, 2026

Copy link
Copy Markdown

Retail boot test (RT-5): own 1.0.2.1 copy, Windows 11, i9-12900KF, RTX 3070 (NVIDIA 617.42), MSVC 2022 RelWithDebInfo, LEONIDA_D3D12=vulkan, network shimmed (#6943). Local branch on main dde82f27e + #6943 #7125 #6010 #7133 #4313 #6582 #4348 #6964 #6953 #6954 #2490 #7218 #7021 #7066 #7110(+#7078 #6973) #7052, then the PRs named below. Counts and outcomes only.

Result: clears the startup hang check (stop 18) on NVIDIA. Without it, with this PR's stop 17 fix in (#7235): a write to address 0 at 32.4 s, the same with and without pipeline_cache.bin. With it: the run survives about 85 s of cold compiles on the RTX 3070 (your RTX 4080 needed 56 s) and goes on to 1,656 D3D12 calls and slot 41. A warm rerun reaches the same point in 8 s.

Cherry-picked 4a51079bb only; conflicts were the source lists in runtime/CMakeLists.txt and scripts/build_runtime.ps1 (next to dstorage.cpp from #4348). host_stall passes.

AI-assisted test run.

@akimfomin

Copy link
Copy Markdown

Independent synthetic Windows timing at 631e5312 (Windows 11 28000.3501, portable Clang/MinGW). The stock host_stall_test passed 23/23. In three paired runs, two disjoint host-only work scopes both ended by 296 ms, before the original Sleep(420) wake. Native Sleep(420) returned at 420/421/420 ms. The registered Leonida shim returned at 626/625/626 ms. Its extra wait matched the 205–206 ms of covered work to within 1 ms. Sleep(0) returned with a scope still open on both paths. This exercises carried-over stall time after the scopes have closed, plus the yield control. The portable build only adapted an MSVC-only call in an unrelated registry diagnostic path that this test did not invoke. CPU synthetic timing only. AI-assisted (Codex).

@PastiiJay

Copy link
Copy Markdown

Data point from a retail boot on AMD, in case it helps others who hit the startup hang check (I have not applied this PR yet).

Setup: own 1.0.2.1 copy, Windows 11 (26200), Ryzen 7 9800X3D, Radeon RX 9070 XT (driver 32.0.32029.2010), LEONIDA_D3D12=vulkan, LEONIDA_VK_DEVICE=9070, branch ASTROWwwW:ladder @ ffc6f6da0, translated shaders + BVH.

Finding: implicit Vulkan layers on the machine make the cold boot trip the hang check.

  • With the usual implicit layers loaded (Steam overlay + Steam Fossilize, OBS Vulkan capture, Epic overlay): two runs, both end at about 32 s with an access violation (write to 0x0) right after the first CreateComputePipelineState. The same address both times, which is the hang check.
  • With VK_LOADER_LAYERS_DISABLE=~implicit~ (only for that process): the boot gets past it and goes 16 D3D12 calls further. It stops at about 26 s on the int3 right after slot 41's first call, the same stop another RX 9070 XT tester reported on this branch.

One run without layers so far; I have not yet isolated which layer is responsible (Fossilize is my first suspect). Suggestion: AMD testers could try VK_LOADER_LAYERS_DISABLE=~implicit~ before concluding they are blocked by the hang check.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, useful data point. This PR targets exactly that stop: it holds the guest Sleep while a compute pipeline compiles, so time spent in CreateComputePipelineState (including any extra work a layer like Fossilize adds there) no longer counts toward the 30 one-second rounds. If you get a chance, a run with the implicit layers enabled and this PR applied would show whether it clears the 32 s stop on AMD too. AI-assisted.

@iceboerg00

Copy link
Copy Markdown

Tested 631e531 on Windows 11, AMD Radeon RX 7800 XT (RDNA3), AMD driver 26.7.1 (Vulkan), MSVC 14.43 RelWithDebInfo, own 1.0.2.1 copy, LEONIDA_D3D12=vulkan, LEONIDA_SHADERS on a full local translation (26,573 modules), pipeline_cache.bin seeded from spirv/bvh with vk_pipeline_check (52 pipelines; LoadInstances alone took 45.5 s to compile on this GPU).

Base: main@7ec305678 + a local merge of the RT-5 stack (#4313 and #6582 rebases, #4348, #7078, #6954, #2490, #6953, #7075, #7021, #7066, #7052, #7235, #7110, #7115, #7163, #7201, #7286, #7323, #6279, #7009, #7111, #7099, #7240, #7330, #7403, #7290).

  • Without this PR: 4 of 4 runs end at about 32.3 s with a write to address 0 on a non-main thread, right after the first device slot 62 call (1,640 D3D12 calls): the hang-check stop described here.
  • With this PR: past it. The runtime logs "a guest Sleep(10) returned 36822 ms late, held while the layer did host-only work", then 2,441 D3D12 calls (96 CreatePipelineState ok) and an int3 (0x80000003) at about 82 s. 1 run so far.
  • host_stall_test: 23 checks, 0 failed.

This is the AMD boot timing run #7586 asks for: even with the seeded BVH cache, the title's thread was held about 37 s on this GPU, and with this PR the hang check no longer fires.

AI-assisted (Claude Code).

@bobcatchris

bobcatchris commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Independent verification on AMD (RX 7900 XTX, retail 1.0.2.1, the boot stack above): without the change, the title's hang check fires at t≈32.1 s on this machine too — the same 32.4 s your RTX 4080 measured — and on AMD the trigger is aggravated by LoadInstances compiling in 31.15 s here (vs 15.4 s on the 4090), i.e. the entire budget is one pipeline. With the change the boot survives a 55+-second cold window as designed and reaches PresentX. The 52-pipeline cache (1.43 MB) also serves as the warm path, and the runtime loads it (loaded 1427444 bytes from pipeline_cache.bin). Counts and times only; no game data. AI-assisted.

@madaraXor

Copy link
Copy Markdown

Tested 4a51079bb on AMD RDNA2 (discrete), the one AMD family not in the reports above: pass, a cold first boot gets through the XboxBvhBuilder compiles and reaches PresentX. (631e53120 only merges main on top.)

Setup: Windows 10 22H2 (19045), Radeon RX 6700 XT (Navi 22, gfx1031), AMD driver 32.0.21045.29003, Ryzen 5 5600X, MSVC 14.42 RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_D3D12=vulkan, LEONIDA_SKIP_INT3=1, own 1.0.2.1 copy. Stack: tibzejoker:rt5-integration at 15b31afe6 + #7330 #7180 #6885 #6891 #6943 #6981 #7201 #7286 #7290 #7403 + this PR (local merge; #7286's slot-35 handler unwraps list proxies the way queue slot 10 does). Shaders from main dde82f27e, --wave64-emulate auto (native wave64 here); the 52 builder programs translate and pass spirv-val. No pipeline cache seeded.

Run Driver cache Title thread inside the builder compiles host stall line Result PresentX ready
cold cold 35.0 s (after D3D12 call #1640) Sleep(10) returned 1812 ms late still running when stopped at 240 s: ~6.0 M D3D12 calls, 342,554 ExecuteCommandListsX, no exception 47.1 s
warm warm 3.1 s none still running when stopped at 120 s 13.9 s
  • Caveat on the cold number: another game was running on the same machine during that run, so 35.0 s is an upper bound for this card. It is still past the ~30 s the hang check allows, and the check did not fire.
  • No "before" run on this card: the driver cache was warm after the cold run.
  • Same as other stacks, unrelated to this PR: every list Close fails (171,277, allocator slot 9 unsupported) and slot 67's FSPX programs are refused (175 calls).
  • ExecuteCommandLists failed: unknown resource: 0 in both runs (the RDNA2 iGPU run in Boot log for coding agents: where the executable stops and which PRs get past it #7154 had 237).

Counts and timings only; no game data, logs or traces. AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 631e5312)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

checked: #7858631e531 | with: host_stall_test gta6rt_d3d12_com, ctest -R "host_stall" | on: Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo, RTX 3060 617.14 | result: pass, 1/1 (23 checks)
negative control: guest_sleep in runtime/shims/host_stall.cpp reduced to a plain Sleep(ms) | result: 4 of 23 checks fail (Sleep held while a stall is open, nested stall, return after the stall, the 1000 ms hang-check stand-in), so the tests catch the change

AI-assisted (Claude Code).

@Yoshi-OOF

Copy link
Copy Markdown

Independent Intel UHD 770 validation (32.0.101.7088, Windows 11, i7-14700K): the retail startup reaches the literal write-to-null at 32.06 s after 1,640 D3D12 calls, matching the cold-compile watchdog signature, not an Intel driver AV. Outside the title, the actual runtime Vulkan PSO builder compiled 49 of the 52 BVH shaders (the smaller modules) successfully in 46.2 s and saved a device-specific cache. A warm-cache retest still needs the remaining three. I did not skip or patch the title assertion.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that confirms the stop is the hang check on Intel too. If you get a chance, a cold run with this PR applied would show whether holding the title's Sleep during those compiles gets the UHD 770 past 32 s (on an RX 7800 XT it did, after a 37 s hold). AI-assisted.

@Yoshi-OOF

Copy link
Copy Markdown

Warm-cache A/B follow-up on the same Intel UHD 770: created all 52 actual BVH compute PSOs (the largest alone took 118.45 s cold). The title loaded the 16,284,980-byte Intel cache; nine instrumented large BVH compiles now finished in 0 ms each. It passed the previous cold stop and reached 1,656 graphics calls, then a different title breakpoint with E_NOTIMPL in the error path, before the first present. No timer change or assertion skip. The cache removes the cold-compile barrier in this case; it does not make the title playable.

@fladit123 fladit123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows concurrency and timing review — REQUEST CHANGES

Tested head: 631e53120fa12d58ee30bc1601d72756af9bead7
Comparison baseline: dfe4e4ad3acfc7fe804e299e643ab06a88f1c8a7
Environment: Windows 11 build 26300, MSVC 19.51, RTX 4060, NVIDIA 610.88, Vulkan SDK 1.4.363.1.

The existing host_stall_test passes all 23 checks. The synthetic watchdog also resumes detecting lack of progress after the final stall.

However, additional independent probes identified three issues that I recommend addressing before merging.

1. Process-wide Sleep interception can prevent unrelated thread progress

In a bounded synthetic test, the thread holding the stall marker waited up to 180 ms for an acknowledgement from another thread using Sleep(10).

  • Baseline: acknowledgement arrived within the deadline.
  • PR: the wait expired; acknowledgement arrived only after the stall ended.
  • SleepEx(10, FALSE) control: acknowledgement arrived within the deadline on both versions.

This demonstrates a circular progress dependency with a safety timeout. An unbounded dependency of the same shape could deadlock.

I did not observe a permanent deadlock in the Vulkan driver or retail title.

Please consider a narrower interception policy that preserves unrelated thread progress, together with a strategy for detecting a host compilation that never returns.

2. Late native wake-ups can be compensated twice

Ledger::wake_time() uses the actual host wake-up time plus the accumulated stall duration. If the native wake-up was already delayed, this can charge part of that delay twice.

In a controlled probe:

  • Requested sleep: 15 ms.
  • Native wake-up: approximately 185 ms.
  • Covered stall time: 185 ms.
  • Guest return: approximately 386 ms.
  • Expected completion under the documented non-stalled-time contract: approximately 200 ms.

A deterministic virtual-clock example confirms the discrepancy:

Event Time
Sleep(1000) starts 0 s
Stall ends / native thread resumes 6 s
Required non-stalled budget completed 7 s
Current calculated deadline 12 s

Please capture the starting timestamp together with the ledger mark and compensate only for the remaining non-stalled sleep budget.

3. The stall scope also covers pipeline-cache initialization

The scope is constructed before evaluating device_.pipeline_cache() as a function argument.

Instrumented Vulkan calls on RTX 4060 showed:

Vulkan call Baseline: stall active PR: stall active
vkCreatePipelineCache 0/1 1/1
vkCreateComputePipelines 0/2 2/2
vkCreatePipelineLayout 0/2 0/2

The marker closed correctly after successful compilation and a synthetic driver error. No Khronos validation errors were observed.

If the intended scope is specifically driver pipeline compilation, retrieve the pipeline cache before constructing Scope. This also excludes cache-seed loading and waiting inside std::call_once. Otherwise, please explicitly document and justify the broader scope.

Additional observations

  • Overlapping and nested stalls were counted correctly.
  • Cross-thread completion preserved the remaining active marker.
  • No internal lost wakeup was reproduced.
  • Sleep(0), Sleep(INFINITE), SleepEx and the other tested synchronization bindings behaved as expected.
  • The synthetic watchdog fired again after the last stall.

However, a virtual-clock model with recurring stalls accumulated 30 seconds of non-stalled time over 63 seconds of wall time without triggering the watchdog, because each late round restarted its counter. Thus, preservation of hang detection is conditional on the stall pattern.

Verdict: REQUEST CHANGES.

The startup improvement reported by other contributors is valuable. My concern is the broader synchronization contract and the possibility of masking or introducing genuine progress failures.

I recommend addressing the unrelated-thread dependency, correcting deadline accounting and narrowing or explicitly defining the compilation scope, with deterministic regression tests.

Synthetic fixtures only. No proprietary game files, repository changes or assertion bypasses. AI-assisted review and testing with OpenAI Codex.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…ly pipeline compiles, so the title's startup hang check survives a cold boot (RT-5 follow-up, stop 18)

Squashed from ItsNotRexed#7858 by throny, head 4a51079 (security scan PASS).

Conflict in scripts/build_runtime.ps1 only: the file list keeps ItsNotRexed#7516's xbox_bvh_builder.cpp and adds host_stall.cpp.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…ompiles are host stalls

Slot 57 now creates every pipeline as one pipeline state stream through the
proxy's create_pso_from_stream (ItsNotRexed#7759), which keeps the stream on the PSO, so
slot 55 can derive from slot-57 pipelines; the stub request goes the same way.
A device without ID3D12Device2 refuses slot 57 as it refuses slot 86.

The Vulkan device's vkCreateGraphicsPipelines now runs inside the same
rt::host_stall::Scope as the compute compile (ItsNotRexed#7858), so a guest Sleep sits
out the slot-57 compile burst instead of tripping the title's hang check.

xs_native_pso_test: the mock answers only PC slot 47, its root signature and
pipelines are COM objects with private data, and a new case derives through
slot 55 from a slot-57 pipeline.
throny and others added 4 commits November 23, 2026 22:39
The Scope around vkCreateComputePipelines was constructed before
device_.pipeline_cache() was evaluated as an argument, so the first
call also counted vkCreatePipelineCache, the seed load and a second
thread's wait inside std::call_once as a host-only stall.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tside stalls, and a stall counts for at most 60 s

- Only a Sleep of 1,000 ms or more is held; a shorter one is a poll and
  stays the host's, so a thread the stall's holder waits for goes on.
- Ledger::owed replaces wake_time: the sleep's start time is read with
  the ledger mark, and a sleep returns once its length has passed
  outside stalls. A late host wake-up is no longer charged twice.
- Stalls are tracked one by one and each counts for at most
  kStallLimit (60 s). After that held Sleeps return, the time counts as
  the title's, and the shim prints one line.
- host_stall_test: the ledger, the limit, sleeps and a stand-in hang
  check on a virtual clock, and the served Sleep on real threads.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…es that take turns

One compute pipeline compile measured here took 50 s, so 60 s left no
room for a slower machine. host_stall_test gains the compile-gate
order: a compiler that waits for its turn opens the stall only around
its driver call, no stall time is counted between two turns, and
Sleep(1) polls and a Sleep(1000) go on there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@fladit123 all three points and the note are changed at a346492c6; host_stall_test now has 69 checks and passes (3 of 3 runs, MSVC 14.44, Windows 11 26300).

  • 1, unrelated threads (28a717a85): only a Sleep of 1,000 ms or more is held; a shorter one is the host's. Test: a thread polling with Sleep(10) answers the stall's holder while the stall is open. A host call that never returns: one stall counts for at most 10 minutes (804a2f447; a single compile took 118 s on the UHD 770 above), then held Sleeps return and the runtime prints one line. Tests: virtual clock, and a real Sleep(1000) under a stall that never ends.
  • 2, double charge (28a717a85): Ledger::owed replaces wake_time; the start time is read with the ledger mark and a sleep returns once its length has passed outside stalls. Your table is a test: Sleep(1000) at 0 s under a stall to 6 s returns at 7 s; your 15 ms / 185 ms probe returns at 200 ms. This also covers akimfomin's Sleep(420) case.
  • 3, scope (915db783f): the pipeline cache is fetched before the Scope. No test of its own: host_stall_test has no device. gta6rt_d3d12_com compiles.
  • Recurring stalls: bounded per case in docs/retail_boot_chain.md §5.2 and the description; each is a virtual-clock test. With no stall open: 30 rounds. Call that never returns: limit + 31 s. Other threads still compiling: 31 s after the last compile. Stalls under 2 s reset nothing.
  • d3d12_vulkan: bound concurrent compute-pipeline compiles by a host-memory budget (RT-5, A31 memory side) #9082's gate (your comment there): test compiles_that_take_turns follows your order: turn, then Scope around the driver call, then turn back. Between two turns no stall time is counted, 4 of 4 Sleep(1) polls return, and a Sleep(1000) is not held.
  • Negative controls: every Sleep held, 4 of 69 fail; stall time charged twice, 18 fail; Sleep never held, 4 fail. Not done yet: a retail cold boot with these commits.

AI-assisted (Claude Code).

@AAyberkU

Copy link
Copy Markdown
Contributor

A measured side effect of the global gate on a cold cache, from the retail 1.0.2.1 boot. Base: GitHub main + the boot PRs + this PR + #7021 + #9137 + #9276/#9014 + #9586. RTX 5060 Ti, driver 621.01. AI-assisted.

Loading stalls while compute pipelines compile, because every title Sleep is held.

  • Title file I/O stops about 30 s in, after about 870k reads and 3.7 GB. From 30 s to 120 s there are 0 reads. A trickle (about 1.3k reads) comes at about 130 s, then nothing again. Meanwhile the frame loop keeps presenting the empty boot frame.
  • Thread dump at 150 s (86 threads):
    • About 10 threads are inside the driver's shader compiler, all busy. 10–13 cores stay busy the whole time.
    • 5 title threads are parked in host_stall::Gate::hold inside the guest Sleep shim.
    • About 19 title threads are in WaitForSingleObject, and the runtime queue workers are idle.
  • The same run's log: one translated compute pipeline took 116 s to compile (about 1M SPIR-V words), and another took 3.8 s. The 2.36 GB pipeline cache is loaded but does not cover them.
  • The timing matches: I/O stops while the compiles run, and the brief resume comes when the 116 s compile ends.

So on a cold cache the gate turns long back-to-back compute compiles into a loader stall of minutes. The title's Sleep-based loader and poller threads stay held the whole time, not only the thread that waits on the compile. This is a strong inference from the dump and the timing; I have not yet run the on/off test.

Possible directions, untested:

beamdotdev added a commit to beamdotdev/Leonida that referenced this pull request Nov 23, 2026
…; link Threads

Review on ItsNotRexed#9082 (the ItsNotRexed#7858 integration order): the pipeline cache is now fetched before the gate, so creating the
cache or loading its seed holds no ticket, and the ticket covers vkCreateComputePipelines alone. A host-stall marker
placed around that call (ItsNotRexed#7858) then nests inside the ticket, in the order measured to keep unrelated guest Sleeps
returning between admissions: cache, ticket, contention log, marker, driver call, marker closed, ticket released.

admits() compares without adding, so a weight near UINT64_MAX cannot wrap; compile_gate_test links Threads::Threads
like the other threaded runtime tests, for toolchains whose pthreads are not in libc.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A single compute pipeline compile of 626 s was measured on an RTX 4080
(a wave64-emulated module of 8.6 MiB), above the 10 minutes of the
previous commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Correction to my reply above: the stall limit is 60 minutes at a4241cc7c, not 10.

  • A single compute pipeline compile of 626 s was measured on an RTX 4080 (an 8.6 MiB module translated with --wave64-emulate, alone in vk_pipeline_check), so 10 minutes would have released the hold inside a real compile.
  • Bound for a marked host call that never returns: 60 min + 31 s, with the one-line diagnostic at 60 min. The other cases are unchanged.
  • host_stall_test: 69 of 69, unchanged (its cases pass their own limits).

AI-assisted (Claude Code).

@AAyberkU

Copy link
Copy Markdown
Contributor

Measured your new head (a346492c6) on the retail 1.0.2.1 boot. Base: GitHub main + the boot PRs + #7021 + #9137 + #9276/#9014 + #9586 (local switch). RTX 5060 Ti, driver 621.01. 240 s run, AI-assisted.

The gate is now nearly empty, but loading still waits on the compiles themselves.

  • Gate::hold: 1 title thread at 150 s, against 5 before.
  • Title file I/O:
    • 3.73 GB by 30 s, the same as before.
    • After that it trickles: 3.86 GB at 40 s and 3.95 GB at 240 s.
    • 11 of the 21 later 10 s windows still read nothing. Before your change it was 0 except for one 5 MiB burst.
  • 13 compute compiles over 2 s on a cold cache, the longest 244 s. Several of about 1.0–1.15M SPIR-V words took 110–180 s each. About 10 cores stay busy throughout.
  • The title does not advance: the same resource counts as before, no uploads and no Dispatch.

So with your change the gate itself no longer blocks loading. What remains is the first-time compile of a handful of huge compute modules. With those stubbed (#9250), loading moves on. Numbers are on #9250 and #8851.

@fladit123

Copy link
Copy Markdown
Contributor

Independent Windows revalidation — follow-up

Thanks @throny for addressing the earlier findings.

I independently revalidated a4241cc7c together with #9082 at 885283a8a.

The following findings from my original review are resolved in the tested composition:

  • Pipeline-cache initialization is outside the host-stall scope.
  • Late-wake accounting no longer double-charges elapsed time.
  • Admission waits and contention diagnostics remain outside the stall scope.
  • The per-stall cutoff and watchdog resumption passed virtual-clock tests.

All 69 host-stall checks and 76 experimental scenarios produced the expected results, including negative controls.

One concern remains: an independent worker returned from Sleep(999) while the synthetic driver was active, but Sleep(1000) and Sleep(1001) were held until the driver returned and the remaining non-stall time elapsed.

The duration threshold reduces the impact, but does not distinguish watchdog-related waits from unrelated long sleeps.

I also acknowledge AAyberkU's newer retail results showing substantially fewer held threads and improved loading progress. My synthetic result does not establish that the reported retail loading stall persists on the current head.

Could we narrow eligibility to the watchdog context, or establish that holding other long sleepers is safe for independent progress?

The integration order with #9082 is now validated from my side. The remaining question is limited to global Sleep eligibility.

Synthetic inputs only. AI-assisted investigation with OpenAI Codex.

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.