WIP: d3d12-gpu: LEONIDA_ALIAS_LATER mappings wait for what their queue had before them (D3D12-ALIAS-LATER-QUEUE-ORDER) #3352

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "github-pr/3352:github-pr/3352"
git switch "github-pr/3352"
Draft
leonida/mandy
MoonEyes wants to merge 2 commits from github-pr/3352 into main

This pull request is marked as a work in progress.

This pull request cannot be merged because it is marked as being a work in progress.

Conversation
Reviewers 0 approvals
  • No reviewers
Details

This pull request can be merged automatically.

This pull request is marked as a work in progress.

This pull request cannot be merged because it is marked as being a work in progress.

This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'github-pr/3352:github-pr/3352'
git switch 'github-pr/3352'
MoonEyes commented 2026-12-03 15:31:37 +00:00

Claimed in the coordination issue as: D3D12-ALIAS-LATER-QUEUE-ORDER (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7383293227)

Fixes: #3329

What and why

alias_later put the mapping work on the leonida-alias thread, which ran it at once. Only Job::Alias held back the jobs after it in its lane, not the ones before it, so an older submission blocked on a wait could read pages already remapped.

The mapping work now stays queued in the title's order. Each entry has its own release flag: met(Ask::Alias) releases a queue head's entry only, so a mapping behind an unfinished wait in another queue is not let go when a later one reaches the head of its own. The worker (or the lane, with no thread) takes only the front entry, and only when released. The forced path (a present, via alias_wait) raises forced and releases up to that number, so the line cannot stay stuck at a present. The unreachable Ask::Alias arm of settle is removed.

Tested

  • New tests in queue/behind.rs: a_mapping_waits_for_what_its_queue_had_before_it and a_mapping_does_not_let_go_an_older_one_of_another_queue (waits go through a look_until helper with a 10 s bound; a static mutex serializes tests sharing the process-wide alias state).
  • Not compiled or run on this machine: leonida-gpu does not build on Linux. The mapping section (alias_queue, alias_release, alias_next, alias_do, alias_wait) was compiled alone with stubs and its two-mapping scenario passes; the Job/Lane integration and both tests were only read. No red/green was executed: please run python -I scripts/red_green.py <PR> and cargo test -p leonida-gpu --locked on Windows (CI will compile it).
  • python -I scripts/check_no_game_data.py passes.
  • A separate read-only reviewer agent found no blocking issue, and traced that both tests fail on the old eager behaviour.

Known risks (opt-in switch only)

  • Q1 [Wait(f), Alias(k)] with Q2 [Alias(k+1), ..., Signal f]: the worker cannot finish k+1 before k, and k waits for the signal. Only a present unblocks it (not with LEONIDA_WAIT_FORCE=0). The old eager worker did not have this case. To confirm on Windows with a title run.
  • The forced path still releases older mappings of other queues, bounded to a present.
  • Two title threads calling alias_later on the same queue could order Alias(n+1) before Alias(k): unlikely, as calls on one queue are normally serialized.
  • The forced path has no test.

GPUs tested: n/a

AI-assisted: yes (Claude Code, reviewed by a separate read-only reviewer agent)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption.
  • A new translator rule is in the contract table of docs/design.md: n/a

Generated by Claude Code

Claimed in the coordination issue as: D3D12-ALIAS-LATER-QUEUE-ORDER (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7383293227) Fixes: #3329 ### What and why `alias_later` put the mapping work on the `leonida-alias` thread, which ran it at once. Only `Job::Alias` held back the jobs after it in its lane, not the ones before it, so an older submission blocked on a wait could read pages already remapped. The mapping work now stays queued in the title's order. Each entry has its own release flag: `met(Ask::Alias)` releases a queue head's entry only, so a mapping behind an unfinished wait in another queue is not let go when a later one reaches the head of its own. The worker (or the lane, with no thread) takes only the front entry, and only when released. The forced path (a present, via `alias_wait`) raises `forced` and releases up to that number, so the line cannot stay stuck at a present. The unreachable `Ask::Alias` arm of `settle` is removed. ### Tested - New tests in `queue/behind.rs`: `a_mapping_waits_for_what_its_queue_had_before_it` and `a_mapping_does_not_let_go_an_older_one_of_another_queue` (waits go through a `look_until` helper with a 10 s bound; a static mutex serializes tests sharing the process-wide alias state). - **Not compiled or run on this machine**: `leonida-gpu` does not build on Linux. The mapping section (alias_queue, alias_release, alias_next, alias_do, alias_wait) was compiled alone with stubs and its two-mapping scenario passes; the `Job`/`Lane` integration and both tests were only read. No red/green was executed: please run `python -I scripts/red_green.py <PR>` and `cargo test -p leonida-gpu --locked` on Windows (CI will compile it). - `python -I scripts/check_no_game_data.py` passes. - A separate read-only reviewer agent found no blocking issue, and traced that both tests fail on the old eager behaviour. ### Known risks (opt-in switch only) - Q1 `[Wait(f), Alias(k)]` with Q2 `[Alias(k+1), ..., Signal f]`: the worker cannot finish k+1 before k, and k waits for the signal. Only a present unblocks it (not with `LEONIDA_WAIT_FORCE=0`). The old eager worker did not have this case. To confirm on Windows with a title run. - The forced path still releases older mappings of other queues, bounded to a present. - Two title threads calling `alias_later` on the same queue could order Alias(n+1) before Alias(k): unlikely, as calls on one queue are normally serialized. - The forced path has no test. GPUs tested: n/a AI-assisted: yes (Claude Code, reviewed by a separate read-only reviewer agent) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption. - [ ] A new translator rule is in the contract table of `docs/design.md`: n/a --- _Generated by [Claude Code](https://claude.ai/code)_
Kal0s-design commented 2026-12-03 16:10:03 +00:00

Ran natively on Windows 11, head 309f2abf0 merged into current main (9b9efd5cd, clean merge).

It compiles. Both new tests are red on main and green on the merge, and the full leonida-gpu suite has no new failures. There is one clippy error. I also measured the risks you listed and the cost of doing the mappings in ask order across queues (details below).

Your asks (measured)

check result
cargo test -p leonida-gpu --lib --locked build (lib + tests) builds, no warnings
same, run with 4 threads merge: 725 passed, 0 failed, 59 ignored (4 runs). main: 723 passed, 0 failed, 59 ignored. The 2 extra are the new tests
cargo clippy -p leonida-gpu --all-targets -- -D warnings 1 error on the merge, 0 on main: clippy::single_match in Job::settle (behind.rs:534). Removing the Ask::Alias arm left a one-arm match. if let Ask::Lists(recordings) = ask { ... } fixes it. With that lint allowed, nothing else comes up. CI runs clippy as a report only, so it won't block
cargo fmt --check not clean, but it isn't clean on main either, and CI doesn't check it. behind.rs gets 6 more rustfmt hunks than on main, all long lines in the PR's code, the same style as the rest of the file. queue.rs has no new ones
python -I scripts/red_green.py verdict "red does not build": cannot find function alias_queue. The tests call alias_queue, which the PR adds outside #[cfg(test)], so the test-only red side can't compile. On green, all 784 tests ran: 725 passed, 59 ignored, none failed

Red/green done by hand. I put the two tests on main's behind.rs with a test-only alias_queue. It is main's alias_later minus the LANE.push: it numbers the work, hands it to the worker and notifies it.

test main + shim, 10 runs merge, 20 runs alone merge, both together 4 threads, 20 runs
a_mapping_waits_for_what_its_queue_had_before_it 10/10 fail, "mapped while the queue stood at its wait" 20/20 pass, at most 0.05 s 20/20
a_mapping_does_not_let_go_an_older_one_of_another_queue 10/10 fail, "a mapping ran ahead of the older one standing at a wait" 20/20 pass, at most 0.05 s 20/20

The whole queue::behind module, 4 threads: 20/20 on the merge. No flakes seen. From reading the code: the alias line is process-global and the worker only takes the front entry. If one test fails with its entry still queued, later mappings in that process stand behind it, so the other test would time out after its 10 s too.

Known risks, measured. These are throwaway tests with Lane<Job>, real fences and Job::Present(None, None, ..) (with LEONIDA_PASSES_AHEAD=0). Each ran in a process of its own with a 5 s bound. "stuck" means nothing moved in 5 s.

case main merge merge, LEONIDA_WAIT_FORCE=0
Q1 [Wait(f), Alias(k)], Q2 [Alias(k+1), Signal(f)], no present done at once stuck, 4 entries left not run (no present for the switch to act on)
same, plus a present on Q3 done, 266 ms done, 264 ms stuck: the present goes, the 4 entries stay
Q1 [Wait(f), Alias(k)], Q2 [Alias(k+1)], no cycle, f set by another thread at 300 ms Q2's mapping done at 0 ms Q2's mapping done at 302 ms not run
present-forced release: Q2 [Alias(k+1)] oldest, Q1 [Wait(f), Alias(k)], present k runs k runs while Q1 is still at its wait (f = 0) not run
one queue, Alias(k+1) put in before Alias(k) (your third risk), no present done at once stuck stuck

main takes about the same 250 ms as the merge in the rows with a present, so that time isn't from the PR.

So the cycle is real. It holds until a present is in the line, and with LEONIDA_WAIT_FORCE=0 it never clears. From reading step, what clears it in the cycle row is the line forcing Q1's Wait at the present, which makes Alias(k) a head. It is not the forced counter. Only the fourth row reaches that counter, through alias_wait.

The third row is the cost of the ask order, which the PR intends (the alias_later doc and the second test). Q2's mapping waits for Q1's fence even though nothing in Q2 depends on it: 302 ms against 0 ms on main. With the default switches that holds Q2's later submissions until a present is in the line. Because the line is global, one entry stuck at a wait holds every later mapping of every queue. Is the cross-queue order needed? Doing released entries in release order, and keeping ask order only within a queue, would remove rows 1 and 3. It would also reverse what a_mapping_does_not_let_go_an_older_one_of_another_queue asserts, so it depends on why you wanted that order.

Read, not run. No lost wakeups that I can see. alias_next checks its predicate in a loop under the ALIAS mutex, alias_release changes the state under the same mutex before it notifies, and alias_wait loops on ALIAS_DONE with a 2 ms timeout. The lane's thread polls every 1 ms while it holds entries, so a missed LANE.wake() costs at most that.

forced is only raised with max under the mutex and read under it. It's a u64, so overflow isn't a concern.

met(Ask::Alias) now has a side effect. That looks fine: step calls it only for a queue's head, and take_along never takes an Alias. The removed settle arm was unreachable, because drain settles only folded entries (Lists).

If spawn fails once and works on a later alias_queue, the lane thread's inline loop and the new worker can each pop an entry and run them at the same time. ALIAS_DONE.store(number) could then go backwards. That's unlikely, and fetch_max would close it.

Shutdown: the worker is never joined, as on main. Mappings still queued at exit are dropped, where main would already have run them. drain only waits for what is free to run, so it returns past a stuck alias. Outside behind.rs, the only users of the alias line are copy_page_mappings and alias_behind in queue.rs. On a device loss host::fail ends the process (crash report or abort), so nothing drains the alias line there.

Conflicts. Five other open PRs touch queue.rs. #3039 also touches behind.rs: it adds timing around alias_wait in go. All five auto-merge on these two files on top of this merge. #3176, #3039 and #2958 already conflict with main in files this PR doesn't touch (d3d12.yml, switches.md, play-nvidia.ps1, test_win_launchers.py). #3151 and #2833 merge cleanly. #2833 bounds copy_page_mappings, the caller of alias_later. This PR adds no conflicts.

Not checked: the title, so no visible effect either way. Whether the title reaches a present at all while it is in the cycle. If it waits for that fence on the CPU first, the default-switch case is a hang, not a hitch. The same-queue inversion with a present. Whether a submission's title-memory reads all happen inside its go: I read send_late as far as submit_for but didn't trace the relay thread. The forced path with more than two queues. --release. The diagnostics feature.

GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).

Ran natively on Windows 11, head `309f2abf0` merged into current `main` (`9b9efd5cd`, clean merge). It compiles. Both new tests are red on `main` and green on the merge, and the full `leonida-gpu` suite has no new failures. There is one clippy error. I also measured the risks you listed and the cost of doing the mappings in ask order across queues (details below). **Your asks** (measured) | check | result | |---|---| | `cargo test -p leonida-gpu --lib --locked` build (lib + tests) | builds, no warnings | | same, run with 4 threads | merge: 725 passed, 0 failed, 59 ignored (4 runs). `main`: 723 passed, 0 failed, 59 ignored. The 2 extra are the new tests | | `cargo clippy -p leonida-gpu --all-targets -- -D warnings` | 1 error on the merge, 0 on `main`: `clippy::single_match` in `Job::settle` (behind.rs:534). Removing the `Ask::Alias` arm left a one-arm `match`. `if let Ask::Lists(recordings) = ask { ... }` fixes it. With that lint allowed, nothing else comes up. CI runs clippy as a report only, so it won't block | | `cargo fmt --check` | not clean, but it isn't clean on `main` either, and CI doesn't check it. `behind.rs` gets 6 more rustfmt hunks than on `main`, all long lines in the PR's code, the same style as the rest of the file. `queue.rs` has no new ones | | `python -I scripts/red_green.py` | verdict "red does not build": `cannot find function alias_queue`. The tests call `alias_queue`, which the PR adds outside `#[cfg(test)]`, so the test-only red side can't compile. On green, all 784 tests ran: 725 passed, 59 ignored, none failed | **Red/green done by hand.** I put the two tests on `main`'s `behind.rs` with a test-only `alias_queue`. It is `main`'s `alias_later` minus the `LANE.push`: it numbers the work, hands it to the worker and notifies it. | test | `main` + shim, 10 runs | merge, 20 runs alone | merge, both together 4 threads, 20 runs | |---|---|---|---| | `a_mapping_waits_for_what_its_queue_had_before_it` | 10/10 fail, "mapped while the queue stood at its wait" | 20/20 pass, at most 0.05 s | 20/20 | | `a_mapping_does_not_let_go_an_older_one_of_another_queue` | 10/10 fail, "a mapping ran ahead of the older one standing at a wait" | 20/20 pass, at most 0.05 s | 20/20 | The whole `queue::behind` module, 4 threads: 20/20 on the merge. No flakes seen. From reading the code: the alias line is process-global and the worker only takes the front entry. If one test fails with its entry still queued, later mappings in that process stand behind it, so the other test would time out after its 10 s too. **Known risks, measured.** These are throwaway tests with `Lane<Job>`, real fences and `Job::Present(None, None, ..)` (with `LEONIDA_PASSES_AHEAD=0`). Each ran in a process of its own with a 5 s bound. "stuck" means nothing moved in 5 s. | case | `main` | merge | merge, `LEONIDA_WAIT_FORCE=0` | |---|---|---|---| | Q1 `[Wait(f), Alias(k)]`, Q2 `[Alias(k+1), Signal(f)]`, no present | done at once | **stuck**, 4 entries left | not run (no present for the switch to act on) | | same, plus a present on Q3 | done, 266 ms | done, 264 ms | **stuck**: the present goes, the 4 entries stay | | Q1 `[Wait(f), Alias(k)]`, Q2 `[Alias(k+1)]`, no cycle, f set by another thread at 300 ms | Q2's mapping done at 0 ms | Q2's mapping done at **302 ms** | not run | | present-forced release: Q2 `[Alias(k+1)]` oldest, Q1 `[Wait(f), Alias(k)]`, present | k runs | k runs while Q1 is still at its wait (f = 0) | not run | | one queue, `Alias(k+1)` put in before `Alias(k)` (your third risk), no present | done at once | **stuck** | stuck | `main` takes about the same 250 ms as the merge in the rows with a present, so that time isn't from the PR. So the cycle is real. It holds until a present is in the line, and with `LEONIDA_WAIT_FORCE=0` it never clears. From reading `step`, what clears it in the cycle row is the line forcing Q1's `Wait` at the present, which makes `Alias(k)` a head. It is not the `forced` counter. Only the fourth row reaches that counter, through `alias_wait`. The third row is the cost of the ask order, which the PR intends (the `alias_later` doc and the second test). Q2's mapping waits for Q1's fence even though nothing in Q2 depends on it: 302 ms against 0 ms on `main`. With the default switches that holds Q2's later submissions until a present is in the line. Because the line is global, one entry stuck at a wait holds every later mapping of every queue. Is the cross-queue order needed? Doing released entries in release order, and keeping ask order only within a queue, would remove rows 1 and 3. It would also reverse what `a_mapping_does_not_let_go_an_older_one_of_another_queue` asserts, so it depends on why you wanted that order. **Read, not run.** No lost wakeups that I can see. `alias_next` checks its predicate in a loop under the `ALIAS` mutex, `alias_release` changes the state under the same mutex before it notifies, and `alias_wait` loops on `ALIAS_DONE` with a 2 ms timeout. The lane's thread polls every 1 ms while it holds entries, so a missed `LANE.wake()` costs at most that. `forced` is only raised with `max` under the mutex and read under it. It's a `u64`, so overflow isn't a concern. `met(Ask::Alias)` now has a side effect. That looks fine: `step` calls it only for a queue's head, and `take_along` never takes an `Alias`. The removed `settle` arm was unreachable, because `drain` settles only folded entries (`Lists`). If `spawn` fails once and works on a later `alias_queue`, the lane thread's inline loop and the new worker can each pop an entry and run them at the same time. `ALIAS_DONE.store(number)` could then go backwards. That's unlikely, and `fetch_max` would close it. Shutdown: the worker is never joined, as on `main`. Mappings still queued at exit are dropped, where `main` would already have run them. `drain` only waits for what is free to run, so it returns past a stuck alias. Outside `behind.rs`, the only users of the alias line are `copy_page_mappings` and `alias_behind` in `queue.rs`. On a device loss `host::fail` ends the process (crash report or `abort`), so nothing drains the alias line there. **Conflicts.** Five other open PRs touch `queue.rs`. #3039 also touches `behind.rs`: it adds timing around `alias_wait` in `go`. All five auto-merge on these two files on top of this merge. #3176, #3039 and #2958 already conflict with `main` in files this PR doesn't touch (`d3d12.yml`, `switches.md`, `play-nvidia.ps1`, `test_win_launchers.py`). #3151 and #2833 merge cleanly. #2833 bounds `copy_page_mappings`, the caller of `alias_later`. This PR adds no conflicts. Not checked: the title, so no visible effect either way. Whether the title reaches a present at all while it is in the cycle. If it waits for that fence on the CPU first, the default-switch case is a hang, not a hitch. The same-queue inversion with a present. Whether a submission's title-memory reads all happen inside its `go`: I read `send_late` as far as `submit_for` but didn't trace the relay thread. The forced path with more than two queues. `--release`. The `diagnostics` feature. GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
x2Tweek reviewed 2026-12-03 16:17:05 +00:00
x2Tweek left a comment
No description provided.
Review of #3352 (claimed in #3312 as REVIEW-3352). I reported #3329. **Windows build and tests (PR merged onto current main, d0dc89ef9):** - `cargo test -p leonida-gpu --features diagnostics --locked`: 806 passed, 0 failed. Both new tests pass. - `python -I scripts/red_green.py 3352 --remote upstream --crate leonida-gpu`: **verdict "red does not build"**. The new tests call `alias_queue`, which does not exist on main, so the red side does not show that they catch the old eager behaviour. **Code review (with a second, read-only reviewer):** 1. **Blocking: `LEONIDA_ALIAS_LATER` is on by default, not opt-in.** `queue.rs:1607` uses `crate::toggled!`, so it is on unless set to `0`, whenever the submission line is on. The "Known risks (opt-in switch only)" section therefore applies to every player. 2. **Blocking: cross-queue stall/deadlock with one global FIFO** (`queue/behind.rs:344-364`, `:940-950`). This is the case listed under known risks: Q1 `[Wait(f), Alias(k)]` and Q2 `[Alias(k+1), ..., Signal(f)]`. The worker will not pass the unreleased `k`, so Q2 never reaches `Signal(f)`. With `LEONIDA_WAIT_FORCE=0` it is a real deadlock. With forcing, only a present gets it moving again: a hitch, and the wait is dropped. Graphics plus async compute can plausibly interleave like this. Suggested fix: one FIFO per queue, or run any released queue head, with completion tracked per entry. 3. **Should fix: forced `alias_wait` releases every lower ticket.** Tickets are handed out and lane entries are inserted in separate critical sections, so two concurrent calls can publish them in reverse order, and forcing can release a mapping that its own queue has not reached yet. Suggested fix: take the ticket and the lane slot under one lock, and force only the selected entry. Related path: the unaligned mapper fallback (`leonida-hle/src/modules/xmem.rs:1632-1640`) calls `map_aliases` synchronously, before its lane entry exists. 4. **Should fix: the inline fallback can overlap the worker** (`queue/behind.rs:907-935`, `:953-973`). After a spawn failure the lane can run a mapping inline while a later enqueue starts the worker. The worker then publishes a higher `ALIAS_DONE`, which the inline completion overwrites with a lower value. Suggested fix: keep a single executor. 5. **Tests:** they check ordering (safety) but not liveness. Please add the Q1/Q2 case above with `LEONIDA_WAIT_FORCE=0`, signalled through the lane, and replace the 50 ms sleeps with synchronization so that the eager-worker failure is deterministic. No lock inversion or missed wakeup found on the ordinary worker path. I have not run it with the title yet. I can do an in-game run (RTX 5090, HW RT, walk + camera) comparing PR and main for hitches if that helps. AI-assisted: yes (Claude Code + Codex, read-only)
First-time contributor

Read-only audit of this PR against main (no game run, no build). The race in #3329 is real and still present on main, and this PR still applies cleanly (git merge-tree main origin/github-pr/3352, exit 0). But I do not think it is ready to ship as written.

What is right: alias_release is only called from met(Ask::Alias), which is evaluated for a queue head (behind.rs:334-348), so a mapping no longer runs before an earlier entry of its own queue has been prepared. That addresses the CPU-prepare race.

What holds it back:

  1. Global FIFO + per-queue release = cross-queue head-of-line stall. alias_next only takes the front of one global deque. Q1 [Wait(f), Alias(k)] and Q2 [Alias(k+1), Signal(f)] is stuck; with LEONIDA_WAIT_FORCE=0 it never clears. The queue is blocked by an entry that is only a Wait, which cannot read title memory.
  2. The gate is stronger than the race needs. Only earlier submissions (Run/Lists) can read title memory; an unmet Wait/Signal ahead of the mapping cannot. The faithful minimum is 'no earlier submission of this queue is still in the line', not 'this entry is the head'. The first test asserts the over-block.
  3. Over-release: alias_wait(n) uses alias_release(n, true), which releases every lower ticket, including mappings of other queues whose own queues have not reached them.
  4. Publish order: alias_later pushes the work under the ticket lock but calls LANE.push after it, so Alias(n+1) can be published before Alias(n); under this PR that is a permanent stall, where main recovers.
  5. Two executors: alias_release runs inline when worker == false; if a later alias_queue spawns the worker, both can pop, and ALIAS_DONE.store can go backwards (fetch_max).
  6. Smaller: the one-arm match left in settle trips clippy::single_match; and the tests call alias_queue, which does not exist on main, so they do not give a real red.

