Skip to content

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

Closed
ufoptg wants to merge 2 commits into
mainfrom
upstream-pr/924
Closed

ufoptg wants to merge 2 commits into
mainfrom
upstream-pr/924

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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 xcl-dev#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 xcl-dev#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) xcl-dev/xcl#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 (xcl-dev#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


Mirror of xcl-dev#924 (auto-synced, do not edit).

Xeltax and others added 2 commits November 24, 2026 09:03
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>
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>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#924 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/924 branch November 25, 2026 00:07
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.

2 participants