Skip to content

Tests: alloc_pool checks for STATE held by the caller, not by a parallel test - #3190

Open
tiagonleal wants to merge 2 commits into
xcl-dev:mainfrom
tiagonleal:tests/alloc-pool-timing
Open

tiagonleal wants to merge 2 commits into
xcl-dev:mainfrom
tiagonleal:tests/alloc-pool-timing

Conversation

@tiagonleal

@tiagonleal tiagonleal commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3180. Two alloc_pool tests failed on CI today on commits that do not touch them: submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker ("queue invalidation can run while Signal is outside STATE") and completion_queries_run_outside_allocator_state ("in-flight polling must not hold STATE").

Both check that a callback runs outside STATE with a single STATE.try_lock().is_ok(). STATE is one mutex for the whole process, and the other alloc_pool tests, which run in parallel, hold it for short stretches. So the single try_lock fails whenever another test holds the lock at that moment, with nothing wrong in the code under test.

A third test in the file, transferred_owner_is_released_once_outside_state_after_logical_forget, fails under load for a related reason: other tests call forget(), whose sweep runs over every retired backing in the shared STATE, so a parallel test can release this test's owner first. The test's own sweep then finds nothing and returns while the other thread is still inside the release, and the check reads (refs, releases) = (1, 0). The owner is still released exactly once; it is not a runtime defect. andrewDoing reproduced this interleaving independently in a comment below.

Rebased onto main f97120dc. main added a test at the place of the helper; both are kept, and the diff is unchanged (+22/-4).

What is in it

  • alloc_pool.rs (test module): a helper state_not_held_by_caller() retries try_lock for up to 10 s, and the four checks use it. A try_lock from the thread that holds the lock never succeeds, so the deadline is reached only when the code really holds STATE. Test code only, no assertion removed.
  • Second commit: transferred_owner_is_released_once_outside_state_after_logical_forget waits up to 10 s for the release to arrive before the same assertions as before. +6.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug
  • Before: the alloc_pool tests run 40 times with --test-threads=32: 31 runs failed, with these two tests panicking 23 and 18 times, at the lines of both CI messages. After: 40 runs, neither test failed.
  • The tests still catch the defect: with STATE held around the queue Signal and around GetCompletedValue in the code under test (scratch edits, reverted), both fail after 10 s with "queue Signal must run outside STATE" and "in-flight polling must not hold STATE".
  • cargo test -p xcl --lib hle::d3d12x::alloc_pool -- --test-threads=4: 27 passed, 0 failed.
  • cargo test -p xcl --lib alloc_pool -- --test-threads=32, 20 runs on head fb24a2e6: 0 failures.
  • Third test: with temporary logging, 5 late releases in 40 runs at --test-threads=32, each from another test's sweep (released_lists_leave_only_live_recordings_and_gpu_work_holding_the_backing, submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker twice, submit_reservation_drop_and_failure_are_fail_closed, submit_reservation_keeps_pre_reset_attribution_across_queues). The test failed in 2 of 40 and 5 of 40 runs in two earlier loops and 1 of 40 in the loop before this commit; 0 of 40 after.
  • After the rebase onto main f97120dc (head 353546c6): cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4, one run: 2841 passed, 0 failed, 51 ignored (24 SKIPPED lines: 22 no wave64, 2 no heap windows; the same 24 in both logs); main f97120dc on this machine: 2841 passed, 0 failed, 51 ignored.

Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e (Newer Retail Game), release builds in clean trees, one run each, XCL_PREPARE=0, same DXIL cache. No code outside #[cfg(test)] changes; the run is there because alloc_pool.rs is a runtime file.

main (f97120dc):

xcl-smoke v1
commit: f97120dc196ca05e7f47e919d3675f7d5a2b478a
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1635 (PresentX 1635)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15366 MB

This PR (353546c6):

xcl-smoke v1
commit: 353546c6bb26a05d777600fa1ce21b516379db0f
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1681 (PresentX 1681)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15728 MB

Not tested

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

@tiagonleal
tiagonleal marked this pull request as ready for review November 28, 2026 17:26
@andrewDoing

Copy link
Copy Markdown
Contributor

I reproduced one interleaving that explains the remaining transferred_owner_is_released_once_outside_state_after_logical_forget counter failure at bfc9e9fa.

With a test-only change to that fixture, I let a competing thread call the actual sweep_release_owners_with and pause in its release_transferred callback before dropping the fake allocator. The backing had already been removed under STATE. The fixture thread then called its own sweep; it returned normally because the backing was gone. At the stock assertion point the fake COM counters were (refs=1, releases=0). I let the competing callback finish and reran the same reads: (0,1), and the existing outside-lock and backing-removal checks passed. Both channel waits were bounded. One focused Windows test passed without skips; no GPU used.

A test-local completion notification from the fake allocator callback after its final counter update, with a bounded wait before checking the counters, would preserve the exactly-once check while allowing another sweep to own the release. The production ordering deliberately releases outside the lock. This establishes a possible counter failure on the real sweep path; it does not identify the schedule of the earlier stress failures.

AI use: OpenAI Codex added the focused interleaving, ran the test and prepared this report.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Independently reran the pinned standalone CPU executable for bfc9e9faffbe0272e8313a76132f6ea2f621283a on Windows 11 x64 build 26200.9974 with a Ryzen 7 3800X. The executable was built with Rust 1.100.1 (x86_64 MSVC). The 328-byte state_not_held_by_caller helper matched the Git source byte for byte. The harness used a stand-in Mutex<()> for STATE.

alloc_pool_lock_helper.exe --exact tests::other_thread_releases_state --nocapture --test-threads=1
alloc_pool_lock_helper.exe --exact tests::caller_keeps_state_through_deadline --nocapture --test-threads=1

Both native processes exited 0. Total was 2 passed, 0 failed, 0 ignored, 0 skipped. With another thread holding the lock, try_lock returned WouldBlock before the call, and the helper returned true after the holder dropped the guard following the fixture's 500 ms delay. With the calling thread holding the lock, the helper returned false at the ten-second deadline. The lock still returned WouldBlock until the caller dropped its guard, and the idle helper check then returned true.

Not tested

Real allocator state, the allocator test module, runtime callbacks, D3D12, GPU, retail titles, the workspace suite, performance, and flake rate.

AI use

T3 Code through Codex (gpt-6.2-sol, high) prepared the standalone fixture, verified the source and executable, independently reran both tests, and drafted this report.

@tiagonleal

Copy link
Copy Markdown
Contributor Author

@andrewDoing thanks, that is the interleaving. Temporary logging here showed the same thing from the other side: in 40 runs at --test-threads=32, 5 late releases, each made by another test's sweep after it had taken this test's backing out under STATE. The second commit (e20411ad) does what you describe in a smaller form: after its own sweep the test waits up to 10 s for the release to arrive and then runs the same assertions. It does not add a completion notification to the fake allocator; if a maintainer prefers that, it is a small change on top.

@JJAutoCompare thanks for the check of the helper.

AI use: Claude Code wrote this comment (Claude Fable 5.2); Claude Opus 5.5 ran the loops.

@tiagonleal
tiagonleal force-pushed the tests/alloc-pool-timing branch from e20411a to fb24a2e Compare November 29, 2026 11:32
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@tiagonleal
tiagonleal force-pushed the tests/alloc-pool-timing branch from fb24a2e to 2d2dc34 Compare November 29, 2026 19:17
completion_queries_run_outside_allocator_state and
submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker check
that a callback runs outside STATE with a single STATE.try_lock(). STATE
is process-wide and other alloc_pool tests running in parallel take it
for short sections, so that try_lock fails whenever a sibling test holds
it at that instant, even though the caller does not (xcl-dev#3180).

The checks now retry try_lock for up to 10 s. If the calling thread
holds STATE, try_lock keeps returning WouldBlock and the assertion still
fails (checked by taking STATE around the Signal call and the in_flight
GetCompletedValue call: both tests fail after 10 s).

Before: alloc_pool tests with --test-threads=32, 40 runs: 31 failed,
these two tests failed 41 times. After: 0 failures of these two.
transferred_owner_is_released_once_outside_state_after_logical_forget
asserts (refs, releases) == (0, 1) right after its own sweep. STATE is
process-wide, and other alloc_pool tests call forget(), which runs
sweep_release_owners() over every retired backing. Under
--test-threads=32 one of those sweeps can remove this test's backing
first; our sweep then finds nothing and returns while the other thread
is still inside the (deliberately slow) fake Release, so the check saw
(1, 0). Temporary logging showed the late release came from
released_lists_leave_only_live_recordings_and_gpu_work_holding_the_backing,
submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker and
two submit_reservation_* tests, each releasing exactly once.

Wait (bounded, 10 s) for the release to land before the unchanged
assertions. 40 runs at 32 threads: 1 failure before, 0 after.
@tiagonleal
tiagonleal force-pushed the tests/alloc-pool-timing branch from 2d2dc34 to 353546c Compare November 30, 2026 04:41
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: 353546c

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 86e86fc
head: 353546c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2889 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same run: 2889 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache).
review: no blocking finding; test-only, one file (+22/-4), every line read. The four STATE.try_lock().is_ok() checks go through state_not_held_by_caller(), which retries until a 10 s deadline: std::sync::Mutex is not re-entrant, so when the calling thread itself holds STATE every try_lock fails and the helper still returns false, which keeps the checks meaningful. transferred_owner_is_released_once_outside_state_after_logical_forget waits up to 10 s for a release another test's sweep may be finishing, then makes the same (0, 1) assertion as before. Both waits spin with yield_now, so a real failure now takes 10 s of one core before it reports; not blocking. The failures this is for did not occur on the base in this run, so the run shows no regression, not the fix. No runtime code changes.
performance: none: tests only.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 353546c

#3183 and #3472 are also part of #3180 but touch other tests (pipeline_library serialisation, fake allocator backings in bind.rs/list_x.rs); no open or merged PR changes these four alloc_pool checks or the late-release wait. The helper only retries try_lock and keeps the 10 s fail path when the caller really holds STATE; no problems found in the diff.

Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 353546c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2900 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+22/-4, inside the alloc_pool.rs test module). state_not_held_by_caller() retries STATE.try_lock() for up to 10 s instead of once. A std::sync::Mutex held by the calling thread makes try_lock return WouldBlock every time, so a real "called inside STATE" still fails, now after the deadline, as the description's scratch-edit check shows. A lock held briefly by a parallel test no longer fails it. The third test waits up to 10 s for the release that another test's forget() sweep can deliver first, then makes the same assertions. Findings (minor): a genuine regression now costs 10 s per check before the test fails, which is fine for a test. Fine: no assertion is removed or weakened, nothing outside #[cfg(test)] changes, and the description's 40-run loops at --test-threads=32 (31 failing before, 0 after) match the two CI messages in #3180. No smoke run here: test-only.
performance: no smoke run (the default path doesn't reach this change); not measured. Test-only: no runtime path changes.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added the ready-to-merge Has 2 independent safe merge-checks on current head (#3041) label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants