From 1448ca32d6b8ff625d1136189a17def2aa4e2f69 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 15 Nov 2026 23:41:02 -0800 Subject: [PATCH] scheduler_held_wakes: read the counts once the scheduler sleeps again The pass that sends a batch counts a slice's rescue only after its submission returned (scheduler/mod.rs, `pass`), so the batch's command buffer can complete, and the test's poll see it, before that count is made. On gem10's PHOENIX under load (round 44505b3807) the held-wake test read 0 rescues while its steps showed the slice's pass send the kept group and then "a slice's rescue" 350 us after the kept fill's completion was published: the test, not the product, was wrong. Each of the file's three reads of the counts after the work now waits for the scheduler's thread to sleep again (scheduler_wakes' `asleep`, now pub(super)), when no pass is under way and its counts are made. The two tests that assert no rescue came read too early in the same way and could pass with a rescue uncounted. event_wake_bench and submit_long_bench print the same delta and take the same wait. Verified: see the lane's lavapipe control (a 20 ms delay before the count: the old test fails, this one passes) and the PHOENIX run. --- crates/metal2vulkan-runtime/src/tests/event_wake_bench.rs | 1 + crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs | 4 ++++ crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs | 4 +++- crates/metal2vulkan-runtime/src/tests/submit_long_bench.rs | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/metal2vulkan-runtime/src/tests/event_wake_bench.rs b/crates/metal2vulkan-runtime/src/tests/event_wake_bench.rs index 23660d044..1bcfe533b 100644 --- a/crates/metal2vulkan-runtime/src/tests/event_wake_bench.rs +++ b/crates/metal2vulkan-runtime/src/tests/event_wake_bench.rs @@ -148,6 +148,7 @@ fn repeat(rig: &Rig, shape: Shape, value: u64, times: &mut Times) { assert!(start.elapsed() < WAIT, "the completed handler never ran"); std::thread::sleep(Duration::from_micros(50)); }; + super::scheduler_wakes::asleep(device, "the waiting command buffer's pass"); times.rescues += device.work_counts().scheduler_slice_rescues - before; let mut ahead_end = t0; for other in &ahead { diff --git a/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs b/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs index de218aa20..40c63ea66 100644 --- a/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs @@ -33,6 +33,7 @@ //! `DeviceOptions::assume_submissions_merge`. use super::plan_room::device_with_room; +use super::scheduler_wakes::asleep; use crate::command_buffer::completion::trace::{self, Point}; use crate::{ Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, @@ -181,6 +182,7 @@ fn a_kept_group_whose_completion_was_published_as_it_was_kept_goes_in_that_pass( completes(&second, "the second command buffer"); trace::release(Point::KeptGate); let took = completes(&kept, "the kept command buffer"); + asleep(&device, "the kept group's pass"); let after = device.work_counts(); let rescues = after.scheduler_slice_rescues - before.scheduler_slice_rescues; let kept_groups = after.groups_kept_pending - before.groups_kept_pending; @@ -265,6 +267,7 @@ fn a_held_batch_whose_wake_never_came_goes_at_the_next_slice() { completes(&first, "the first command buffer"); completes(&second, "the second command buffer"); let took = completes(&kept, "the kept command buffer"); + asleep(&device, "the kept group's pass"); let after = device.work_counts(); let steps = trace::stop(); let rescues = after.scheduler_slice_rescues - before.scheduler_slice_rescues; @@ -367,6 +370,7 @@ fn a_batch_held_for_an_unshared_queue_goes_at_the_completion_published_as_it_was trace::release(Point::Leave); let took = completes(&behind, "the command buffer behind"); completes(&ahead, "the first command buffer"); + asleep(&device, "the pass behind the first command buffer"); let after = device.work_counts(); let rescues = after.scheduler_slice_rescues - before.scheduler_slice_rescues; let looks = after.heads_held_for_unshared_isolation - before.heads_held_for_unshared_isolation; diff --git a/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs b/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs index d27ac9e2c..58cd79a77 100644 --- a/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs @@ -127,7 +127,9 @@ fn settle(completed: &AtomicU64, count: u64, what: &str) { /// Wait until the scheduler's thread sleeps (`Scheduler::asleep`), failing where it stays awake /// for [`BOUND`]: what the last commit or completion set going is over, and no pass is under way. -fn asleep(device: &Device, what: &str) { +/// The counts a pass makes are then made: a pass counts a slice's rescue once its submission +/// returned (`WorkCounts::scheduler_slice_rescues`), which the batch's completion can come before. +pub(super) fn asleep(device: &Device, what: &str) { let since = Instant::now(); while !device.shared().scheduler.asleep() { assert!( diff --git a/crates/metal2vulkan-runtime/src/tests/submit_long_bench.rs b/crates/metal2vulkan-runtime/src/tests/submit_long_bench.rs index 1f33da3ee..bc8d324fc 100644 --- a/crates/metal2vulkan-runtime/src/tests/submit_long_bench.rs +++ b/crates/metal2vulkan-runtime/src/tests/submit_long_bench.rs @@ -285,6 +285,7 @@ fn run(device: &Device, arm: Arm, chain: &Chain, fill: &Buffer) -> (WorkCounts, for command_buffer in flight { command_buffer.wait_until_completed_for(WAIT).unwrap(); } + super::scheduler_wakes::asleep(device, "the arm's last pass"); let after = device.work_counts(); stop.store(true, Ordering::Relaxed); if let Some(thread) = compositor {