From 3ce7cf118b5e16cd294aa9d562bf6190d0f899fe Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 21 Nov 2026 11:05:03 -0800 Subject: [PATCH] rt tests: stalled lowering writes stay in their queue, so a full queue drops the next one every_device_writes_its_lowerings_off_the_creating_thread_and_drops_them_past_its_queue hung on lavapipe after 7a9458f983 (capover's check m3-max-64386: SLOW past 300 s; it passed at 8bef47758f in m3-max-64358). The stall made the reaper pop a file and then spin in write_kept, so the queue could be empty when the test set its bound to the bytes waiting. Since 7a9458f983 an empty queue takes a file of any size, so the second kernel's lowering was kept, not dropped; the assertion failed with the writes still stalled, and the device's teardown waited forever on a reaper spinning in write_kept. Now the stall is taken where the reaper takes a write: next_write answers none while stalled, the queue keeps every file handed over, and the test pokes the reaper when it lets them go. The product path is unchanged (the stall is test-only). --- crates/metal2vulkan-runtime/src/cache.rs | 21 +++++++++++-------- .../src/tests/translate.rs | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/cache.rs b/crates/metal2vulkan-runtime/src/cache.rs index c4d206cfc..10dae941e 100644 --- a/crates/metal2vulkan-runtime/src/cache.rs +++ b/crates/metal2vulkan-runtime/src/cache.rs @@ -1197,7 +1197,9 @@ impl Caches { self.blob.get().map(PathBuf::as_path) } - /// Makes the reaper's writes of lowerings wait, or go on, for a test. + /// Keeps the lowerings waiting to be written in their queue, or lets the reaper take them, for + /// a test: the reaper takes none while they are stalled, so the queue holds every one handed + /// over. A test that lets them go pokes the reaper. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) fn stall_writes(&self, stalled: bool) { (self.writes_stalled).store(stalled, std::sync::atomic::Ordering::Release); @@ -1307,21 +1309,22 @@ impl Caches { kept.flatten() } - /// The next lowering, refusal or record waiting for the reaper to write it. + /// The next lowering, refusal or record waiting for the reaper to write it; none while a test + /// stalls the writes, which then stay in the queue. pub(crate) fn next_write(&self) -> Option<(String, Vec)> { + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + if self + .writes_stalled + .load(std::sync::atomic::Ordering::Acquire) + { + return None; + } lock(&self.pending).pop() } /// On the reaper: writes `bytes` under `file` in the store, as [`keep_translation`] queued /// them. pub(crate) fn write_kept(&self, file: &str, bytes: &[u8], counters: &Counters) { - #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] - while self - .writes_stalled - .load(std::sync::atomic::Ordering::Acquire) - { - std::thread::sleep(Duration::from_millis(1)); - } if let Some(store) = &self.store { if store.put(file, bytes) { counters.cache_written(bytes.len() as u64); diff --git a/crates/metal2vulkan-runtime/src/tests/translate.rs b/crates/metal2vulkan-runtime/src/tests/translate.rs index bbb108605..b42ac0b34 100644 --- a/crates/metal2vulkan-runtime/src/tests/translate.rs +++ b/crates/metal2vulkan-runtime/src/tests/translate.rs @@ -2109,6 +2109,7 @@ mod on_device { ); caches.set_pending_bound(crate::cache::PENDING_BYTES); caches.stall_writes(false); + device.core().reaper.poke(); within("the writes", || counters.metrics().cache_bytes_written > 0); drop((a, b)); drop(device);