From c602bae0a913ae77f284f67fdd3d056ce5adfc67 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 23 Nov 2026 14:05:45 -0500 Subject: [PATCH 1/7] drm/asahi/g16: keep single-queue compute pipe-affine and micro-coalesce busy horizons Keep single-queue barrier-free compute streams affine to their active CDM pipe in choose_compute_pipe() and remove pipe_fold_cap from publish_prefix_body() so deep single-queue horizons fold into one workqueue prefix without bouncing between pipes or injecting cross-pipe c2c barriers, while independent queues and cross-VM compute still balance across both CDM pipes. Add busy-state same-queue horizon micro-coalescing (COALESCE_MAX_CMDS = 6, COALESCE_WINDOW_US = 18): only when a single queue already has >= 2 active commands in flight and every pending job belongs to that same queue and VM as a foldable barrier-free compute or non-InitBM render horizon, submit_locked() defers publish_checked() behind an hrtimer (rearm_after()) for up to 18 us so back-to-back SUBMIT ioctls fold into one multi-command flight. Shallow d=1/d=2 pipelines, barriered streams, RT/SCS work, and multi-queue/cross-VM arrivals bypass coalescing immediately with zero added latency, and any flight retirement or deadline expiry flushes the held batch immediately. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/engine.rs | 277 +++++++++++++++--- drivers/gpu/drm/asahi/g16/hw.rs | 6 + drivers/gpu/drm/asahi/g16/poll.rs | 63 ++-- drivers/gpu/drm/asahi/g16/recovery.rs | 1 + .../drivers/gpu/asahi-m4/test-poll-retire.py | 86 +++++- .../drivers/gpu/asahi-m4/test-publication.py | 209 +++++++++++-- 6 files changed, 571 insertions(+), 71 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 179b912db6809..64b40c56ce513 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -607,6 +607,9 @@ pub(crate) struct Engine { pub(crate) ta_wave_wait: bool, /// An EP 0x20 event arrived with a flight still settling its final receipt: repoll sooner. pub(crate) short_repoll: bool, + /// Absolute deadline (`ktime_get_ns`) for busy-state same-queue horizon micro-coalescing + /// (0 when no batch is held). + pub(crate) coalesce_deadline_ns: u64, /// Progress tracking of the oldest compute pipe 0/1 and render flights. pub(crate) progress_flight: [u64; 3], pub(crate) progress: [Option; 4], @@ -651,6 +654,7 @@ impl Engine { slot_wait: false, ta_wave_wait: false, short_repoll: false, + coalesce_deadline_ns: 0, progress_flight: [0; 3], progress: [None; 4], stats: KBox::zeroed(GFP_KERNEL)?, @@ -999,6 +1003,7 @@ impl Firmware { self.engine.chan_wait = false; self.engine.slot_wait = false; self.engine.ta_wave_wait = false; + self.engine.coalesce_deadline_ns = 0; while self.recovery.failed().is_none() && !self.engine.frozen && !self.engine.pending.is_empty() @@ -1540,6 +1545,193 @@ impl Firmware { } } + /// Whether `self.engine.pending` is an eligible single-queue, single-VM busy horizon + /// batch that can accumulate more same-queue commands before publishing. + fn can_defer_busy_coalesce(&self) -> bool { + if self.recovery.failed().is_some() + || self.engine.frozen + || self.engine.flights.is_empty() + || self.engine.pending.is_empty() + || self.engine.flights.len() >= super::hw::sizes::FLIGHTS + || self.engine.chan_wait + || self.engine.slot_wait + || self.engine.ta_wave_wait + || self + .engine + .flights + .iter() + .any(|f| f.doomed || f.recovery_suspect || f.initbm) + { + return false; + } + let head = &self.engine.pending[0]; + let head_sent = head.progress.sent(); + if head.vm.status.get() != 0 + || head.long() + || !self.can_queue_behind(head) + || self + .engine + .pending + .iter() + .any(|j| !Arc::ptr_eq(&j.queue, &head.queue) || !Arc::ptr_eq(&j.vm, &head.vm)) + { + return false; + } + let Some(head_order) = head.command_order(head_sent) else { + return false; + }; + match command(head, head_sent) { + Some(Command::Compute(c)) => { + if head.resources.compute_scs() + || c.is_rt() + || head_order.wait_through != [None, None] + || !head.fw_waits.is_empty() + { + return false; + } + let queue_active: usize = self + .engine + .flights + .iter() + .filter(|fl| fl.computes != 0 && Arc::ptr_eq(&fl.job.queue, &head.queue)) + .map(|fl| fl.computes as usize) + .sum(); + if queue_active < 2 { + return false; + } + let Some(mut next_seq) = head_order.sequence.checked_add(1) else { + return false; + }; + let mut pending_cmds = 1usize; + for k in (head_sent + 1)..head.progress.count() { + let Some(Command::Compute(c2)) = command(head, k) else { + return false; + }; + if c2.is_rt() || !head.can_fold_horizon_cmd(k, next_seq) { + return false; + } + let Some(s) = next_seq.checked_add(1) else { + return false; + }; + next_seq = s; + pending_cmds += 1; + } + for j in &self.engine.pending[1..] { + let n = j.progress.count(); + if j.long() + || j.resources.compute_scs() + || !j.can_fold_horizon_job(next_seq) + || (0..n).any(|k| { + matches!(command(j, k), Some(Command::Compute(c2)) if c2.is_rt()) + }) + { + return false; + } + let Some(s) = next_seq.checked_add(u64::from(n)) else { + return false; + }; + next_seq = s; + pending_cmds += n as usize; + } + let active_computes: usize = self + .engine + .flights + .iter() + .map(|fl| fl.computes as usize) + .sum(); + let Ok(slot_mask) = head.resources.compute_slot_mask() else { + return false; + }; + let pipe = self.choose_compute_pipe(&head.queue, [None, None], slot_mask, false); + let free_c = self.slots.free_compute_in_mask_for_pipe(slot_mask, pipe) as usize; + let cap = super::hw::sizes::COALESCE_MAX_CMDS + .min(free_c) + .min(params::compute_flights().saturating_sub(active_computes)) + .min(super::hw::sizes::COMPUTE_SLOTS); + cap > 1 && pending_cmds < cap + } + Some(Command::Render(_)) => { + if head.resources.render_scs() || !head.fw_waits.is_empty() { + return false; + } + let queue_active: usize = self + .engine + .flights + .iter() + .filter(|fl| fl.renders != 0 && Arc::ptr_eq(&fl.job.queue, &head.queue)) + .map(|fl| fl.renders as usize) + .sum(); + if queue_active < 2 { + return false; + } + let Some(mut next_seq) = head_order.sequence.checked_add(1) else { + return false; + }; + let mut pending_cmds = 1usize; + for k in (head_sent + 1)..head.progress.count() { + if !head.can_fold_render_cmd(k, next_seq) { + return false; + } + let Some(s) = next_seq.checked_add(1) else { + return false; + }; + next_seq = s; + pending_cmds += 1; + } + for j in &self.engine.pending[1..] { + let n = j.progress.count(); + if j.long() + || j.resources.render_scs() + || !j.can_fold_render_horizon_job(next_seq) + { + return false; + } + let Some(s) = next_seq.checked_add(u64::from(n)) else { + return false; + }; + next_seq = s; + pending_cmds += n as usize; + } + let active_renders: usize = self + .engine + .flights + .iter() + .map(|fl| fl.renders as usize) + .sum(); + let ta_room = super::hw::sizes::TA_WAVE_PASSES + .saturating_sub(self.ta_pending_passes()); + let cap = super::hw::sizes::COALESCE_MAX_CMDS + .min(params::render_flights().saturating_sub(active_renders)) + .min(ta_room) + .min(super::hw::sizes::RENDER_SLOTS); + cap > 1 && pending_cmds < cap + } + None => false, + } + } + + /// Defers immediate publication for up to `COALESCE_WINDOW_US` while a single queue already + /// has `>= 2` active commands in flight so consecutive same-queue `SUBMIT` ioctls accumulate + /// into one multi-command flight (up to `COALESCE_MAX_CMDS`), cutting `SubmitRecord`s, WC + /// producer updates, and doorbells without delaying `d=1`/`d=2`, barriered streams, RT/SCS + /// work, or multi-queue/cross-VM handoffs. + pub(crate) fn defer_busy_coalesce(&mut self, now: u64) -> Option { + if !self.can_defer_busy_coalesce() { + self.engine.coalesce_deadline_ns = 0; + return None; + } + if self.engine.coalesce_deadline_ns == 0 { + self.engine.coalesce_deadline_ns = + now.saturating_add(super::hw::sizes::COALESCE_WINDOW_NS); + } + if now >= self.engine.coalesce_deadline_ns { + self.engine.coalesce_deadline_ns = 0; + return None; + } + let rem_ns = self.engine.coalesce_deadline_ns.saturating_sub(now); + Some((rem_ns.div_ceil(1000) as u32).clamp(1, super::hw::sizes::COALESCE_WINDOW_US)) + } + /// Resolves the newest in-flight target stamp and producer `InitBM` state for `class` /// (`RENDER` -> `r_fs_stamp`, `COMPUTE` -> `cstamp`) across `job`'s same-queue `target_seq` /// and any cross-queue `job.fw_waits` (plus an earlier member of an in-progress render batch @@ -1814,10 +2006,14 @@ impl Firmware { /// split across two pipes. /// - If the command waits only on one pipe, reuse that pipe (in-order ring, zero `c2c` /// barrier). - /// - If barrier-free (`[None, None]`) or waiting on both pipes (`[Some, Some]`), pick the - /// pipe with fewer active compute commands, breaking ties by `next_compute_pipe`. + /// - If barrier-free (`[None, None]`) and `queue` already has an active compute flight on a + /// single pipe with free units, keep that queue pipe-affine so consecutive horizon submits + /// fold onto one workqueue without splitting across pipes. + /// - Otherwise (other queues, cross-VM compute, or waiting on both pipes `[Some, Some]`), + /// pick the pipe with fewer active compute commands, breaking ties by `next_compute_pipe`. fn choose_compute_pipe( &self, + queue: &Arc, waits: [Option; sizes::COMPUTE_PIPES], slot_mask: u32, rt_compute: bool, @@ -1833,27 +2029,47 @@ impl Firmware { return 0; } match waits { - [Some(_), None] => 0, - [None, Some(_)] => 1, - _ => { - if !self.slots.compute_available_in_mask_for_pipe(slot_mask, 0) { - return 1; - } - let mut active = [0usize; sizes::COMPUTE_PIPES]; + [Some(_), None] => return 0, + [None, Some(_)] => return 1, + [None, None] => { + let mut q_pipe: Option = None; for fl in &self.engine.flights { - if fl.computes != 0 { + if fl.computes != 0 && Arc::ptr_eq(&fl.job.queue, queue) { let p = (fl.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); - active[p] += fl.computes as usize; + match q_pipe { + None => q_pipe = Some(p), + Some(prev) if prev == p => {} + Some(_) => { + q_pipe = None; + break; + } + } } } - if active[0] < active[1] { - 0 - } else if active[1] < active[0] { - 1 - } else { - (self.engine.next_compute_pipe as usize) % sizes::COMPUTE_PIPES + if let Some(p) = q_pipe { + if self.slots.compute_available_in_mask_for_pipe(slot_mask, p) { + return p; + } } } + [Some(_), Some(_)] => {} + } + if !self.slots.compute_available_in_mask_for_pipe(slot_mask, 0) { + return 1; + } + let mut active = [0usize; sizes::COMPUTE_PIPES]; + for fl in &self.engine.flights { + if fl.computes != 0 { + let p = (fl.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); + active[p] += fl.computes as usize; + } + } + if active[0] < active[1] { + 0 + } else if active[1] < active[0] { + 1 + } else { + (self.engine.next_compute_pipe as usize) % sizes::COMPUTE_PIPES } } @@ -2080,7 +2296,10 @@ impl Firmware { job.command_order(index) .and_then(|o| o.wait_through[super::command::COMPUTE]), )?; - (self.choose_compute_pipe(waits, slot_mask, rt_compute), waits) + ( + self.choose_compute_pipe(&job.queue, waits, slot_mask, rt_compute), + waits, + ) }; let pipe_behind = !render && self @@ -2190,26 +2409,18 @@ impl Firmware { .slots .free_compute_in_mask_for_pipe(slot_mask, compute_pipe) as usize; - let mut active_pipe = [0usize; sizes::COMPUTE_PIPES]; - for fl in &self.engine.flights { - if fl.computes != 0 { - let p = (fl.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); - active_pipe[p] += fl.computes as usize; - } - } - let active_computes = active_pipe[0] + active_pipe[1]; - // Keep barrier-free work balanced across both compute pipes: fold extra commands - // into this pipe only when the alternate pipe already has deeper queued work, so - // independent submits distribute across pipes 0 and 1 in the same doorbell batch. - let pipe_fold_cap = - active_pipe[1 - compute_pipe].saturating_sub(active_pipe[compute_pipe] + 1); + let active_computes: usize = self + .engine + .flights + .iter() + .map(|fl| fl.computes as usize) + .sum(); let used = prefix.c_head.wrapping_sub(c_read) % sizes::QUEUE_CAP; let ring_more = (sizes::QUEUE_CAP.saturating_sub(4)).saturating_sub(used) as usize; let mut more_slots = free_c .min(params::compute_flights().saturating_sub(active_computes + 1)) .min(sizes::COMPUTE_SLOTS.saturating_sub(1)) - .min(ring_more) - .min(pipe_fold_cap); + .min(ring_more); let rt_head = job.resources.compute_scs() || c.is_rt(); // Fold trailing barrier-free compute commands of the base job first. while !rt_head && more_slots > 0 && end < job.progress.count() { diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index d556b290062e5..39d0a17303a4c 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -896,6 +896,12 @@ pub(crate) mod sizes { ); /// Maximum jobs folded into one barrier-free compute horizon prefix. pub(crate) const HORIZON_JOBS: u32 = COMPUTE_UNITS as u32; + /// Maximum commands accumulated in a busy-state horizon micro-coalescing batch before + /// immediate publication, and maximum hold window (18 us) while a queue already has >= 2 + /// active commands in flight. + pub(crate) const COALESCE_MAX_CMDS: usize = 6; + pub(crate) const COALESCE_WINDOW_US: u32 = 18; + pub(crate) const COALESCE_WINDOW_NS: u64 = (COALESCE_WINDOW_US as u64) * 1000; /// Jobs admitted to the engine per logical queue: enough to keep a queue's commands /// in flight back to back without scheduler backpressure stalls; exact prior-command /// dependencies still gate each one. diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 78b4415f27e42..285b14fce52d7 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -141,7 +141,18 @@ impl Shared { ) { Ok(true) if retry_tail => {} Ok(true) => { - self.rearm(firmware.engine.chan_wait || firmware.engine.short_repoll) + let soon = firmware.engine.chan_wait || firmware.engine.short_repoll; + if firmware.engine.coalesce_deadline_ns != 0 && !soon { + let rem_us = (firmware + .engine + .coalesce_deadline_ns + .saturating_sub(now_ns()) + .div_ceil(1000) as u32) + .clamp(1, super::hw::sizes::COALESCE_WINDOW_US); + self.rearm_after(rem_us.min(self.rearm_us(false))); + } else { + self.rearm(soon); + } } // Idle: arm a delayed poll while DVFS utilization is decaying or a CLPC // floor hold is still pending so both expire cleanly to idle power. @@ -271,20 +282,26 @@ impl Shared { Ok(()) }); } + let mut coalesce_us = None; if pub_res.is_ok() { if retired_any || !had_flights { firmware.reclaim_closed_vm_slots(); } - pub_res = if recovery_pending { - let r = firmware.publish(done); - if r.is_ok() { - firmware.last_housekeeping_ns = now; - firmware.last_aux_drain_ns = now; - } - r - } else { - firmware.publish_checked(done) - }; + if !recovery_pending && !retired_any && !restored_event && had_flights { + coalesce_us = firmware.defer_busy_coalesce(now); + } + if coalesce_us.is_none() { + pub_res = if recovery_pending { + let r = firmware.publish(done); + if r.is_ok() { + firmware.last_housekeeping_ns = now; + firmware.last_aux_drain_ns = now; + } + r + } else { + firmware.publish_checked(done) + }; + } } if pub_res.is_ok() && !firmware.engine.flights.is_empty() @@ -300,11 +317,15 @@ impl Shared { // If an EP 0x20 event retired an older flight while later flights remain active, // or arrived before the oldest receipt became visible, arm a short repoll so // trailing completions never fall back to `resnap_us`. - self.rearm( - firmware.engine.chan_wait - || restored_event - || (was_evented && retired_any && !firmware.engine.flights.is_empty()), - ); + if let Some(us) = coalesce_us { + self.rearm_after(us.min(self.rearm_us(false))); + } else { + self.rearm( + firmware.engine.chan_wait + || restored_event + || (was_evented && retired_any && !firmware.engine.flights.is_empty()), + ); + } } else { firmware.power.report_work(false); self.arm_idle_power_poll(firmware); @@ -527,10 +548,15 @@ impl Shared { /// Re-checks a published command soon: hrtimer, with a throttled 1-jiffy backup; sooner while /// a ready prefix waits for record consumption or a post-event receipt tail is settling. pub(crate) fn rearm(self: &Arc, soon: bool) { + self.rearm_after(self.rearm_us(soon)); + } + + /// Arms the poll hrtimer for `us` microseconds (coalescing with an already-armed deadline + /// within 5 us) plus the throttled 1-jiffy backup poll. + pub(crate) fn rearm_after(self: &Arc, us: u32) { if self.sleeping.load(Ordering::Acquire) { return; } - let us = self.rearm_us(soon); let now = now_ns(); let target_ns = now.saturating_add(u64::from(us) * 1000); let armed_ns = self.resnap_deadline_ns.load(Ordering::Acquire); @@ -683,6 +709,8 @@ impl Firmware { // while `publish_woke` covers external state changes (VM close, unstarted queue // cancellation) and `ta_wave_ready()` wakes TA-wave-paced renders when a `0x70` TA // pass finishes while FS is still running. + let coalesce_due = self.engine.coalesce_deadline_ns != 0 + && (!evented || now >= self.engine.coalesce_deadline_ns); let should_publish = !self.engine.pending.is_empty() && (retired_any || !had_flights @@ -692,6 +720,7 @@ impl Firmware { || scrub_woke || publish_woke || self.ta_wave_ready() + || coalesce_due || housekeeping_due); let published = if should_publish { self.publish_checked(done) diff --git a/drivers/gpu/drm/asahi/g16/recovery.rs b/drivers/gpu/drm/asahi/g16/recovery.rs index e641735511142..f0d082eea46d4 100644 --- a/drivers/gpu/drm/asahi/g16/recovery.rs +++ b/drivers/gpu/drm/asahi/g16/recovery.rs @@ -290,6 +290,7 @@ impl Firmware { self.floor_power(error); } self.engine.frozen = true; + self.engine.coalesce_deadline_ns = 0; self.events.grow.clear(); self.fail_flights(error, done); self.fail_all_vms(EIO); diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py index 03099634f7b6c..9b7c2ff187656 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py @@ -68,6 +68,7 @@ def item(declaration, text=source): pub const TA_WAVE_PASSES: usize = 4; pub const TA_WAVE_REFILL: usize = TA_WAVE_PASSES / 2; pub const COMPUTE_PIPES: usize = 2; + pub const COALESCE_WINDOW_US: u32 = 18; } } @@ -161,6 +162,7 @@ def item(declaration, text=source): slot_wait: bool, ta_wave_wait: bool, short_repoll: bool, + coalesce_deadline_ns: u64, frozen: bool, stats: Stats, prof: Prof, @@ -217,6 +219,8 @@ def item(declaration, text=source): rearmed: Cell, idle_power_polls: Cell, rearm_soon: Cell, + rearm_after_calls: Cell, + last_rearm_us: Cell, poll_now_calls: Cell, } impl Shared { @@ -229,9 +233,18 @@ def item(declaration, text=source): rearmed: Cell::new(0), idle_power_polls: Cell::new(0), rearm_soon: Cell::new(0), + rearm_after_calls: Cell::new(0), + last_rearm_us: Cell::new(0), poll_now_calls: Cell::new(0), }) } + fn rearm_us(&self, soon: bool) -> u32 { + if soon { 25 } else { 100 } + } + fn rearm_after(&self, us: u32) { + self.rearm_after_calls.set(self.rearm_after_calls.get() + 1); + self.last_rearm_us.set(us); + } fn rearm(&self, soon: bool) { self.rearmed.set(self.rearmed.get() + 1); if soon { @@ -311,6 +324,7 @@ def item(declaration, text=source): drain_fs_delta: u32, drain_compute_delta: u32, ta_pending: usize, + coalesce_us: Option, retire_calls: u32, publish_full_calls: u32, publish_checked_calls: u32, @@ -347,6 +361,7 @@ def item(declaration, text=source): slot_wait: false, ta_wave_wait: false, short_repoll: false, + coalesce_deadline_ns: 0, frozen: false, stats: Stats::default(), prof: Prof::default(), @@ -364,6 +379,7 @@ def item(declaration, text=source): drain_fs_delta: 0, drain_compute_delta: 0, ta_pending: 0, + coalesce_us: None, retire_calls: 0, publish_full_calls: 0, publish_checked_calls: 0, @@ -425,9 +441,13 @@ def item(declaration, text=source): Ok(()) } fn publish_checked(&mut self, _done: &mut Completions) -> Result { + self.engine.coalesce_deadline_ns = 0; self.publish_checked_calls += 1; Ok(()) } + fn defer_busy_coalesce(&mut self, _now: u64) -> Option { + self.coalesce_us + } fn ta_pending_passes(&self) -> usize { self.ta_pending } @@ -1017,6 +1037,58 @@ def item(declaration, text=source): assert!(!fw.engine.short_repoll); } +#[test] +fn submit_locked_and_poll_step_micro_coalesce_busy_horizons() { + CLOCK.with(|c| c.set(100_000)); + let shared = Shared::new(); + let mut fw = Firmware::new(); + fw.engine.flights.push(Flight { + computes: 2, + compute_pipe: 0, + renders: 0, + target: 0x200, + fs_target: 0, + }); + fw.engine.target[0] = 0x200; + fw.coalesce_us = Some(18); + fw.engine.coalesce_deadline_ns = 118_000; + + // submit_locked skips publish_checked and arms rearm_after(18) when defer_busy_coalesce fires. + let mut done = vec![]; + shared + .submit_locked(&mut fw, Arc::new(Job { id: 3 }), &mut done) + .unwrap(); + assert_eq!(fw.publish_checked_calls, 0); + assert_eq!(shared.rearm_after_calls.get(), 1); + assert_eq!(shared.last_rearm_us.get(), 18); + assert_eq!(shared.rearmed.get(), 0); + + // An early non-retiring event poll before the deadline does not flush prematurely. + CLOCK.with(|c| c.set(105_000)); + let (mut retry_tail, mut deferred) = (false, false); + assert!(fw + .poll_step(true, EVENT_RETIRE_POLLS, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert_eq!(fw.publish_checked_calls, 0); + + // Reaching the deadline on an event poll flushes immediately. + CLOCK.with(|c| c.set(118_000)); + assert!(fw + .poll_step(true, EVENT_RETIRE_POLLS, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert_eq!(fw.publish_checked_calls, 1); + assert_eq!(fw.engine.coalesce_deadline_ns, 0); + + // A timer poll (!evented) with an active coalesce deadline also flushes immediately. + fw.engine.coalesce_deadline_ns = 136_000; + CLOCK.with(|c| c.set(125_000)); + assert!(fw + .poll_step(false, 0, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert_eq!(fw.publish_checked_calls, 2); + assert_eq!(fw.engine.coalesce_deadline_ns, 0); +} + mod boot { pub fn eproto() -> super::Error { super::Error(-71) @@ -1328,6 +1400,7 @@ def item(declaration, text=source): __IDLE_RESNAP__ __REARM_US__ __REARM__ + __REARM_AFTER__ __NOTE_FLIGHT_US__ } @@ -1415,11 +1488,21 @@ def item(declaration, text=source): assert_eq!(shared.drops.load(Ordering::Acquire), 1); assert_eq!(shared.resnap_deadline_ns.load(Ordering::Acquire), 127_000); + // Coalesce rearm_after(18) pulls in a 25 us timer (>5 us earlier) and coalesces within 5 us. + shared.rearm_after(18); + assert_eq!(shared.starts.load(Ordering::Acquire), 3); + assert_eq!(shared.drops.load(Ordering::Acquire), 2); + assert_eq!(shared.resnap_deadline_ns.load(Ordering::Acquire), 120_000); + CLOCK.store(106_000, Ordering::Release); + shared.rearm_after(14); + assert_eq!(shared.starts.load(Ordering::Acquire), 3); + assert_eq!(shared.drops.load(Ordering::Acquire), 2); + // cancel_resnap unconditionally clears deadline and drops handle. shared.cancel_resnap(); assert_eq!(shared.resnap_deadline_ns.load(Ordering::Acquire), 0); assert!(shared.resnap_handle.lock().is_none()); - assert_eq!(shared.drops.load(Ordering::Acquire), 2); + assert_eq!(shared.drops.load(Ordering::Acquire), 3); } #[test] @@ -1578,6 +1661,7 @@ def item(declaration, text=source): '__IDLE_RESNAP__': 'pub(crate) fn idle_resnap(', '__REARM_US__': 'pub(crate) fn rearm_us(', '__REARM__': 'pub(crate) fn rearm(', + '__REARM_AFTER__': 'pub(crate) fn rearm_after(', '__POLL_NOW__': 'pub(crate) fn poll_now(', }.items(): harness = harness.replace(token, item(decl).replace('super::hw::', 'hw::')) diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 5cefe344b3090..cf9c0cad5c322 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -80,6 +80,7 @@ def item(declaration): assert 'self.graph.render.threshold.w32(0, prefix.draw as u32)?;' in publish_prefix_body_fn assert 'self.graph.render.threshold.w32(8, prefix.draw as u32)?;' in publish_prefix_body_fn assert 'earliest_unfinished_ta_draw' not in source and 'rearm_ta_threshold' not in source +assert 'pipe_fold_cap' not in source, 'pipe_fold_cap must be removed so single-queue horizons fold cleanly' harness = r''' @@ -132,7 +133,7 @@ def item(declaration): struct Flight{job:Arc,claims:Claims,group:Vec>,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,doomed:bool,recovery_suspect:bool,initbm:bool} impl Flight{fn new(job:Arc)->Self{Self{job,claims:Claims,group:vec![],computes:0,renders:0,compute_pipe:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false}}} __SCS_COMPUTE_CONFLICT__ -struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,ta_wave_wait:bool} +struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,ta_wave_wait:bool,coalesce_deadline_ns:u64} impl Engine { __PICK__ __UNPEND__ @@ -178,7 +179,7 @@ def item(declaration): // containment branch below decides whether the unit becomes claimable again. pub fn preserve_compute_descriptor(refs:&ComputeRefs,_old:&[u8;160],_before:u64,_work:&mut[u8;8192])->Result<(),()>{if refs.invalid{Err(())}else{Ok(())}} } -mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_REFILL:usize=TA_WAVE_PASSES/2; pub const COMPUTE_PIPES:usize=2; pub const PIPE1_COMPUTE_START:usize=6; } } +mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_REFILL:usize=TA_WAVE_PASSES/2; pub const COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; } } mod command {pub const RENDER:usize=0;pub const COMPUTE:usize=1;} thread_local!{static CLOCK:std::cell::Cell=const{std::cell::Cell::new(0)};} fn now_ns()->u64{CLOCK.with(|clock|clock.get())} @@ -291,7 +292,7 @@ def item(declaration): } fn firmware(jobs:Vec>,stages:Vec<(Result,bool)>)->Firmware{ Firmware{session:Session{shared:Shared{sleeping:AtomicBool::new(false)},rings:vec![],ring_fail:false,checks:AtomicU32::new(0),transports:AtomicU32::new(0)},objects:Checks,recovery:Recovery{error:None,publication_wait_deadline:None}, - engine:Engine{ordinal:0,draw:0,pending:jobs,flights:vec![],frozen:false,turn:0,stats:Stats::default(),chan_wait:false,slot_wait:false,ta_wave_wait:false}, + engine:Engine{ordinal:0,draw:0,pending:jobs,flights:vec![],frozen:false,turn:0,stats:Stats::default(),chan_wait:false,slot_wait:false,ta_wave_wait:false,coalesce_deadline_ns:0}, slots:Slots{compute_exhausted:false,render_exhausted:false,releases:0,quarantines:0},pools:Pools{exhausted:false,exhausted_vm:None,block_pipeline_vm:None},power:Power::default(), unavailable:vec![],stages:stages.into_iter().map(|(result,visible)|Stage{result,visible}).collect(), retained:vec![],attempted:vec![],fail_stops:0,allow_behind:false,block_render_behind:false,block_compute_behind:false} @@ -1696,37 +1697,45 @@ def item(declaration): let c1=mk(1,vm1.clone(),q1.clone(),1); let c2=mk(2,vm1.clone(),q1.clone(),2); let c_vm2=mk(3,vm2.clone(),q2.clone(),1); + let q3=Queue::new(0,2); let mut host=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:0,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; - // Empty engine uses next_compute_pipe (0), then balances onto pipe 1 while pipe 0 is active. - assert_eq!(host.choose_compute_pipe([None, None], (1u32 << 24) - 1, false), 0); + // Empty engine uses next_compute_pipe (0). + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); host.engine.flights.push(QueueBehindFlight{ job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); - assert_eq!(host.choose_compute_pipe([None, None], (1u32 << 24) - 1, false), 1); - // RT/SCS compute stays pinned to pipe 0 even while pipe 0 is active. - assert_eq!(host.choose_compute_pipe([None, None], (1u32 << 24) - 1, true), 0); - // A 2-unit base-only VM stays pinned to pipe 0 even while pipe 0 is active. - assert_eq!(host.choose_compute_pipe([None, None], 0b11, false), 0); - assert_eq!(host.choose_compute_pipe([None, None], 0b110, false), 0); + // Single-queue barrier-free compute stays affine to its active pipe (pipe 0), + // while a second independent queue balances onto idle pipe 1. + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false), 1); + // RT/SCS compute stays pinned to pipe 0 even for another queue while pipe 0 is active. + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, true), 0); + // A 2-unit base-only or SCS VM (bits < PIPE1_COMPUTE_START) stays pinned to pipe 0 + // even for another queue while pipe 0 is active. + assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b11, false), 0); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b110, false), 0); assert!(host.can_queue_behind(&c2)); - // Add second concurrent flight on pipe 1: both pipes active, - // tie-break uses next_compute_pipe, and cross-VM compute overlaps cleanly. + // Add second concurrent flight on pipe 1 from q2: both pipes active, + // q1 stays affine to pipe 0, q2 stays affine to pipe 1, and a third queue q3 + // tie-breaks by next_compute_pipe. host.engine.flights.push(QueueBehindFlight{ - job:c2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,target:0x100, + job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false), 1); host.engine.next_compute_pipe=1; - assert_eq!(host.choose_compute_pipe([None, None], (1u32 << 24) - 1, false), 1); + assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false), 1); host.engine.next_compute_pipe=0; - assert_eq!(host.choose_compute_pipe([None, None], (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false), 0); assert!(host.can_queue_behind(&c_vm2)); // Same-VM compute still pipelines without draining. assert!(host.can_queue_behind(&c2)); @@ -1767,13 +1776,13 @@ def item(declaration): // Waiting on seq 1 (pipe 0 only) returns [Some(0x100), None] and reuses pipe 0 (zero c2c barrier). let w1 = host.wait_compute_stamps_for(&c3, Some(1)).unwrap(); assert_eq!(w1, [Some(WaitTarget{stamp:0x100,initbm:false}), None]); - assert_eq!(host.choose_compute_pipe(w1, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w1, (1u32 << 24) - 1, false), 0); // Waiting on seq 2 (both pipe 0 seq 1 and pipe 1 seq 2 <= 2) returns both stamps and // selects the least-loaded pipe (pipe 0 has 1 active vs pipe 1 has 2 -> picks pipe 0, // so prefix_compute emits one cross-pipe c2c barrier on pipe 1's 0x200). let w2 = host.wait_compute_stamps_for(&c4, Some(2)).unwrap(); assert_eq!(w2, [Some(WaitTarget{stamp:0x100,initbm:false}), Some(WaitTarget{stamp:0x200,initbm:false})]); - assert_eq!(host.choose_compute_pipe(w2, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w2, (1u32 << 24) - 1, false), 0); // Unpublished seq 3 returns Err(EAGAIN). assert_eq!(host.wait_compute_stamps_for(&c4, Some(3)), Err(EAGAIN)); // If seq 2 retired out-of-order on pipe 1 while seq 1 is still active on pipe 0, @@ -1784,7 +1793,7 @@ def item(declaration): assert!(q1.is_compute_retired(2)); let w2_ooo = host.wait_compute_stamps_for(&c4, Some(2)).unwrap(); assert_eq!(w2_ooo, [Some(WaitTarget{stamp:0x100,initbm:false}), None]); - assert_eq!(host.choose_compute_pipe(w2_ooo, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w2_ooo, (1u32 << 24) - 1, false), 0); // Once contiguous completed[COMPUTE] reaches 2, wait_compute_stamps_for returns [None, None]. q1.completed[command::COMPUTE].store(2, Ordering::Release); q1.compute_ooo.store(0, Ordering::Release); @@ -1844,7 +1853,7 @@ def item(declaration): // Cross-queue compute wait resolves pipe 0 stamp 0x100 and keeps q2 on pipe 0 (zero c2c). let cw=host.wait_compute_stamps_for(&c2_wait_q1,None).unwrap(); assert_eq!(cw,[Some(WaitTarget{stamp:0x100,initbm:false}),None]); - assert_eq!(host.choose_compute_pipe(cw,(1u32<<24)-1,false),0); + assert_eq!(host.choose_compute_pipe(&q2,cw,(1u32<<24)-1,false),0); // Cross-queue render wait resolves q1's FS stamp 0x200. assert_eq!(host.wait_stamp_for(&c2_wait_q1,command::RENDER,None),Ok(Some(WaitTarget{stamp:0x200,initbm:false}))); // query_access compute waiting via fw_waits on a timestamped q1 flight must wait to retire; @@ -2506,6 +2515,164 @@ def item(declaration): assert_eq!(fw.recovery_prepare(1, 16, 0x300, [0, 0, 0, 0]), Err(ENOENT)); } } +mod busy_coalesce_scope { + use super::{Arc, AtomicBool, AtomicU32, Command, ComputeCommand, Order, Progress, Queue, Recovery, Result, Status, Vm}; + mod params { + pub fn compute_flights() -> usize { 23 } + pub fn render_flights() -> usize { 47 } + } + struct Resources { units: usize, scs: bool } + impl Resources { + fn compute_slot_mask(&self) -> Result { + Ok(if self.units >= 32 { u32::MAX } else { (1u32 << self.units) - 1 }) + } + fn compute_scs(&self) -> bool { self.scs } + fn render_scs(&self) -> bool { self.scs } + } + struct Job { + vm: Arc, + queue: Arc, + progress: Progress, + commands: Vec, + orders: Vec, + fw_waits: Vec<()>, + resources: Resources, + is_long: bool, + foldable: bool, + } + impl Job { + fn long(&self) -> bool { self.is_long } + fn command_order(&self, idx: u32) -> Option { self.orders.get(idx as usize).copied() } + fn can_fold_horizon_cmd(&self, idx: u32, expected: u64) -> bool { + self.foldable + && self.orders.get(idx as usize).is_some_and(|o| o.engine == crate::command::COMPUTE && o.sequence == expected && o.wait_through == [None, None]) + } + fn can_fold_horizon_job(&self, first: u64) -> bool { + self.foldable + && self.orders.iter().enumerate().all(|(i, o)| o.engine == crate::command::COMPUTE && o.sequence == first + i as u64 && o.wait_through == [None, None]) + } + fn can_fold_render_cmd(&self, idx: u32, expected: u64) -> bool { + self.foldable + && self.orders.get(idx as usize).is_some_and(|o| o.engine == crate::command::RENDER && o.sequence == expected) + } + fn can_fold_render_horizon_job(&self, first: u64) -> bool { + self.foldable + && self.orders.iter().enumerate().all(|(i, o)| o.engine == crate::command::RENDER && o.sequence == first + i as u64) + } + } + fn command(job: &Job, k: u32) -> Option<&Command> { job.commands.get(k as usize) } + struct Flight { + job: Arc, + computes: u32, + renders: u32, + doomed: bool, + recovery_suspect: bool, + initbm: bool, + } + struct Engine { + flights: Vec, + pending: Vec>, + frozen: bool, + chan_wait: bool, + slot_wait: bool, + ta_wave_wait: bool, + coalesce_deadline_ns: u64, + } + struct Slots { free_c: u32 } + impl Slots { + fn free_compute_in_mask_for_pipe(&self, _m: u32, _p: usize) -> u32 { self.free_c } + } + struct Host { + recovery: Recovery, + engine: Engine, + slots: Slots, + allow_behind: bool, + ta_pending: usize, + } + impl Host { + fn can_queue_behind(&self, _job: &Arc) -> bool { self.allow_behind } + fn choose_compute_pipe(&self, _q: &Arc, _w: [Option<()>; 2], _m: u32, _rt: bool) -> usize { 0 } + fn ta_pending_passes(&self) -> usize { self.ta_pending } + __CAN_DEFER_BUSY_COALESCE__ + __DEFER_BUSY_COALESCE__ + } + fn mk_job(vm: &Arc, q: &Arc, render: bool, seq: u64, wait: [Option; 2]) -> Arc { + Arc::new(Job { + vm: vm.clone(), + queue: q.clone(), + progress: Progress { sent: AtomicU32::new(0), count: 1, pending: AtomicBool::new(true) }, + commands: vec![if render { Command::Render(()) } else { Command::Compute(ComputeCommand { query_access: false, rt: false }) }], + orders: vec![Order { engine: if render { crate::command::RENDER } else { crate::command::COMPUTE }, sequence: seq, wait_through: wait }], + fw_waits: vec![], + resources: Resources { units: 24, scs: false }, + is_long: false, + foldable: true, + }) + } + #[test] + fn busy_coalesce_holds_deep_single_queue_bursts_and_never_delays_shallow_or_other_queues() { + let vm1 = Arc::new(Vm { status: Status(AtomicU32::new(0)), slot: 1 }); + let q1 = Queue::new(0, 2); + let q2 = Queue::new(0, 2); + let c1 = mk_job(&vm1, &q1, false, 1, [None, None]); + let mut h = Host { + recovery: Recovery { error: None, publication_wait_deadline: None }, + engine: Engine { + flights: vec![Flight { job: c1.clone(), computes: 1, renders: 0, doomed: false, recovery_suspect: false, initbm: false }], + pending: vec![mk_job(&vm1, &q1, false, 2, [None, None])], + frozen: false, + chan_wait: false, + slot_wait: false, + ta_wave_wait: false, + coalesce_deadline_ns: 0, + }, + slots: Slots { free_c: 20 }, + allow_behind: true, + ta_pending: 0, + }; + // d=2 (queue_active == 1 < 2): ZERO coalescing delay. + assert_eq!(h.defer_busy_coalesce(100_000), None); + + // Once queue_active >= 2, barrier-free compute holds up to 18 us and accumulates up to K=6. + h.engine.flights[0].computes = 2; + h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; + assert_eq!(h.defer_busy_coalesce(100_000), Some(18)); + assert_eq!(h.engine.coalesce_deadline_ns, 118_000); + // Second job arrives 5 us later -> remaining 13 us. + h.engine.pending.push(mk_job(&vm1, &q1, false, 4, [None, None])); + assert_eq!(h.defer_busy_coalesce(105_000), Some(13)); + // Reaching K=6 pending commands flushes immediately. + for seq in 5..=8 { + h.engine.pending.push(mk_job(&vm1, &q1, false, seq, [None, None])); + } + assert_eq!(h.defer_busy_coalesce(110_000), None); + assert_eq!(h.engine.coalesce_deadline_ns, 0); + + // Deadline expiry flushes even with 1 pending command. + h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; + assert_eq!(h.defer_busy_coalesce(200_000), Some(18)); + assert_eq!(h.defer_busy_coalesce(218_000), None); + assert_eq!(h.engine.coalesce_deadline_ns, 0); + + // Another queue arriving in pending flushes immediately (no cross-queue head-of-line delay). + assert_eq!(h.defer_busy_coalesce(300_000), Some(18)); + h.engine.pending.push(mk_job(&vm1, &q2, false, 1, [None, None])); + assert_eq!(h.defer_busy_coalesce(302_000), None); + + // Barriered compute flushes immediately (0 delay). + h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, Some(2)])]; + assert_eq!(h.defer_busy_coalesce(400_000), None); + + // Render with queue_active == 2 and ta_pending == 2 (ta_room == 2) holds 1 pass and flushes at 2. + let r1 = mk_job(&vm1, &q1, true, 1, [None, None]); + h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, doomed: false, recovery_suspect: false, initbm: false }]; + h.ta_pending = 2; + h.engine.pending = vec![mk_job(&vm1, &q1, true, 3, [Some(2), None])]; + assert_eq!(h.defer_busy_coalesce(500_000), Some(18)); + h.engine.pending.push(mk_job(&vm1, &q1, true, 4, [Some(3), None])); + assert_eq!(h.defer_busy_coalesce(505_000), None); + } +} ''' harness = harness.replace('__LOGIC__', str(production.parent / 'recovery/logic.rs')) harness = harness.replace('__USAGE__', str(production.parent.parent / 'usage.rs')) @@ -2565,6 +2732,8 @@ def item(declaration): '__PUBLISH_PRODUCER__': 'fn publish_producer(', '__TA_PENDING_PASSES__': 'pub(crate) fn ta_pending_passes(', '__CAN_QUEUE_BEHIND__': 'fn can_queue_behind(', + '__CAN_DEFER_BUSY_COALESCE__': 'fn can_defer_busy_coalesce(', + '__DEFER_BUSY_COALESCE__': 'pub(crate) fn defer_busy_coalesce(', '__WAIT_STAMP_FOR_WITH__': 'fn wait_stamp_for_with(', '__WAIT_STAMP_FOR__': 'fn wait_stamp_for(', '__CROSS_ENGINE_WAIT__': 'fn cross_engine_wait(', From 726fb859b58cb354041c19458b5143c26b608a24 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 23 Nov 2026 14:16:39 -0500 Subject: [PATCH 2/7] drm/asahi/g16: adaptive TA wave window, O(1) pending scan, and cursor-ordered async pass pre-scrub Light single-layer render passes (tilemap_bytes <= 64 KiB) do not saturate M4 firmware's TA/scene pipeline at 4 passes, while deep single-queue render bursts (d=64) hit three avoidable CPU/pacing cliffs: 1) TA_WAVE_PASSES=4 caps light render waves and limits render busy micro-coalescing to 2 passes; 2) publish_checked() re-read WC fw_stamp and rescanned pending[..i] for every blocked follower of the head queue; and 3) stage_displaced_pass_scrubs() scanned slots 0..47 instead of starting at pass_cursor, leaving upcoming slots dirty when >8 displaced slots were pending. Precompute RenderCommand::heavy_ta on admission, raise the light single- layer TA wave cap to TA_WAVE_PASSES_LIGHT=8 while keeping conservative TA_WAVE_PASSES=4 whenever any active or pending pass is heavy, adapt ta_wave_ready() hysteresis to cap - 2, and raise SCHEDULER_CREDITS to 64. Hoist ta_pending_passes() once per publish_checked() pass and skip blocked same-queue followers in O(1), and scan stage_displaced_pass_scrubs() cursor-ordered from pass_cursor while preserving pick_pass_in_for's same_dirty > unowned preference. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/command.rs | 13 + drivers/gpu/drm/asahi/g16/engine.rs | 174 ++++++++++-- drivers/gpu/drm/asahi/g16/hw.rs | 22 +- drivers/gpu/drm/asahi/g16/poll.rs | 7 +- drivers/gpu/drm/asahi/g16/slots.rs | 9 +- .../gpu/asahi-m4/test-command-stream.py | 2 +- .../drivers/gpu/asahi-m4/test-poll-retire.py | 24 +- .../drivers/gpu/asahi-m4/test-publication.py | 252 ++++++++++++------ .../drivers/gpu/asahi-m4/test-resources.py | 41 +++ 9 files changed, 417 insertions(+), 127 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/command.rs b/drivers/gpu/drm/asahi/g16/command.rs index c45d53bc86eab..b21c9eb1f9b53 100644 --- a/drivers/gpu/drm/asahi/g16/command.rs +++ b/drivers/gpu/drm/asahi/g16/command.rs @@ -181,6 +181,15 @@ pub(crate) struct RenderCommand { /// Explicit hardware attachments in effect for each render engine. pub(crate) vertex_attachments: KVec, pub(crate) fragment_attachments: KVec, + /// Whether this pass exceeds the light-TA wave threshold (multi-layer or large tilemap). + pub(crate) heavy_ta: bool, +} + +impl RenderCommand { + /// Whether this render pass requires the conservative `TA_WAVE_PASSES` wave window. + pub(crate) fn is_heavy_ta(&self) -> bool { + self.heavy_ta + } } /// A validated compute command. @@ -1517,6 +1526,9 @@ pub(crate) fn parse_stream(bytes: &[u8], early_tiling: bool) -> Result 1 + || super::encode::Geometry::new(&packet, 0).tilemap_bytes + > hw::sizes::TA_LIGHT_TILEMAP_BYTES; commands.push(Command::Render(KBox::new( RenderCommand { cmd: packet, @@ -1525,6 +1537,7 @@ pub(crate) fn parse_stream(bytes: &[u8], early_tiling: bool) -> Result = None; + if !self.engine.flights.is_empty() + && !self.can_queue_behind_with_ta(&job, &mut ta_pending) + { if self.needs_engine_drain(&job) { self.engine.stats.hold[0] += 1; break; } - let ta_wave_paused = self.ta_pending_passes() >= super::hw::sizes::TA_WAVE_PASSES; + let ta_val = *ta_pending.get_or_insert_with(|| self.ta_pending_passes()); + let ta_wave_paused = ta_val >= self.active_ta_wave_cap(); let mut alt: Option = None; for (i, cand) in self.engine.pending.iter().enumerate() { - if i == index || !self.can_queue_behind(cand) { + if i == index { + continue; + } + // Fast O(1) skip for blocked head-queue followers: `Engine::pick` chose the + // earliest pending job of `job.queue`, so later jobs of the same queue are + // FIFO-blocked unless an independent non-query compute may bypass TA-wave + // paused renders. + if i > index + && Arc::ptr_eq(&cand.queue, &job.queue) + && !(ta_wave_paused + && matches!( + command(cand, cand.progress.sent()), + Some(Command::Compute(c)) if !c.query_access + )) + { + continue; + } + if !self.can_queue_behind_with_ta(cand, &mut ta_pending) { continue; } // Preserve per-queue FIFO: never jump a later job of a queue ahead @@ -1047,7 +1071,8 @@ impl Firmware { ) && matches!( command(earlier, earlier.progress.sent()), - Some(Command::Render(_)) + Some(Command::Render(r)) + if ta_val >= self.ta_wave_cap_for(r.is_heavy_ta()) ) && !self.needs_engine_drain(earlier) && earlier @@ -1080,17 +1105,16 @@ impl Firmware { .pending .iter() .any(|cand| self.blocked_on_slot_headroom(cand)); - self.engine.ta_wave_wait = self.ta_pending_passes() - >= super::hw::sizes::TA_WAVE_PASSES - && self.engine.pending.iter().any(|cand| { - matches!( - command(cand, cand.progress.sent()), - Some(Command::Render(_)) - ) && !self.needs_engine_drain(cand) - && cand - .check_command_dependencies(cand.progress.sent()) - .is_ok() - }); + self.engine.ta_wave_wait = self.engine.pending.iter().any(|cand| { + matches!( + command(cand, cand.progress.sent()), + Some(Command::Render(r)) + if ta_val >= self.ta_wave_cap_for(r.is_heavy_ta()) + ) && !self.needs_engine_drain(cand) + && cand + .check_command_dependencies(cand.progress.sent()) + .is_ok() + }); self.engine.stats.hold[0] += 1; break; } @@ -1190,12 +1214,12 @@ impl Firmware { if job.progress.sent() == job.progress.count() { self.engine.unpend(&job); // fully published } - // Ring TA/FS immediately once a render wave fills TA_WAVE_PASSES so the GPU - // starts tiling right away instead of waiting behind another loop iteration - // or an alt-class compute publication. + // Ring TA/FS immediately once a render wave fills the active TA wave window so + // the GPU starts tiling right away instead of waiting behind another loop + // iteration or an alt-class compute publication. if pending_rings & ((1u8 << (Channel::Fs as u8)) | (1u8 << (Channel::Ta as u8))) != 0 - && self.ta_pending_passes() >= super::hw::sizes::TA_WAVE_PASSES + && self.ta_pending_passes() >= self.active_ta_wave_cap() { if let Err(e) = self.flush_doorbells(&mut pending_rings) { dev_err!( @@ -1413,6 +1437,45 @@ impl Firmware { pending } + /// Adaptive TA wave window for a candidate render pass: conservative `TA_WAVE_PASSES` (4) + /// when either the candidate or any active render flight is heavy (multi-layer or tilemap + /// above `TA_LIGHT_TILEMAP_BYTES`), and `TA_WAVE_PASSES_LIGHT` (8) for light single-layer + /// render bursts. + fn ta_wave_cap_for(&self, cand_heavy: bool) -> usize { + if cand_heavy + || self + .engine + .flights + .iter() + .any(|fl| fl.renders != 0 && fl.heavy_render) + { + super::hw::sizes::TA_WAVE_PASSES + } else { + super::hw::sizes::TA_WAVE_PASSES_LIGHT + } + } + + /// Active TA wave window across in-flight renders and pending render heads, used for + /// immediate wave doorbell flushes and `ta_wave_ready()` hysteresis. + pub(crate) fn active_ta_wave_cap(&self) -> usize { + if self + .engine + .flights + .iter() + .any(|fl| fl.renders != 0 && fl.heavy_render) + || self.engine.pending.iter().any(|cand| { + matches!( + command(cand, cand.progress.sent()), + Some(Command::Render(r)) if r.is_heavy_ta() + ) + }) + { + super::hw::sizes::TA_WAVE_PASSES + } else { + super::hw::sizes::TA_WAVE_PASSES_LIGHT + } + } + /// Whether `job`'s next command may be published behind the flights in flight: /// /// - Compute queues behind healthy non-InitBM compute flights of any VM or same-VM @@ -1433,6 +1496,14 @@ impl Firmware { /// firmware DM1 timeout. Cold InitBM priming renders and every failure or recovery path /// still drain the engine first. fn can_queue_behind(&self, job: &Arc) -> bool { + let mut ta_pending = None; + self.can_queue_behind_with_ta(job, &mut ta_pending) + } + + /// [`Self::can_queue_behind`] with an optional caller-hoisted cache of + /// [`Self::ta_pending_passes`] so scanning many pending jobs performs at most one WC stamp + /// read per pass. + fn can_queue_behind_with_ta(&self, job: &Arc, ta_pending: &mut Option) -> bool { let e = &self.engine; let sent = job.progress.sent(); if job.vm.status.get() != 0 @@ -1511,15 +1582,16 @@ impl Firmware { .compute_slot_mask() .is_ok_and(|mask| self.slots.compute_available_in_mask(mask)) } - Some(Command::Render(_)) => { + Some(Command::Render(r)) => { let cross_vm_compute = e .flights .iter() .any(|f| f.computes != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm)); let render_count: usize = e.flights.iter().map(|f| f.renders as usize).sum(); + let ta_cap = self.ta_wave_cap_for(r.is_heavy_ta()); !cross_vm_compute && render_count < params::render_flights() - && self.ta_pending_passes() < super::hw::sizes::TA_WAVE_PASSES + && *ta_pending.get_or_insert_with(|| self.ta_pending_passes()) < ta_cap && !self.slots.render_exhausted() && !self.pools.exhausted() && super::recovery::logic::next_ordinal(e.draw).is_some() @@ -1650,7 +1722,7 @@ impl Firmware { .min(super::hw::sizes::COMPUTE_SLOTS); cap > 1 && pending_cmds < cap } - Some(Command::Render(_)) => { + Some(Command::Render(r)) => { if head.resources.render_scs() || !head.fw_waits.is_empty() { return false; } @@ -1667,11 +1739,15 @@ impl Firmware { let Some(mut next_seq) = head_order.sequence.checked_add(1) else { return false; }; + let mut wave_heavy = r.is_heavy_ta(); let mut pending_cmds = 1usize; for k in (head_sent + 1)..head.progress.count() { if !head.can_fold_render_cmd(k, next_seq) { return false; } + if matches!(command(head, k), Some(Command::Render(r2)) if r2.is_heavy_ta()) { + wave_heavy = true; + } let Some(s) = next_seq.checked_add(1) else { return false; }; @@ -1686,6 +1762,11 @@ impl Firmware { { return false; } + if (0..n).any(|k| { + matches!(command(j, k), Some(Command::Render(r2)) if r2.is_heavy_ta()) + }) { + wave_heavy = true; + } let Some(s) = next_seq.checked_add(u64::from(n)) else { return false; }; @@ -1698,8 +1779,8 @@ impl Firmware { .iter() .map(|fl| fl.renders as usize) .sum(); - let ta_room = super::hw::sizes::TA_WAVE_PASSES - .saturating_sub(self.ta_pending_passes()); + let wave_cap = self.ta_wave_cap_for(wave_heavy); + let ta_room = wave_cap.saturating_sub(self.ta_pending_passes()); let cap = super::hw::sizes::COALESCE_MAX_CMDS .min(params::render_flights().saturating_sub(active_renders)) .min(ta_room) @@ -2581,10 +2662,18 @@ impl Firmware { .iter() .map(|fl| fl.renders as usize) .sum(); + let ta_pending_before = self.ta_pending_passes(); + let mut wave_heavy = + self.ta_wave_cap_for(r.is_heavy_ta()) == sizes::TA_WAVE_PASSES; + let wave_cap = if wave_heavy { + sizes::TA_WAVE_PASSES + } else { + sizes::TA_WAVE_PASSES_LIGHT + }; let mut more_renders = params::render_flights() .saturating_sub(active_renders + 1) .min(sizes::RENDER_SLOTS.saturating_sub(1)) - .min(sizes::TA_WAVE_PASSES.saturating_sub(self.ta_pending_passes() + 1)); + .min(wave_cap.saturating_sub(ta_pending_before + 1)); while more_renders > 0 && end < job.progress.count() { let Some(next_seq) = last_seq.and_then(|s| s.checked_add(1)) else { break; @@ -2597,6 +2686,18 @@ impl Firmware { let Some(Command::Render(r2)) = command(job, end) else { break; }; + if r2.is_heavy_ta() && !wave_heavy { + if ta_pending_before + prefix.renders as usize + 1 + > sizes::TA_WAVE_PASSES + { + break; + } + wave_heavy = true; + more_renders = more_renders.min( + sizes::TA_WAVE_PASSES + .saturating_sub(ta_pending_before + prefix.renders as usize), + ); + } let Some(o2) = job.command_order(end) else { break; }; @@ -2672,7 +2773,7 @@ impl Firmware { more_renders -= 1; } // Cross-job render horizon: fold subsequent ready render-only jobs of - // the same queue and VM into the same <= TA_WAVE_PASSES flight, sharing + // the same queue and VM into the same adaptive TA wave flight, sharing // one TA/FS producer advance, one UMA submitted update, and one doorbell. // Any non-qualifying job of this queue ends the scan so no later job // overtakes it. @@ -2725,14 +2826,18 @@ impl Firmware { { break; } - let mut picked = [0usize; sizes::TA_WAVE_PASSES]; + let mut picked = [0usize; sizes::TA_WAVE_PASSES_LIGHT]; let mut picked_mask = f.claims.pass_mask; let mut precheck_ok = true; + let mut job_heavy = false; for k in 0..n2 { let Some(Command::Render(r2)) = command(&j2, k) else { precheck_ok = false; break; }; + if r2.is_heavy_ta() { + job_heavy = true; + } let Some(o2) = j2.command_order(k) else { precheck_ok = false; break; @@ -2789,7 +2894,13 @@ impl Firmware { picked[k as usize] = slot; picked_mask |= 1u64 << slot; } - if !precheck_ok || f.group.reserve(1, GFP_NOWAIT).is_err() { + if !precheck_ok + || (job_heavy + && !wave_heavy + && ta_pending_before + prefix.renders as usize + n2_usize + > sizes::TA_WAVE_PASSES) + || f.group.reserve(1, GFP_NOWAIT).is_err() + { break; } let _ = f.group.push_within_capacity(j2.clone()); @@ -2818,6 +2929,12 @@ impl Firmware { } last_seq = Some(first_seq + u64::from(n2 - 1)); more_renders -= n2_usize; + if job_heavy && !wave_heavy { + wave_heavy = true; + let ta_in_wave = ta_pending_before + prefix.renders as usize; + more_renders = more_renders + .min(sizes::TA_WAVE_PASSES.saturating_sub(ta_in_wave)); + } } } } @@ -3363,6 +3480,7 @@ impl Firmware { (refs, false) }; f.has_timestamps |= !cmd.timestamp_outputs.is_empty(); + f.heavy_render |= cmd.is_heavy_ta(); let p = resources.render_pass(k)?; let pass = p.refs(); let heap_bytes = if cmd.cmd.layers > 1 { 0x1000 } else { 0x200 }; diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 39d0a17303a4c..e7c8e8f6e6b9d 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -782,13 +782,19 @@ pub(crate) mod sizes { /// Worst-case firmware work-ring entries per compute command (`fs2c` barrier + cross-pipe /// `c2c` barrier + `work`). pub(crate) const MAX_COMPUTE_RING_ENTRIES: usize = 3; - /// Maximum unfinished TA passes kept in flight at once so multi-pass render bursts stay - /// inside M4 firmware's `<= 4`-pass TA/scene pipeline without throttling single-pass - /// pipelining (where TA finishes well ahead of FS). + /// Maximum unfinished TA passes kept in flight at once for heavy multi-layer or large-tilemap + /// renders so heavy bursts stay inside M4 firmware's `<= 4`-pass TA/scene pipeline. pub(crate) const TA_WAVE_PASSES: usize = 4; - /// Unfinished TA pass count at or below which a TA-wave-paused render queue wakes to + /// Maximum unfinished TA passes kept in flight at once for light single-layer renders + /// (`tilemap_bytes <= TA_LIGHT_TILEMAP_BYTES`), doubling the wave window for light render + /// bursts and deeper micro-coalesced batches. + pub(crate) const TA_WAVE_PASSES_LIGHT: usize = 8; + /// Tilemap byte threshold at or below which a single-layer render qualifies for + /// `TA_WAVE_PASSES_LIGHT`. + pub(crate) const TA_LIGHT_TILEMAP_BYTES: u64 = 64 * 1024; + /// Headroom below the active TA wave cap at which a TA-wave-paused render queue wakes to /// launch the next wave, avoiding 1-pass stub drips. - pub(crate) const TA_WAVE_REFILL: usize = TA_WAVE_PASSES / 2; + pub(crate) const TA_WAVE_REFILL_HEADROOM: usize = 2; /// Base render pass slots allocated on first render (full TPC/tilemap capacity). pub(crate) const BASE_RENDER_SLOTS: usize = 2; /// Retained render pass slots per VM at most. A slot is reused only after a later render @@ -902,10 +908,10 @@ pub(crate) mod sizes { pub(crate) const COALESCE_MAX_CMDS: usize = 6; pub(crate) const COALESCE_WINDOW_US: u32 = 18; pub(crate) const COALESCE_WINDOW_NS: u64 = (COALESCE_WINDOW_US as u64) * 1000; - /// Jobs admitted to the engine per logical queue: enough to keep a queue's commands - /// in flight back to back without scheduler backpressure stalls; exact prior-command + /// Jobs admitted to the engine per logical queue: enough to keep deep queues (`d=64`) + /// queued back to back without scheduler backpressure stalls; exact prior-command /// dependencies still gate each one. - pub(crate) const SCHEDULER_CREDITS: u32 = 32; + pub(crate) const SCHEDULER_CREDITS: u32 = 64; /// Unconsumed records per 256-entry channel ring a prefix may be posted behind. pub(crate) const AHEAD_RECORDS: u32 = 128; /// Policy bound on logical queues reported in QUEUE_LIMITS (not a firmware limit). diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 285b14fce52d7..bce0353298654 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -845,10 +845,13 @@ impl Firmware { Some((compute, render)) } - /// Whether a render job paused by `TA_WAVE_PASSES` pacing has enough TA headroom to publish + /// Whether a render job paused by TA wave pacing has enough TA headroom to publish /// the next wave without dribbling 1-pass stub flights. fn ta_wave_ready(&self) -> bool { - self.engine.ta_wave_wait && self.ta_pending_passes() <= super::hw::sizes::TA_WAVE_REFILL + let cap = self.active_ta_wave_cap(); + self.engine.ta_wave_wait + && self.ta_pending_passes() + <= cap.saturating_sub(super::hw::sizes::TA_WAVE_REFILL_HEADROOM) } /// Cheap single-stage stamp check for the oldest compute pipe 0/1 and oldest render flights' diff --git a/drivers/gpu/drm/asahi/g16/slots.rs b/drivers/gpu/drm/asahi/g16/slots.rs index 697598889f1f7..1d48b4cd996d4 100644 --- a/drivers/gpu/drm/asahi/g16/slots.rs +++ b/drivers/gpu/drm/asahi/g16/slots.rs @@ -1138,12 +1138,15 @@ impl Slots { pub(crate) fn note_render_retired(&mut self) { self.render.scrub_pending = true; } - /// Stages any newly displaced, cleanly retired render pass slots for off-lock pre-scrubbing. - /// Never touches `Published` or undisplaced `Retired` slots. + /// Stages any newly displaced, cleanly retired render pass slots for off-lock pre-scrubbing, + /// scanning cursor-ordered from `pass_cursor` so the slots `pick_pass_in_for` will reach next + /// are scrubbed first. Never touches `Published` or undisplaced `Retired` slots. pub(crate) fn stage_displaced_pass_scrubs(&mut self) { self.render.scrub_pending = false; self.fold_scrub_stats(); - for k in 0..sizes::RENDER_SLOTS { + let start = self.pass_cursor as usize % sizes::RENDER_SLOTS; + for i in 0..sizes::RENDER_SLOTS { + let k = (start + i) % sizes::RENDER_SLOTS; let bit = 1u64 << k; if self.pass_busy & bit != 0 || !self.render.lifetime.available(k) diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py index 27093fdfdf1e7..0a779b3fb7d3d 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py @@ -124,7 +124,7 @@ mod file { pub const MAX_COMMANDS_PER_SUBMISSION: u32 = 64; } mod hw { pub const USER_RANGE: core::ops::Range = 0x4000..((1u64 << 42) - 0x8000); - pub mod sizes { pub const MAX_ATTACHMENTS: usize = 16; } + pub mod sizes { pub const MAX_ATTACHMENTS: usize = 16; pub const TA_LIGHT_TILEMAP_BYTES: u64 = 64 * 1024; } pub mod client { pub const PB_HEAP_SIZE:u64=0x10000000; CAPACITIES } } mod fw { diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py index 9b7c2ff187656..df5d84c420362 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py @@ -66,7 +66,8 @@ def item(declaration, text=source): mod hw { pub mod sizes { pub const TA_WAVE_PASSES: usize = 4; - pub const TA_WAVE_REFILL: usize = TA_WAVE_PASSES / 2; + pub const TA_WAVE_PASSES_LIGHT: usize = 8; + pub const TA_WAVE_REFILL_HEADROOM: usize = 2; pub const COMPUTE_PIPES: usize = 2; pub const COALESCE_WINDOW_US: u32 = 18; } @@ -324,6 +325,7 @@ def item(declaration, text=source): drain_fs_delta: u32, drain_compute_delta: u32, ta_pending: usize, + ta_wave_cap: usize, coalesce_us: Option, retire_calls: u32, publish_full_calls: u32, @@ -379,6 +381,7 @@ def item(declaration, text=source): drain_fs_delta: 0, drain_compute_delta: 0, ta_pending: 0, + ta_wave_cap: hw::sizes::TA_WAVE_PASSES, coalesce_us: None, retire_calls: 0, publish_full_calls: 0, @@ -451,6 +454,9 @@ def item(declaration, text=source): fn ta_pending_passes(&self) -> usize { self.ta_pending } + fn active_ta_wave_cap(&self) -> usize { + self.ta_wave_cap + } __RECLAIM_CLOSED_VM_SLOTS__ __POLL_STEP__ @@ -1018,8 +1024,7 @@ def item(declaration, text=source): assert!(!retry_tail); assert!(fw.engine.short_repoll); - // TA drains to 2 (<= TA_WAVE_REFILL): immediately wakes publish_checked() to launch the - // next wave cleanly. + // TA drains to 2 (<= cap - TA_WAVE_REFILL_HEADROOM): immediately wakes publish_checked(). fw.ta_pending = 2; assert!(fw .poll_step(true, 0, &mut retry_tail, &mut deferred, &mut done) @@ -1027,6 +1032,19 @@ def item(declaration, text=source): assert_eq!(fw.publish_checked_calls, 1); assert!(fw.engine.short_repoll); + // Light TA wave cap (8): stays paused at 7 (> 8 - 2), wakes at 6 (<= 6). + fw.ta_wave_cap = hw::sizes::TA_WAVE_PASSES_LIGHT; + fw.ta_pending = 7; + assert!(fw + .poll_step(true, 0, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert_eq!(fw.publish_checked_calls, 1); + fw.ta_pending = 6; + assert!(fw + .poll_step(true, 0, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert_eq!(fw.publish_checked_calls, 2); + // Once ta_wave_wait clears, a TA-only 0x70 IRQ stays non_terminal_only (no spin/short_repoll). fw.engine.ta_wave_wait = false; retry_tail = false; diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index cf9c0cad5c322..9552965a75209 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -45,7 +45,7 @@ def item(declaration): assert 'const HORIZON_JOBS: u32 = COMPUTE_UNITS as u32;' in hw_src prefix_render_fn = item('fn prefix_render(') prefix_compute_fn = item('fn prefix_compute(') -can_queue_behind_fn = item('fn can_queue_behind(') +can_queue_behind_fn = item('fn can_queue_behind_with_ta(') assert 'let render_bar = cross_engine_barrier_type(producer_initbm, init_buffer);' in prefix_render_fn assert ( prefix_render_fn.index('let render_bar = cross_engine_barrier_type(producer_initbm, init_buffer);') @@ -97,7 +97,11 @@ def item(declaration): #[derive(Copy,Clone,Debug,PartialEq,Eq)]enum Channel { Ta = 0, Fs = 1, Compute = 2 } #[derive(Copy,Clone)]struct ComputeCommand { query_access: bool, rt: bool } impl ComputeCommand { fn is_rt(&self) -> bool { self.rt } } -#[derive(Copy,Clone)]enum Command { Compute(ComputeCommand), Render(()) } +#[derive(Copy,Clone)]struct RenderCommand { heavy_ta: bool } +impl RenderCommand { fn is_heavy_ta(&self) -> bool { self.heavy_ta } } +const R_LIGHT: RenderCommand = RenderCommand { heavy_ta: false }; +const R_HEAVY: RenderCommand = RenderCommand { heavy_ta: true }; +#[derive(Copy,Clone)]enum Command { Compute(ComputeCommand), Render(RenderCommand) } struct Status(AtomicU32);impl Status{fn get(&self)->u32{self.0.load(Ordering::Relaxed)}} struct Vm { status:Status, slot:u32 } struct Queue { turn:AtomicU64, priority:u32, completed:[AtomicU64;2], compute_ooo:AtomicU64 } @@ -130,8 +134,8 @@ def item(declaration): fn complete(done:&mut Completions,job:&Arc,result:Result){done.push((job.id,result));} #[derive(Default)]struct Stats{hold:[u64;3],grouped:u64} struct Claims; -struct Flight{job:Arc,claims:Claims,group:Vec>,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,doomed:bool,recovery_suspect:bool,initbm:bool} -impl Flight{fn new(job:Arc)->Self{Self{job,claims:Claims,group:vec![],computes:0,renders:0,compute_pipe:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false}}} +struct Flight{job:Arc,claims:Claims,group:Vec>,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,doomed:bool,recovery_suspect:bool,initbm:bool,heavy_render:bool} +impl Flight{fn new(job:Arc)->Self{Self{job,claims:Claims,group:vec![],computes:0,renders:0,compute_pipe:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false,heavy_render:false}}} __SCS_COMPUTE_CONFLICT__ struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,ta_wave_wait:bool,coalesce_deadline_ns:u64} impl Engine { @@ -179,7 +183,7 @@ def item(declaration): // containment branch below decides whether the unit becomes claimable again. pub fn preserve_compute_descriptor(refs:&ComputeRefs,_old:&[u8;160],_before:u64,_work:&mut[u8;8192])->Result<(),()>{if refs.invalid{Err(())}else{Ok(())}} } -mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_REFILL:usize=TA_WAVE_PASSES/2; pub const COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; } } +mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_PASSES_LIGHT:usize=8; pub const TA_LIGHT_TILEMAP_BYTES:u64=64*1024; pub const TA_WAVE_REFILL_HEADROOM:usize=2; pub const COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; } } mod command {pub const RENDER:usize=0;pub const COMPUTE:usize=1;} thread_local!{static CLOCK:std::cell::Cell=const{std::cell::Cell::new(0)};} fn now_ns()->u64{CLOCK.with(|clock|clock.get())} @@ -219,25 +223,34 @@ def item(declaration): session:Session,objects:Checks,recovery:Recovery,engine:Engine,slots:Slots,pools:Pools,power:Power, unavailable:Vec<(usize,Error)>,stages:VecDeque,retained:Vec,attempted:Vec,fail_stops:u32, allow_behind:bool,block_render_behind:bool,block_compute_behind:bool, + ta_pending_calls:std::cell::Cell, } impl Firmware { fn mark_class_unavailable(&mut self,class:usize,error:Error){self.unavailable.push((class,error));} fn sync_quarantine_hints(&self){} __NEEDS_ENGINE_DRAIN__ + __TA_WAVE_CAP_FOR__ + __ACTIVE_TA_WAVE_CAP__ fn blocked_on_slot_headroom(&self,job:&Arc)->bool{ if self.engine.flights.is_empty()||self.needs_engine_drain(job){return false;} if job.check_command_dependencies(job.progress.sent()).is_err(){return false;} - (self.block_render_behind&&matches!(command(job,job.progress.sent()),Some(Command::Render(())))) + (self.block_render_behind&&matches!(command(job,job.progress.sent()),Some(Command::Render(_)))) ||(self.block_compute_behind&&matches!(command(job,job.progress.sent()),Some(Command::Compute(_)))) } fn ta_pending_passes(&self)->usize{ + self.ta_pending_calls.set(self.ta_pending_calls.get()+1); self.engine.flights.iter().map(|f|f.renders as usize).sum() } fn can_queue_behind(&self,job:&Arc)->bool{ + let mut ta_pending=None; + self.can_queue_behind_with_ta(job,&mut ta_pending) + } + fn can_queue_behind_with_ta(&self,job:&Arc,ta_pending:&mut Option)->bool{ if !self.allow_behind{return false;} if self.needs_engine_drain(job){return false;} - if matches!(command(job,job.progress.sent()),Some(Command::Render(()))){ - if self.block_render_behind||self.ta_pending_passes()>=hw::sizes::TA_WAVE_PASSES{return false;} + if let Some(Command::Render(r))=command(job,job.progress.sent()){ + let cap=self.ta_wave_cap_for(r.is_heavy_ta()); + if self.block_render_behind||*ta_pending.get_or_insert_with(||self.ta_pending_passes())>=cap{return false;} } if self.block_compute_behind&&matches!(command(job,job.progress.sent()),Some(Command::Compute(_))){return false;} true @@ -264,9 +277,10 @@ def item(declaration): let idx=job.progress.sent.fetch_add(1,Ordering::Relaxed); let mut fl=Flight::new(job.clone()); match command(job,idx){ - Some(Command::Render(()))=>{ + Some(Command::Render(r))=>{ *pending_rings|=(1<<(Channel::Fs as u8))|(1<<(Channel::Ta as u8)); fl.renders=1; + fl.heavy_render=r.is_heavy_ta(); fl.initbm=!self.pools.can_pipeline(&job.vm); } _=>{*pending_rings|=1<<(Channel::Compute as u8);fl.computes=1;} @@ -281,11 +295,14 @@ def item(declaration): __PUBLISH_CHECKED__ } fn mk_vm(slot:u32)->Arc{Arc::new(Vm{status:Status(AtomicU32::new(0)),slot})} -fn job_on_vm(id:u32,vm:Arc,render:bool,sent:u32,dependency:Result)->Arc{ +fn job_on_vm_mode(id:u32,vm:Arc,render:bool,heavy:bool,sent:u32,dependency:Result)->Arc{ Arc::new(Job{id,vm, queue:Queue::new(0,0), progress:Progress{sent:AtomicU32::new(sent),count:sent+1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:true,rt:false})};sent as usize+1],dependency,terminal_marked:AtomicBool::new(false),resources:Resources}) + commands:vec![if render{Command::Render(RenderCommand{heavy_ta:heavy})}else{Command::Compute(ComputeCommand{query_access:true,rt:false})};sent as usize+1],dependency,terminal_marked:AtomicBool::new(false),resources:Resources}) +} +fn job_on_vm(id:u32,vm:Arc,render:bool,sent:u32,dependency:Result)->Arc{ + job_on_vm_mode(id,vm,render,false,sent,dependency) } fn job(id:u32,render:bool,sent:u32,dependency:Result)->Arc{ job_on_vm(id,mk_vm(id),render,sent,dependency) @@ -295,7 +312,8 @@ def item(declaration): engine:Engine{ordinal:0,draw:0,pending:jobs,flights:vec![],frozen:false,turn:0,stats:Stats::default(),chan_wait:false,slot_wait:false,ta_wave_wait:false,coalesce_deadline_ns:0}, slots:Slots{compute_exhausted:false,render_exhausted:false,releases:0,quarantines:0},pools:Pools{exhausted:false,exhausted_vm:None,block_pipeline_vm:None},power:Power::default(), unavailable:vec![],stages:stages.into_iter().map(|(result,visible)|Stage{result,visible}).collect(), - retained:vec![],attempted:vec![],fail_stops:0,allow_behind:false,block_render_behind:false,block_compute_behind:false} + retained:vec![],attempted:vec![],fail_stops:0,allow_behind:false,block_render_behind:false,block_compute_behind:false, + ta_pending_calls:std::cell::Cell::new(0)} } #[cfg(test)]mod tests{ use super::*; @@ -439,7 +457,7 @@ def item(declaration): id,vm:vm1.clone(), queue:Queue::new(0,priority), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], dependency:Ok(()),terminal_marked:AtomicBool::new(false),resources:Resources, }); // Head render (prio 2) is blocked behind active render flight; alt-class fallback @@ -558,7 +576,7 @@ def item(declaration): let mk_q=|id:u32,q:Arc,render:bool|Arc::new(Job{ id,vm:vm1.clone(),queue:q, progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], dependency:Ok(()),terminal_marked:AtomicBool::new(false),resources:Resources, }); // q1 has blocked render job 1 followed by compute job 2 on the SAME queue q1; @@ -621,21 +639,57 @@ def item(declaration): assert_eq!(f.session.rings,[Channel::Compute,Channel::Fs,Channel::Ta]); } #[test]fn ta_wave_pacing_flushes_doorbell_at_four_passes_and_arms_ta_wave_wait(){ + // Heavy renders fill TA_WAVE_PASSES (4) and ring FS+TA immediately; pass 5 pauses. let vm1=mk_vm(1); - let mut jobs:Vec>=(1..=5).map(|id|job_on_vm(id,vm1.clone(),true,0,Ok(()))).collect(); - jobs.push(job_on_vm(6,vm1,false,0,Ok(()))); + let mut jobs:Vec>=(1..=5).map(|id|job_on_vm_mode(id,vm1.clone(),true,true,0,Ok(()))).collect(); + jobs.push(job_on_vm(6,vm1.clone(),false,0,Ok(()))); let stages=vec![(Ok(()),true);5]; let mut f=firmware(jobs,stages); f.allow_behind=true; let mut done=vec![]; assert_eq!(f.publish_checked(&mut done),Ok(())); - // Passes 1..4 fill TA_WAVE_PASSES (4) and ring FS+TA immediately; pass 5 pauses with - // ta_wave_wait=true while alt compute job 6 still publishes on Compute. assert_eq!(f.attempted,[1,2,3,4,6]); assert_eq!(f.session.rings,[Channel::Fs,Channel::Ta,Channel::Compute]); assert!(f.engine.ta_wave_wait); assert!(!f.engine.slot_wait); assert_eq!(f.engine.pending.len(),1); + + // Light renders fill TA_WAVE_PASSES_LIGHT (8) and ring FS+TA immediately; pass 9 pauses. + let mut light_jobs:Vec>=(1..=9).map(|id|job_on_vm_mode(id,vm1.clone(),true,false,0,Ok(()))).collect(); + light_jobs.push(job_on_vm(10,vm1,false,0,Ok(()))); + let mut fl=firmware(light_jobs,vec![(Ok(()),true);9]); + fl.allow_behind=true; + assert_eq!(fl.publish_checked(&mut done),Ok(())); + assert_eq!(fl.attempted,[1,2,3,4,5,6,7,8,10]); + assert_eq!(fl.session.rings,[Channel::Fs,Channel::Ta,Channel::Compute]); + assert!(fl.engine.ta_wave_wait); + assert!(!fl.engine.slot_wait); + assert_eq!(fl.engine.pending.len(),1); + } + #[test]fn publish_checked_d64_blocked_single_queue_hoists_ta_pending_and_skips_same_queue_in_o1(){ + let vm1=mk_vm(1); + let q1=Queue::new(0,0); + let mk=|id:u32|Arc::new(Job{ + id,vm:vm1.clone(),queue:q1.clone(), + progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, + commands:vec![Command::Render(R_LIGHT)], + dependency:Ok(()),terminal_marked:AtomicBool::new(false),resources:Resources, + }); + let pending:Vec>=(9..=68).map(mk).collect(); + let mut f=firmware(pending,vec![]); + for id in 1..=8 { + let mut fl=Flight::new(mk(id)); + fl.renders=1; + f.engine.flights.push(fl); + } + f.allow_behind=true; + let mut done=vec![]; + assert_eq!(f.publish_checked(&mut done),Ok(())); + assert!(f.attempted.is_empty()); + assert!(f.engine.ta_wave_wait); + assert_eq!(f.engine.pending.len(),60); + // Hoisted ta_pending + O(1) same-queue skip reads TA stamp at most once across 60 jobs. + assert_eq!(f.ta_pending_calls.get(),1); } #[test]fn same_queue_independent_compute_bypasses_ta_wave_paused_render_only(){ let vm1=mk_vm(1); @@ -643,14 +697,15 @@ def item(declaration): let mk=|id:u32,render:bool,query_access:bool,dep:Result|Arc::new(Job{ id,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access,rt:false})}], + commands:vec![if render{Command::Render(R_HEAVY)}else{Command::Compute(ComputeCommand{query_access,rt:false})}], dependency:dep,terminal_marked:AtomicBool::new(false),resources:Resources, }); - // Seed 4 active TA passes so TA wave pacing is active. + // Seed 4 active heavy TA passes so TA wave pacing is active. let mut active_flights=Vec::new(); for id in 1..=4 { let mut fl=Flight::new(mk(id,true,false,Ok(()))); fl.renders=1; + fl.heavy_render=true; active_flights.push(fl); } // On q1: render 9 is TA-wave paused; independent !query_access compute 10 bypasses it. @@ -732,7 +787,7 @@ def item(declaration): struct QueueBehindRenderGraph{fw_stamp:[QueueBehindStamp;2]} struct QueueBehindGraph{render:QueueBehindRenderGraph} impl QueueBehindGraph{fn new()->Self{Self{render:QueueBehindRenderGraph{fw_stamp:[QueueBehindStamp::new(0),QueueBehindStamp::new(0)]}}}} -struct QueueBehindFlight{job:Arc,group:Vec>,first:usize,count:usize,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,target:u32,cstamp:[u32;16],r_ta_stamp:[u32;16],r_fs_stamp:[u32;16],fs_target:u32,initbm:bool,has_timestamps:bool,doomed:bool,recovery_suspect:bool} +struct QueueBehindFlight{job:Arc,group:Vec>,first:usize,count:usize,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,heavy_render:bool,target:u32,cstamp:[u32;16],r_ta_stamp:[u32;16],r_fs_stamp:[u32;16],fs_target:u32,initbm:bool,has_timestamps:bool,doomed:bool,recovery_suspect:bool} struct QueueBehindEngine{ordinal:u64,draw:u64,ta_target:u32,next_compute_pipe:u8,flights:Vec} struct QueueBehindSlots{compute_exhausted:bool,render_exhausted:bool,compute_available:bool,pass_available:bool} impl QueueBehindSlots{ @@ -795,7 +850,9 @@ def item(declaration): __NEEDS_ENGINE_DRAIN__ __BLOCKED_ON_SLOT_HEADROOM__ __TA_PENDING_PASSES__ + __TA_WAVE_CAP_FOR__ __CAN_QUEUE_BEHIND__ + __CAN_QUEUE_BEHIND_WITH_TA__ __WAIT_STAMP_FOR_WITH__ __WAIT_STAMP_FOR__ __CROSS_ENGINE_WAIT__ @@ -808,7 +865,7 @@ def item(declaration): let q1=Queue::new(0,0); let mk=|id:u32,vm:Arc,queue:Arc,render:bool|Arc::new(QueueBehindJob{ id,vm,queue,progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:true,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:true,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -818,7 +875,7 @@ def item(declaration): let j_render=mk(4,vm1.clone(),q1.clone(),true); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -860,7 +917,7 @@ def item(declaration): order:Order{engine:command::COMPUTE,sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); - let flight=|job:Arc,rt_compute:bool,compute_pipe:u8|QueueBehindFlight{job,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe,rt_compute,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}; + let flight=|job:Arc,rt_compute:bool,compute_pipe:u8|QueueBehindFlight{job,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe,rt_compute,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}; let rq=mk(1,vm1.clone(),q1.clone(),true); let rq_next=mk(2,vm1.clone(),q1.clone(),true); let rq_post=mk(3,vm1.clone(),q1.clone(),false); @@ -918,7 +975,7 @@ def item(declaration): let other_queue=mk(2,q2.clone(),true,None,Some(1)); let p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -930,13 +987,13 @@ def item(declaration): let timed_render=Arc::new(QueueBehindJob{ id:1,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:1,wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); let pr=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -950,7 +1007,7 @@ def item(declaration): let q1=Queue::new(0,0); let mk=|id:u32,vm:Arc,render:bool|Arc::new(QueueBehindJob{ id,vm,queue:q1.clone(),progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:true,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:true,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -960,7 +1017,7 @@ def item(declaration): let c1=mk(4,vm1.clone(),false); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -995,7 +1052,7 @@ def item(declaration): let q2=Queue::new(0,0); let mk=|id:u32,vm:Arc,queue:Arc,render:bool|Arc::new(QueueBehindJob{ id,vm,queue,progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1004,7 +1061,7 @@ def item(declaration): let vm2_r=mk(3,vm2.clone(),q2.clone(),true); let vm2_c=mk(4,vm2.clone(),q2.clone(),false); let mk_flight=|job:Arc,c:u32,r:u32|QueueBehindFlight{ - job,group:vec![],first:0,count:1,computes:c,renders:r,compute_pipe:0,rt_compute:false, + job,group:vec![],first:0,count:1,computes:c,renders:r,compute_pipe:0,rt_compute:false,heavy_render:false, target:if c!=0{0x100}else{0},cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a}, fs_target:if r!=0{0x200}else{0},initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; @@ -1037,7 +1094,7 @@ def item(declaration): let mk=|id:u32,queue:Arc,render:bool,seq:u64,wait:[Option;2]|Arc::new(QueueBehindJob{ id,vm:vm1.clone(),queue, progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:seq,wait_through:wait}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1049,8 +1106,8 @@ def item(declaration): let p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ - QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x500;a},fs_target:0x500,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, - QueueBehindFlight{job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x700,cstamp:{let mut a=[0;16];a[0]=0x700;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x500;a},fs_target:0x500,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x700,cstamp:{let mut a=[0;16];a[0]=0x700;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, ]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, @@ -1086,7 +1143,7 @@ def item(declaration): let pm=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:3,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ - QueueBehindFlight{job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, ]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, @@ -1109,7 +1166,7 @@ def item(declaration): let mk=|id:u32,render:bool,seq:u64,wait:[Option;2]|Arc::new(QueueBehindJob{ id,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:seq,wait_through:wait}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1119,7 +1176,7 @@ def item(declaration): let host=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_initbm,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0, + job:r_initbm,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0, cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x900;a},fs_target:0x900, initbm:true,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, @@ -1158,14 +1215,14 @@ def item(declaration): let r_job=Arc::new(QueueBehindJob{ id:2,vm:vm1.clone(),queue:q_rend.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:1,wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:c_job.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, + job:c_job.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1176,7 +1233,7 @@ def item(declaration): assert_eq!(p.cross_engine_wait(&r_job,0,command::COMPUTE),Ok(None)); // Symmetrically, Queue 0 compute queues directly behind Queue 1 render on the same VM. p.engine.flights[0]=QueueBehindFlight{ - job:r_job,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, + job:r_job,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert!(p.can_queue_behind(&c_job)); @@ -1188,7 +1245,7 @@ def item(declaration): let mk=|id:u32,render:bool,seq:u64,wait:[Option;2]|Arc::new(QueueBehindJob{ id,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access:false,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:seq,wait_through:wait}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1203,7 +1260,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:3,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:c1,group:vec![c2,c3],first:0,count:1,computes:3,renders:0,compute_pipe:0,rt_compute:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, + job:c1,group:vec![c2,c3],first:0,count:1,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1222,7 +1279,7 @@ def item(declaration): let multi=Arc::new(QueueBehindJob{ id:1,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:3,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(()),Command::Render(()),Command::Render(())], + commands:vec![Command::Render(R_LIGHT),Command::Render(R_LIGHT),Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:1,wait_through:[None,None]}, extra_orders:vec![ Order{engine:command::RENDER,sequence:1,wait_through:[None,None]}, @@ -1234,7 +1291,7 @@ def item(declaration): let next_r=Arc::new(QueueBehindJob{ id:2,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:4,wait_through:[Some(3),None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1243,7 +1300,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:0,draw:3,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:multi.clone(),group:vec![],first:0,count:3,computes:0,renders:3,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:r_fs,fs_target:0x300, + job:multi.clone(),group:vec![],first:0,count:3,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:r_fs,fs_target:0x300, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1258,7 +1315,7 @@ def item(declaration): let mut cur_fs=[0u32;16]; cur_fs[0]=0x400; let cur=QueueBehindFlight{ - job:next_r.clone(),group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:cur_fs,fs_target:0x400, + job:next_r.clone(),group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:cur_fs,fs_target:0x400, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert_eq!(p.wait_stamp_for_with(&next_r,command::RENDER,Some(4),Some(&cur)),Ok(Some(WaitTarget{stamp:0x400,initbm:false}))); @@ -1266,21 +1323,21 @@ def item(declaration): let r_fold_a=Arc::new(QueueBehindJob{ id:10,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:5,wait_through:[Some(4),None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); let r_fold_b=Arc::new(QueueBehindJob{ id:11,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:6,wait_through:[Some(5),None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); let mut grp_fs=[0u32;16]; grp_fs[0]=0x400;grp_fs[1]=0x500;grp_fs[2]=0x600; let cur_grp=QueueBehindFlight{ - job:next_r.clone(),group:vec![r_fold_a.clone(),r_fold_b.clone()],first:0,count:1,computes:0,renders:3,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:grp_fs,fs_target:0x600, + job:next_r.clone(),group:vec![r_fold_a.clone(),r_fold_b.clone()],first:0,count:1,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:grp_fs,fs_target:0x600, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(4),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x400,initbm:false}))); @@ -1297,24 +1354,25 @@ def item(declaration): #[test]fn ta_pending_passes_paces_unfinished_ta_waves_without_throttling_finished_ta(){ let vm1=Arc::new(Vm{status:Status(AtomicU32::new(0)),slot:1}); let q1=Queue::new(0,2); - let mk=|id:u32|Arc::new(QueueBehindJob{ + let mk=|id:u32,heavy:bool|Arc::new(QueueBehindJob{ id,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(RenderCommand{heavy_ta:heavy})], order:Order{engine:command::RENDER,sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); - let r_live=mk(1); - let next_r=mk(2); + let r_live=mk(1,false); + let next_light=mk(2,false); + let next_heavy=mk(3,true); let mut r_ta=[0u32;16]; - for i in 0..4 { + for i in 0..8 { r_ta[i]=(i as u32 + 1)*0x100; } let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:0,draw:4,ta_target:0x400,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_live,group:vec![],first:0,count:4,computes:0,renders:3,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16], - r_ta_stamp:r_ta,r_fs_stamp:r_ta,fs_target:0x400, + engine:QueueBehindEngine{ordinal:0,draw:8,ta_target:0x800,next_compute_pipe:0,flights:vec![QueueBehindFlight{ + job:r_live,group:vec![],first:0,count:8,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16], + r_ta_stamp:r_ta,r_fs_stamp:r_ta,fs_target:0x800, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1323,21 +1381,32 @@ def item(declaration): // Below TA_WAVE_PASSES (3 < 4): zero WC fw_stamp reads. assert_eq!(p.ta_pending_passes(),3); assert_eq!(p.graph.render.fw_stamp[0].reads.get(),0); - assert!(p.can_queue_behind(&next_r)); - // 4 unfinished TA passes: paces render queue_behind until TA advances. + assert!(p.can_queue_behind(&next_light)); + assert!(p.can_queue_behind(&next_heavy)); + // 4 unfinished TA passes: heavy render pauses at 4, light render keeps pipelining up to 8. p.engine.flights[0].renders=4; assert_eq!(p.ta_pending_passes(),4); assert!(p.graph.render.fw_stamp[0].reads.get()>0); - assert!(!p.can_queue_behind(&next_r)); - // Once pass 0 finishes TA (obs=0x100) while FS is still running, ta_pending drops to 3. + assert!(!p.can_queue_behind(&next_heavy)); + assert!(p.can_queue_behind(&next_light)); + // Heavy active flight also enforces conservative cap 4 on light followers. + p.engine.flights[0].heavy_render=true; + assert!(!p.can_queue_behind(&next_light)); + p.engine.flights[0].heavy_render=false; + // 8 unfinished light TA passes pauses light renders until TA advances. + p.engine.flights[0].renders=8; + assert_eq!(p.ta_pending_passes(),8); + assert!(!p.can_queue_behind(&next_light)); + // Once pass 0 finishes TA (obs=0x100) while FS is still running, ta_pending drops to 7. p.graph.render.fw_stamp[0].val.set(0x100); - assert_eq!(p.ta_pending_passes(),3); - assert!(p.can_queue_behind(&next_r)); - // Even with 16 active FS passes, finished TA (obs=0x400) leaves single-pass pipelining unthrottled. - p.graph.render.fw_stamp[0].val.set(0x400); + assert_eq!(p.ta_pending_passes(),7); + assert!(p.can_queue_behind(&next_light)); + // Even with 16 active FS passes, finished TA (obs=0x800) leaves single-pass pipelining unthrottled. + p.graph.render.fw_stamp[0].val.set(0x800); p.engine.flights[0].renders=16; assert_eq!(p.ta_pending_passes(),0); - assert!(p.can_queue_behind(&next_r)); + assert!(p.can_queue_behind(&next_light)); + assert!(p.can_queue_behind(&next_heavy)); } #[test]fn slot_wait_arms_only_for_same_vm_slot_or_flight_headroom_blocks(){ let vm1=Arc::new(Vm{status:Status(AtomicU32::new(0)),slot:1}); @@ -1346,7 +1415,7 @@ def item(declaration): let mk=|id:u32,vm:Arc,render:bool,dep:Result,query_access:bool,wait:[Option;2]|Arc::new(QueueBehindJob{ id,vm,queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![if render{Command::Render(())}else{Command::Compute(ComputeCommand{query_access,rt:false})}], + commands:vec![if render{Command::Render(R_LIGHT)}else{Command::Compute(ComputeCommand{query_access,rt:false})}], order:Order{engine:if render{command::RENDER}else{command::COMPUTE},sequence:u64::from(id),wait_through:wait}, extra_orders:vec![],dependency:dep,resources:Resources,fw_waits:vec![], }); @@ -1358,7 +1427,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_live,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0,cstamp:[0;16], + job:r_live,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16], r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x100;a},fs_target:0x100, initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false, }]}, @@ -1707,7 +1776,7 @@ def item(declaration): // Empty engine uses next_compute_pipe (0). assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); host.engine.flights.push(QueueBehindFlight{ - job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100, + job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); @@ -1726,7 +1795,7 @@ def item(declaration): // q1 stays affine to pipe 0, q2 stays affine to pipe 1, and a third queue q3 // tie-breaks by next_compute_pipe. host.engine.flights.push(QueueBehindFlight{ - job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,target:0x100, + job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); @@ -1758,12 +1827,12 @@ def item(declaration): graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:2,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![ QueueBehindFlight{ - job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100, + job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, cstamp:{let mut a=[0;16];a[0]=0x100;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, QueueBehindFlight{ - job:c2,group:vec![],first:0,count:1,computes:2,renders:0,compute_pipe:1,rt_compute:false,target:0x200, + job:c2,group:vec![],first:0,count:1,computes:2,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,target:0x200, cstamp:{let mut a=[0;16];a[0]=0x200;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, @@ -1813,7 +1882,7 @@ def item(declaration): let r1=Arc::new(QueueBehindJob{ id:2,vm:vm1.clone(),queue:q1.clone(), progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, - commands:vec![Command::Render(())], + commands:vec![Command::Render(R_LIGHT)], order:Order{engine:command::RENDER,sequence:1,wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); @@ -1837,12 +1906,12 @@ def item(declaration): graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ QueueBehindFlight{ - job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,target:0x100, + job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, cstamp:{let mut a=[0;16];a[0]=0x100;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false, }, QueueBehindFlight{ - job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,target:0, + job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0, cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, @@ -2516,7 +2585,7 @@ def item(declaration): } } mod busy_coalesce_scope { - use super::{Arc, AtomicBool, AtomicU32, Command, ComputeCommand, Order, Progress, Queue, Recovery, Result, Status, Vm}; + use super::{Arc, AtomicBool, AtomicU32, Command, ComputeCommand, Order, Progress, Queue, Recovery, RenderCommand, Result, Status, Vm}; mod params { pub fn compute_flights() -> usize { 23 } pub fn render_flights() -> usize { 47 } @@ -2568,6 +2637,7 @@ def item(declaration): doomed: bool, recovery_suspect: bool, initbm: bool, + heavy_render: bool, } struct Engine { flights: Vec, @@ -2593,15 +2663,16 @@ def item(declaration): fn can_queue_behind(&self, _job: &Arc) -> bool { self.allow_behind } fn choose_compute_pipe(&self, _q: &Arc, _w: [Option<()>; 2], _m: u32, _rt: bool) -> usize { 0 } fn ta_pending_passes(&self) -> usize { self.ta_pending } + __TA_WAVE_CAP_FOR__ __CAN_DEFER_BUSY_COALESCE__ __DEFER_BUSY_COALESCE__ } - fn mk_job(vm: &Arc, q: &Arc, render: bool, seq: u64, wait: [Option; 2]) -> Arc { + fn mk_job_mode(vm: &Arc, q: &Arc, render: bool, heavy: bool, seq: u64, wait: [Option; 2]) -> Arc { Arc::new(Job { vm: vm.clone(), queue: q.clone(), progress: Progress { sent: AtomicU32::new(0), count: 1, pending: AtomicBool::new(true) }, - commands: vec![if render { Command::Render(()) } else { Command::Compute(ComputeCommand { query_access: false, rt: false }) }], + commands: vec![if render { Command::Render(RenderCommand { heavy_ta: heavy }) } else { Command::Compute(ComputeCommand { query_access: false, rt: false }) }], orders: vec![Order { engine: if render { crate::command::RENDER } else { crate::command::COMPUTE }, sequence: seq, wait_through: wait }], fw_waits: vec![], resources: Resources { units: 24, scs: false }, @@ -2609,6 +2680,9 @@ def item(declaration): foldable: true, }) } + fn mk_job(vm: &Arc, q: &Arc, render: bool, seq: u64, wait: [Option; 2]) -> Arc { + mk_job_mode(vm, q, render, false, seq, wait) + } #[test] fn busy_coalesce_holds_deep_single_queue_bursts_and_never_delays_shallow_or_other_queues() { let vm1 = Arc::new(Vm { status: Status(AtomicU32::new(0)), slot: 1 }); @@ -2618,7 +2692,7 @@ def item(declaration): let mut h = Host { recovery: Recovery { error: None, publication_wait_deadline: None }, engine: Engine { - flights: vec![Flight { job: c1.clone(), computes: 1, renders: 0, doomed: false, recovery_suspect: false, initbm: false }], + flights: vec![Flight { job: c1.clone(), computes: 1, renders: 0, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }], pending: vec![mk_job(&vm1, &q1, false, 2, [None, None])], frozen: false, chan_wait: false, @@ -2663,14 +2737,25 @@ def item(declaration): h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, Some(2)])]; assert_eq!(h.defer_busy_coalesce(400_000), None); - // Render with queue_active == 2 and ta_pending == 2 (ta_room == 2) holds 1 pass and flushes at 2. + // Light render with queue_active == 2 and ta_pending == 2 (wave_cap 8 -> ta_room 6) + // coalesces up to K=6 passes before flushing. let r1 = mk_job(&vm1, &q1, true, 1, [None, None]); - h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, doomed: false, recovery_suspect: false, initbm: false }]; + h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }]; h.ta_pending = 2; h.engine.pending = vec![mk_job(&vm1, &q1, true, 3, [Some(2), None])]; assert_eq!(h.defer_busy_coalesce(500_000), Some(18)); - h.engine.pending.push(mk_job(&vm1, &q1, true, 4, [Some(3), None])); + for seq in 4..=7 { + h.engine.pending.push(mk_job(&vm1, &q1, true, seq, [Some(seq - 1), None])); + assert_eq!(h.defer_busy_coalesce(502_000), Some(16)); + } + h.engine.pending.push(mk_job(&vm1, &q1, true, 8, [Some(7), None])); assert_eq!(h.defer_busy_coalesce(505_000), None); + + // Heavy render keeps conservative wave_cap 4 (ta_room == 2): holds 1 pass, flushes at 2. + h.engine.pending = vec![mk_job_mode(&vm1, &q1, true, true, 3, [Some(2), None])]; + assert_eq!(h.defer_busy_coalesce(600_000), Some(18)); + h.engine.pending.push(mk_job_mode(&vm1, &q1, true, true, 4, [Some(3), None])); + assert_eq!(h.defer_busy_coalesce(605_000), None); } } ''' @@ -2731,7 +2816,10 @@ def item(declaration): '__DESCRIPTOR_CONTAINMENT__': 'if encode::preserve_compute_descriptor(', '__PUBLISH_PRODUCER__': 'fn publish_producer(', '__TA_PENDING_PASSES__': 'pub(crate) fn ta_pending_passes(', + '__TA_WAVE_CAP_FOR__': 'fn ta_wave_cap_for(', + '__ACTIVE_TA_WAVE_CAP__': 'pub(crate) fn active_ta_wave_cap(', '__CAN_QUEUE_BEHIND__': 'fn can_queue_behind(', + '__CAN_QUEUE_BEHIND_WITH_TA__': 'fn can_queue_behind_with_ta(', '__CAN_DEFER_BUSY_COALESCE__': 'fn can_defer_busy_coalesce(', '__DEFER_BUSY_COALESCE__': 'pub(crate) fn defer_busy_coalesce(', '__WAIT_STAMP_FOR_WITH__': 'fn wait_stamp_for_with(', diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py index dd7931881e3f4..5aa9f7afbabfd 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py @@ -1299,6 +1299,47 @@ def module(text, name): assert_eq!(render.passes[0].pre[0].fills.lock().unwrap().len(),pre0_before); } + #[test]fn stage_displaced_pass_scrubs_prioritizes_pass_cursor_order(){ + let mut o=Objects::new();let mut s=Slots::new().unwrap(); + let mut passes=KVec::new(); + for k in 0..20 { + passes.push(g16::slots::PassSlot::new(&mut o, k as u64, 1, &crate::g16::object::test_cmds((k as u64) as u64)).unwrap(), 0).unwrap(); + } + let render=sync::Arc::new(render_arena(passes), 0).unwrap(); + let prep=g16::resources::Prepared{compute:KVec::new(),render:Some(render.clone()),hw_slots:None}; + let a=vm(1); + // Publish and retire slots 0..20 in order so slots 0..19 are displaced dirty and + // slot 19 is the undisplaced newest retired slot. + for k in 0..20 { + let mut c=Claims::new();c.pass[0]=k as u32;c.pass_count=1;c.pass_mask=1u64< Date: Mon, 23 Nov 2026 15:02:55 -0500 Subject: [PATCH 3/7] drm/asahi: g16: make compute pipe affinity and busy coalesce adaptive Unconditional single-queue 1-pipe compute affinity helped light compute streams fold onto one CDM workqueue, but serialized heavy compute streams (bandwidth/fill/overlap passes >= 200 us per command) onto a single CDM pipe and left multi-queue overlap workloads susceptible to the 18 us busy-coalesce window when another queue already had an active flight. Track a lock-free per-queue EWMA of retired hardware CDM GPU execution duration in microseconds (from the existing single- and multi-command timestamp reads in stat_retire, without extra WC reads) and add a cold-start probe for a sole single-command compute flight exceeding 180 us before its first retirement: - Light single-queue compute (< 200 us) keeps 1-pipe affinity, unbounded same-pipe horizon folding, and busy coalescing. - Heavy compute (>= 200 us EWMA or sole inflight >= 180 us) bypasses busy coalescing, fans out across both CDM pipes, and caps barrier-free folding to keep both pipes balanced. - Busy coalescing also bypasses immediately whenever any active flight belongs to a different queue so multi-queue render and async compute/render overlap see zero micro-coalesce delay. Extend the publication host selftests to cover adaptive heavy detection, EWMA transitions, pipe balancing, and cross-queue/heavy busy-coalesce bypasses. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/engine.rs | 90 ++++++++--- drivers/gpu/drm/asahi/g16/hw.rs | 6 + drivers/gpu/drm/asahi/g16/poll.rs | 17 +++ drivers/gpu/drm/asahi/g16/queue.rs | 18 +++ .../drivers/gpu/asahi-m4/test-publication.py | 141 +++++++++++------- 5 files changed, 200 insertions(+), 72 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index ad418b5b78c1e..30960124b5cfb 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -1619,7 +1619,7 @@ impl Firmware { /// Whether `self.engine.pending` is an eligible single-queue, single-VM busy horizon /// batch that can accumulate more same-queue commands before publishing. - fn can_defer_busy_coalesce(&self) -> bool { + fn can_defer_busy_coalesce(&self, now: u64) -> bool { if self.recovery.failed().is_some() || self.engine.frozen || self.engine.flights.is_empty() @@ -1641,6 +1641,11 @@ impl Firmware { if head.vm.status.get() != 0 || head.long() || !self.can_queue_behind(head) + || self + .engine + .flights + .iter() + .any(|fl| !Arc::ptr_eq(&fl.job.queue, &head.queue)) || self .engine .pending @@ -1658,6 +1663,7 @@ impl Firmware { || c.is_rt() || head_order.wait_through != [None, None] || !head.fw_waits.is_empty() + || self.compute_queue_is_heavy(&head.queue, now) { return false; } @@ -1714,7 +1720,8 @@ impl Firmware { let Ok(slot_mask) = head.resources.compute_slot_mask() else { return false; }; - let pipe = self.choose_compute_pipe(&head.queue, [None, None], slot_mask, false); + let pipe = + self.choose_compute_pipe(&head.queue, [None, None], slot_mask, false, false); let free_c = self.slots.free_compute_in_mask_for_pipe(slot_mask, pipe) as usize; let cap = super::hw::sizes::COALESCE_MAX_CMDS .min(free_c) @@ -1797,7 +1804,7 @@ impl Firmware { /// producer updates, and doorbells without delaying `d=1`/`d=2`, barriered streams, RT/SCS /// work, or multi-queue/cross-VM handoffs. pub(crate) fn defer_busy_coalesce(&mut self, now: u64) -> Option { - if !self.can_defer_busy_coalesce() { + if !self.can_defer_busy_coalesce(now) { self.engine.coalesce_deadline_ns = 0; return None; } @@ -2081,23 +2088,54 @@ impl Firmware { Ok(waits) } + /// Whether `queue`'s recent or active compute work is heavy enough to benefit from 2-pipe + /// CDM fanout rather than 1-pipe affinity and horizon folding: + /// - per-queue retired CDM GPU duration EWMA `>= COMPUTE_HEAVY_EMA_US`, or + /// - a sole active single-command compute flight of `queue` on its pipe has already been + /// executing for `>= COMPUTE_HEAVY_INFLIGHT_NS` without completing (instant detection + /// before retirement updates the EWMA, while queued multi-flight light bursts never false- + /// trigger from queueing age). + fn compute_queue_is_heavy(&self, queue: &Arc, now: u64) -> bool { + if queue.compute_ewma_us.load(Ordering::Relaxed) >= super::hw::sizes::COMPUTE_HEAVY_EMA_US { + return true; + } + let mut pipe_flights = [0usize; super::hw::sizes::COMPUTE_PIPES]; + for fl in &self.engine.flights { + if fl.computes != 0 { + let p = (fl.compute_pipe as usize).min(super::hw::sizes::COMPUTE_PIPES - 1); + pipe_flights[p] += 1; + } + } + self.engine.flights.iter().any(|fl| { + let p = (fl.compute_pipe as usize).min(super::hw::sizes::COMPUTE_PIPES - 1); + fl.computes == 1 + && pipe_flights[p] == 1 + && Arc::ptr_eq(&fl.job.queue, queue) + && fl.published_ns != 0 + && now.saturating_sub(fl.published_ns) + >= super::hw::sizes::COMPUTE_HEAVY_INFLIGHT_NS + }) + } + /// Chooses which compute pipe (`0..COMPUTE_PIPES`) executes the next compute command: /// - Base-only/SCS VMs (bits strictly in `0..PIPE1_COMPUTE_START`) or states where pipe 1 /// has no available unit in `slot_mask` stay on pipe 0 so `0..PIPE1_COMPUTE_START` never /// split across two pipes. /// - If the command waits only on one pipe, reuse that pipe (in-order ring, zero `c2c` /// barrier). - /// - If barrier-free (`[None, None]`) and `queue` already has an active compute flight on a - /// single pipe with free units, keep that queue pipe-affine so consecutive horizon submits - /// fold onto one workqueue without splitting across pipes. - /// - Otherwise (other queues, cross-VM compute, or waiting on both pipes `[Some, Some]`), - /// pick the pipe with fewer active compute commands, breaking ties by `next_compute_pipe`. + /// - If barrier-free (`[None, None]`), `!heavy_compute`, and `queue` already has an active + /// compute flight on a single pipe with free units, keep that light queue pipe-affine so + /// consecutive horizon submits fold onto one workqueue without splitting across pipes. + /// - Otherwise (heavy compute streams, other queues, cross-VM compute, or waiting on both + /// pipes `[Some, Some]`), pick the pipe with fewer active compute commands, breaking ties + /// by `next_compute_pipe`. fn choose_compute_pipe( &self, queue: &Arc, waits: [Option; sizes::COMPUTE_PIPES], slot_mask: u32, rt_compute: bool, + heavy_compute: bool, ) -> usize { if rt_compute || self @@ -2112,7 +2150,7 @@ impl Firmware { match waits { [Some(_), None] => return 0, [None, Some(_)] => return 1, - [None, None] => { + [None, None] if !heavy_compute => { let mut q_pipe: Option = None; for fl in &self.engine.flights { if fl.computes != 0 && Arc::ptr_eq(&fl.job.queue, queue) { @@ -2133,7 +2171,7 @@ impl Firmware { } } } - [Some(_), Some(_)] => {} + [None, None] | [Some(_), Some(_)] => {} } if !self.slots.compute_available_in_mask_for_pipe(slot_mask, 0) { return 1; @@ -2366,8 +2404,8 @@ impl Firmware { } else { &[Channel::Compute] }; - let (compute_pipe, c_waits) = if render { - (0usize, [None; sizes::COMPUTE_PIPES]) + let (compute_pipe, c_waits, heavy_compute) = if render { + (0usize, [None; sizes::COMPUTE_PIPES], false) } else { let slot_mask = job.resources.compute_slot_mask()?; let rt_compute = job.resources.compute_scs() @@ -2377,9 +2415,11 @@ impl Firmware { job.command_order(index) .and_then(|o| o.wait_through[super::command::COMPUTE]), )?; + let heavy = self.compute_queue_is_heavy(&job.queue, now_ns()); ( - self.choose_compute_pipe(&job.queue, waits, slot_mask, rt_compute), + self.choose_compute_pipe(&job.queue, waits, slot_mask, rt_compute, heavy), waits, + heavy, ) }; let pipe_behind = !render @@ -2490,18 +2530,28 @@ impl Firmware { .slots .free_compute_in_mask_for_pipe(slot_mask, compute_pipe) as usize; - let active_computes: usize = self - .engine - .flights - .iter() - .map(|fl| fl.computes as usize) - .sum(); + let mut active_pipe = [0usize; sizes::COMPUTE_PIPES]; + for fl in &self.engine.flights { + if fl.computes != 0 { + let p = (fl.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); + active_pipe[p] += fl.computes as usize; + } + } + let active_computes = active_pipe[0] + active_pipe[1]; + // Keep heavy barrier-free compute balanced across both CDM pipes while light + // single-queue compute streams stay pipe-affine and fold freely into one batch. + let pipe_fold_cap = if heavy_compute && c_waits == [None; sizes::COMPUTE_PIPES] { + active_pipe[1 - compute_pipe].saturating_sub(active_pipe[compute_pipe] + 1) + } else { + usize::MAX + }; let used = prefix.c_head.wrapping_sub(c_read) % sizes::QUEUE_CAP; let ring_more = (sizes::QUEUE_CAP.saturating_sub(4)).saturating_sub(used) as usize; let mut more_slots = free_c .min(params::compute_flights().saturating_sub(active_computes + 1)) .min(sizes::COMPUTE_SLOTS.saturating_sub(1)) - .min(ring_more); + .min(ring_more) + .min(pipe_fold_cap); let rt_head = job.resources.compute_scs() || c.is_rt(); // Fold trailing barrier-free compute commands of the base job first. while !rt_head && more_slots > 0 && end < job.progress.count() { diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index e7c8e8f6e6b9d..3d9cf3793dc03 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -908,6 +908,12 @@ pub(crate) mod sizes { pub(crate) const COALESCE_MAX_CMDS: usize = 6; pub(crate) const COALESCE_WINDOW_US: u32 = 18; pub(crate) const COALESCE_WINDOW_NS: u64 = (COALESCE_WINDOW_US as u64) * 1000; + /// Per-queue retired CDM execution EWMA threshold (microseconds) at or above which + /// barrier-free compute fans out across both CDM pipes instead of staying 1-pipe affine. + pub(crate) const COMPUTE_HEAVY_EMA_US: u32 = 200; + /// Elapsed wall-clock time (nanoseconds) on a sole active single-command compute flight + /// that immediately classifies the queue as heavy before its first retirement updates EWMA. + pub(crate) const COMPUTE_HEAVY_INFLIGHT_NS: u64 = 180_000; /// Jobs admitted to the engine per logical queue: enough to keep deep queues (`d=64`) /// queued back to back without scheduler backpressure stalls; exact prior-command /// dependencies still gate each one. diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index bce0353298654..e11cfd22168f2 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -1868,6 +1868,8 @@ impl Firmware { }; let (mut lo, mut hi) = (u64::MAX, 0u64); let (mut first, mut last) = (u64::MAX, 0u64); + let mut cdm_flight_ticks = 0u64; + let mut cdm_counted = 0u32; let work_ticks = self.init.abi.compute().work_ticks; let s = &mut self.engine.stats; @@ -1904,6 +1906,10 @@ impl Firmware { &mut s.cdm_ticks, crate::usage::Engine::Compute, ); + if ticks[1] >= ticks[0] { + cdm_flight_ticks = ticks[1] - ticks[0]; + cdm_counted = 1; + } } else { // Multi-command prefix fallback: read each member's internal timestamp cells. let mut stage = |o: &super::object::FwObject, @@ -1942,9 +1948,20 @@ impl Firmware { }; if let Ok((start, end)) = Self::compute_ticks_with(work_ticks, c) { add_interval(start, end, &mut s.cdm_ticks, crate::usage::Engine::Compute); + if start != 0 && end >= start { + cdm_flight_ticks = cdm_flight_ticks.saturating_add(end - start); + cdm_counted += 1; + } } } } + if cdm_counted != 0 { + let per_cmd_ticks = cdm_flight_ticks / u64::from(cdm_counted); + let per_cmd_us = (per_cmd_ticks.saturating_mul(1_000_000) + / super::hw::COMMAND_TIMESTAMP_HZ) + .clamp(1, 100_000) as u32; + f.job.queue.note_compute_us(per_cmd_us); + } if hi > lo { s.span_ticks = s.span_ticks.saturating_add(hi - lo); } diff --git a/drivers/gpu/drm/asahi/g16/queue.rs b/drivers/gpu/drm/asahi/g16/queue.rs index 319232fd46334..28332f8de5e74 100644 --- a/drivers/gpu/drm/asahi/g16/queue.rs +++ b/drivers/gpu/drm/asahi/g16/queue.rs @@ -76,6 +76,9 @@ pub(crate) struct QueueState { /// engine when a job arrives. pub(crate) owned: [AtomicU32; 32], pub(crate) owned_index: AtomicU32, + /// EWMA of retired per-command CDM GPU execution duration (microseconds) for adaptive + /// 1-pipe affinity vs 2-pipe heavy compute fanout. + pub(crate) compute_ewma_us: AtomicU32, } impl QueueState { @@ -124,6 +127,20 @@ impl QueueState { let shift = seq.wrapping_sub(completed).wrapping_sub(2); shift < 64 && (self.compute_ooo.load(Ordering::Acquire) & (1u64 << shift)) != 0 } + + /// Updates the lock-free EWMA of recent retired per-command CDM GPU execution duration + /// (microseconds) for this queue using a symmetric 50% step so transitions between light + /// and heavy compute streams adapt within 2-3 completions. + pub(crate) fn note_compute_us(&self, us: u32) { + let us = us.clamp(1, 100_000); + let prev = self.compute_ewma_us.load(Ordering::Relaxed); + let next = if prev == 0 { + us + } else { + prev.saturating_add(us) / 2 + }; + self.compute_ewma_us.store(next, Ordering::Relaxed); + } } /// One per-file logical-queue credit, released after the queue scheduler drains. @@ -212,6 +229,7 @@ impl Queue { published: [const { AtomicU64::new(0) }; 2], owned: [const { AtomicU32::new(0) }; 32], owned_index: AtomicU32::new(0), + compute_ewma_us: AtomicU32::new(0), }, GFP_KERNEL, )?; diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 9552965a75209..ad2fac33e3c92 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -80,7 +80,7 @@ def item(declaration): assert 'self.graph.render.threshold.w32(0, prefix.draw as u32)?;' in publish_prefix_body_fn assert 'self.graph.render.threshold.w32(8, prefix.draw as u32)?;' in publish_prefix_body_fn assert 'earliest_unfinished_ta_draw' not in source and 'rearm_ta_threshold' not in source -assert 'pipe_fold_cap' not in source, 'pipe_fold_cap must be removed so single-queue horizons fold cleanly' +assert 'let pipe_fold_cap = if heavy_compute && c_waits == [None; sizes::COMPUTE_PIPES]' in publish_prefix_body_fn, 'pipe_fold_cap must only apply to heavy barrier-free compute' harness = r''' @@ -104,11 +104,12 @@ def item(declaration): #[derive(Copy,Clone)]enum Command { Compute(ComputeCommand), Render(RenderCommand) } struct Status(AtomicU32);impl Status{fn get(&self)->u32{self.0.load(Ordering::Relaxed)}} struct Vm { status:Status, slot:u32 } -struct Queue { turn:AtomicU64, priority:u32, completed:[AtomicU64;2], compute_ooo:AtomicU64 } +struct Queue { turn:AtomicU64, priority:u32, completed:[AtomicU64;2], compute_ooo:AtomicU64, compute_ewma_us:AtomicU32 } impl Queue { fn new(turn:u64, priority:u32)->Arc{ - Arc::new(Self{turn:AtomicU64::new(turn),priority,completed:[AtomicU64::new(0),AtomicU64::new(0)],compute_ooo:AtomicU64::new(0)}) + Arc::new(Self{turn:AtomicU64::new(turn),priority,completed:[AtomicU64::new(0),AtomicU64::new(0)],compute_ooo:AtomicU64::new(0),compute_ewma_us:AtomicU32::new(0)}) } + __NOTE_COMPUTE_US__ fn is_compute_retired(&self, seq:u64)->bool{ let c=self.completed[command::COMPUTE].load(Ordering::Acquire); if seq<=c { return true; } @@ -183,7 +184,7 @@ def item(declaration): // containment branch below decides whether the unit becomes claimable again. pub fn preserve_compute_descriptor(refs:&ComputeRefs,_old:&[u8;160],_before:u64,_work:&mut[u8;8192])->Result<(),()>{if refs.invalid{Err(())}else{Ok(())}} } -mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_PASSES_LIGHT:usize=8; pub const TA_LIGHT_TILEMAP_BYTES:u64=64*1024; pub const TA_WAVE_REFILL_HEADROOM:usize=2; pub const COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; } } +mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_PASSES_LIGHT:usize=8; pub const TA_LIGHT_TILEMAP_BYTES:u64=64*1024; pub const TA_WAVE_REFILL_HEADROOM:usize=2; pub const COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; pub const COMPUTE_HEAVY_EMA_US:u32=200; pub const COMPUTE_HEAVY_INFLIGHT_NS:u64=180_000; } } mod command {pub const RENDER:usize=0;pub const COMPUTE:usize=1;} thread_local!{static CLOCK:std::cell::Cell=const{std::cell::Cell::new(0)};} fn now_ns()->u64{CLOCK.with(|clock|clock.get())} @@ -787,7 +788,7 @@ def item(declaration): struct QueueBehindRenderGraph{fw_stamp:[QueueBehindStamp;2]} struct QueueBehindGraph{render:QueueBehindRenderGraph} impl QueueBehindGraph{fn new()->Self{Self{render:QueueBehindRenderGraph{fw_stamp:[QueueBehindStamp::new(0),QueueBehindStamp::new(0)]}}}} -struct QueueBehindFlight{job:Arc,group:Vec>,first:usize,count:usize,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,heavy_render:bool,target:u32,cstamp:[u32;16],r_ta_stamp:[u32;16],r_fs_stamp:[u32;16],fs_target:u32,initbm:bool,has_timestamps:bool,doomed:bool,recovery_suspect:bool} +struct QueueBehindFlight{job:Arc,group:Vec>,first:usize,count:usize,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,heavy_render:bool,published_ns:u64,target:u32,cstamp:[u32;16],r_ta_stamp:[u32;16],r_fs_stamp:[u32;16],fs_target:u32,initbm:bool,has_timestamps:bool,doomed:bool,recovery_suspect:bool} struct QueueBehindEngine{ordinal:u64,draw:u64,ta_target:u32,next_compute_pipe:u8,flights:Vec} struct QueueBehindSlots{compute_exhausted:bool,render_exhausted:bool,compute_available:bool,pass_available:bool} impl QueueBehindSlots{ @@ -857,6 +858,7 @@ def item(declaration): __WAIT_STAMP_FOR__ __CROSS_ENGINE_WAIT__ __WAIT_COMPUTE_STAMPS_FOR__ + __COMPUTE_QUEUE_IS_HEAVY__ __CHOOSE_COMPUTE_PIPE__ } #[test]fn timed_compute_queues_behind_same_vm_and_coexists_with_render(){ @@ -875,7 +877,7 @@ def item(declaration): let j_render=mk(4,vm1.clone(),q1.clone(),true); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -917,7 +919,7 @@ def item(declaration): order:Order{engine:command::COMPUTE,sequence:u64::from(id),wait_through:[None,None]}, extra_orders:vec![],dependency:Ok(()),resources:Resources,fw_waits:vec![], }); - let flight=|job:Arc,rt_compute:bool,compute_pipe:u8|QueueBehindFlight{job,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe,rt_compute,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}; + let flight=|job:Arc,rt_compute:bool,compute_pipe:u8|QueueBehindFlight{job,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe,rt_compute,heavy_render:false,published_ns:0,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}; let rq=mk(1,vm1.clone(),q1.clone(),true); let rq_next=mk(2,vm1.clone(),q1.clone(),true); let rq_post=mk(3,vm1.clone(),q1.clone(),false); @@ -975,7 +977,7 @@ def item(declaration): let other_queue=mk(2,q2.clone(),true,None,Some(1)); let p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -993,7 +995,7 @@ def item(declaration): }); let pr=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -1017,7 +1019,7 @@ def item(declaration): let c1=mk(4,vm1.clone(),false); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; @@ -1061,7 +1063,7 @@ def item(declaration): let vm2_r=mk(3,vm2.clone(),q2.clone(),true); let vm2_c=mk(4,vm2.clone(),q2.clone(),false); let mk_flight=|job:Arc,c:u32,r:u32|QueueBehindFlight{ - job,group:vec![],first:0,count:1,computes:c,renders:r,compute_pipe:0,rt_compute:false,heavy_render:false, + job,group:vec![],first:0,count:1,computes:c,renders:r,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0, target:if c!=0{0x100}else{0},cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a}, fs_target:if r!=0{0x200}else{0},initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; @@ -1106,8 +1108,8 @@ def item(declaration): let p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ - QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x500;a},fs_target:0x500,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, - QueueBehindFlight{job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x700,cstamp:{let mut a=[0;16];a[0]=0x700;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x500;a},fs_target:0x500,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x700,cstamp:{let mut a=[0;16];a[0]=0x700;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, ]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, @@ -1143,7 +1145,7 @@ def item(declaration): let pm=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:3,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ - QueueBehindFlight{job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, + QueueBehindFlight{job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false}, ]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, @@ -1176,7 +1178,7 @@ def item(declaration): let host=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_initbm,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0, + job:r_initbm,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0, cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x900;a},fs_target:0x900, initbm:true,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, @@ -1222,7 +1224,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:c_job.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, + job:c_job.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x100,cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1233,7 +1235,7 @@ def item(declaration): assert_eq!(p.cross_engine_wait(&r_job,0,command::COMPUTE),Ok(None)); // Symmetrically, Queue 0 compute queues directly behind Queue 1 render on the same VM. p.engine.flights[0]=QueueBehindFlight{ - job:r_job,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, + job:r_job,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert!(p.can_queue_behind(&c_job)); @@ -1260,7 +1262,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:3,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:c1,group:vec![c2,c3],first:0,count:1,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, + job:c1,group:vec![c2,c3],first:0,count:1,computes:3,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x300,cstamp,r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1300,7 +1302,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:0,draw:3,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:multi.clone(),group:vec![],first:0,count:3,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:r_fs,fs_target:0x300, + job:multi.clone(),group:vec![],first:0,count:3,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:r_fs,fs_target:0x300, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, slots:QueueBehindSlots{compute_exhausted:false,render_exhausted:false,compute_available:true,pass_available:true}, @@ -1315,7 +1317,7 @@ def item(declaration): let mut cur_fs=[0u32;16]; cur_fs[0]=0x400; let cur=QueueBehindFlight{ - job:next_r.clone(),group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:cur_fs,fs_target:0x400, + job:next_r.clone(),group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:cur_fs,fs_target:0x400, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert_eq!(p.wait_stamp_for_with(&next_r,command::RENDER,Some(4),Some(&cur)),Ok(Some(WaitTarget{stamp:0x400,initbm:false}))); @@ -1337,7 +1339,7 @@ def item(declaration): let mut grp_fs=[0u32;16]; grp_fs[0]=0x400;grp_fs[1]=0x500;grp_fs[2]=0x600; let cur_grp=QueueBehindFlight{ - job:next_r.clone(),group:vec![r_fold_a.clone(),r_fold_b.clone()],first:0,count:1,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:grp_fs,fs_target:0x600, + job:next_r.clone(),group:vec![r_fold_a.clone(),r_fold_b.clone()],first:0,count:1,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:grp_fs,fs_target:0x600, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }; assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(4),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x400,initbm:false}))); @@ -1371,7 +1373,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:0,draw:8,ta_target:0x800,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_live,group:vec![],first:0,count:8,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16], + job:r_live,group:vec![],first:0,count:8,computes:0,renders:3,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16], r_ta_stamp:r_ta,r_fs_stamp:r_ta,fs_target:0x800, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }]}, @@ -1427,7 +1429,7 @@ def item(declaration): let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![QueueBehindFlight{ - job:r_live,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0,cstamp:[0;16], + job:r_live,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0,cstamp:[0;16], r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x100;a},fs_target:0x100, initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false, }]}, @@ -1774,37 +1776,54 @@ def item(declaration): pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; // Empty engine uses next_compute_pipe (0). - assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, false), 0); host.engine.flights.push(QueueBehindFlight{ - job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, + job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:1_000_000,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); - // Single-queue barrier-free compute stays affine to its active pipe (pipe 0), - // while a second independent queue balances onto idle pipe 1. - assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); - assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false), 1); - // RT/SCS compute stays pinned to pipe 0 even for another queue while pipe 0 is active. - assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, true), 0); - // A 2-unit base-only or SCS VM (bits < PIPE1_COMPUTE_START) stays pinned to pipe 0 - // even for another queue while pipe 0 is active. - assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b11, false), 0); - assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b110, false), 0); + // Cold-start heavy probe: sole single-command compute flight becomes heavy at >= 180 us. + assert!(!host.compute_queue_is_heavy(&q1, 1_179_999)); + assert!(host.compute_queue_is_heavy(&q1, 1_180_000)); + // Folded multi-command light flight does not trigger the cold-start probe. + host.engine.flights[0].computes = 3; + assert!(!host.compute_queue_is_heavy(&q1, 2_000_000)); + host.engine.flights[0].computes = 1; + // Per-queue retired hardware CDM EWMA transitions cleanly at 200 us. + q1.note_compute_us(30); + assert!(!host.compute_queue_is_heavy(&q1, 1_050_000)); + q1.note_compute_us(500); + assert!(host.compute_queue_is_heavy(&q1, 1_050_000)); + q1.note_compute_us(20); + assert!(!host.compute_queue_is_heavy(&q1, 1_050_000)); + q1.compute_ewma_us.store(0, Ordering::Relaxed); + // Light single-queue barrier-free compute stays affine to its active pipe (pipe 0), + // while heavy single-queue compute and a second independent queue balance onto idle pipe 1. + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, true), 1); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false, false), 1); + // RT/SCS compute stays pinned to pipe 0 even for another queue or heavy compute. + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, true, true), 0); + // A 2-unit base-only or SCS VM (bits < PIPE1_COMPUTE_START) stays pinned to pipe 0. + assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b11, false, true), 0); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], 0b110, false, true), 0); assert!(host.can_queue_behind(&c2)); // Add second concurrent flight on pipe 1 from q2: both pipes active, // q1 stays affine to pipe 0, q2 stays affine to pipe 1, and a third queue q3 // tie-breaks by next_compute_pipe. host.engine.flights.push(QueueBehindFlight{ - job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,target:0x100, + job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,published_ns:1_000_000,target:0x100, cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); - assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false), 0); - assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false), 1); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, false), 0); + assert_eq!(host.choose_compute_pipe(&q2, [None, None], (1u32 << 24) - 1, false, false), 1); host.engine.next_compute_pipe=1; - assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false), 1); + assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false, false), 1); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, true), 1); host.engine.next_compute_pipe=0; - assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q3, [None, None], (1u32 << 24) - 1, false, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, [None, None], (1u32 << 24) - 1, false, true), 0); assert!(host.can_queue_behind(&c_vm2)); // Same-VM compute still pipelines without draining. assert!(host.can_queue_behind(&c2)); @@ -1827,12 +1846,12 @@ def item(declaration): graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:2,draw:0,ta_target:0,next_compute_pipe:0,flights:vec![ QueueBehindFlight{ - job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, + job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x100, cstamp:{let mut a=[0;16];a[0]=0x100;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, QueueBehindFlight{ - job:c2,group:vec![],first:0,count:1,computes:2,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,target:0x200, + job:c2,group:vec![],first:0,count:1,computes:2,renders:0,compute_pipe:1,rt_compute:false,heavy_render:false,published_ns:0,target:0x200, cstamp:{let mut a=[0;16];a[0]=0x200;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, @@ -1845,13 +1864,13 @@ def item(declaration): // Waiting on seq 1 (pipe 0 only) returns [Some(0x100), None] and reuses pipe 0 (zero c2c barrier). let w1 = host.wait_compute_stamps_for(&c3, Some(1)).unwrap(); assert_eq!(w1, [Some(WaitTarget{stamp:0x100,initbm:false}), None]); - assert_eq!(host.choose_compute_pipe(&q1, w1, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w1, (1u32 << 24) - 1, false, true), 0); // Waiting on seq 2 (both pipe 0 seq 1 and pipe 1 seq 2 <= 2) returns both stamps and // selects the least-loaded pipe (pipe 0 has 1 active vs pipe 1 has 2 -> picks pipe 0, // so prefix_compute emits one cross-pipe c2c barrier on pipe 1's 0x200). let w2 = host.wait_compute_stamps_for(&c4, Some(2)).unwrap(); assert_eq!(w2, [Some(WaitTarget{stamp:0x100,initbm:false}), Some(WaitTarget{stamp:0x200,initbm:false})]); - assert_eq!(host.choose_compute_pipe(&q1, w2, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w2, (1u32 << 24) - 1, false, false), 0); // Unpublished seq 3 returns Err(EAGAIN). assert_eq!(host.wait_compute_stamps_for(&c4, Some(3)), Err(EAGAIN)); // If seq 2 retired out-of-order on pipe 1 while seq 1 is still active on pipe 0, @@ -1862,7 +1881,7 @@ def item(declaration): assert!(q1.is_compute_retired(2)); let w2_ooo = host.wait_compute_stamps_for(&c4, Some(2)).unwrap(); assert_eq!(w2_ooo, [Some(WaitTarget{stamp:0x100,initbm:false}), None]); - assert_eq!(host.choose_compute_pipe(&q1, w2_ooo, (1u32 << 24) - 1, false), 0); + assert_eq!(host.choose_compute_pipe(&q1, w2_ooo, (1u32 << 24) - 1, false, true), 0); // Once contiguous completed[COMPUTE] reaches 2, wait_compute_stamps_for returns [None, None]. q1.completed[command::COMPUTE].store(2, Ordering::Release); q1.compute_ooo.store(0, Ordering::Release); @@ -1906,12 +1925,12 @@ def item(declaration): graph:QueueBehindGraph::new(), engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,flights:vec![ QueueBehindFlight{ - job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,target:0x100, + job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0x100, cstamp:{let mut a=[0;16];a[0]=0x100;a},r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0, initbm:false,has_timestamps:true,doomed:false,recovery_suspect:false, }, QueueBehindFlight{ - job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,target:0, + job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute:false,heavy_render:false,published_ns:0,target:0, cstamp:[0;16],r_ta_stamp:[0;16],r_fs_stamp:{let mut a=[0;16];a[0]=0x200;a},fs_target:0x200, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, }, @@ -1922,7 +1941,7 @@ def item(declaration): // Cross-queue compute wait resolves pipe 0 stamp 0x100 and keeps q2 on pipe 0 (zero c2c). let cw=host.wait_compute_stamps_for(&c2_wait_q1,None).unwrap(); assert_eq!(cw,[Some(WaitTarget{stamp:0x100,initbm:false}),None]); - assert_eq!(host.choose_compute_pipe(&q2,cw,(1u32<<24)-1,false),0); + assert_eq!(host.choose_compute_pipe(&q2,cw,(1u32<<24)-1,false,false),0); // Cross-queue render wait resolves q1's FS stamp 0x200. assert_eq!(host.wait_stamp_for(&c2_wait_q1,command::RENDER,None),Ok(Some(WaitTarget{stamp:0x200,initbm:false}))); // query_access compute waiting via fw_waits on a timestamped q1 flight must wait to retire; @@ -2585,7 +2604,7 @@ def item(declaration): } } mod busy_coalesce_scope { - use super::{Arc, AtomicBool, AtomicU32, Command, ComputeCommand, Order, Progress, Queue, Recovery, RenderCommand, Result, Status, Vm}; + use super::{Arc, AtomicBool, AtomicU32, Command, ComputeCommand, Order, Ordering, Progress, Queue, Recovery, RenderCommand, Result, Status, Vm}; mod params { pub fn compute_flights() -> usize { 23 } pub fn render_flights() -> usize { 47 } @@ -2634,6 +2653,8 @@ def item(declaration): job: Arc, computes: u32, renders: u32, + compute_pipe: u8, + published_ns: u64, doomed: bool, recovery_suspect: bool, initbm: bool, @@ -2661,8 +2682,9 @@ def item(declaration): } impl Host { fn can_queue_behind(&self, _job: &Arc) -> bool { self.allow_behind } - fn choose_compute_pipe(&self, _q: &Arc, _w: [Option<()>; 2], _m: u32, _rt: bool) -> usize { 0 } + fn choose_compute_pipe(&self, _q: &Arc, _w: [Option<()>; 2], _m: u32, _rt: bool, _heavy: bool) -> usize { 0 } fn ta_pending_passes(&self) -> usize { self.ta_pending } + __COMPUTE_QUEUE_IS_HEAVY__ __TA_WAVE_CAP_FOR__ __CAN_DEFER_BUSY_COALESCE__ __DEFER_BUSY_COALESCE__ @@ -2692,7 +2714,7 @@ def item(declaration): let mut h = Host { recovery: Recovery { error: None, publication_wait_deadline: None }, engine: Engine { - flights: vec![Flight { job: c1.clone(), computes: 1, renders: 0, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }], + flights: vec![Flight { job: c1.clone(), computes: 1, renders: 0, compute_pipe: 0, published_ns: 90_000, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }], pending: vec![mk_job(&vm1, &q1, false, 2, [None, None])], frozen: false, chan_wait: false, @@ -2737,10 +2759,23 @@ def item(declaration): h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, Some(2)])]; assert_eq!(h.defer_busy_coalesce(400_000), None); + // Heavy compute queue (EWMA >= 200 us) bypasses busy coalescing so 2-pipe fanout runs immediately. + h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; + q1.note_compute_us(500); + assert_eq!(h.defer_busy_coalesce(420_000), None); + q1.compute_ewma_us.store(25, Ordering::Relaxed); + assert_eq!(h.defer_busy_coalesce(420_000), Some(18)); + + // Active flight from another queue bypasses busy coalescing immediately (multi-queue/async_cr). + let r_other = mk_job(&vm1, &q2, true, 1, [None, None]); + h.engine.flights.push(Flight { job: r_other, computes: 0, renders: 1, compute_pipe: 0, published_ns: 410_000, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }); + assert_eq!(h.defer_busy_coalesce(425_000), None); + h.engine.flights.pop(); + // Light render with queue_active == 2 and ta_pending == 2 (wave_cap 8 -> ta_room 6) // coalesces up to K=6 passes before flushing. let r1 = mk_job(&vm1, &q1, true, 1, [None, None]); - h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }]; + h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, compute_pipe: 0, published_ns: 490_000, doomed: false, recovery_suspect: false, initbm: false, heavy_render: false }]; h.ta_pending = 2; h.engine.pending = vec![mk_job(&vm1, &q1, true, 3, [Some(2), None])]; assert_eq!(h.defer_busy_coalesce(500_000), Some(18)); @@ -2768,6 +2803,7 @@ def item(declaration): harness = harness.replace('__QUEUE_CREDIT_STRUCT__', item_in(queue_src, 'struct QueueCredit {')) harness = harness.replace('__QUEUE_CREDIT_IMPL__', item_in(queue_src, 'impl QueueCredit {')) harness = harness.replace('__QUEUE_CREDIT_DROP__', item_in(queue_src, 'impl Drop for QueueCredit {')) +harness = harness.replace('__NOTE_COMPUTE_US__', item_in(queue_src, 'pub(crate) fn note_compute_us(')) harness = harness.replace( '__CAN_FOLD_CMD__', item_in(job_src, 'pub(crate) fn can_fold_horizon_cmd(') @@ -2826,6 +2862,7 @@ def item(declaration): '__WAIT_STAMP_FOR__': 'fn wait_stamp_for(', '__CROSS_ENGINE_WAIT__': 'fn cross_engine_wait(', '__WAIT_COMPUTE_STAMPS_FOR__': 'fn wait_compute_stamps_for(', + '__COMPUTE_QUEUE_IS_HEAVY__': 'fn compute_queue_is_heavy(', '__CHOOSE_COMPUTE_PIPE__': 'fn choose_compute_pipe(', '__SCS_COMPUTE_CONFLICT__': 'fn scs_compute_conflict(', '__WAIT_TARGET__': 'struct WaitTarget {', From cb390f549d1ec8fbc9f9e96ac670156502bf8504 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Tue, 24 Nov 2026 07:00:50 -0500 Subject: [PATCH 4/7] drm/asahi: g16: repoll soon when SUBMIT leaves a paced job waiting publish_checked() marks a ready job that it could not publish for want of TA wave headroom (ta_wave_wait) or pass and flight headroom (slot_wait). A poll pass that sees either flag repolls after repoll_us (8 us by default), so the job publishes as soon as TA progress or a retirement makes room. A SUBMIT that publishes inline and leaves the same state behind did not do this. It rearmed the poll timer with rearm_us(false), which is half the flight duration EWMA clamped to resnap_us, so 100 us for renders longer than 200 us. Unless a stage event arrived first, the job waited that long after the room appeared. This is the case for the later passes of a multi-pass render that does not fit in one TA wave. Treat the two flags in submit_locked() as poll_step() does: rearm soon when the engine is not frozen and a job is still pending. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/poll.rs | 8 +++- .../drivers/gpu/asahi-m4/test-poll-retire.py | 44 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index e11cfd22168f2..4b81ad843cc24 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -316,13 +316,19 @@ impl Shared { if !firmware.engine.flights.is_empty() || firmware.engine.chan_wait { // If an EP 0x20 event retired an older flight while later flights remain active, // or arrived before the oldest receipt became visible, arm a short repoll so - // trailing completions never fall back to `resnap_us`. + // trailing completions never fall back to `resnap_us`. A ready job this + // publication left waiting on TA wave or slot headroom repolls as soon as + // `poll_step()` would rearm it, not a full `resnap_us` later. if let Some(us) = coalesce_us { self.rearm_after(us.min(self.rearm_us(false))); } else { + let paced = !firmware.engine.frozen + && !firmware.engine.pending.is_empty() + && (firmware.engine.slot_wait || firmware.engine.ta_wave_wait); self.rearm( firmware.engine.chan_wait || restored_event + || paced || (was_evented && retired_any && !firmware.engine.flights.is_empty()), ); } diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py index df5d84c420362..0281cadec9efa 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py @@ -327,6 +327,7 @@ def item(declaration, text=source): ta_pending: usize, ta_wave_cap: usize, coalesce_us: Option, + publish_waits: Option<(bool, bool)>, retire_calls: u32, publish_full_calls: u32, publish_checked_calls: u32, @@ -383,6 +384,7 @@ def item(declaration, text=source): ta_pending: 0, ta_wave_cap: hw::sizes::TA_WAVE_PASSES, coalesce_us: None, + publish_waits: None, retire_calls: 0, publish_full_calls: 0, publish_checked_calls: 0, @@ -445,6 +447,10 @@ def item(declaration, text=source): } fn publish_checked(&mut self, _done: &mut Completions) -> Result { self.engine.coalesce_deadline_ns = 0; + if let Some((slot_wait, ta_wave_wait)) = self.publish_waits { + self.engine.slot_wait = slot_wait; + self.engine.ta_wave_wait = ta_wave_wait; + } self.publish_checked_calls += 1; Ok(()) } @@ -1055,6 +1061,42 @@ def item(declaration, text=source): assert!(!fw.engine.short_repoll); } +#[test] +fn submit_locked_repolls_soon_when_its_publication_leaves_a_paced_job() { + // publish_checked() leaves a ready job on TA wave or slot headroom: SUBMIT arms the same + // short repoll poll_step() arms for it, unless the engine is frozen. + CLOCK.with(|c| c.set(100_000)); + for (slot_wait, ta_wave_wait, frozen, soon) in [ + (false, false, false, 0), + (true, false, false, 1), + (false, true, false, 1), + (false, true, true, 0), + ] { + let shared = Shared::new(); + let mut fw = Firmware::new(); + fw.last_housekeeping_ns = 100_000; + fw.engine.flights.push(Flight { + computes: 0, + compute_pipe: 0, + renders: 1, + target: 0, + fs_target: 0x100, + }); + fw.engine.fs_target = 0x100; + fw.engine.frozen = frozen; + fw.publish_waits = Some((slot_wait, ta_wave_wait)); + let mut done = vec![]; + shared + .submit_locked(&mut fw, Arc::new(Job { id: 2 }), &mut done) + .unwrap(); + assert_eq!(fw.retire_calls, 0); + assert_eq!(fw.publish_checked_calls, 1); + assert_eq!(shared.rearmed.get(), 1); + assert_eq!(shared.rearm_soon.get(), soon); + assert_eq!(shared.poll_now_calls.get(), 0); + } +} + #[test] fn submit_locked_and_poll_step_micro_coalesce_busy_horizons() { CLOCK.with(|c| c.set(100_000)); @@ -1707,7 +1749,7 @@ def item(declaration, text=source): json.dumps( { 'passed': True, - 'tests': 22, + 'tests': 23, 'cpu_only': True, 'hardware_execution': False, 'scope': 'Verbatim production submit_locked inline retirement and poll_step TA-only non-spin logic.', From e94ea5c88400cfe38dca6fca4ce505900cd33ad3 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Tue, 24 Nov 2026 07:07:58 -0500 Subject: [PATCH 5/7] drm/asahi: g16: keep idle poll passes on the housekeeping cadence poll_step() ran the full idle housekeeping on every pass that started with nothing in flight: Session::check() (an ASC control read, a powered SGX pstate read and a walk of the adopted UAT bindings), Objects::health(), service_power() and a drain of every receive ring, including the nine log sub-rings and ktrace. A pass with work in flight holds the same checks to their cadence, 5 ms while active. Shallow back-to-back submissions reach the idle state after every completion, and idle_resnap() keeps a short poll timer armed across that gap. The timer pass then repeated all of these checks under the device lock, between one completion and the next SUBMIT, which waits on the same lock. Inside the 1 ms idle cadence, drain only the event and statistics rings, which carry completion and recovery notifications, then check for a pending recovery. A recovery or a receipt fault still runs the full pass at once. The skipped housekeeping is owed: run_poll() queues the backup poll for the end of the cadence, and the owed state clears when any full or periodic housekeeping runs. The backup poll may replace a later idle power poll; that pass calls service_power() and arms the power poll again. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/engine.rs | 4 ++ drivers/gpu/drm/asahi/g16/poll.rs | 43 +++++++++++--- .../drivers/gpu/asahi-m4/test-poll-retire.py | 56 ++++++++++++++++++- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 30960124b5cfb..c0b4db6535a5e 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -610,6 +610,9 @@ pub(crate) struct Engine { pub(crate) ta_wave_wait: bool, /// An EP 0x20 event arrived with a flight still settling its final receipt: repoll sooner. pub(crate) short_repoll: bool, + /// An idle poll pass inside the housekeeping cadence skipped housekeeping: queue a backup + /// poll so it runs once the cadence elapses. + pub(crate) housekeeping_owed: bool, /// Absolute deadline (`ktime_get_ns`) for busy-state same-queue horizon micro-coalescing /// (0 when no batch is held). pub(crate) coalesce_deadline_ns: u64, @@ -657,6 +660,7 @@ impl Engine { slot_wait: false, ta_wave_wait: false, short_repoll: false, + housekeeping_owed: false, coalesce_deadline_ns: 0, progress_flight: [0; 3], progress: [None; 4], diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 4b81ad843cc24..f22cd3055270a 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -100,6 +100,18 @@ impl Shared { self.mod_poll(kernel::time::msecs_to_jiffies((delay_ns / 1_000_000) as u32).max(1)); } + /// Queues the backup poll for idle housekeeping that a pass skipped inside its cadence, at + /// the end of that cadence. It may replace a later idle power poll: that pass runs the + /// housekeeping, including `service_power()`, and arms the power poll again. + fn queue_owed_housekeeping(self: &Arc, firmware: &Firmware) { + if !firmware.engine.housekeeping_owed || firmware.recovery.failed().is_some() { + return; + } + let elapsed = now_ns().wrapping_sub(firmware.last_housekeeping_ns); + let ms = HOUSEKEEPING_NS.saturating_sub(elapsed).div_ceil(1_000_000) as u32; + self.mod_poll(kernel::time::msecs_to_jiffies(ms).max(1)); + } + /// One poll pass (the poll work item). pub(crate) fn run_poll(self: Arc) { // The domain may be off. The sleep's end queues a pass. @@ -158,6 +170,7 @@ impl Shared { // floor hold is still pending so both expire cleanly to idle power. Ok(false) => { self.arm_idle_power_poll(firmware); + self.queue_owed_housekeeping(firmware); if firmware.recovery.failed().is_some() { self.cancel_resnap(); } else { @@ -670,14 +683,29 @@ impl Firmware { // failure of the next prefix. Drain the receive rings before deciding, published or // not, so the error count is current and idle log/trace/stats traffic is consumed. With // prefixes published the retirement loop below drains first. + // + // Inside the housekeeping cadence, with no recovery pending, an idle pass drains only + // the event and statistics rings, which carry completion and recovery notifications. + // The session, object, power and auxiliary ring checks then wait for the cadence, so + // back-to-back shallow submissions do not repeat them, under the device lock, between + // one completion and the next SUBMIT. `run_poll()` queues a backup poll for them. if !had_flights { - self.session.check()?; - self.objects.health()?; - self.service_power()?; - self.last_housekeeping_ns = now; - self.last_aux_drain_ns = now; - ran_housekeeping = true; - self.drain_rings()?; + let full = housekeeping_due || self.recovery.receipt_fault || { + self.drain_events_and_stats()?; + self.recovery_pending()? + }; + if full { + self.session.check()?; + self.objects.health()?; + self.service_power()?; + self.last_housekeeping_ns = now; + self.last_aux_drain_ns = now; + ran_housekeeping = true; + self.engine.housekeeping_owed = false; + self.drain_rings()?; + } else { + self.engine.housekeeping_owed = true; + } self.reclaim_closed_vm_slots(); if self.recovery_idle()? && self.engine.pending.is_empty() { let _ = self.slots.take_scrub_woke(); @@ -817,6 +845,7 @@ impl Firmware { self.last_aux_drain_ns = now; } self.last_housekeeping_ns = now; + self.engine.housekeeping_owed = false; self.reclaim_closed_vm_slots(); if !self.engine.flights.is_empty() || recovery_pending { self.check_hangs(done)?; diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py index 0281cadec9efa..789f95ed290c8 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py @@ -163,6 +163,7 @@ def item(declaration, text=source): slot_wait: bool, ta_wave_wait: bool, short_repoll: bool, + housekeeping_owed: bool, coalesce_deadline_ns: u64, frozen: bool, stats: Stats, @@ -334,6 +335,7 @@ def item(declaration, text=source): housekeeping_calls: u32, aux_drain_calls: u32, power_calls: u32, + hot_drain_calls: u32, } impl Firmware { @@ -364,6 +366,7 @@ def item(declaration, text=source): slot_wait: false, ta_wave_wait: false, short_repoll: false, + housekeeping_owed: false, coalesce_deadline_ns: 0, frozen: false, stats: Stats::default(), @@ -391,6 +394,7 @@ def item(declaration, text=source): housekeeping_calls: 0, aux_drain_calls: 0, power_calls: 0, + hot_drain_calls: 0, } } @@ -411,6 +415,10 @@ def item(declaration, text=source): fn drain_rings(&mut self) -> Result { Ok(()) } + fn drain_events_and_stats(&mut self) -> Result { + self.hot_drain_calls += 1; + Ok(()) + } fn drain_auxiliary_rings(&mut self) -> Result { self.aux_drain_calls += 1; Ok(()) @@ -471,6 +479,52 @@ def item(declaration, text=source): __OLDEST_STAMP_REACHED__ } +#[test] +fn idle_poll_step_runs_full_housekeeping_only_on_its_cadence() { + let mut fw = Firmware::new(); + let (mut retry_tail, mut hk_deferred, mut done) = (false, false, vec![]); + let mut idle_pass = |fw: &mut Firmware, now: u64| { + CLOCK.with(|c| c.set(now)); + fw.poll_step(false, 0, &mut retry_tail, &mut hk_deferred, &mut done) + .unwrap() + }; + // Due: the full idle housekeeping runs and owes nothing. + assert!(!idle_pass(&mut fw, 2_000_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (1, 0)); + assert_eq!(fw.last_housekeeping_ns, 2_000_000); + assert!(!fw.engine.housekeeping_owed); + // Inside the cadence: only the event and statistics rings drain; the rest is owed. + assert!(!idle_pass(&mut fw, 2_300_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (1, 1)); + assert_eq!(fw.last_housekeeping_ns, 2_000_000); + assert!(fw.engine.housekeeping_owed); + // A recovery found by that drain runs the full pass inside the cadence. + fw.recovery.pending = true; + assert!(idle_pass(&mut fw, 2_400_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (2, 2)); + assert_eq!(fw.last_housekeeping_ns, 2_400_000); + assert!(!fw.engine.housekeeping_owed); + fw.recovery.pending = false; + // So does a receipt fault, without a hot drain first. + fw.recovery.receipt_fault = true; + assert!(!idle_pass(&mut fw, 2_500_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (3, 2)); + fw.recovery.receipt_fault = false; + assert!(!idle_pass(&mut fw, 2_600_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (3, 3)); + assert!(fw.engine.housekeeping_owed); + // Once the cadence elapses the owed housekeeping runs. + assert!(!idle_pass(&mut fw, 3_500_000)); + assert_eq!((fw.power_calls, fw.hot_drain_calls), (4, 3)); + assert!(!fw.engine.housekeeping_owed); + // Periodic housekeeping also settles what an idle pass owed. + assert!(!idle_pass(&mut fw, 3_600_000)); + assert!(fw.engine.housekeeping_owed); + CLOCK.with(|c| c.set(4_600_000)); + fw.run_housekeeping(&mut done).unwrap(); + assert!(!fw.engine.housekeeping_owed); +} + #[test] fn idle_poll_step_reclaims_closed_vm_slots_and_rearms_while_remaining() { CLOCK.with(|c| c.set(1_000_000)); @@ -1749,7 +1803,7 @@ def item(declaration, text=source): json.dumps( { 'passed': True, - 'tests': 23, + 'tests': 24, 'cpu_only': True, 'hardware_execution': False, 'scope': 'Verbatim production submit_locked inline retirement and poll_step TA-only non-spin logic.', From acb4513824e834492d87087bf93e4c61f8bc7e1a Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Tue, 24 Nov 2026 07:29:41 -0500 Subject: [PATCH 6/7] drm/asahi: g16: count publication holds by cause hold[0] counts publication passes that stopped at a ready job behind in-flight work, but it lumps together a job that must wait for an empty engine and one that waits for headroom. The two are released by different events, so the counter cannot say which one a stalled multi-pass render is waiting for. Count each such hold once more by its cause, and print the split as a hold_causes line of aurora-g16/stats: - drain_failed: the VM failed, or a flight is doomed or recovery-suspect; - drain_initbm: a cold InitBM render is in flight; - drain_cross: render and compute of different VMs; - drain_pb: no warm PB/UMA allocator slot of the VM can take the render; - ta_wave: the TA wave window is full; - slot: flight, render pass or compute unit headroom; - dependency: the job's dependency check failed; - other: any other refusal behind in-flight work. The cause is evaluated only when a pass holds. The PB pipelining test that needs_engine_drain() and can_queue_behind_with_ta() each spelled out moves to render_can_pipeline(), which the classification uses too. hold[0] keeps its meaning. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/engine.rs | 135 ++++++++++++++---- drivers/gpu/drm/asahi/g16/poll.rs | 5 + .../drivers/gpu/asahi-m4/test-publication.py | 58 +++++++- 3 files changed, 168 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index c0b4db6535a5e..a9457dd64ceba 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -424,6 +424,45 @@ enum PublicationError { Uncertain(Error), } +/// Why a publication pass stopped at a ready job without publishing it (`Stats::hold_causes`). +/// +/// A drain cause means the job waits for an empty engine; the others wait behind in-flight +/// work for headroom or ordering. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) enum HoldCause { + /// The job's VM failed, or a flight is doomed or suspect in a recovery. + DrainFailed, + /// A cold `InitBM` render is in flight. + DrainInitbm, + /// Compute and render of different VMs, or an SCS compute conflict. + DrainCross, + /// No warm PB/UMA allocator slot of the VM can take the render behind active flights. + DrainPb, + /// The TA wave window is full. + TaWave, + /// Flight, render pass or compute unit headroom. + Slot, + /// The job's dependency check failed: it fails once it reaches publication. + /// (`Engine::pick()` skips jobs still waiting for a dependency.) + Dependency, + /// Any other admission refusal behind in-flight work. + Other, +} + +impl HoldCause { + pub(crate) const COUNT: usize = 8; + pub(crate) const NAMES: [&'static str; Self::COUNT] = [ + "drain_failed", + "drain_initbm", + "drain_cross", + "drain_pb", + "ta_wave", + "slot", + "dependency", + "other", + ]; +} + /// Engine statistics, printed by `aurora-g16/stats`. #[derive(Default, Zeroable)] pub(crate) struct Stats { @@ -474,6 +513,8 @@ pub(crate) struct Stats { /// Why ready jobs stayed unpublished: both flights published, a channel record unconsumed, /// no free slot. pub(crate) hold: [u64; 3], + /// `hold[0]` split by [`HoldCause`]. + pub(crate) hold_causes: [u64; HoldCause::COUNT], /// Compute commands published behind in-flight ones. pub(crate) behind: u64, /// Most flights in flight at once. @@ -1032,7 +1073,7 @@ impl Firmware { && !self.can_queue_behind_with_ta(&job, &mut ta_pending) { if self.needs_engine_drain(&job) { - self.engine.stats.hold[0] += 1; + self.note_hold(&job, true, 0); break; } let ta_val = *ta_pending.get_or_insert_with(|| self.ta_pending_passes()); @@ -1119,7 +1160,7 @@ impl Firmware { .check_command_dependencies(cand.progress.sent()) .is_ok() }); - self.engine.stats.hold[0] += 1; + self.note_hold(&job, false, ta_val); break; } } @@ -1357,20 +1398,68 @@ impl Firmware { || (((is_compute && f.renders != 0) || (is_render && f.computes != 0)) && !Arc::ptr_eq(&f.job.vm, &job.vm)) }) - || (is_render - && !job - .resources - .pb_slot_mask() - .and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?))) - .is_ok_and(|(mask, home, blocks)| { - self.pools.can_pipeline_in_mask_blocks_mode( - &job.vm, - mask, - home, - blocks, - job.resources.render_scs(), - ) - })) + || (is_render && !self.render_can_pipeline(job)) + } + + /// Whether `job`'s render can reuse a warm PB/UMA allocator slot of its VM behind active + /// flights, without the drain that a fresh `InitBM` epoch needs. + fn render_can_pipeline(&self, job: &Arc) -> bool { + job.resources + .pb_slot_mask() + .and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?))) + .is_ok_and(|(mask, home, blocks)| { + self.pools.can_pipeline_in_mask_blocks_mode( + &job.vm, + mask, + home, + blocks, + job.resources.render_scs(), + ) + }) + } + + /// Why a publication pass stopped at `job`: `drain` when [`Self::needs_engine_drain`] + /// held it, otherwise the first refusal of [`Self::can_queue_behind_with_ta`] that + /// applies, with `ta_pending` from that check. Of the drain causes, a failure, an `InitBM` + /// flight and the PB check are tested directly; what remains of `needs_engine_drain()` is a + /// cross-VM or SCS overlap. + fn hold_cause(&self, job: &Arc, drain: bool, ta_pending: usize) -> HoldCause { + let render = command(job, job.progress.sent()); + if drain { + if job.vm.status.get() != 0 + || self + .engine + .flights + .iter() + .any(|f| f.doomed || f.recovery_suspect) + { + HoldCause::DrainFailed + } else if self.engine.flights.iter().any(|f| f.initbm) { + HoldCause::DrainInitbm + } else if matches!(render, Some(Command::Render(_))) && !self.render_can_pipeline(job) { + HoldCause::DrainPb + } else { + HoldCause::DrainCross + } + } else if job.check_command_dependencies(job.progress.sent()).is_err() { + HoldCause::Dependency + } else if matches!(render, Some(Command::Render(r)) + if ta_pending >= self.ta_wave_cap_for(r.is_heavy_ta())) + { + HoldCause::TaWave + } else if self.blocked_on_slot_headroom(job) { + HoldCause::Slot + } else { + HoldCause::Other + } + } + + /// Counts a publication pass that stopped at the ready `job` behind in-flight work. + fn note_hold(&mut self, job: &Arc, drain: bool, ta_pending: usize) { + let cause = self.hold_cause(job, drain, ta_pending); + let s = &mut self.engine.stats; + s.hold[0] += 1; + s.hold_causes[cause as usize] += 1; } /// Whether `job` is ready to run without an engine drain but currently blocked solely on @@ -1599,19 +1688,7 @@ impl Firmware { && !self.slots.render_exhausted() && !self.pools.exhausted() && super::recovery::logic::next_ordinal(e.draw).is_some() - && job - .resources - .pb_slot_mask() - .and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?))) - .is_ok_and(|(mask, home, blocks)| { - self.pools.can_pipeline_in_mask_blocks_mode( - &job.vm, - mask, - home, - blocks, - job.resources.render_scs(), - ) - }) + && self.render_can_pipeline(job) && job .resources .render_passes() diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index f22cd3055270a..81728d7f5c595 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -2261,6 +2261,11 @@ impl Firmware { s.hold[1], s.hold[2] )?; + write!(f, "hold_causes:")?; + for (name, n) in super::engine::HoldCause::NAMES.iter().zip(s.hold_causes) { + write!(f, " {} {}", name, n)?; + } + writeln!(f)?; } let p = &self.engine.prof; writeln!( diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index ad2fac33e3c92..b1f06cacd4d00 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -133,7 +133,10 @@ def item(declaration): fn command(job:&Job,k:u32)->Option<&Command>{job.commands.get(k as usize)} type Completions=Vec<(u32,Result)>; fn complete(done:&mut Completions,job:&Arc,result:Result){done.push((job.id,result));} -#[derive(Default)]struct Stats{hold:[u64;3],grouped:u64} +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +__HOLD_CAUSE__ +__HOLD_CAUSE_IMPL__ +#[derive(Default)]struct Stats{hold:[u64;3],hold_causes:[u64;HoldCause::COUNT],grouped:u64} struct Claims; struct Flight{job:Arc,claims:Claims,group:Vec>,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,doomed:bool,recovery_suspect:bool,initbm:bool,heavy_render:bool} impl Flight{fn new(job:Arc)->Self{Self{job,claims:Claims,group:vec![],computes:0,renders:0,compute_pipe:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false,heavy_render:false}}} @@ -230,6 +233,9 @@ def item(declaration): fn mark_class_unavailable(&mut self,class:usize,error:Error){self.unavailable.push((class,error));} fn sync_quarantine_hints(&self){} __NEEDS_ENGINE_DRAIN__ + __RENDER_CAN_PIPELINE__ + __HOLD_CAUSE_FN__ + __NOTE_HOLD__ __TA_WAVE_CAP_FOR__ __ACTIVE_TA_WAVE_CAP__ fn blocked_on_slot_headroom(&self,job:&Arc)->bool{ @@ -499,6 +505,50 @@ def item(declaration): assert_eq!(f.publish_checked(&mut done),Ok(())); assert_eq!(f.attempted,[2,3]); } + #[test]fn hold_causes_split_hold0_by_the_gate_that_stopped_publication(){ + let vm1=mk_vm(1); + let vm2=mk_vm(2); + // One held publication pass per case: (in-flight job and kind, its flags, held job, + // host knobs) -> exactly one hold[0] of the expected cause. + let run=|flight:Arc,renders:u32,initbm:bool,doomed:bool,held:Arc, + allow_behind:bool,block_pipeline:Option,block_render:bool,expect:HoldCause|{ + let mut f=firmware(vec![held],vec![]); + let mut fl=Flight::new(flight); + if renders==0{fl.computes=1;}else{fl.renders=renders;} + fl.initbm=initbm; + fl.doomed=doomed; + f.engine.flights.push(fl); + f.allow_behind=allow_behind; + f.pools.block_pipeline_vm=block_pipeline; + f.block_render_behind=block_render; + let mut done=vec![]; + assert_eq!(f.publish_checked(&mut done),Ok(())); + assert!(f.attempted.is_empty(),"{:?}",expect); + assert_eq!(f.engine.stats.hold[0],1,"{:?}",expect); + let mut want=[0u64;HoldCause::COUNT]; + want[expect as usize]=1; + assert_eq!(f.engine.stats.hold_causes,want,"{:?}",expect); + }; + let r=|id:u32,vm:&Arc,dep:Result|job_on_vm(id,vm.clone(),true,0,dep); + // A warm same-VM render whose allocator cannot pipeline waits for an empty engine. + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,Some(vm1.slot),false,HoldCause::DrainPb); + // A cold InitBM flight drains first. + run(r(1,&vm1,Ok(())),1,true,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainInitbm); + // Another VM's compute in flight: no cross-VM render/compute overlap. + run(job_on_vm(1,vm2.clone(),false,0,Ok(())),0,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainCross); + // A doomed flight drains first. + run(r(1,&vm1,Ok(())),1,false,true,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainFailed); + // A full light TA wave (8 renders) pauses the next light render. + run(r(1,&vm1,Ok(())),8,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::TaWave); + // Pass, flight or unit headroom. + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,None,true,HoldCause::Slot); + // A failed dependency (pick() skips jobs still waiting for one). + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Err(ECANCELED)),false,None,false,HoldCause::Dependency); + // Any other refusal. + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),false,None,false,HoldCause::Other); + assert_eq!(HoldCause::NAMES.len(),HoldCause::COUNT); + assert_eq!(HoldCause::Other as usize,HoldCause::COUNT-1); + } #[test]fn alt_bypass_does_not_starve_cold_cross_vm_initbm_while_warm_overlaps(){ let vm1=mk_vm(1); let vm2=mk_vm(2); @@ -849,6 +899,7 @@ def item(declaration): __SCS_COMPUTE_CONFLICT__ impl QueueBehindHost { __NEEDS_ENGINE_DRAIN__ + __RENDER_CAN_PIPELINE__ __BLOCKED_ON_SLOT_HEADROOM__ __TA_PENDING_PASSES__ __TA_WAVE_CAP_FOR__ @@ -2848,6 +2899,11 @@ def item(declaration): '__PUBLISH__': 'pub(crate) fn publish(&mut self', '__PUBLISH_CHECKED__': 'pub(crate) fn publish_checked(&mut self', '__NEEDS_ENGINE_DRAIN__': 'fn needs_engine_drain(', + '__RENDER_CAN_PIPELINE__': 'fn render_can_pipeline(', + '__HOLD_CAUSE__': 'enum HoldCause {', + '__HOLD_CAUSE_IMPL__': 'impl HoldCause {', + '__HOLD_CAUSE_FN__': 'fn hold_cause(', + '__NOTE_HOLD__': 'fn note_hold(', '__BLOCKED_ON_SLOT_HEADROOM__': 'fn blocked_on_slot_headroom(', '__DESCRIPTOR_CONTAINMENT__': 'if encode::preserve_compute_descriptor(', '__PUBLISH_PRODUCER__': 'fn publish_producer(', From 6c6dac64f82aaad25641773819dbc53363f107c1 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Tue, 24 Nov 2026 07:35:47 -0500 Subject: [PATCH 7/7] drm/asahi: g16: repoll soon while a job waits behind its own flights When publish_checked() stops at a ready job, the poll repolls after repoll_us only if it set slot_wait or ta_wave_wait. A job held for any other reason waits for the next retirement poll. That is an EP 0x20 event, or the poll timer: rearm_us(false) is half the flight-duration EWMA clamped to resnap_us, so 100 us for renders longer than 200 us. An event for a stage that is not terminal is also not allowed to spin the receipt tail. A multi-pass render held this way behind its own earlier passes can therefore be published up to resnap_us after the retirement that frees it, with the GPU idle in between. Mark such holds held_wait when every flight belongs to the held job's VM and the cause is not a failure, a cross-VM overlap or a failed dependency. The job's own VM's retirements are then what releases it. held_wait is treated like the two existing flags: poll_step() repolls at repoll_us and keeps stage events eligible for the receipt tail, submit_locked() rearms soon, and busy coalescing does not hold behind it. publish_checked() clears it with them. A hold behind another VM's work keeps the existing cadence, so a long cross-VM drain does not repoll every few microseconds. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/engine.rs | 21 +++++- drivers/gpu/drm/asahi/g16/poll.rs | 17 +++-- .../drivers/gpu/asahi-m4/test-poll-retire.py | 65 ++++++++++++++++--- .../drivers/gpu/asahi-m4/test-publication.py | 35 ++++++---- 4 files changed, 112 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index a9457dd64ceba..e3074d55cabdd 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -654,6 +654,10 @@ pub(crate) struct Engine { /// An idle poll pass inside the housekeeping cadence skipped housekeeping: queue a backup /// poll so it runs once the cadence elapses. pub(crate) housekeeping_owed: bool, + /// A ready job is held behind flights that all belong to its own VM, for any cause but a + /// failure, a cross-VM overlap or a failed dependency: one of those flights retiring is + /// what releases it, so repoll soon instead of after `resnap_us`. + pub(crate) held_wait: bool, /// Absolute deadline (`ktime_get_ns`) for busy-state same-queue horizon micro-coalescing /// (0 when no batch is held). pub(crate) coalesce_deadline_ns: u64, @@ -702,6 +706,7 @@ impl Engine { ta_wave_wait: false, short_repoll: false, housekeeping_owed: false, + held_wait: false, coalesce_deadline_ns: 0, progress_flight: [0; 3], progress: [None; 4], @@ -1051,6 +1056,7 @@ impl Firmware { self.engine.chan_wait = false; self.engine.slot_wait = false; self.engine.ta_wave_wait = false; + self.engine.held_wait = false; self.engine.coalesce_deadline_ns = 0; while self.recovery.failed().is_none() && !self.engine.frozen @@ -1454,12 +1460,24 @@ impl Firmware { } } - /// Counts a publication pass that stopped at the ready `job` behind in-flight work. + /// Counts a publication pass that stopped at the ready `job` behind in-flight work, and + /// marks it [`Engine::held_wait`] when only its own VM's flights hold it. fn note_hold(&mut self, job: &Arc, drain: bool, ta_pending: usize) { let cause = self.hold_cause(job, drain, ta_pending); let s = &mut self.engine.stats; s.hold[0] += 1; s.hold_causes[cause as usize] += 1; + if !matches!( + cause, + HoldCause::DrainFailed | HoldCause::DrainCross | HoldCause::Dependency + ) && self + .engine + .flights + .iter() + .all(|f| Arc::ptr_eq(&f.job.vm, &job.vm)) + { + self.engine.held_wait = true; + } } /// Whether `job` is ready to run without an engine drain but currently blocked solely on @@ -1709,6 +1727,7 @@ impl Firmware { || self.engine.chan_wait || self.engine.slot_wait || self.engine.ta_wave_wait + || self.engine.held_wait || self .engine .flights diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 81728d7f5c595..43647519f2202 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -337,7 +337,9 @@ impl Shared { } else { let paced = !firmware.engine.frozen && !firmware.engine.pending.is_empty() - && (firmware.engine.slot_wait || firmware.engine.ta_wave_wait); + && (firmware.engine.slot_wait + || firmware.engine.ta_wave_wait + || firmware.engine.held_wait); self.rearm( firmware.engine.chan_wait || restored_event @@ -777,7 +779,8 @@ impl Firmware { published?; // A TA-only (0x70) EP 0x20 interrupt while FS is still running does not signal flight // retirement: avoid burning the receipt-tail spin or arming a short repoll storm for it, - // unless a render queue is actively waiting on TA wave headroom (`ta_wave_wait`). + // unless a render queue is actively waiting on TA wave headroom (`ta_wave_wait`) or a + // ready job waits behind its own VM's flights (`held_wait`). let non_terminal_only = !retired_any && term_before.is_some() && self.events.stage_events != stage_before @@ -785,7 +788,8 @@ impl Firmware { && !self.oldest_stamp_reached() && !self.recovery.receipt_fault && !recovery_pending - && !self.engine.ta_wave_wait; + && !self.engine.ta_wave_wait + && !self.engine.held_wait; // After an EP 0x20 event, retry up to `EVENT_RETIRE_POLLS` times (outside the device // lock) only while no flight has retired yet and flights remain in flight. Once any // flight retires, stop spinning so deeper queues do not burn tail waits per interrupt. @@ -811,13 +815,16 @@ impl Firmware { } // If a terminal EP 0x20 event arrived with flights outstanding and nothing retired within // the trailing polls, or a ready same-VM pending job is blocked on slot/flight/work-ring - // or TA-wave headroom, repoll at `repoll_us` instead of sleeping `resnap_us`. + // or TA-wave headroom, or held behind its own VM's flights, repoll at `repoll_us` + // instead of sleeping `resnap_us`. self.engine.short_repoll = !self.engine.flights.is_empty() && !self.engine.frozen && !non_terminal_only && ((evented && had_flights && !retired_any) || (!self.engine.pending.is_empty() - && (self.engine.slot_wait || self.engine.ta_wave_wait))); + && (self.engine.slot_wait + || self.engine.ta_wave_wait + || self.engine.held_wait))); Ok(!self.engine.flights.is_empty() || self.engine.chan_wait || self.recovery.needs_repoll() diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py index 789f95ed290c8..4634f0cc2bd0e 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-poll-retire.py @@ -164,6 +164,7 @@ def item(declaration, text=source): ta_wave_wait: bool, short_repoll: bool, housekeeping_owed: bool, + held_wait: bool, coalesce_deadline_ns: u64, frozen: bool, stats: Stats, @@ -328,7 +329,7 @@ def item(declaration, text=source): ta_pending: usize, ta_wave_cap: usize, coalesce_us: Option, - publish_waits: Option<(bool, bool)>, + publish_waits: Option<(bool, bool, bool)>, retire_calls: u32, publish_full_calls: u32, publish_checked_calls: u32, @@ -367,6 +368,7 @@ def item(declaration, text=source): ta_wave_wait: false, short_repoll: false, housekeeping_owed: false, + held_wait: false, coalesce_deadline_ns: 0, frozen: false, stats: Stats::default(), @@ -455,9 +457,10 @@ def item(declaration, text=source): } fn publish_checked(&mut self, _done: &mut Completions) -> Result { self.engine.coalesce_deadline_ns = 0; - if let Some((slot_wait, ta_wave_wait)) = self.publish_waits { + if let Some((slot_wait, ta_wave_wait, held_wait)) = self.publish_waits { self.engine.slot_wait = slot_wait; self.engine.ta_wave_wait = ta_wave_wait; + self.engine.held_wait = held_wait; } self.publish_checked_calls += 1; Ok(()) @@ -1044,6 +1047,49 @@ def item(declaration, text=source): assert!(!fw.engine.short_repoll); } +#[test] +fn held_wait_spins_stage_events_and_repolls_soon_until_a_retirement() { + CLOCK.with(|c| c.set(100_000)); + let mut fw = Firmware::new(); + fw.engine.flights.push(Flight { + computes: 0, + compute_pipe: 0, + renders: 2, + target: 0, + fs_target: 0x200, + }); + fw.engine.fs_target = 0x200; + fw.engine.pending.push(Arc::new(Job { id: 2 })); + fw.drain_stage_delta = 1; + let (mut retry_tail, mut deferred, mut done) = (false, false, vec![]); + // Nothing held: a stage-only event is non-terminal, with no tail spin and no short repoll. + assert!(fw + .poll_step(true, EVENT_RETIRE_POLLS, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert!(!retry_tail); + assert!(!fw.engine.short_repoll); + // A ready job held behind its own VM's flights spins the receipt tail on the same event... + fw.engine.held_wait = true; + assert!(fw + .poll_step(true, EVENT_RETIRE_POLLS, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert!(retry_tail); + // ...and a timer pass repolls at repoll_us while the hold lasts, without publishing. + retry_tail = false; + fw.drain_stage_delta = 0; + assert!(fw + .poll_step(false, 0, &mut retry_tail, &mut deferred, &mut done) + .unwrap()); + assert!(fw.engine.short_repoll); + assert_eq!(fw.publish_checked_calls, 0); + // The retirement that can release it reaches publish_checked(). + fw.retire_on_call = true; + let _ = fw + .poll_step(false, 0, &mut retry_tail, &mut deferred, &mut done) + .unwrap(); + assert_eq!(fw.publish_checked_calls, 1); +} + #[test] fn ta_only_irq_wakes_ta_wave_wait_with_hysteresis_and_short_repoll() { CLOCK.with(|c| c.set(100_000)); @@ -1120,11 +1166,12 @@ def item(declaration, text=source): // publish_checked() leaves a ready job on TA wave or slot headroom: SUBMIT arms the same // short repoll poll_step() arms for it, unless the engine is frozen. CLOCK.with(|c| c.set(100_000)); - for (slot_wait, ta_wave_wait, frozen, soon) in [ - (false, false, false, 0), - (true, false, false, 1), - (false, true, false, 1), - (false, true, true, 0), + for (slot_wait, ta_wave_wait, held_wait, frozen, soon) in [ + (false, false, false, false, 0), + (true, false, false, false, 1), + (false, true, false, false, 1), + (false, false, true, false, 1), + (false, true, false, true, 0), ] { let shared = Shared::new(); let mut fw = Firmware::new(); @@ -1138,7 +1185,7 @@ def item(declaration, text=source): }); fw.engine.fs_target = 0x100; fw.engine.frozen = frozen; - fw.publish_waits = Some((slot_wait, ta_wave_wait)); + fw.publish_waits = Some((slot_wait, ta_wave_wait, held_wait)); let mut done = vec![]; shared .submit_locked(&mut fw, Arc::new(Job { id: 2 }), &mut done) @@ -1803,7 +1850,7 @@ def item(declaration, text=source): json.dumps( { 'passed': True, - 'tests': 24, + 'tests': 25, 'cpu_only': True, 'hardware_execution': False, 'scope': 'Verbatim production submit_locked inline retirement and poll_step TA-only non-spin logic.', diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index b1f06cacd4d00..3cc505d49350b 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -141,7 +141,7 @@ def item(declaration): struct Flight{job:Arc,claims:Claims,group:Vec>,computes:u32,renders:u32,compute_pipe:u8,rt_compute:bool,doomed:bool,recovery_suspect:bool,initbm:bool,heavy_render:bool} impl Flight{fn new(job:Arc)->Self{Self{job,claims:Claims,group:vec![],computes:0,renders:0,compute_pipe:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false,heavy_render:false}}} __SCS_COMPUTE_CONFLICT__ -struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,ta_wave_wait:bool,coalesce_deadline_ns:u64} +struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,ta_wave_wait:bool,held_wait:bool,coalesce_deadline_ns:u64} impl Engine { __PICK__ __UNPEND__ @@ -316,7 +316,7 @@ def item(declaration): } fn firmware(jobs:Vec>,stages:Vec<(Result,bool)>)->Firmware{ Firmware{session:Session{shared:Shared{sleeping:AtomicBool::new(false)},rings:vec![],ring_fail:false,checks:AtomicU32::new(0),transports:AtomicU32::new(0)},objects:Checks,recovery:Recovery{error:None,publication_wait_deadline:None}, - engine:Engine{ordinal:0,draw:0,pending:jobs,flights:vec![],frozen:false,turn:0,stats:Stats::default(),chan_wait:false,slot_wait:false,ta_wave_wait:false,coalesce_deadline_ns:0}, + engine:Engine{ordinal:0,draw:0,pending:jobs,flights:vec![],frozen:false,turn:0,stats:Stats::default(),chan_wait:false,slot_wait:false,ta_wave_wait:false,held_wait:false,coalesce_deadline_ns:0}, slots:Slots{compute_exhausted:false,render_exhausted:false,releases:0,quarantines:0},pools:Pools{exhausted:false,exhausted_vm:None,block_pipeline_vm:None},power:Power::default(), unavailable:vec![],stages:stages.into_iter().map(|(result,visible)|Stage{result,visible}).collect(), retained:vec![],attempted:vec![],fail_stops:0,allow_behind:false,block_render_behind:false,block_compute_behind:false, @@ -511,7 +511,8 @@ def item(declaration): // One held publication pass per case: (in-flight job and kind, its flags, held job, // host knobs) -> exactly one hold[0] of the expected cause. let run=|flight:Arc,renders:u32,initbm:bool,doomed:bool,held:Arc, - allow_behind:bool,block_pipeline:Option,block_render:bool,expect:HoldCause|{ + allow_behind:bool,block_pipeline:Option,block_render:bool,expect:HoldCause, + held_wait:bool|{ let mut f=firmware(vec![held],vec![]); let mut fl=Flight::new(flight); if renders==0{fl.computes=1;}else{fl.renders=renders;} @@ -528,24 +529,28 @@ def item(declaration): let mut want=[0u64;HoldCause::COUNT]; want[expect as usize]=1; assert_eq!(f.engine.stats.hold_causes,want,"{:?}",expect); + // Only a hold behind the job's own VM's flights asks for the short repoll. + assert_eq!(f.engine.held_wait,held_wait,"{:?}",expect); }; let r=|id:u32,vm:&Arc,dep:Result|job_on_vm(id,vm.clone(),true,0,dep); // A warm same-VM render whose allocator cannot pipeline waits for an empty engine. - run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,Some(vm1.slot),false,HoldCause::DrainPb); + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,Some(vm1.slot),false,HoldCause::DrainPb,true); // A cold InitBM flight drains first. - run(r(1,&vm1,Ok(())),1,true,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainInitbm); + run(r(1,&vm1,Ok(())),1,true,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainInitbm,true); // Another VM's compute in flight: no cross-VM render/compute overlap. - run(job_on_vm(1,vm2.clone(),false,0,Ok(())),0,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainCross); + run(job_on_vm(1,vm2.clone(),false,0,Ok(())),0,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainCross,false); // A doomed flight drains first. - run(r(1,&vm1,Ok(())),1,false,true,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainFailed); + run(r(1,&vm1,Ok(())),1,false,true,r(2,&vm1,Ok(())),true,None,false,HoldCause::DrainFailed,false); // A full light TA wave (8 renders) pauses the next light render. - run(r(1,&vm1,Ok(())),8,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::TaWave); + run(r(1,&vm1,Ok(())),8,false,false,r(2,&vm1,Ok(())),true,None,false,HoldCause::TaWave,true); // Pass, flight or unit headroom. - run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,None,true,HoldCause::Slot); + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),true,None,true,HoldCause::Slot,true); // A failed dependency (pick() skips jobs still waiting for one). - run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Err(ECANCELED)),false,None,false,HoldCause::Dependency); + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Err(ECANCELED)),false,None,false,HoldCause::Dependency,false); // Any other refusal. - run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),false,None,false,HoldCause::Other); + run(r(1,&vm1,Ok(())),1,false,false,r(2,&vm1,Ok(())),false,None,false,HoldCause::Other,true); + // Behind another VM's render (warm cross-VM renders overlap): counted, but no short repoll. + run(r(1,&vm2,Ok(())),1,false,false,r(2,&vm1,Ok(())),false,None,false,HoldCause::Other,false); assert_eq!(HoldCause::NAMES.len(),HoldCause::COUNT); assert_eq!(HoldCause::Other as usize,HoldCause::COUNT-1); } @@ -2718,6 +2723,7 @@ def item(declaration): chan_wait: bool, slot_wait: bool, ta_wave_wait: bool, + held_wait: bool, coalesce_deadline_ns: u64, } struct Slots { free_c: u32 } @@ -2771,6 +2777,7 @@ def item(declaration): chan_wait: false, slot_wait: false, ta_wave_wait: false, + held_wait: false, coalesce_deadline_ns: 0, }, slots: Slots { free_c: 20 }, @@ -2795,6 +2802,12 @@ def item(declaration): assert_eq!(h.defer_busy_coalesce(110_000), None); assert_eq!(h.engine.coalesce_deadline_ns, 0); + // A job held behind the VM's own flights is never coalesced behind them. + h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; + h.engine.held_wait = true; + assert_eq!(h.defer_busy_coalesce(150_000), None); + h.engine.held_wait = false; + // Deadline expiry flushes even with 1 pending command. h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; assert_eq!(h.defer_busy_coalesce(200_000), Some(18));