Skip to content

XGameRuntime: drain active task queue monitors on unregister - #2836

Closed
CryingLaughing wants to merge 1 commit into
xcl-dev:mainfrom
CryingLaughing:fix/taskqueue-monitor-unregister
Closed

CryingLaughing wants to merge 1 commit into
xcl-dev:mainfrom
CryingLaughing:fix/taskqueue-monitor-unregister

Conversation

@CryingLaughing

Copy link
Copy Markdown
Contributor

XTaskQueueUnregisterMonitor could return while a monitor still used its context. It could also leave a copied notification snapshot able to invoke the removed registration. Native Windows unregister waited for the running callback in the synthetic comparison. Related to #2021, which covers monitor delivery through shared ports.

What is in it

  • Revoke the registration so notification snapshots skip it. Keep it discoverable until its active invocations finish, so concurrent unregister calls can wait for the same drain.
  • Release the queue and registration locks before invoking monitor code. Calls from a monitor callback stack revoke without waiting, preserving XCL’s existing reentrant behavior.
  • Cover an active callback with two concurrent unregister callers, a revoked entry in an older snapshot, and a monitor unregistering itself.

Tested

  • Head 43a4eb9dacbe1cc1e746609f979597d27538979f on 8b957bec6f82495aec940944c6bf47faa02db590. Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11, debug.
  • The native xgameruntime.dll 10.0.26100.9656 probe ran nine trials in three fresh CPU processes. The external unregister caller returned only after the held callback ended in all nine. Every subsequent submission completed without another monitor invocation.
  • The same three focused tests reported 1 passed, 2 failed, 0 ignored on main with the test-only overlay and 3 passed, 0 failed, 0 ignored on the exact head. Both main failures reproduced the intended timing or stale-snapshot condition. The focused cases had zero capability skips.
  • cargo build --workspace --locked -j 4 passed. cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output reported 1,449 passed, 0 failed, 47 ignored across 38 harnesses. The pass count includes 29 capability skips and 10 separate unset optional sample messages.

Regression run

Matched retail smoke is pending.

Not tested

  • Native Windows reentrant monitor management, other Windows runtime versions, and retail-title behavior.

A notification snapshot can outlive removal from the queue registry. Revoke each registration before waiting, keep it discoverable until its active calls finish, and skip revoked entries in older snapshots. Keep callback-stack unregistration nonblocking so existing monitor callbacks can unregister safely.
@MatyEjsr

MatyEjsr commented Nov 26, 2026 •

Copy link
Copy Markdown

Independent NVIDIA Windows verification and concurrency review of PR #2836 at exact head 43a4eb9dacbe1cc1e746609f979597d27538979f (currently MERGEABLE onto base main 8b957bec6f82495aec940944c6bf47faa02db590).

Tested

  • Windows 11 Pro for Workstations (build 26200.7171), AMD Ryzen 7 7800X3D, 31.4 GB RAM (32 GB), NVIDIA GeForce RTX 3090 (driver 32.0.16.1742, wave32 only), rustc 1.100.0, DXC 1.9.2602.17.
  • cargo build --workspace -j 8 and cargo build --release --workspace -j 8 on 43a4eb9d: passed.
  • cargo test -p xcl --lib hle::xgameruntime::taskqueue:: -- --nocapture:
    • Base main (8b957bec): 10 passed, 0 failed, 0 ignored, 0 skipped.
    • PR head (43a4eb9d, debug): 13 passed, 0 failed, 0 ignored, 0 skipped (the 3 new monitor drain/revocation tests pass).
    • PR head (43a4eb9d, release, 10 consecutive runs): 10/10 passed (13 passed, 0 failed, 0 ignored, 0 skipped each; 0.25-0.26 s per run).
  • cargo test --workspace -j 8 -- --test-threads=8 --nocapture (43a4eb9d, debug): 1,449 passed, 0 failed, 47 ignored across 38 harnesses; 28 explicit SKIPPED lines (21 no wave64, 3 wave32, per-lane form: refused, 3 missing D3D12 debug layer, 1 no heap windows) and 10 unset optional XCL_SAMPLE_* skips (8 XCL_SAMPLE_RPF, 1 XCL_SAMPLE_TTPF, 1 XCL_SAMPLE_AWC) — reported separately and not counted as coverage.
  • cargo test --release -p xcl --test e2e -- --nocapture (43a4eb9d, release): 4 passed, 0 failed, 0 ignored; 2 D3D12 debug-layer SKIPPED subcases for missing d3d12SDKLayers.dll (not counted as coverage).

