Skip to content

kernelx: XCL_TRACE_WAITS names what the title's waiting threads wait on - #924

Open
Xeltax wants to merge 2 commits into
xcl-dev:mainfrom
Xeltax:trace-waits
Open

Xeltax wants to merge 2 commits into
xcl-dev:mainfrom
Xeltax:trace-waits

Conversation

@Xeltax

@Xeltax Xeltax commented Nov 24, 2026 •

Copy link
Copy Markdown

XCL_TRACE_WAITS=1: at each thread dump (XCL_THREAD_DUMP_AT, a crash), XCL lists the title's threads that have waited 2 s or more on the title's own events and semaphores. For each one it gives the handles, where in the title each handle was made, and when and from where it was last set or released ("never" when the title never signaled it). The thread stacks say where each thread is; this says which object a waiting thread is waiting for, and so which other thread it depends on. Part of #505.

What is in it

  • a2b5007: each dump starts with the size of the tracer's two tables (handles known, threads waiting), after a Wine run in this thread saw host memory grow with the variable set.
  • crates/xcl/src/hle/waits.rs (new):
    • wrappers for the title's CreateEventA/W, CreateEventExW, CreateSemaphoreW, CreateSemaphoreExW, SetEvent, ReleaseSemaphore, CloseHandle, WaitForSingleObject(Ex) and WaitForMultipleObjects(Ex). Each calls Windows, then records the handle's maker and last signaler, and the calling thread's wait.
    • long_waits() builds the report lines. A handle not made through these imports is named by its kernel type (NtQueryObject). Polls (timeout 0) are not recorded as waits.
  • crates/xcl/src/hle/mod.rs: with the variable set, the wrappers join kernelx's exports, so the title's kernel-family imports reach them. Without it, the import table is unchanged.
  • crates/xcl/src/eh.rs: dump_threads logs the list after the thread stacks.
  • Tests (unit, real Windows objects):
    • a_thread_waiting_on_an_event_nobody_set_is_listed_until_the_event_is_set
    • a_poll_is_not_a_wait_and_semaphores_count_releases
    • an_object_made_elsewhere_is_named_by_its_kernel_type

What it showed on the retail title of #505 (RTX 4080, main 1ec4c98 + this change, XCL_THREAD_DUMP_AT=88,98, A pressed through XCL_PRESS_AT; frames stop at ~74 s, +0x23cf683 at ~104 s)
The dumps give one chain of waits, from the main thread down to a compute bind:

  • The main thread (+0x23cf735) waits on semaphore 0xff8. The frame-loop thread released it 619 times, from +0x23cf2c9, the last time at 73.6 s.
  • The frame-loop thread (+0x23cf104; it makes the first ListX #101 call) waits from ~85 s until the abort at +0x43c3d5d. It waits on an event of a 128-entry ring made at start (+0x43c39dc, one event per entry). The title never sets that event through SetEvent.
  • That ring's worker thread (+0x43c4314 ← +0x43c4591) builds compute pipelines in its binds during the stall: 31 builds on its own thread between 74 and 96.6 s, per the log lines.
  • The other ~45 title threads wait on job-system events that were set until ~74 s, then go idle.
  • With D3D12.X: XCL_PSO_WAIT_MS bounds how long a bind waits for a pipeline being built (retail world renders) #891 (XCL_PSO_WAIT_MS=50) merged locally, the frame-loop thread's wait ends after ~25 s.

This agrees with the compute-bind waits that throny (#232), leondood1298 and emusynths (#505) found in thread stacks. The new part is the objects and which thread each wait depends on.

Tested

Regression run (60 s, XCL_TRACE_WAITS unset)

main:

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: NVIDIA GeForce RTX 4080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16479 MB

PR:

xcl-smoke v1
commit: a2b500731907c40f1171520af53820d70918312f
gpu: NVIDIA GeForce RTX 4080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1644 (PresentX 1644)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17742 MB

Not tested

  • AMD and Intel GPUs. The change does not touch the GPU path, but no run was made there.
  • Waits that do not go through the title's imports: SleepConditionVariable*, SleepEx, WaitOnAddress, and handles waited on inside system DLLs.
  • What sets the ring's events. It is neither the title's SetEvent nor ID3D12Fence::SetEventOnCompletion (checked with a local hook that is not part of this PR).

@throny: here is the branch, as you offered to run it.

AI use

  • Claude Code (Claude Opus 5.5) wrote the code, the tests and this description, ran the title and the tests, and read the logs.

🤖 Generated with Claude Code

A thread dump shows where each thread is, not what a waiting thread
waits for. In the retail title's world-loading stall (xcl-dev#505) most title
threads sit in WaitForSingleObject called straight from the title, so
the stacks alone cannot tell which thread depends on which.

With XCL_TRACE_WAITS=1 the title's event and semaphore imports
(CreateEvent*, CreateSemaphore*, SetEvent, ReleaseSemaphore,
CloseHandle, WaitForSingleObject(Ex), WaitForMultipleObjects(Ex)) go
through wrappers in hle::waits that record each handle's maker and last
signaler and each thread's current wait. Every thread dump then lists
the title's threads waiting 2 s or more, with those details; a handle
made elsewhere is named by its kernel type. Without the variable the
import table is unchanged.

On the retail title this showed the frame-loop thread (+0x23cf104)
waiting at +0x43c3d5d on an event of a 128-entry ring made at
+0x43c39dc, never set through SetEvent, while that ring's worker
(+0x43c4314) built compute pipelines in its binds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frozht

frozht commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Correction: this report was wrong. The memory growth was not caused by #924.

Between runs, the earlier-run pipeline list (used-pipelines.txt, which #690 preloads) grew from 397 to 1010 entries. Preloading 1010 entries runs the same build out of memory at about 170 s with XCL_TRACE_WAITS unset. With the list trimmed back to 397, memory is 7.6 GB at 300 s. The run I reported here preloaded the larger list, so it says nothing about XCL_TRACE_WAITS. Sorry for the noise. I'll post a new result here only after a run with the same list.

Previous text: XCL_TRACE_WAITS=1 grows host memory: 16 GB at 121 s against 8.7 GB, OOM at 318 s.

  • Correction written with Claude Code (Claude Opus 5.5).

A test run under Wine (xcl-dev#924) saw the process's host memory grow much
faster with the variable set than without it. On Windows the commit
with and without it is the same at 20 to 100 s. The tracer's two tables
are keyed by handle and by thread and should stay small; printing their
sizes with every dump shows whether they are what grows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Xeltax

Xeltax commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks for the run, @frozht. I can't reproduce the growth on Windows, and the tracer's own tables stay small:

  • Commit with and without the variable (RTX 4080, Windows 11, 1ec4c98 + this change, world loading):

    20 s 40 s 60 s 80 s 100 s
    without XCL_TRACE_WAITS 15.1 GB 16.5 GB 19.6 GB 28.1 GB 28.8 GB
    with it 15.4 GB 16.5 GB 19.8 GB 28.2 GB 28.5 GB
  • The tables themselves. I pushed a2b5007, which makes each dump start with the size of the two tables. On Windows, with XCL_THREAD_DUMP_AT=60,120 and the abort at 115 s, they held 851 and 878 handles, and 42 and 44 waiting threads. Both are keyed by handle and by thread, and an entry goes with CloseHandle or when its wait returns.

So if the 7 GB you see comes from this code, it is not these tables. Could you rerun a2b5007 under Wine with XCL_THREAD_DUMP_AT=60?

  • If the counts are small there too, the growth is somewhere the wrappers call into.
  • A guess, not checked: Wine's RtlCaptureStackBackTrace, which every recorded wait calls once to find the title's caller. If that is it, recording the caller only for waits that last could be the fix. I'd rather measure first.

AI use: Claude Code (Claude Opus 5.5) ran the comparison and wrote this reply.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head dc0fb78 onto main 02bfd1d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 719 passed, 11 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). XCL_TRACE_WAITS naming green.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants