Skip to content

D3D12-TIMELINE-REPORT-WAKER-ISOLATION: synchronize thread startup in timeline::report wait test - #2933

Open
bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-timeline-report-wait-handshake
Open

bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-timeline-report-wait-handshake

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-TIMELINE-REPORT-WAKER-ISOLATION (#2570 (comment); ref finding #2570 (comment))

What and why

timeline::report::tests::real_waits_are_recorded_with_who_ended_them (d3d12/crates/leonida-gpu/src/timeline/report.rs) intermittently failed under parallel whole-suite runs (reported 3/40 on main) because it assumed newly spawned threads reached their synchronization points within fixed sleeps:

  1. second was spawned while the test thread held lock, slept a fixed 20 ms, and dropped lock. Under parallel test contention, thread creation/startup could consume >10 ms so second either waited less than the 10 ms filter or never contended at all (contended == None).
  2. worker started its timed work span immediately on spawn without waiting for the test thread to acquire gate.0 and enter gate.1.wait.

Fix:

  • Synchronize worker with an unhooked AtomicBool (waiting) set while holding gate.0, then sleep 10 ms before starting the 40 ms timed span so gate.1.wait overlaps the full span.
  • Synchronize second with an unhooked AtomicBool (ready) set immediately before lock.lock(), and hold lock for 50 ms after ready is observed so slow thread startup cannot eat the 10 ms wait filter.
  • Use trace.waits.get(&second).into_iter().flatten() instead of direct map indexing.

Tested

  • Windows 11, Rust 1.98.1, cargo test --locked -p leonida-gpu --lib --features diagnostics timeline::report::tests: 6 passed, 0 failed.
  • Full parallel leonida-gpu lib suite (--features diagnostics -- --skip depth_bounds_pipeline_loads_and_filters_draws), 15 consecutive runs: 15/15 passed, 0 failures in real_waits_are_recorded_with_who_ended_them (724 passed, 0 failed, 59 ignored per run).
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/timeline/report.rs: clean.

GPUs tested: n/a (CPU-only timeline hook test; Windows 11).

AI-assisted: yes — Gemini 4 Neon (implementation and an independent read-only reviewer pass).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.

@merzleckeier

Copy link
Copy Markdown
Contributor

Controlled second-worker scheduling check at 45e0aae5 against 99a29d10 under Win64 Wine 11.22. I inserted the same optional 150 ms delay in the test on both trees. The compared fixture builds carry matching PDBs and mark the test function inline(never) to keep the separate stack-name assertion stable.

Delay placement Main PR
None 3/3 3/3
At second worker entry, before publishing ready 0/3 3/3
Immediately before the mutex, after the PR publishes ready 0/3 0/3

The failures had no matching waker. Delayed startup no longer consumes the holder’s wait window. The deliberately injected stall after ready.store still can. The six-test timeline selection also passed on both fixture builds without an injected delay. An earlier optimized probe of the PR reached the expected waker with delayed startup, then separately failed the symbol-name assertion under Wine. These are isolated scheduling tests. AI-assisted (Codex).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diagnosis and fix both hold up. At 4× oversubscription the parent commit failed this test in 10/24 suite runs (report.rs:1455 "no entry found for key"; :1459 None vs Some(tid)); this branch is 0/24 at 4× and 0/16 at 8×, and 20/20 on the exact timeline::report filter. The flags are sound: one store, acquire load, no lost wakeup, no lock-order issue, and yield_now prevents starvation.

It narrows rather than closes, though: ready is still published before lock.lock() (:1453-1454), so a stall after publication is covered only by the fixed 50 ms hold (40 ms above the 10 ms filter). I injected 60 ms there and it fails 3/3; 60 ms after waiting.store fails the work assertion 2/2. The fix removes the startup-latency charge against the window — which is the real runner behaviour it was fighting — but a scheduling stall inside the window still flakes.

Two suggestions:

  • Drop the >= 10 ms duration filter (:1475) and assert on the wait that ends at the release (the last wait of second) and its waker. That removes one avoidable failure mode and tests the property rather than a duration.
  • Prefer a std::sync::Barrier over the yield_now spin (:1416): if the test thread panics before waiting.store (:1437), the worker spins forever (libtest still exits, but it burns CPU). The pre-existing gate.1.wait already has that hazard; a barrier would remove the class.

The .get(&second).into_iter().flatten() change is a strict improvement over the index panic either way. Merge-tree against current main is clean, and #2884 is complementary (different test, same thread-startup class, mutually exclusive via TEST_GLOBAL_LOCK).

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.

3 participants