XGameRuntime: grow the task queue thread pool when all workers are busy #799

Open
mastrr9 wants to merge 1 commit from upstream-pr/805 into main
mastrr9 commented 2026-11-24 05:41:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T05:41:30Z.


ThreadPool and SerializedThreadPool ports share a single fixed pool of available_parallelism().clamp(2, 8) workers fed by an mpsc channel. When that many callbacks block simultaneously (for example, waiting on an event set by a later callback or on XAsync work queued to the same pool), no other thread-pool callback can run and the title hangs. The Windows system thread pool grows on demand when work items block.

What is in it

  • crates/xcl/src/hle/xgameruntime/taskqueue.rs: replaces the fixed mpsc pool with Mutex<PoolState> + Condvar. spawn() wakes an idle worker when g.idle >= g.queue.len(), otherwise starts a new worker up to MAX_WORKERS = 256 (rolling back workers and notifying on spawn failure). Excess workers above base (available_parallelism().clamp(2, 8)) exit after 30 s idle.
  • Regression test thread_pool_callbacks_finish_when_more_block_than_there_are_cores (blocks 2 * base + 1 callbacks and verifies the releasing callback queued last runs within 2 s).
  • Note: PR #315 also touches taskqueue.rs (waiter tracking / termination), not the worker pool.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Negative control (unmodified main d208e14): thread_pool_callbacks_finish_when_more_block_than_there_are_cores failed after 4.00 s (left: 7, right: 16, confirming pool starvation).
  • Command (identical tree at 42486b2 / pushed head 0aac79f): cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 705 passed, 0 failed, 41 ignored (0 new warnings; new test passed in 0.01 s).
  • SKIPPED (2): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run
Smoke run by @Toons29 in comment below: https://github.com/xcl-dev/xcl/pull/805#issuecomment-7151483419
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.

main:

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB

PR:

xcl-smoke v1
commit: e88ee4d1ce9b4121f95f6c857e4ee14bf9f40858
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14810 MB

Tester's setup and limits: AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

Tester's AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; the tester checked the blocks before posting.

Not tested

  • By the author: AMD/wave64 hardware, release build, and 30 s idle worker exit timing.
  • Whether the community regression run above reaches the code this PR changes.

AI use

  • Claude Opus 5.5 (via Claude Duet / Claude Code) identified the bug from source review and drafted the initial patch.
  • Antigravity (Gemini 4 Neon) audited the code, verified the negative control and full Windows RTX 5080 MSVC workspace suite, and drafted this PR description.
  • Claude Code (Claude Sonnet 5.5) added the community regression run to this description and updated the lines that it made out of date or that the PR check requires.