Regression run & PR checks

  • scripts/smoke.ps1 -Seconds 60 on PR head 43a4eb9d (default -StartupTimeoutSeconds 120) timed out at 180 s during base 8b957bec's pre-launch shader preparation over 26,503 pack records before reaching guest execution (XCL printed no log path, exit code 1). No xcl-smoke v1 pair was produced.
  • The PR checks / PR description check currently fails on 43a4eb9d because the PR body is missing the **AI use** section and both matched xcl-smoke blocks (main + PR head) under **Regression run**.

Code review & overlap check

  • Concurrency and lock ordering in crates/xcl/src/hle/xgameruntime/taskqueue.rs look sound: Monitor::invoke checks revoked before incrementing running, remove_monitor runs only once revoked && running == 0, and neither q.monitors nor monitor.state is held across callbacks or idle.wait(...).
  • Note on MONITOR_DEPTH: because it is a thread-local nesting counter rather than a per-token set, calling XTaskQueueUnregisterMonitor on a distinct monitor B from inside monitor A's callback takes the non-blocking path and returns without draining B if B is active on another thread. That avoids AB-BA deadlock between two monitors unregistering each other and aligns with the PR's Not tested note on reentrant monitor management.
  • Overlap triage: not a duplicate of any merged or open PR; nvidia-dev does not touch taskqueue.rs. Open PR XGameRuntime: a task queue's termination callback runs on its completion port #1154 (termination callback) is unrelated; open PR XGameRuntime: notify shared-port monitors with temporary queue handles #2021 also modifies monitor notification in taskqueue.rs (distinct change; minor rebase coordination if both land); open PR XGameRuntime: dispatch serialized task queue work on the caller #2806 updates the same README.md feature-table row (trivial rebase conflict for whichever lands second).

Not tested

  • Completed retail xcl-smoke v1 pair (blocked by base 8b957bec startup shader preparation exceeding the default smoke.ps1 timeout), AMD / Intel / native wave64 GPUs, D3D12 debug-layer subcases, heap_window_out_of_memory_falls_back_to_the_switch_form, optional XCL_SAMPLE_* tests, and native Windows reentrant monitor behavior.

AI use

  • Antigravity (agy) with gemini-pro-orchestrator (audited by gemini-pro-orchestrator-argon) ran the build, test, release stress, and smoke checks, reviewed the concurrency diff and PR overlap, and audited this report.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…ue shape (both twins)

Upstream xcl-dev#2836 (43a4eb9, OPEN) drains in-flight taskqueue monitor
callbacks on unregister (revoked flag + running count + Condvar +
MONITOR_DEPTH reentrancy guard + skip-revoked-snapshot). Cannot land
verbatim: tree diverged via xcl-dev#2021 (d1ce58c) - Monitor has no
queue_handle, notify_monitors is Port-level fan-out with synthesized
temp handles in BOTH hle/xgameruntime/taskqueue.rs and
hle/xtaskqueue_linux.rs (Linux-live twin).

Adaptation: Arc<Monitor> with state/idle, invoke(handle,port),
revoke/wait, remove-if-drained; register/unregister updated; 3
upstream tests ported per twin failing-first (Linux twin 2 failed
pre-fix as predicted, 3/3 post-fix; Windows-twin tests mirror but
cannot execute on Linux - parse-verified only).

Gates: checks 0 errors; lib 783/0/1; e2e sets identical to baseline;
retail SIGSEGV exe+0x2237320 stubs 20 xgr XAsync/XNetworking/XUser HOLDS.
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