Repository navigation
Conversation
The clock released the origin semaphore and only then queued the origin's
QPC. A WaitFrameEventX woken by that release could take the ORIGINS lock
first, find the queue empty and use a fresh QPC. The next wait then got the
older origin, so origins went backwards. The frame-statistics test caught
this now and then ("each frame its own origin").
publish_origin now holds the queue lock across the release and the push,
and take_origin is the wait's side. Reported in a review comment on ivall#165.
Test: a_woken_wait_takes_the_origin_that_woke_it pauses between the
release and the push. With the old order it fails every time (20 of 20
runs: the wait gets no origin); with the lock held it passes (0 of 20).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
488e5fe to
5107d8a
Compare
|
Rebased on main eaa36b6 (5107d8a, no conflicts). Overlaps: main's 956a476 (every event type due at one deadline fires) and #165, closed as covered by it. This PR is the separate ordering race between queueing an origin and the wait it wakes, which neither changed. |
|
Independent static concurrency audit of Summary: Fixes the publish/take race cleanly and deadlock-free
One subtle edge case under full-semaphore backpressure (
|
|
Merged into main (6da33fa) as 488e5fe, the head before your last rebase - the same patch (identical patch-id), so GitHub does not show it as merged; closing it by hand. Checked on an RX 9070 (RDNA4) with the 22 PRs merged together: 582 unit tests passed, 0 failed, the integration and e2e tests passed, and the retail game still reaches its first menu (646 frames in 30 s, no device removal). Thanks! |
Based on main 956a476. Commit 488e5fe.
Problem
On every origin (type 0), the clock thread released the origin semaphore and then queued the origin's QPC in
ORIGINS(frame.rs,clock_thread). AWaitFrameEventXwoken by that release could take theORIGINSlock before the clock did. It found the queue empty and fell back to a freshqpc(). The next wait then took the origin left in the queue, which was older. So origins could go backwards, and frame statistics could name the wrong frame's origin. The ordering was pointed out in a review comment on #165 (#165 (comment)).The existing test
statistics_name_each_frames_origin_and_rescheduled_handles_outlive_the_clock_tickhits this now and then. It failed once ("each frame its own origin", the third origin earlier than the second) in a full workspace run for #199, and passed on the rerun.Change
publish_origin(the clock's side) holds theORIGINSlock acrossReleaseSemaphoreand the push. A woken wait blocks on the lock until its origin is queued.take_originis the wait's side, unchanged in behaviour.ORIGIN_SEMAPHORE_MAXpending) still drops the origin, as before.after_releaseis a closure that runs between the release and the push. Production passes|| {}; the test uses it to pause there.Tests
a_woken_wait_takes_the_origin_that_woke_it(CPU, its own semaphore and queue, not the process clock). It pauses 100 ms between the release and the push, and the woken wait must get that origin. Two more origins must then come back in order.hle::d3d12x::frame), 50 runs each,--test-threads=2: this branch 50 of 50 pass (4 tests); main 956a476 50 of 50 pass (3 tests). The original flake didn't show up in isolation on either. The forced interleaving above is the reproduction.cargo test -p xcl --lib -- --test-threads=2on an RTX 5070 Ti (NVIDIA 610.74, Windows 11): 537 passed, 0 failed, 19 ignored. That is main's 536 plus the new test; two wave64 tests skip on this GPU.Overlap
#165 rewrites the same block of
clock_threadand keeps the old order, so the two will conflict textually. Whichever lands second needs a one-line merge: callpublish_origininside #165's loop.Not covered
AI-assisted (Claude Code). No game data.
🤖 Generated with Claude Code