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.
This commit is contained in:
Anees Iqbal committed 2026-11-12 11:43:25 -08:00
1 parent 3940efbd6c
commit 119097f9b6
1 file changed
+21 -1
+21 -1
View File
@@ -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<PipelineRecord> {
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