<!-- greyfinch-sync:ivall/xcl:issue:5466792013 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805). Originally posted by [mastrr9](https://github.com/mastrr9) on 2026-11-24T05:41:30Z. --- `ThreadPool` and `SerializedThreadPool` ports share a single fixed pool of `available_parallelism().clamp(2, 8)` workers fed by an `mpsc` channel. When that many callbacks block simultaneously (for example, waiting on an event set by a later callback or on `XAsync` work queued to the same pool), no other thread-pool callback can run and the title hangs. The Windows system thread pool grows on demand when work items block. **What is in it** - `crates/xcl/src/hle/xgameruntime/taskqueue.rs`: replaces the fixed `mpsc` pool with `Mutex<PoolState>` + `Condvar`. `spawn()` wakes an idle worker when `g.idle >= g.queue.len()`, otherwise starts a new worker up to `MAX_WORKERS = 256` (rolling back `workers` and notifying on spawn failure). Excess workers above `base` (`available_parallelism().clamp(2, 8)`) exit after 30 s idle. - Regression test `thread_pool_callbacks_finish_when_more_block_than_there_are_cores` (blocks `2 * base + 1` callbacks and verifies the releasing callback queued last runs within 2 s). - Note: PR #315 also touches `taskqueue.rs` (waiter tracking / termination), not the worker pool. **Tested** - **Environment:** NVIDIA GeForce RTX 5080 (16 GB, wave32, driver `617.42` / `32.0.16.1742`), Windows 11 Pro 25H2 (`26200.9974`), D3D12 debug layer installed (`d3d12SDKLayers.dll`), `rustc 1.100.0 (0ef1bc386 2026-11-09)` MSVC, DXC from Windows SDK `10.0.26100.0`, debug build. - **Negative control (unmodified `main` `d208e14`):** `thread_pool_callbacks_finish_when_more_block_than_there_are_cores` **failed** after 4.00 s (`left: 7, right: 16`, confirming pool starvation). - **Command (identical tree at `42486b2` / pushed head `0aac79f`):** `cargo build --workspace && cargo test --workspace -- --test-threads=4` - **Result:** **705 passed, 0 failed, 41 ignored** (0 new warnings; new test passed in 0.01 s). - **SKIPPED (2):** `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` (`no wave64`), `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (`no wave64`). **Regression run** Smoke run by @Toons29 in comment below: https://github.com/xcl-dev/xcl/pull/805#issuecomment-7151483419 Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted. main: ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` PR: ``` xcl-smoke v1 commit: e88ee4d1ce9b4121f95f6c857e4ee14bf9f40858 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1617 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14810 MB ``` Tester's setup and limits: AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. Tester's AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; the tester checked the blocks before posting. **Not tested** - By the author: AMD/wave64 hardware, release build, and 30 s idle worker exit timing. - Whether the community regression run above reaches the code this PR changes. **AI use** - Claude Opus 5.5 (via Claude Duet / Claude Code) identified the bug from source review and drafted the initial patch. - Antigravity (Gemini 4 Neon) audited the code, verified the negative control and full Windows RTX 5080 MSVC workspace suite, and drafted this PR description. - Claude Code (Claude Sonnet 5.5) added the community regression run to this description and updated the lines that it made out of date or that the PR check requires.
futurepro62 commented 2026-11-24 07:06:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T07:06:09Z.


Full-suite run, since this PR has no test report yet. Tested exact head 0aac79f (on its base d208e14).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 705 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: thread_pool_callbacks_finish_when_more_block_than_there_are_cores.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7124617813 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/805#issuecomment-7124617813). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T07:06:09Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `0aac79f` (on its base `d208e14`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **705 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `thread_pool_callbacks_finish_when_more_block_than_there_are_cores`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
SlopTart commented 2026-11-24 09:07:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T08:09:48Z.


Linux / AMD RDNA3 datapoint.

Merged state: head 0aac79f onto main 1ec4c98, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 705 passed, 11 failed, 41 ignored. Failures = the known Wine-lane set from my #42 rows plus #718 trio members and a hit of gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes (new flake, see #718 addendum). task-queue thread-pool growth tests 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.

<!-- greyfinch-sync:ivall/xcl:comment:7125800020 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/805#issuecomment-7125800020). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-24T08:09:48Z. --- Linux / AMD RDNA3 datapoint. **Merged state:** head `0aac79f` onto main `1ec4c98`, clean merge. **Full suite, `cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4`:** **705 passed, 11 failed, 41 ignored**. Failures = the known Wine-lane set from my #42 rows plus #718 trio members and a hit of `gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes` (new flake, see #718 addendum). task-queue thread-pool growth tests 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.
Toons29 commented 2026-11-25 03:05:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:00:01Z.


Regression run of e88ee4d1 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: e88ee4d1ce9b4121f95f6c857e4ee14bf9f40858
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14810 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7151483419 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805#issuecomment-7151483419). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:00:01Z. --- Regression run of `e88ee4d1` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: e88ee4d1ce9b4121f95f6c857e4ee14bf9f40858 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1617 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14810 MB ``` Against the limits in CONTRIBUTING.md: 100 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
DavidM1911 commented 2026-11-25 11:09:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:58:29Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7160419778 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805#issuecomment-7160419778). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T10:58:29Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
upipibi commented 2026-11-25 22:06:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T21:13:20Z.


NVIDIA test report for e88ee4d (head as is, base d208e14), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after cargo build --workspace:

  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 696 passed, 0 failed, 41 ignored. The end-to-end title tests pass, and so does the new taskqueue::tests::thread_pool_callbacks_finish_when_more_block_than_there_are_cores.
  • Skipped hle::xaudio2, because its tests fail or hang on this machine on main too. The PR doesn't touch it.
  • SKIPPED lines: 2, both no wave64 on this card.

AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.

<!-- greyfinch-sync:ivall/xcl:comment:7174776350 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805#issuecomment-7174776350). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T21:13:20Z. --- NVIDIA test report for `e88ee4d` (head as is, base `d208e14`), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after `cargo build --workspace`: - `cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2`: **696 passed, 0 failed, 41 ignored**. The end-to-end title tests pass, and so does the new `taskqueue::tests::thread_pool_callbacks_finish_when_more_block_than_there_are_cores`. - Skipped `hle::xaudio2`, because its tests fail or hang on this machine on `main` too. The PR doesn't touch it. - SKIPPED lines: 2, both `no wave64` on this card. AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
github-actions[bot] commented 2026-11-30 08:40:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:40:12Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273195220 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805#issuecomment-7273195220). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:40:12Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:10:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:10:03Z.


Triage (#1607) – head e88ee4d

No open or merged PR changes the task queue's worker pool. Main still has the fixed mpsc pool of available_parallelism().clamp(2, 8) workers. The closed #2836 touched monitors, not the pool.
spawn starts a new worker whenever the queue is longer than the idle count. A burst of short callbacks can therefore create up to MAX_WORKERS (256) threads even when nothing blocks; they exit after 30 s idle. That is more aggressive than "when all workers are busy", so please say whether this was measured on a title.
Recommendation: keep open.

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

<!-- greyfinch-sync:ivall/xcl:comment:7300447943 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/805#issuecomment-7300447943). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:10:03Z. --- **Triage (#1607)** – head e88ee4d No open or merged PR changes the task queue's worker pool. Main still has the fixed `mpsc` pool of `available_parallelism().clamp(2, 8)` workers. The closed #2836 touched monitors, not the pool. `spawn` starts a new worker whenever the queue is longer than the idle count. A burst of short callbacks can therefore create up to `MAX_WORKERS` (256) threads even when nothing blocks; they exit after 30 s idle. That is more aggressive than "when all workers are busy", so please say whether this was measured on a title. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/805:upstream-pr/805'
git switch 'upstream-pr/805'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/805'
git switch 'upstream-pr/805'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/805'
git switch 'upstream-pr/805'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/805'
git switch 'main'
git merge --squash 'upstream-pr/805'
git switch 'main'
git merge --ff-only 'upstream-pr/805'
git switch 'main'
git merge 'upstream-pr/805'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!799
No description provided.