From 119097f9b67b3b4bb0ea1570a7ea72d3feb0d5be Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 11:34:50 -0800 Subject: [PATCH] Tests: the warm tests' recording device goes in its drop, once the pipeline pool is idle `recorded` dropped its states and its device at once, then its callers read the shader cache directory: the kernel's library record, which the device's cache thread writes, was missing once on a loaded host (warm::an_unread_record_is_announced_and_the_pass_goes_on, warm.rs:614, "removed 0"). A render state's creation waits for the makings it hands the pool a bound at most (`pipeline_creation_wait`, 4.5 s); a making past it runs on and holds the device. Dropped meanwhile, the state's piece gives back to the reaper, whose release is then the device's last: the teardown, which drains the cache thread's queue, runs there after the test's drop returned, and the directory is read before the record is written. That is read from the code, not reproduced (the failing run printed no creation counts). `recorded` now keeps the states until the pool is idle (each piece's hold given back to its state, so the states' drop lets go of it on the test's thread), then drops them and the device, and asserts the device went in that drop. Verified: the warm and teardown_threads modules on lavapipe, and clippy, in the jobs named in the report. --- crates/metal2vulkan-runtime/src/tests/warm.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/metal2vulkan-runtime/src/tests/warm.rs b/crates/metal2vulkan-runtime/src/tests/warm.rs index 667a4d9e3..97f4b39ca 100644 --- a/crates/metal2vulkan-runtime/src/tests/warm.rs +++ b/crates/metal2vulkan-runtime/src/tests/warm.rs @@ -166,12 +166,32 @@ fn make( /// The records a device over `cache` hands over for [`make_states`]; the device is gone when /// this returns, so its cache thread wrote what it was handed. +/// +/// A creation waits for the makings it hands the device's pool a bound at most +/// (`DevicePolicy::pipeline_creation_wait`): one past it runs on and holds the device, so a drop +/// of the states and the device meanwhile leaves the device's teardown, and its cache thread's +/// last writes, to the reaper's thread, after this drop returns. So the states go only once the +/// pool is idle, each piece's hold given back to its state. pub(super) fn recorded(cache: &Path) -> Vec { let records = Arc::new(Mutex::new(Vec::new())); let device = device(cache, Some(&records), None); - drop(make_states(&device)); + let states = make_states(&device); + let started = Instant::now(); + while device.work_counts().pipeline_pool_busy != 0 { + assert!( + started.elapsed() < crate::tests::SETTLE, + "the pipeline pool still busy" + ); + std::thread::sleep(Duration::from_millis(1)); + } + drop(states); assert_eq!(device.warm_statistics().records_made, STATES); + let weak = device.downgrade(); drop(device); + assert!( + weak.upgrade().is_none(), + "the device outlived its last handle: its cache thread's writes may not be done" + ); let records = records.lock().unwrap().clone(); assert_eq!(records.len() as u64, STATES, "one record per creation"); records