Minimal rework I would suggest: per-queue release keyed to earlier submissions (track each queue's lane entries and let a mapping go once no earlier Run/Lists of that queue is still in the line); drop the cross-queue ordering requirement (mappings on different queues are unordered on the console too); force only the selected ticket; one executor; fetch_max for ALIAS_DONE.

A device-free red is possible against alias_later (it exists on both sides): push Job::Wait(f,1) on queue 1, call alias_later(1, closure), lane.look(limit), assert the closure has not run within a short window, then set the fence. On main the worker runs it immediately (red); with the corrected release it waits. The faithful version — an earlier submission whose go reads the pages — still needs a device, because Job::Run goes through host::host()/HostList.

Unproven either way: #3352 holds mappings until earlier submissions are prepared and sent (execute_late), not until the card has run them; whether the GPU can still DMA from pages remapped after the send has not been checked.

Read-only audit of this PR against `main` (no game run, no build). **The race in #3329 is real and still present on `main`, and this PR still applies cleanly** (`git merge-tree main origin/github-pr/3352`, exit 0). But I do not think it is ready to ship as written. What is right: `alias_release` is only called from `met(Ask::Alias)`, which is evaluated for a queue head (`behind.rs:334-348`), so a mapping no longer runs before an earlier entry of its own queue has been prepared. That addresses the CPU-prepare race. What holds it back: 1. **Global FIFO + per-queue release = cross-queue head-of-line stall.** `alias_next` only takes the front of one global deque. Q1 `[Wait(f), Alias(k)]` and Q2 `[Alias(k+1), Signal(f)]` is stuck; with `LEONIDA_WAIT_FORCE=0` it never clears. The queue is blocked by an entry that is only a `Wait`, which cannot read title memory. 2. **The gate is stronger than the race needs.** Only earlier *submissions* (`Run`/`Lists`) can read title memory; an unmet `Wait`/`Signal` ahead of the mapping cannot. The faithful minimum is 'no earlier submission of this queue is still in the line', not 'this entry is the head'. The first test asserts the over-block. 3. **Over-release:** `alias_wait(n)` uses `alias_release(n, true)`, which releases every lower ticket, including mappings of other queues whose own queues have not reached them. 4. **Publish order:** `alias_later` pushes the work under the ticket lock but calls `LANE.push` after it, so `Alias(n+1)` can be published before `Alias(n)`; under this PR that is a permanent stall, where `main` recovers. 5. **Two executors:** `alias_release` runs inline when `worker == false`; if a later `alias_queue` spawns the worker, both can pop, and `ALIAS_DONE.store` can go backwards (`fetch_max`). 6. **Smaller:** the one-arm `match` left in `settle` trips `clippy::single_match`; and the tests call `alias_queue`, which does not exist on `main`, so they do not give a real red. Minimal rework I would suggest: per-queue release keyed to earlier **submissions** (track each queue's lane entries and let a mapping go once no earlier `Run`/`Lists` of that queue is still in the line); drop the cross-queue ordering requirement (mappings on different queues are unordered on the console too); force only the selected ticket; one executor; `fetch_max` for `ALIAS_DONE`. A device-free red is possible **against `alias_later`** (it exists on both sides): push `Job::Wait(f,1)` on queue 1, call `alias_later(1, closure)`, `lane.look(limit)`, assert the closure has not run within a short window, then set the fence. On `main` the worker runs it immediately (red); with the corrected release it waits. The faithful version — an earlier *submission* whose `go` reads the pages — still needs a device, because `Job::Run` goes through `host::host()`/`HostList`. Unproven either way: #3352 holds mappings until earlier submissions are prepared and sent (`execute_late`), not until the card has run them; whether the GPU can still DMA from pages remapped after the send has not been checked.
Sign in to join this conversation.
No description provided.