diff --git a/drivers/gpu/drm/asahi/g16/encode/render.rs b/drivers/gpu/drm/asahi/g16/encode/render.rs index 7212a2b501e9b..c99386668bab4 100644 --- a/drivers/gpu/drm/asahi/g16/encode/render.rs +++ b/drivers/gpu/drm/asahi/g16/encode/render.rs @@ -37,6 +37,8 @@ pub(crate) struct RenderRefs { pub(crate) uma_submitted: u64, pub(crate) uuid: u32, pub(crate) usc_base: u64, + /// `[TA, FS]` completion events of the render's queue pair (`work::render_pair::events`). + pub(crate) event: [u32; 2], } /// Addresses retained for one render pass. @@ -149,7 +151,7 @@ fn metadata(w: &mut [u8], off: usize, r: &RenderRefs, engine: usize, target: u32 put64(w, off, r.user_stamp[engine]); put64(w, off + 8, r.fw_stamp[engine]); put32(w, off + 0x10, target); - put32(w, off + 0x14, 0x70 + engine as u32); + put32(w, off + 0x14, r.event[engine]); put32(w, off + 0x1c, 1); put32(w, off + 0x20, r.uuid); // Wire sequence stays zero; host reservations are 64-bit notifier state. @@ -163,7 +165,7 @@ fn inline_uma(q: &mut [u8], off: usize, r: &RenderRefs, engine: usize, engine_by r.uma_gpu + if engine == 0 { 0x100 } else { 0x200 }, ); put64(q, off + 0x28, r.counter[engine]); - put32(q, off + 0x30, 0x70 + engine as u32); + put32(q, off + 0x30, r.event[engine]); if engine_byte { put8(q, off + 0x34, engine as u8); } @@ -452,7 +454,7 @@ pub(crate) fn encode_ta_rt( put64(w, ta::TPC_BYTES, geo.tpc_bytes); put64(w, 0x770, p.ta_seq); put32(w, 0x778, ta::SEQ_SIZE as u32); - put32(w, 0x77c, 0x71); + put32(w, 0x77c, r.event[1]); put32(w, 0x780, target); put64(w, 0x7a8, compact(p.pre_gva[0])); metadata(w, 0x878, r, 0, target); @@ -890,12 +892,12 @@ pub(crate) fn encode_fs_rt( put32(q, f + 0xa0, 0u32.wrapping_sub(f as u32)); put64(q, f + 0xa5, work + layout.completion as u64); if layout.compact_finalize { - put32(q, f + 0xad, 0x71); + put32(q, f + 0xad, r.event[1]); put32(q, f + 0xb4, work::op::END); } else { put32(q, f + 0xad, 1); put8(q, f + 0xb1, 1); - put32(q, f + 0xb2, 0x71); + put32(q, f + 0xb2, r.event[1]); put32(q, f + 0xbc, work::op::END); } } @@ -977,7 +979,7 @@ pub(crate) fn scene_prefix(r: &RenderRefs, ctx: u32, target: u32, init: bool) -> &barrier( r.fw_stamp[0], target, - 0x70, + r.event[0], target, 0, work::BarrierType::Stamp, @@ -1005,7 +1007,7 @@ pub(crate) fn scene_render( &barrier( r.fw_stamp[0], target, - 0x70, + r.event[0], target, 0, work::BarrierType::Stamp, diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index d96e24b6d851a..a4d0bce1fd9be 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -142,6 +142,9 @@ struct WaitTarget { stamp: u32, /// True if the waited producer flight carries `InitBM` (buffer-manager initialization). initbm: bool, + /// Render queue pair of a waited render (0 for compute): an `fs2c` barrier waits on that + /// pair's FS stamp and event. + pair: u8, } /// Selects the hardware ring barrier type for a same-VM handoff. @@ -175,19 +178,23 @@ fn scs_compute_conflict(f: &Flight, vm: &Arc, scs: bool) -> f.computes != 0 && (f.rt_compute != scs || (scs && !Arc::ptr_eq(&f.job.vm, vm))) } -/// Whether a render of `vm` must wait for flight `f` to retire before it is published. +/// Whether a render of `vm` on render queue pair `pair` must wait for flight `f` of another VM +/// to retire before it is published. /// -/// Every VM's render passes share the one firmware TA/FS queue pair. While passes of two VMs -/// are both published there, the GPU faults in the VM whose pass runs (linux#3201): its VDM -/// reads the pass slot's kernel prefix and its control stream, and its shader cores read -/// from a null base, at addresses that are not mapped in its context. Multisampled passes -/// also lose coverage and their fragment shaders read VA 0. Ordering the two passes' TA and -/// FS with ring barriers does not prevent it; publishing one only after the other retired -/// does. A render of another VM also never runs beside compute, so a long compute dispatch -/// cannot starve its fragment shading into a firmware DM1 timeout. Renders of one VM still -/// share the queues. -fn cross_vm_render_conflict(f: &Flight, vm: &Arc) -> bool { +/// While render passes of two VMs are both published on one firmware TA/FS queue pair, the GPU +/// faults in the VM whose pass runs (linux#3201): its VDM reads the pass slot's kernel prefix +/// and its control stream, and its shader cores read from a null base, at addresses that are +/// not mapped in its context. Multisampled passes also lose coverage and their fragment +/// shaders read VA 0. Ordering the two passes' TA and FS with ring barriers does not prevent +/// it; publishing one only after the other retired does. Renders of different VMs on different +/// pairs run cleanly side by side. macOS 26B123 likewise gives every Metal process its own TA +/// and FS queue, each with its own job-list entry, all rung through one doorbell. +/// +/// A render of another VM also never runs beside compute, so a long compute dispatch cannot +/// starve its fragment shading into a firmware DM1 timeout. +fn cross_vm_render_conflict(f: &Flight, vm: &Arc, pair: usize) -> bool { !Arc::ptr_eq(&f.job.vm, vm) + && (f.computes != 0 || (f.renders != 0 && f.render_pair as usize == pair)) } /// Resolved ring-barrier placement for one render pass (legacy, `FRAGMENT_BARRIERS`, or @@ -297,6 +304,8 @@ pub(crate) struct Flight { pub(crate) renders: u32, /// Compute pipe (`0..COMPUTE_PIPES`) this flight was published to. pub(crate) compute_pipe: u8, + /// Render queue pair (`0..RENDER_PAIRS`) this flight was published to. + pub(crate) render_pair: u8, /// Compute: final FW stamp, ring end (exclusive) and ring position before the prefix. pub(crate) target: u32, pub(crate) head: u32, @@ -313,6 +322,9 @@ pub(crate) struct Flight { /// Whether `Channel::Compute` read and completion cursors already passed `rec[2]` before /// the shared submit ring could wrap past this flight. pub(crate) chan_settled: bool, + /// Whether `Channel::Ta` / `Channel::Fs` read and completion cursors already passed + /// `rec[0]` / `rec[1]` before another render pair's records could lap them. + pub(crate) render_chan_settled: [bool; 2], /// Compute member j's FW stamp target, the FS target it waits on directly (0: none), and /// its private UMA counter value after publication. pub(crate) cstamp: [u32; sizes::COMPUTE_SLOTS], @@ -342,8 +354,10 @@ pub(crate) struct Flight { pub(crate) pb: Option>, /// Its allocator slot (`0` or `1`, decoupled from `claims.pass[0]`). pub(crate) pb_slot: u32, - /// Its allocator slot binding (`Pools::bind`). + /// Its allocator slot binding (`Pools::bind`) and publication sequence + /// (`Pools::publish_flight`). pub(crate) pb_binding: u64, + pub(crate) pb_seq: u64, /// Whether this render carries InitBM (priming renders always drain before pipelining). pub(crate) initbm: bool, /// Whether this flight publishes CPU-written command timestamps on retirement. @@ -362,6 +376,7 @@ impl Flight { computes: 0, renders: 0, compute_pipe: 0, + render_pair: 0, target: 0, head: 0, c_start: 0, @@ -373,6 +388,7 @@ impl Flight { fs_start: 0, rec: [0; 3], chan_settled: false, + render_chan_settled: [false; 2], cstamp: [0; sizes::COMPUTE_SLOTS], cwait: [0; sizes::COMPUTE_SLOTS], csubmitted: [0; sizes::COMPUTE_SLOTS], @@ -390,6 +406,7 @@ impl Flight { pb: None, pb_slot: 0, pb_binding: 0, + pb_seq: 0, initbm: false, has_timestamps: false, rt_compute: false, @@ -405,16 +422,20 @@ struct Prefix { computes: u32, renders: u32, compute_pipe: usize, + /// Render queue pair of a render prefix. + render_pair: usize, prev: Prev, /// This prefix (re)initializes the PB with InitBM. initbm: bool, c_head: u32, ta_head: u32, fs_head: u32, - /// Last total compute ordinal, per-pipe compute ordinal, and draw ordinal. + /// Last total compute ordinal, per-pipe compute ordinal, draw ordinal, and the render + /// pair's dense draw ordinal (its stamps and thresholds). n: u64, pipe_n: u64, draw: u64, + pair_draw: u64, last_ct: u32, last_ta: u32, last_fs: u32, @@ -438,7 +459,7 @@ pub(crate) enum HoldCause { DrainFailed, /// A cold `InitBM` render is in flight. DrainInitbm, - /// Compute behind render of another VM, render behind any flight of another VM, or an SCS + /// Compute behind render of another VM, render behind compute of another VM, or an SCS /// compute conflict. DrainCross, /// No warm PB/UMA allocator slot of the VM can take the render behind active flights. @@ -521,6 +542,10 @@ pub(crate) struct Stats { pub(crate) behind: u64, /// Most flights in flight at once. pub(crate) max_flights: u64, + /// Render prefixes published per render pair, and those published while another VM's + /// renders were in flight on another pair (`render_pairs:` in `aurora-g16/stats`). + pub(crate) render_pair_publications: [u64; sizes::RENDER_PAIRS], + pub(crate) cross_pair_renders: u64, } /// Host-side phase timers of publication and polling, on with `debug_flags` bit 49 @@ -624,17 +649,19 @@ pub(crate) struct Engine { /// flight (`[start, end, 0, 0]` for compute; `[ta_start, ta_end, fs_start, fs_end]` for /// render), reused by accounting without re-reading WC cells. pub(crate) retired_ticks: [u64; 4], - /// Host compute ordinal, per-pipe compute ordinals, and draw ordinal of the last publication. + /// Host compute ordinal, per-pipe compute ordinals, draw ordinal and per-render-pair draw + /// ordinals of the last publication. pub(crate) ordinal: u64, pub(crate) pipe_ordinal: [u64; sizes::COMPUTE_PIPES], pub(crate) draw: u64, - /// Newest published receipts, the tail. + pub(crate) pair_draw: [u64; sizes::RENDER_PAIRS], + /// Newest published receipts, the tail (per compute pipe, per render pair). pub(crate) target: [u32; sizes::COMPUTE_PIPES], pub(crate) head: [u32; sizes::COMPUTE_PIPES], - pub(crate) ta_target: u32, - pub(crate) fs_target: u32, - pub(crate) ta_head: u32, - pub(crate) fs_head: u32, + pub(crate) ta_target: [u32; sizes::RENDER_PAIRS], + pub(crate) fs_target: [u32; sizes::RENDER_PAIRS], + pub(crate) ta_head: [u32; sizes::RENDER_PAIRS], + pub(crate) fs_head: [u32; sizes::RENDER_PAIRS], /// Event counts at the tail's publication. pub(crate) events: u32, pub(crate) stage_seen: u32, @@ -649,8 +676,15 @@ pub(crate) struct Engine { /// Transient bitmask of compute pipes being drained for handoff to a waiting job that has /// no eligible pipe (e.g. a base-only VM limited to pipe 0). pub(crate) handoff_avoid_pipes: u32, - pub(crate) render_registered: bool, - pub(crate) ta_registered: bool, + /// Transient bitmask of render pairs being drained for handoff to a waiting render whose VM + /// finds every pair holding another VM's renders ([`Firmware::render_handoff_pair`]). + pub(crate) handoff_avoid_pairs: u8, + /// Per TTBAT slot, the render pair of its VM's newest render (`u8::MAX`: none), which the + /// VM takes again when it is free. + pub(crate) vm_pair: [u8; sizes::MAX_VMS as usize + 1], + /// The FS / TA queues of each render pair were registered by a first record. + pub(crate) render_registered: [bool; sizes::RENDER_PAIRS], + pub(crate) ta_registered: [bool; sizes::RENDER_PAIRS], /// A ready prefix waits only for a record's consumption: repoll sooner. pub(crate) chan_wait: bool, /// A ready same-VM pending job is blocked solely on flight, pass/compute slot, or work-ring @@ -669,9 +703,10 @@ pub(crate) struct Engine { /// 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 pipes `0..COMPUTE_PIPES` and render flights. - pub(crate) progress_flight: [u64; sizes::COMPUTE_PIPES + 1], - pub(crate) progress: [Option; sizes::COMPUTE_PIPES + 2], + /// Progress tracking of the oldest flights of compute pipes `0..COMPUTE_PIPES` and of each + /// render pair (`COMPUTE_PIPES + pair`; stages `COMPUTE_PIPES + 2 * pair + {0, 1}`). + pub(crate) progress_flight: [u64; sizes::COMPUTE_PIPES + sizes::RENDER_PAIRS], + pub(crate) progress: [Option; sizes::COMPUTE_PIPES + 2 * sizes::RENDER_PAIRS], /// Boxed with [`Self::prof`]: `Firmware` is built on the probe's stack. pub(crate) stats: KBox, /// Phase timers (debug_flags bit 49). @@ -697,12 +732,13 @@ impl Engine { ordinal: 0, pipe_ordinal: [0; sizes::COMPUTE_PIPES], draw: 0, + pair_draw: [0; sizes::RENDER_PAIRS], target: [0; sizes::COMPUTE_PIPES], head: [0; sizes::COMPUTE_PIPES], - ta_target: 0, - fs_target: 0, - ta_head: 0, - fs_head: 0, + ta_target: [0; sizes::RENDER_PAIRS], + fs_target: [0; sizes::RENDER_PAIRS], + ta_head: [0; sizes::RENDER_PAIRS], + fs_head: [0; sizes::RENDER_PAIRS], events: 0, stage_seen: 0, queue_registered: [false; sizes::COMPUTE_PIPES], @@ -711,16 +747,18 @@ impl Engine { pipe_last_used: [0; sizes::COMPUTE_PIPES], pipe_use_seq: 0, handoff_avoid_pipes: 0, - render_registered: false, - ta_registered: false, + handoff_avoid_pairs: 0, + vm_pair: [u8::MAX; sizes::MAX_VMS as usize + 1], + render_registered: [false; sizes::RENDER_PAIRS], + ta_registered: [false; sizes::RENDER_PAIRS], chan_wait: false, slot_wait: false, short_repoll: false, housekeeping_owed: false, held_wait: false, coalesce_deadline_ns: 0, - progress_flight: [0; sizes::COMPUTE_PIPES + 1], - progress: [None; sizes::COMPUTE_PIPES + 2], + progress_flight: [0; sizes::COMPUTE_PIPES + sizes::RENDER_PAIRS], + progress: [None; sizes::COMPUTE_PIPES + 2 * sizes::RENDER_PAIRS], stats: KBox::zeroed(GFP_KERNEL)?, prof: KBox::zeroed(GFP_KERNEL)?, debugfs: None, @@ -735,6 +773,21 @@ impl Engine { self.flights.first() } + /// The render pair of `vm`'s newest render, if any. + pub(crate) fn render_pair_hint(&self, vm: &super::vm::VmState) -> Option { + self.vm_pair + .get(vm.slot as usize) + .map(|&pair| pair as usize) + .filter(|&pair| pair < sizes::RENDER_PAIRS) + } + + /// `vm` published a render on `pair`. + fn note_render_pair(&mut self, vm: &super::vm::VmState, pair: usize) { + if let Some(entry) = self.vm_pair.get_mut(vm.slot as usize) { + *entry = pair as u8; + } + } + /// Jobs of the queue in published prefixes. fn queue_published(&self, job: &Job) -> u32 { self.flights @@ -799,7 +852,8 @@ impl Firmware { /// Registers the one shared scheduling context using the proven queue-0 zero-stamp /// barrier before any shader work or user ASID is published (exec-runtime.h contract). pub(crate) fn register_context(&mut self) -> Result { - let r = &self.graph.render; + // The shared scheduling context registers through render pair 0's TA queue. + let r = &self.graph.render[0]; let barrier = &r.registration_barrier; let zero = r.legacy_empty.va; let mut bytes = [0u8; work::barrier::SIZE]; @@ -840,15 +894,15 @@ impl Firmware { if now >= deadline { return Err(ETIMEDOUT); } - let context = self.graph.render.sched_ctx.r32(0)?; + let context = self.graph.render[0].sched_ctx.r32(0)?; let registered = context & 0xff != 0xff && (context >> 8) & 0xff != 0xff && (context >> 16) & 0xff == 4; if registered && self.queue_receipt( Channel::Ta, - &self.graph.render.qstate[0], - &self.graph.render.qinfo[0], + &self.graph.render[0].qstate[0], + &self.graph.render[0].qinfo[0], 1, 1, )? @@ -869,17 +923,19 @@ impl Firmware { ) }; } - self.engine.ta_head = 1; - self.engine.ta_registered = true; + self.engine.ta_head[0] = 1; + self.engine.ta_registered[0] = true; Ok(()) } /// The single in-order Finalize frontier for each held M4 event. These cells are never /// reset after first publication, including across client VM switches and recovery. - pub(crate) fn recovery_snapshot(&self) -> Result<[u32; 2 + sizes::COMPUTE_PIPES]> { - let mut stage = [0u32; 2 + sizes::COMPUTE_PIPES]; - stage[0] = self.graph.render.fw_stamp[0].r32(0)?; - stage[1] = self.graph.render.fw_stamp[1].r32(0)?; + pub(crate) fn recovery_snapshot(&self) -> Result<[u32; sizes::STAGES]> { + let mut stage = [0u32; sizes::STAGES]; + for (pair, render) in self.graph.render.iter().enumerate() { + stage[sizes::render_stage(pair, 0)] = render.fw_stamp[0].r32(0)?; + stage[sizes::render_stage(pair, 1)] = render.fw_stamp[1].r32(0)?; + } for (p, compute) in self.graph.compute.iter().enumerate() { stage[2 + p] = compute.fw_stamp.r32(0)?; } @@ -893,7 +949,7 @@ impl Firmware { flags: u32, event: u32, target: u32, - stage: [u32; 2 + sizes::COMPUTE_PIPES], + stage: [u32; sizes::STAGES], ) -> Result { if flags & 1 != 0 && self.recovery.last_retired.contains(event, target) { // A notification may follow the full receipt. It names the retained old @@ -902,22 +958,26 @@ impl Firmware { } // The named owner: the oldest flight, or with compute/render queued behind it a later one. let compute_pipe = work::compute::pipe_of_event(event); + // Render pairs number their stamps densely, so only flights of the event's pair match. + let render = work::render_pair::of_event(event); let f = self .engine .flights .iter_mut() - .find(|f| match event { - 0x70 => { + .find(|f| match render { + Some((pair, 0)) => { f.renders != 0 + && f.render_pair as usize == pair && f.r_ta_stamp[..(f.renders as usize).min(f.r_ta_stamp.len())] .contains(&target) } - 0x71 => { + Some((pair, _)) => { f.renders != 0 + && f.render_pair as usize == pair && f.r_fs_stamp[..(f.renders as usize).min(f.r_fs_stamp.len())] .contains(&target) } - _ => compute_pipe.is_some_and(|pipe| { + None => compute_pipe.is_some_and(|pipe| { f.computes != 0 && f.compute_pipe as usize == pipe && f.cstamp[..(f.computes as usize).min(f.cstamp.len())].contains(&target) @@ -929,9 +989,14 @@ impl Firmware { } if flags & 9 == 9 && f.renders != 0 { let mut cleaned = false; + let pair = (f.render_pair as usize).min(sizes::RENDER_PAIRS - 1); let count = (f.renders as usize).min(f.r_ta_stamp.len()); for m in 0..count { - if super::poll::stamp_reached(stage[0], f.r_ta_stamp[m], self.engine.ta_target) { + if super::poll::stamp_reached( + stage[sizes::render_stage(pair, 0)], + f.r_ta_stamp[m], + self.engine.ta_target[pair], + ) { continue; } let k = f.claims.pass[m] as usize; @@ -959,7 +1024,7 @@ impl Firmware { /// in the snapshot. Keep it until either its full receipt or its passed-abort proof. pub(crate) fn recovery_prepare_suspects( &mut self, - stage: [u32; 2 + sizes::COMPUTE_PIPES], + stage: [u32; sizes::STAGES], _event: u32, fault_asid: Option, ) -> Result { @@ -972,10 +1037,18 @@ impl Firmware { // Every unfinished flight, including compute queued behind the oldest on either pipe. for f in self.engine.flights.iter_mut() { let pipe = (f.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); + let pair = (f.render_pair as usize).min(sizes::RENDER_PAIRS - 1); let unfinished = (f.computes != 0 && !reached(stage[2 + pipe], f.target, target[pipe])) || (f.renders != 0 - && (!reached(stage[0], f.ta_target, ta_target) - || !reached(stage[1], f.fs_target, fs_target))); + && (!reached( + stage[sizes::render_stage(pair, 0)], + f.ta_target, + ta_target[pair], + ) || !reached( + stage[sizes::render_stage(pair, 1)], + f.fs_target, + fs_target[pair], + ))); if unfinished { f.recovery_suspect = true; f.recovery_started_ns = now_ns(); @@ -1064,12 +1137,14 @@ impl Firmware { self.engine.slot_wait = false; self.engine.held_wait = false; self.engine.handoff_avoid_pipes = 0; + self.engine.handoff_avoid_pairs = 0; self.engine.coalesce_deadline_ns = 0; while self.recovery.failed().is_none() && !self.engine.frozen && !self.engine.pending.is_empty() { self.engine.handoff_avoid_pipes = 0; + self.engine.handoff_avoid_pairs = 0; let Some(index) = self.engine.pick() else { break; }; @@ -1094,6 +1169,10 @@ impl Firmware { self.engine.handoff_avoid_pipes = self .compute_handoff_pipe(&job) .map_or(0, |pipe| 1u32 << pipe); + // Likewise, when every render pair holds another VM's renders, let the least + // loaded pair drain for this render's VM while the other pairs keep going. + self.engine.handoff_avoid_pairs = + self.render_handoff_pair(&job).map_or(0, |pair| 1u8 << pair); let mut alt: Option = None; for (i, cand) in self.engine.pending.iter().enumerate() { // `Engine::pick` chose the earliest pending job of `job.queue`, so later @@ -1130,6 +1209,7 @@ impl Firmware { Some(i) => job = self.engine.pending[i].clone(), None => { self.engine.handoff_avoid_pipes = 0; + self.engine.handoff_avoid_pairs = 0; self.engine.slot_wait = self .engine .pending @@ -1219,6 +1299,7 @@ impl Firmware { Ok(()) => {} Err(e) if e == EAGAIN => { self.engine.handoff_avoid_pipes = 0; + self.engine.handoff_avoid_pairs = 0; break; } Err(e) => { @@ -1230,6 +1311,7 @@ impl Firmware { } let pub_res = self.publish_prefix(&job, done, &mut pending_rings); self.engine.handoff_avoid_pipes = 0; + self.engine.handoff_avoid_pairs = 0; match pub_res { Ok(()) => { self.engine.turn += 1; @@ -1342,6 +1424,52 @@ impl Firmware { Ok(()) } + /// The render queue pair of `vm`'s next render: the pair of its renders in flight; + /// otherwise its last pair if free, else the lowest free pair; `None` while every pair holds + /// another VM's renders or drains for a handoff. One VM's renders never use two pairs at + /// once, so its render waits stay within one in-order pair. + pub(crate) fn render_pair_for(&self, vm: &Arc) -> Option { + let flights = &self.engine.flights; + if let Some(f) = flights + .iter() + .find(|f| f.renders != 0 && Arc::ptr_eq(&f.job.vm, vm)) + { + return Some(f.render_pair as usize); + } + let avoid = self.engine.handoff_avoid_pairs; + let free = |pair: usize| { + avoid & (1u8 << pair) == 0 + && !flights + .iter() + .any(|f| f.renders != 0 && f.render_pair as usize == pair) + }; + self.engine + .render_pair_hint(vm) + .filter(|&pair| free(pair)) + .or_else(|| (0..sizes::RENDER_PAIRS).find(|&pair| free(pair))) + } + + /// When the ready render `job` finds every render pair holding another VM's renders, the + /// pair to drain for it, as [`Self::compute_handoff_pipe`] drains a compute pipe: the one + /// with the fewest render passes in flight. Its VM publishes nothing more there meanwhile. + fn render_handoff_pair(&self, job: &Arc) -> Option { + let sent = job.progress.sent(); + if !matches!(command(job, sent), Some(Command::Render(_))) + || job.vm.status.get() != 0 + || job.check_command_dependencies(sent).is_err() + || self.render_pair_for(&job.vm).is_some() + { + return None; + } + let mut load = [0usize; sizes::RENDER_PAIRS]; + for f in &self.engine.flights { + if f.renders != 0 { + load[(f.render_pair as usize).min(sizes::RENDER_PAIRS - 1)] += f.renders as usize; + } + } + (0..sizes::RENDER_PAIRS).min_by_key(|&pair| load[pair]) + } + /// Whether `job` requires `self.engine.flights` to drain to empty before it can /// publish (so `alt`-class bypass must not keep refilling the engine ahead of it). fn needs_engine_drain(&self, job: &Arc) -> bool { @@ -1357,7 +1485,7 @@ impl Firmware { || f.recovery_suspect || f.initbm || (is_compute && scs_compute_conflict(f, &job.vm, is_rt_compute)) - || (is_render && cross_vm_render_conflict(f, &job.vm)) + || (is_render && f.computes != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm)) || (is_compute && f.renders != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm)) }) || (is_render && !self.render_can_pipeline(job)) @@ -1486,7 +1614,8 @@ impl Firmware { /// while reusing that VM's warm PB/UMA allocator slot (`Pools::can_pipeline_within`, /// each owning its own hardware UMA slot `RENDER_UMA_SLOT + slot`). Hardware barriers on /// the CDM/TA/FS rings preserve exact same-engine and cross-engine ordering. A render - /// never queues behind a flight of another VM ([`cross_vm_render_conflict`]). + /// queues behind renders of another VM only on another render pair + /// ([`cross_vm_render_conflict`], [`Self::render_pair_for`]). /// - Compute never queues behind a render of another VM either, so a long compute /// dispatch from one client cannot starve another client's fragment shading into a /// firmware DM1 timeout. Cold InitBM priming renders and every failure or recovery path @@ -1575,10 +1704,13 @@ impl Firmware { .is_ok_and(|mask| self.has_compute_pipe_for_vm(&job.vm, mask, scs)) } Some(Command::Render(_)) => { - let cross_vm = e - .flights - .iter() - .any(|f| cross_vm_render_conflict(f, &job.vm)); + let Some(pair) = self.render_pair_for(&job.vm) else { + return false; + }; + let cross_vm = e.handoff_avoid_pairs & (1u8 << pair) != 0 + || e.flights + .iter() + .any(|f| cross_vm_render_conflict(f, &job.vm, pair)); let render_count: usize = e.flights.iter().map(|f| f.renders as usize).sum(); !cross_vm && render_count < params::render_flights() @@ -1879,6 +2011,7 @@ impl Firmware { *newest = Some(WaitTarget { stamp, initbm: flight.initbm, + pair: flight.render_pair, }); } } @@ -1904,6 +2037,7 @@ impl Firmware { *newest = Some(WaitTarget { stamp, initbm: flight.initbm, + pair: flight.render_pair, }); } } @@ -2023,6 +2157,7 @@ impl Firmware { waits[pipe] = Some(WaitTarget { stamp: *flight.cstamp.get(member).ok_or(EAGAIN)?, initbm: flight.initbm, + pair: 0, }); } } @@ -2046,6 +2181,7 @@ impl Firmware { waits[pipe] = Some(WaitTarget { stamp: *flight.cstamp.get(member).ok_or(EAGAIN)?, initbm: flight.initbm, + pair: 0, }); } } @@ -2405,6 +2541,7 @@ impl Firmware { alloc_slot: usize, job: &Job, draw: u64, + pair: usize, render_pipelined: bool, engine_behind: bool, ) -> Result<(RenderRefs, bool, Arc, u64)> { @@ -2451,7 +2588,7 @@ impl Firmware { let binding = self.pools.bind(alloc_slot, reused); a.pb_mgr = epoch.manager.va; a.mgr_misc = epoch.misc.va; - let r = &self.graph.render; + let r = self.graph.render.get(pair).ok_or(EINVAL)?; let stage = draw.checked_mul(2).ok_or(EOVERFLOW)?; Ok(( RenderRefs { @@ -2477,6 +2614,7 @@ impl Firmware { uma_submitted: a.uma_submitted, uuid: (draw as u32).wrapping_add(1), usc_base: job.queue.usc_base, + event: work::render_pair::events(pair), }, a.init_buffer, epoch, @@ -2491,11 +2629,12 @@ impl Firmware { alloc_slot: usize, job: &Job, draw: u64, + pair: usize, epoch: &super::pools::PbEpoch, prev_uma_submitted: u64, ) -> Result { let a = job.resources.pb_allocator_refs(alloc_slot)?; - let r = &self.graph.render; + let r = self.graph.render.get(pair).ok_or(EINVAL)?; let stage = draw.checked_mul(2).ok_or(EOVERFLOW)?; let uma_submitted = prev_uma_submitted.checked_add(2).ok_or(EOVERFLOW)?; Ok(RenderRefs { @@ -2521,6 +2660,7 @@ impl Firmware { uma_submitted, uuid: (draw as u32).wrapping_add(1), usc_base: job.queue.usc_base, + event: work::render_pair::events(pair), }) } @@ -2586,11 +2726,35 @@ impl Firmware { let index = job.progress.sent(); let cmd = command(job, index).ok_or(EINVAL)?; let render = matches!(cmd, Command::Render(_)); + // The render queue pair of this publication. `class_behind` (any render flight) governs + // the shared TA/FS submit channels, `pair_behind` the pair's own queues, stamps and + // barriers. Two VMs' renders never share a pair (linux#3201). + let pair = if render { + let pair = self.render_pair_for(&job.vm).ok_or(EAGAIN)?; + if self.engine.handoff_avoid_pairs & (1u8 << pair) != 0 + || self + .engine + .flights + .iter() + .any(|fl| cross_vm_render_conflict(fl, &job.vm, pair)) + { + return Err(EAGAIN); + } + pair + } else { + 0 + }; let class_behind = self .engine .flights .iter() .any(|f| if render { f.renders != 0 } else { f.computes != 0 }); + let pair_behind = render + && self + .engine + .flights + .iter() + .any(|fl| fl.renders != 0 && fl.render_pair as usize == pair); if job.vm.status.get() != 0 { return Err(EIO); } @@ -2640,21 +2804,35 @@ impl Firmware { if !render && class_behind { self.latch_compute_channel_receipts()?; } + // Only another pair's records can lap a render flight on the shared TA/FS channels. + let other_pair = render + && self + .engine + .flights + .iter() + .any(|fl| fl.renders != 0 && fl.render_pair as usize != pair); + if other_pair { + self.latch_render_channel_receipts()?; + } for &channel in channels { let pipe = self.channels.channel(channel); let producer = self.channels.producer(channel); let busy = if class_behind { // Behind in-flight commands on this class: post after their unconsumed records - // and never lap an unsettled compute flight's shared submit-channel record. - let wrap_bound = channel == Channel::Compute - && self.engine.flights.iter().any(|fl| { - fl.computes != 0 - && !fl.chan_settled - && producer - .wrapping_sub((fl.rec[2] + RING_SLOTS - 1) % RING_SLOTS) - % RING_SLOTS - >= RING_SLOTS - 2 - }); + // and never lap an unsettled flight's shared submit-channel record (of another + // compute pipe, or of another render pair on TA/FS). + let wrap_bound = self.engine.flights.iter().any(|fl| { + let (active, settled, record) = match channel { + Channel::Compute => (fl.computes != 0, fl.chan_settled, fl.rec[2]), + Channel::Ta => (fl.renders != 0, fl.render_chan_settled[0], fl.rec[0]), + Channel::Fs => (fl.renders != 0, fl.render_chan_settled[1], fl.rec[1]), + }; + active + && !settled + && producer.wrapping_sub((record + RING_SLOTS - 1) % RING_SLOTS) + % RING_SLOTS + >= RING_SLOTS - 2 + }); pipe.write()? != producer || producer.wrapping_sub(pipe.read()?) % RING_SLOTS >= sizes::AHEAD_RECORDS || wrap_bound @@ -2673,10 +2851,11 @@ impl Firmware { } self.engine.stats.prep_from_ns = now_ns(); let (c_head, ta_head, fs_head) = if render { + let r = self.graph.render.get(pair).ok_or(EINVAL)?; ( 0, - self.graph.render.qstate[0].r32(qstate::WRITE)?, - self.graph.render.qstate[1].r32(qstate::WRITE)?, + r.qstate[0].r32(qstate::WRITE)?, + r.qstate[1].r32(qstate::WRITE)?, ) } else { ( @@ -2687,6 +2866,12 @@ impl Firmware { }; let mut prefix = Prefix { compute_pipe, + render_pair: pair, + pair_draw: if render { + self.engine.pair_draw[pair] + } else { + 0 + }, n: self.engine.ordinal, pipe_n: if render { 0 @@ -2705,11 +2890,11 @@ impl Firmware { let mut c_read = prefix.c_head; let mut ta_read = prefix.ta_head; let mut fs_read = prefix.fs_head; - if render && class_behind { + if render && pair_behind { // Room for up to 5 TA entries (prev_barrier, ta_fs_barrier, 2x compute_barrier, // ta_work) and 5 FS entries (fs_dep, 2x fs_compute_barrier, own_barrier, fs_work). - ta_read = self.graph.render.qstate[0].r32(qstate::READ)?; - fs_read = self.graph.render.qstate[1].r32(qstate::READ)?; + ta_read = self.graph.render[pair].qstate[0].r32(qstate::READ)?; + fs_read = self.graph.render[pair].qstate[1].r32(qstate::READ)?; if ta_read >= 256 || fs_read >= 256 || prefix.ta_head.wrapping_sub(ta_read) % sizes::QUEUE_CAP >= sizes::QUEUE_CAP - 6 @@ -2732,6 +2917,8 @@ impl Firmware { } f.first = index as usize; f.compute_pipe = compute_pipe as u8; + f.render_pair = pair as u8; + f.claims.render_pair = pair as u8; f.c_start = prefix.c_head; f.ta_start = prefix.ta_head; f.fs_start = prefix.fs_head; @@ -2929,7 +3116,7 @@ impl Firmware { &mut prefix, f, behind, - class_behind, + pair_behind, )?; f.count = 1; // Batch consecutive ready non-InitBM render passes of the same SUBMIT into @@ -3038,7 +3225,7 @@ impl Firmware { &mut prefix, f, behind, - class_behind, + pair_behind, )?; last_seq = Some(next_seq); end += 1; @@ -3198,7 +3385,7 @@ impl Firmware { &mut prefix, f, behind, - class_behind, + pair_behind, )?; } last_seq = Some(first_seq + u64::from(n2 - 1)); @@ -3249,13 +3436,14 @@ impl Firmware { } job.resources .publish_pb_batch(a, f.uma_submitted, f.renders)?; - self.pools.publish_flight(a); + f.pb_seq = self.pools.publish_flight(a); // Notifier service dereferences u32 counters; the host ordering ledger // remains u64. Eight-byte spacing is retained allocation padding. Always - // advance both TA and FS thresholds to the newest published draw ordinal - // so firmware never skips updating `TA_STAMP` on fast tail flights. - self.graph.render.threshold.w32(0, prefix.draw as u32)?; - self.graph.render.threshold.w32(8, prefix.draw as u32)?; + // advance both TA and FS thresholds to the pair's newest published draw + // ordinal so firmware never skips updating `TA_STAMP` on fast tail flights. + let r = &self.graph.render[pair]; + r.threshold.w32(0, prefix.pair_draw as u32)?; + r.threshold.w32(8, prefix.pair_draw as u32)?; } else { for m in 0..f.claims.slot_count as usize { let k = f.claims.slot[m] as usize; @@ -3271,11 +3459,11 @@ impl Firmware { wmb(); if render { publish_producer( - &self.graph.render.qstate[0], + &self.graph.render[pair].qstate[0], prefix.ta_head, &mut self.engine.stats.publications[1], )?; - self.graph.render.qstate[1].w32(qstate::WRITE, prefix.fs_head)?; + self.graph.render[pair].qstate[1].w32(qstate::WRITE, prefix.fs_head)?; } else { publish_producer( &self.graph.compute[compute_pipe].qstate, @@ -3295,16 +3483,16 @@ impl Firmware { !self.engine.queue_registered[compute_pipe], ), Channel::Ta => ( - self.graph.render.qinfo[0].va, + self.graph.render[pair].qinfo[0].va, prefix.ta_head, - 0x70, - !self.engine.ta_registered, + work::render_pair::events(pair)[0] as u8, + !self.engine.ta_registered[pair], ), Channel::Fs => ( - self.graph.render.qinfo[1].va, + self.graph.render[pair].qinfo[1].va, prefix.fs_head, - 0x71, - !self.engine.render_registered, + work::render_pair::events(pair)[1] as u8, + !self.engine.render_registered[pair], ), }; let record = SubmitRecord { @@ -3337,12 +3525,18 @@ impl Firmware { self.engine.ordinal = prefix.n; self.engine.draw = prefix.draw; if render { - self.engine.ta_target = f.ta_target; - self.engine.fs_target = f.fs_target; - self.engine.ta_head = f.ta_head; - self.engine.fs_head = f.fs_head; - self.engine.ta_registered = true; - self.engine.render_registered = true; + self.engine.note_render_pair(&job.vm, pair); + self.engine.stats.render_pair_publications[pair] += 1; + if other_pair { + self.engine.stats.cross_pair_renders += 1; + } + self.engine.pair_draw[pair] = prefix.pair_draw; + self.engine.ta_target[pair] = f.ta_target; + self.engine.fs_target[pair] = f.fs_target; + self.engine.ta_head[pair] = f.ta_head; + self.engine.fs_head[pair] = f.fs_head; + self.engine.ta_registered[pair] = true; + self.engine.render_registered[pair] = true; } else { self.engine.pipe_ordinal[compute_pipe] = prefix.pipe_n; self.engine.target[compute_pipe] = f.target; @@ -3357,8 +3551,8 @@ impl Firmware { self.engine.stage_seen = self.events.stage_events; f.behind = behind; self.stat_publish(f); - // First in-flight command on this render class or compute pipe starts about now; - // commands queued behind the same class/pipe keep its oldest deadline. + // First in-flight command on this render pair or compute pipe starts about now; + // commands queued behind the same pair/pipe keep its oldest deadline. if render { if !class_behind { self.renew_render_deadline(); @@ -3543,10 +3737,12 @@ impl Firmware { || wait_fs.initbm || self.engine.flights.iter().any(|fl| fl.initbm); let bar_type = cross_engine_barrier_type(producer_initbm, false); + // The waited render's pair names the FS stamp and event. + let wait_pair = wait_fs.pair as usize; let bar = encode::barrier( - self.graph.render.fw_stamp[1].va, + self.graph.render.get(wait_pair).ok_or(EINVAL)?.fw_stamp[1].va, wait_fs.stamp, - 0x71, + work::render_pair::events(wait_pair)[1], target, 0, bar_type, @@ -3630,25 +3826,30 @@ impl Firmware { pf: &mut Prefix, f: &mut Flight, behind: bool, - class_behind: bool, + pair_behind: bool, ) -> Result { let member = pf.renders as usize; if member >= sizes::RENDER_SLOTS { return Err(EAGAIN); } let k = f.claims.pass[member] as usize; + // Stamps and thresholds follow the render pair's dense draw ordinal; the global draw + // ordinal keeps the UMA counters and the work UUID. + let pair = pf.render_pair; + let events = work::render_pair::events(pair); let draw = super::recovery::logic::next_ordinal(pf.draw).ok_or(EOVERFLOW)?; - let target = encode::stamp(draw); - let has_prior_render = class_behind || member > 0; + let pair_draw = super::recovery::logic::next_ordinal(pf.pair_draw).ok_or(EOVERFLOW)?; + let target = encode::stamp(pair_draw); + let has_prior_render = pair_behind || member > 0; let prev_ta = if member > 0 { pf.last_ta } else { - self.engine.ta_target + self.engine.ta_target[pair] }; let prev_fs = if member > 0 { pf.last_fs } else { - self.engine.fs_target + self.engine.fs_target[pair] }; let order = job.command_order(cmd_index); let staged = cmd.cmd.flags @@ -3673,6 +3874,7 @@ impl Firmware { None => Some(WaitTarget { stamp: prev_fs, initbm: false, + pair: pair as u8, }), } } else { @@ -3688,6 +3890,12 @@ impl Firmware { } else { None }; + // A VM's renders stay on one pair, so a render wait never names another pair's stamp. + if fs_wait_render.iter().any(|w| w.pair as usize != pair) + || ta_wait_fs.iter().any(|w| w.pair as usize != pair) + { + return Err(EAGAIN); + } let plan_flags = if !staged && job.fw_waits.iter().any(|w| { w.last_ordinal[super::command::RENDER].is_some_and(|last| { @@ -3732,7 +3940,7 @@ impl Firmware { .ok_or(EAGAIN)?; let slot_pipelined = self.pools.slot_inflight(alloc_slot) > 0; let (refs, init_buffer, epoch, binding) = - self.render_refs(alloc_slot, job, draw, slot_pipelined, behind)?; + self.render_refs(alloc_slot, job, draw, pair, slot_pipelined, behind)?; f.pb = Some(epoch); f.pb_slot = alloc_slot as u32; f.pb_binding = binding; @@ -3747,6 +3955,7 @@ impl Firmware { f.pb_slot as usize, &f.job, draw, + pair, epoch, f.uma_submitted, )?; @@ -3843,7 +4052,7 @@ impl Firmware { // One retained descriptor is shared by TA and FS; its private submitted counter // advances by two per pass. Reused descriptors and their pool/list bytes remain intact. f.uma_submitted = refs.uma_submitted; - let r = &self.graph.render; + let r = self.graph.render.get(pair).ok_or(EINVAL)?; let cap = sizes::QUEUE_CAP; if init_buffer { pf.initbm = true; @@ -3858,7 +4067,33 @@ impl Firmware { // consumer carries `InitBM`: G16 `FINALIZE` flushes producer caches before advancing // `fw_stamp` (unlike G15's `CROSS_ENGINE_HOLD`; see `cross_engine_barrier_type`). // Cold `InitBM` transitions and recovery paths drain completely before publishing. + // Renders reach the TA and FS engines in publication order across render pairs, as on + // one pair's in-order queues: the PB and pass slot displacement proofs rely on it + // (`Pools::retire_flight`). A prefix's first pass whose newest predecessor in flight is + // on another pair waits for that render's TA and FS. Its completion implies every + // earlier render's, so those waits stand in for this pair's own `prev_barrier` and + // `fs_dep`, and a pass still takes at most `MAX_RENDER_RING_ENTRIES` entries per ring. + // The TA of one VM's render still overlaps the FS of the other VM's. + let prior = if member == 0 { + self.engine + .flights + .iter() + .rev() + .find(|fl| fl.renders != 0) + .filter(|fl| fl.render_pair as usize != pair) + .map(|fl| { + ( + fl.render_pair as usize, + fl.ta_target, + fl.fs_target, + fl.initbm, + ) + }) + } else { + None + }; let producer_initbm = pf.initbm + || prior.is_some_and(|(_, _, _, initbm)| initbm) || self.engine.flights.iter().any(|fl| fl.initbm) || ta_wait_compute.iter().flatten().any(|w| w.initbm) || fs_wait_compute.iter().flatten().any(|w| w.initbm) @@ -3870,11 +4105,27 @@ impl Firmware { // behind `prev_fs`. Emit `ta_fs_barrier` only when `plan.ta_fs_wait` names an in-flight // FS stamp, and `fs_dep` only when `plan.fs_render_wait` names an in-flight FS // dependency not already dominated by TA. - if plan.ta_prev_wait { + let (ta_prev, fs_prev) = match prior { + Some((q, ta, fs, _)) => { + let other = self.graph.render.get(q).ok_or(EINVAL)?; + let [ta_event, fs_event] = work::render_pair::events(q); + ( + Some((other.fw_stamp[0].va, ta, ta_event)), + Some((other.fw_stamp[1].va, fs, fs_event)), + ) + } + None => ( + plan.ta_prev_wait + .then_some((r.fw_stamp[0].va, prev_ta, events[0])), + plan.fs_render_wait + .map(|wait_fs| (r.fw_stamp[1].va, wait_fs, events[1])), + ), + }; + if let Some((stamp, wait_ta, event)) = ta_prev { let prev = encode::barrier( - r.fw_stamp[0].va, - prev_ta, - 0x70, + stamp, + wait_ta, + event, target, work::barrier::RENDER_WAIT_UUID, render_bar, @@ -3887,7 +4138,7 @@ impl Firmware { let ta_fs = encode::barrier( r.fw_stamp[1].va, wait_fs, - 0x71, + events[1], target, work::barrier::RENDER_WAIT_UUID, render_bar, @@ -3896,11 +4147,11 @@ impl Firmware { r.ring[0].w64(8 * pf.ta_head as usize, p.ta_fs_barrier.va)?; pf.ta_head = (pf.ta_head + 1) % cap; } - if let Some(wait_fs) = plan.fs_render_wait { + if let Some((stamp, wait_fs, event)) = fs_prev { let dep = encode::barrier( - r.fw_stamp[1].va, + stamp, wait_fs, - 0x71, + event, target, work::barrier::RENDER_WAIT_UUID, render_bar, @@ -3951,7 +4202,7 @@ impl Firmware { let own = encode::barrier( r.fw_stamp[0].va, target, - 0x70, + events[0], target, refs.uuid, BarrierType::Stamp, @@ -3968,6 +4219,7 @@ impl Firmware { pf.renders += 1; f.renders = pf.renders; pf.draw = draw; + pf.pair_draw = pair_draw; pf.last_ta = target; pf.last_fs = target; pf.prev = Prev::Render; diff --git a/drivers/gpu/drm/asahi/g16/event.rs b/drivers/gpu/drm/asahi/g16/event.rs index fa46695cb8768..c6ec315b3f4fb 100644 --- a/drivers/gpu/drm/asahi/g16/event.rs +++ b/drivers/gpu/drm/asahi/g16/event.rs @@ -10,13 +10,18 @@ use kernel::{bindings, device, prelude::*}; use super::channel::Ring; use super::fw::channels::{RING_SLOTS, STATE_READ, STATE_WRITE}; -use super::fw::work::compute; +use super::fw::work::{compute, render_pair}; use super::hw::{rings, sizes}; use super::regs::{mb, rmb, wmb}; pub(crate) const RECORD_WORDS: usize = 18; -pub(crate) const STAGE_COUNT: usize = 2 + sizes::COMPUTE_PIPES; +pub(crate) const STAGE_COUNT: usize = sizes::STAGES; const COMPUTE_EVENT_MASK: u32 = ((1u32 << sizes::COMPUTE_PIPES) - 1) << compute::EVENT; +/// TA/FS events of every render pair, in type-1 word 4. +const RENDER_EVENT_MASK: u32 = + ((1u32 << (2 * sizes::RENDER_PAIRS)) - 1) << (render_pair::TA_EVENT % 32); +const _: () = assert!(render_pair::TA_EVENT / 32 == 3); +const _: () = assert!(sizes::RENDER_PAIRS <= render_pair::MAX_PAIRS); const _: () = assert!(compute::EVENTS.len() == sizes::COMPUTE_PIPES); const _: () = assert!(compute::EVENT as usize + sizes::COMPUTE_PIPES <= 32); /// Retained only for the allocator's pending-growth container. M4 does not @@ -129,7 +134,8 @@ impl Events { match kind { 1 => { // Type 1 carries 128 completion bits across words 1..=4; compute pipe events - // (15..15+COMPUTE_PIPES) live in word 1 and TA/FS (0x70/0x71) live in word 4. + // (15..15+COMPUTE_PIPES) live in word 1 and the TA/FS events of every render + // pair (0x70 + 2p, 0x71 + 2p) live in word 4. let (w1, w4) = match ring.ring.r32(base + 4).and_then(|w1| { Ok((w1, ring.ring.r32(base + 16)?)) }) { @@ -141,14 +147,17 @@ impl Events { return Err(err); } }; - if w4 & (1u32 << (0x70 % 32)) != 0 { - self.event_ns[0] = now; + let mut rbits = w4 & RENDER_EVENT_MASK; + while rbits != 0 { + let bit = rbits.trailing_zeros(); + rbits &= rbits - 1; + let i = (bit - render_pair::TA_EVENT % 32) as usize; + let (pair, stage) = (i / 2, i % 2); + self.event_ns[sizes::render_stage(pair, stage)] = now; self.stage_events = self.stage_events.wrapping_add(1); - } - if w4 & (1u32 << (0x71 % 32)) != 0 { - self.event_ns[1] = now; - self.stage_events = self.stage_events.wrapping_add(1); - self.fs_events = self.fs_events.wrapping_add(1); + if stage == 1 { + self.fs_events = self.fs_events.wrapping_add(1); + } } let mut cbits = w1 & COMPUTE_EVENT_MASK; while cbits != 0 { diff --git a/drivers/gpu/drm/asahi/g16/fw/work.rs b/drivers/gpu/drm/asahi/g16/fw/work.rs index 2b8c74edd3c55..aaa711c2472fb 100644 --- a/drivers/gpu/drm/asahi/g16/fw/work.rs +++ b/drivers/gpu/drm/asahi/g16/fw/work.rs @@ -330,6 +330,32 @@ pub(crate) mod barrier { pub(crate) const RENDER_WAIT_UUID: u32 = 0x3d420; } +/// Completion events of the render queue pairs. Pair `p` finishes its TA work with event +/// `0x70 + 2p` and its FS work with `0x71 + 2p`; pair 0 keeps the 0x70/0x71 of the native +/// runtime's render queues. The block `0x70..0x80` is bits 16..32 of type-1 event word 4, so it +/// names at most [`MAX_PAIRS`] pairs. +pub(crate) mod render_pair { + pub(crate) const TA_EVENT: u32 = 0x70; + pub(crate) const MAX_PAIRS: usize = 8; + const _: () = assert!(TA_EVENT % 32 == 16 && TA_EVENT % 32 + 2 * MAX_PAIRS as u32 == 32); + + /// `[TA, FS]` completion events of render pair `pair`. + pub(crate) const fn events(pair: usize) -> [u32; 2] { + let ta = TA_EVENT + 2 * pair as u32; + [ta, ta + 1] + } + + /// The render pair (`0..MAX_PAIRS`) and stage (0 TA, 1 FS) of a completion event. + pub(crate) const fn of_event(event: u32) -> Option<(usize, usize)> { + if event >= TA_EVENT && event - TA_EVENT < 2 * MAX_PAIRS as u32 { + let i = (event - TA_EVENT) as usize; + Some((i / 2, i % 2)) + } else { + None + } + } +} + /// InitBM record (0x20 bytes). pub(crate) mod initbm { pub(crate) const SIZE: usize = 0x20; diff --git a/drivers/gpu/drm/asahi/g16/graph.rs b/drivers/gpu/drm/asahi/g16/graph.rs index b3eaa19d7ee44..152f4715b59aa 100644 --- a/drivers/gpu/drm/asahi/g16/graph.rs +++ b/drivers/gpu/drm/asahi/g16/graph.rs @@ -293,26 +293,41 @@ struct RenderGraphSession { registration_barrier: Arc, } impl RenderGraphSession { - fn new(o: &mut Objects, context: Arc) -> Result { + /// Pairs after the first share `first`'s `legacy_empty` and `registration_barrier`: the + /// shared scheduling context registers once, through pair 0. + fn new( + o: &mut Objects, + context: Arc, + first: Option<&RenderGraphSession>, + ) -> Result { + // Pair 0 keeps the allocation order of the single render graph. + let ta = QueueSession::new(o)?; + let fs = QueueSession::new(o)?; + let notifier = alloc(o, 0x1000, Class::Fw, None, 0, false)?; + let threshold = alloc(o, 24, Class::Fw, None, 0, false)?; + let job_list = [ + alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?, + alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?, + ]; + let (legacy_empty, registration_barrier) = match first { + Some(first) => ( + first.legacy_empty.clone(), + first.registration_barrier.clone(), + ), + None => ( + alloc(o, 0x40, Class::Shared, None, 0, false)?, + alloc(o, super::fw::work::barrier::SIZE, cmd_fw(), None, 0, false)?, + ), + }; Ok(Self { - ta: QueueSession::new(o)?, - fs: QueueSession::new(o)?, + ta, + fs, sched_ctx: context, - notifier: alloc(o, 0x1000, Class::Fw, None, 0, false)?, - threshold: alloc(o, 24, Class::Fw, None, 0, false)?, - job_list: [ - alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?, - alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?, - ], - legacy_empty: alloc(o, 0x40, Class::Shared, None, 0, false)?, - registration_barrier: alloc( - o, - super::fw::work::barrier::SIZE, - cmd_fw(), - None, - 0, - false, - )?, + notifier, + threshold, + job_list, + legacy_empty, + registration_barrier, }) } fn finish(self, rings: &mut Objects) -> Result { @@ -337,7 +352,7 @@ impl RenderGraphSession { impl RenderGraph { #[allow(dead_code)] fn new(o: &mut Objects, rings: &mut Objects, context: Arc) -> Result { - RenderGraphSession::new(o, context)?.finish(rings) + RenderGraphSession::new(o, context, None)?.finish(rings) } fn init(&self, abi: FwAbi) -> Result { init_notifier(&self.notifier, &self.threshold)?; @@ -362,13 +377,14 @@ impl RenderGraph { /// [`Factory::persistent_objects_probe`] pool. pub(crate) struct GraphSession { compute: KVec, - render: RenderGraphSession, + render: KVec, } pub(crate) struct Graphs { pub(crate) dev: ARef, pub(crate) compute: KVec, - pub(crate) render: RenderGraph, + /// TA/FS render queue pairs `0..RENDER_PAIRS`. + pub(crate) render: KVec, /// Owns the firmware-cached work rings for the device lifetime (never dropped). _ring_objects: core::mem::ManuallyDrop, } @@ -382,7 +398,12 @@ impl Graphs { for _ in 0..sizes::COMPUTE_PIPES { compute.push(ComputeGraphSession::new(o, sched_ctx.clone())?, GFP_KERNEL)?; } - let render = RenderGraphSession::new(o, sched_ctx)?; + let mut render: KVec = + KVec::with_capacity(sizes::RENDER_PAIRS, GFP_KERNEL)?; + for _ in 0..sizes::RENDER_PAIRS { + let pair = RenderGraphSession::new(o, sched_ctx.clone(), render.first())?; + render.push(pair, GFP_KERNEL)?; + } Ok(GraphSession { compute, render }) } @@ -398,7 +419,10 @@ impl Graphs { for c in session.compute { compute.push(c.finish(&mut ring_objects)?, GFP_KERNEL)?; } - let render = session.render.finish(&mut ring_objects)?; + let mut render = KVec::with_capacity(sizes::RENDER_PAIRS, GFP_KERNEL)?; + for r in session.render { + render.push(r.finish(&mut ring_objects)?, GFP_KERNEL)?; + } ring_objects.finish_private()?; Ok(Self { dev: dev.as_ref().as_ref().into(), @@ -419,7 +443,9 @@ impl Firmware { for (pipe, compute) in self.graph.compute.iter().enumerate() { compute.init(self.init.abi, pipe == 0)?; } - self.graph.render.init(self.init.abi)?; + for render in self.graph.render.iter() { + render.init(self.init.abi)?; + } self.slots.init()?; self.init_render_pools(false)?; super::engine::wmb(); diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 2b213c67d80bd..eb0e7457c4314 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -1116,6 +1116,32 @@ pub(crate) mod sizes { /// Maximum concurrent compute pipes one VM may occupy at once, preserving the render /// ring-entry bound (`MAX_RENDER_RING_ENTRIES = 5`) since cross-VM render/compute drains. pub(crate) const MAX_VM_COMPUTE_PIPES: usize = 2; + /// Firmware TA/FS render queue pairs, each leased to one rendering VM at a time + /// (`Firmware::render_pair_for`): two VMs' renders on one pair fault (linux#3201), on two + /// pairs they run side by side, as macOS 26B123 gives every Metal process its own TA and FS + /// queue. Each pair owns a disjoint `RenderGraph` (TA and FS `qinfo`, work rings, `qstate`, + /// stamps, job lists, notifier page, threshold: fourteen objects of one 16 KiB page each, + /// 224 KiB, allocated at probe) and its own completion events (`work::render_pair::events`); + /// all pairs share `sched_ctx`, the `Channel::Ta`/`Channel::Fs` submit rings and their + /// doorbells, as the macOS processes share one doorbell. + /// + /// Eight: as many as the completion-event block names (`work::render_pair::MAX_PAIRS`), so + /// a compositor and seven clients render without a pair handoff. A pair registers with the + /// firmware on its first record, and a VM takes the lowest free pair, so pairs beyond the + /// clients rendering at once stay unregistered. + pub(crate) const RENDER_PAIRS: usize = 8; + const _: () = assert!(RENDER_PAIRS >= 1 && RENDER_PAIRS <= 8); + /// Per-stage event and recovery-snapshot cells: pair 0 TA/FS at `0`/`1`, compute pipes at + /// `2..2 + COMPUTE_PIPES`, then TA/FS of pairs `1..RENDER_PAIRS` ([`render_stage`]). + pub(crate) const STAGES: usize = 2 + COMPUTE_PIPES + 2 * (RENDER_PAIRS - 1); + /// The [`STAGES`] cell of render pair `pair`'s TA (`stage` 0) or FS (`stage` 1). + pub(crate) const fn render_stage(pair: usize, stage: usize) -> usize { + if pair == 0 { + stage + } else { + 2 + COMPUTE_PIPES + 2 * (pair - 1) + stage + } + } const _: () = assert!(COMPUTE_PIPES >= 2 && COMPUTE_PIPES <= 16); const _: () = assert!(MAX_VM_COMPUTE_PIPES >= 2 && MAX_VM_COMPUTE_PIPES <= COMPUTE_PIPES); const _: () = assert!(COMPUTE_UNITS - PIPE1_COMPUTE_START >= (COMPUTE_PIPES - 1) * 2); diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index dbd1e6a18325d..23c08ea7fcc39 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -886,8 +886,9 @@ impl Firmware { let mut oldest_compute: [Option<&Flight>; super::hw::sizes::COMPUTE_PIPES] = [None; super::hw::sizes::COMPUTE_PIPES]; let mut compute_behind = [false; super::hw::sizes::COMPUTE_PIPES]; - let mut oldest_render: Option<&Flight> = None; - let mut render_behind = false; + let mut oldest_render: [Option<&Flight>; super::hw::sizes::RENDER_PAIRS] = + [None; super::hw::sizes::RENDER_PAIRS]; + let mut render_behind = [false; super::hw::sizes::RENDER_PAIRS]; for f in self.engine.flights.iter() { if f.computes != 0 { let p = (f.compute_pipe as usize).min(super::hw::sizes::COMPUTE_PIPES - 1); @@ -898,10 +899,11 @@ impl Firmware { } } if f.renders != 0 { - if oldest_render.is_none() { - oldest_render = Some(f); + let r = (f.render_pair as usize).min(super::hw::sizes::RENDER_PAIRS - 1); + if oldest_render[r].is_none() { + oldest_render[r] = Some(f); } else { - render_behind = true; + render_behind[r] = true; } } } @@ -920,15 +922,17 @@ impl Firmware { } } } - if let Some(f) = oldest_render { - if let Ok(obs) = self.graph.render.fw_stamp[1].r32(0) { - let reached = if render_behind { - stamp_reached(obs, f.fs_target, self.engine.fs_target) - } else { - obs == f.fs_target - }; - if reached { - return true; + for r in 0..super::hw::sizes::RENDER_PAIRS { + if let Some(f) = oldest_render[r] { + if let Ok(obs) = self.graph.render[r].fw_stamp[1].r32(0) { + let reached = if render_behind[r] { + stamp_reached(obs, f.fs_target, self.engine.fs_target[r]) + } else { + obs == f.fs_target + }; + if reached { + return true; + } } } } @@ -950,7 +954,10 @@ impl Firmware { return Ok(false); } let mut retired_any = false; - let (mut check_compute, mut check_render) = ([true; super::hw::sizes::COMPUTE_PIPES], true); + let (mut check_compute, mut check_render) = ( + [true; super::hw::sizes::COMPUTE_PIPES], + [true; super::hw::sizes::RENDER_PAIRS], + ); let mut ret = self.retired_flight_classes(&mut check_compute, &mut check_render); while let Ok(Some((index, receipt))) = ret { let outcome = self.retire_outcome_at(index, receipt); @@ -1051,8 +1058,14 @@ impl Firmware { let p = (f.compute_pipe as usize).min(super::hw::sizes::COMPUTE_PIPES - 1); (f.c_start, f.head, self.engine.head[p]) } - Channel::Ta => (f.ta_start, f.ta_head, self.engine.ta_head), - Channel::Fs => (f.fs_start, f.fs_head, self.engine.fs_head), + Channel::Ta | Channel::Fs => { + let r = (f.render_pair as usize).min(super::hw::sizes::RENDER_PAIRS - 1); + if matches!(channel, Channel::Ta) { + (f.ta_start, f.ta_head, self.engine.ta_head[r]) + } else { + (f.fs_start, f.fs_head, self.engine.fs_head[r]) + } + } }; if head >= cap || start >= cap || tail >= cap { return Err(EINVAL); @@ -1131,6 +1144,46 @@ impl Firmware { Ok(()) } + /// Latches `Channel::Ta` / `Channel::Fs` read and completion proofs onto active render + /// flights before the shared submit rings can lap them, so a long flight on one render pair + /// stays retirable while another pair keeps posting records. + pub(crate) fn latch_render_channel_receipts(&mut self) -> Result { + if !self + .engine + .flights + .iter() + .any(|f| f.renders != 0 && f.render_chan_settled.contains(&false)) + { + return Ok(()); + } + let slots = super::fw::channels::RING_SLOTS; + for (i, channel) in [Channel::Ta, Channel::Fs].into_iter().enumerate() { + let pipe = self.channels.channel(channel); + let read = pipe.read()?; + let comp = pipe.completion()?; + if read >= slots || comp >= slots { + continue; + } + let producer = self.channels.producer(channel); + for f in self.engine.flights.iter_mut() { + if f.renders == 0 || f.render_chan_settled[i] { + continue; + } + let record = f.rec[i]; + if record >= slots { + return Err(EINVAL); + } + let first = (record + slots - 1) % slots; + if ring_passed(read, first, record, producer, slots) + && ring_passed(comp, first, record, producer, slots) + { + f.render_chan_settled[i] = true; + } + } + } + Ok(()) + } + /// Exact M4 queue and submit-pipe proof for one serialized publication. Event /// notifications are wakeups; neither an event nor elapsed time releases an owner. pub(crate) fn queue_receipt( @@ -1148,6 +1201,7 @@ impl Firmware { /// In-order receipt of flight `f` with later flights queued behind it: the NC READ cursor /// (and with uncached queue info its consumers) passed its ring entries, and the submit /// pipe's read and completion cursors passed its record. + #[allow(dead_code)] fn queue_passed( &self, channel: Channel, @@ -1183,7 +1237,10 @@ impl Firmware { /// Inspects the oldest compute flight per pipe and oldest render flight independently so any /// pipe/class can retire as soon as its hardware receipt settles without waiting on another. pub(crate) fn retired_flight(&mut self) -> Result> { - let (mut check_compute, mut check_render) = ([true; super::hw::sizes::COMPUTE_PIPES], true); + let (mut check_compute, mut check_render) = ( + [true; super::hw::sizes::COMPUTE_PIPES], + [true; super::hw::sizes::RENDER_PAIRS], + ); self.retired_flight_classes(&mut check_compute, &mut check_render) } @@ -1192,11 +1249,12 @@ impl Firmware { fn retired_flight_classes( &mut self, check_compute: &mut [bool; super::hw::sizes::COMPUTE_PIPES], - check_render: &mut bool, + check_render: &mut [bool; super::hw::sizes::RENDER_PAIRS], ) -> Result> { + const RP: usize = super::hw::sizes::RENDER_PAIRS; let mut compute_idx = [None; super::hw::sizes::COMPUTE_PIPES]; - let mut render_idx = None; - if check_compute.iter().any(|&c| c) || *check_render { + let mut render_idx: [Option; RP] = [None; RP]; + if check_compute.iter().any(|&c| c) || check_render.iter().any(|&c| c) { for (i, f) in self.engine.flights.iter().enumerate() { if f.computes != 0 { let p = (f.compute_pipe as usize).min(super::hw::sizes::COMPUTE_PIPES - 1); @@ -1204,8 +1262,11 @@ impl Firmware { compute_idx[p] = Some(i); } } - if *check_render && render_idx.is_none() && f.renders != 0 { - render_idx = Some(i); + if f.renders != 0 { + let r = (f.render_pair as usize).min(RP - 1); + if check_render[r] && render_idx[r].is_none() { + render_idx[r] = Some(i); + } } } } @@ -1214,8 +1275,10 @@ impl Firmware { check_compute[p] = false; } } - if render_idx.is_none() { - *check_render = false; + for r in 0..RP { + if render_idx[r].is_none() { + check_render[r] = false; + } } for p in 0..super::hw::sizes::COMPUTE_PIPES { if let Some(index) = compute_idx[p] { @@ -1224,18 +1287,23 @@ impl Firmware { return Ok(Some((index, receipt))); } check_compute[p] = false; - if render_idx == Some(index) { - *check_render = false; - render_idx = None; + for r in 0..RP { + if render_idx[r] == Some(index) { + check_render[r] = false; + render_idx[r] = None; + } } } } - if let Some(index) = render_idx { - let receipt = self.retired_at(index)?; - if receipt.complete() { - return Ok(Some((index, receipt))); + // Render pairs retire independently, out of order across pairs. + for r in 0..RP { + if let Some(index) = render_idx[r] { + let receipt = self.retired_at(index)?; + if receipt.complete() { + return Ok(Some((index, receipt))); + } + check_render[r] = false; } - *check_render = false; } Ok(None) } @@ -1326,34 +1394,52 @@ impl Firmware { } } if f.renders != 0 { + // Renders retire in order per render pair. A later flight on the same pair makes the + // queue and stamp proof a "passed" one; the TA/FS submit channels are shared by every + // pair, so any other render flight or later record makes the channel proof a + // "passed" one, unless latched before another pair's records could lap it. + let pair = (f.render_pair as usize).min(super::hw::sizes::RENDER_PAIRS - 1); let render_behind = self .engine .flights .iter() - .filter(|o| o.renders != 0) + .filter(|o| o.renders != 0 && o.render_pair == f.render_pair) .nth(1) .is_some(); - let g = &self.graph.render; + let chan_behind = self + .engine + .flights + .iter() + .filter(|o| o.renders != 0) + .nth(1) + .is_some() + || f.rec[0] != self.channels.producer(Channel::Ta) + || f.rec[1] != self.channels.producer(Channel::Fs); + let g = &self.graph.render[pair]; let a = f.pb_slot as usize; if render_behind { let e = &self.engine; // Check FS (terminal stage) before TA so running renders fail fast on 1 WC read. - if !stamp_reached(g.fw_stamp[1].r32(0)?, f.fs_target, e.fs_target) - || !stamp_reached(g.fw_stamp[0].r32(0)?, f.ta_target, e.ta_target) - || !self.queue_passed(Channel::Ta, &g.qstate[0], &g.qinfo[0], f)? - || !self.queue_passed(Channel::Fs, &g.qstate[1], &g.qinfo[1], f)? + if !stamp_reached(g.fw_stamp[1].r32(0)?, f.fs_target, e.fs_target[pair]) + || !stamp_reached(g.fw_stamp[0].r32(0)?, f.ta_target, e.ta_target[pair]) + || !self.queue_ring_passed(Channel::Ta, &g.qstate[0], &g.qinfo[0], f)? + || !self.queue_ring_passed(Channel::Fs, &g.qstate[1], &g.qinfo[1], f)? + || !(f.render_chan_settled[0] + || self.channel_receipt(Channel::Ta, f.rec[0], true)?) + || !(f.render_chan_settled[1] + || self.channel_receipt(Channel::Fs, f.rec[1], true)?) { return Ok(Retirement::Pending); } rmb(); let fs_stamp = g.notifier.r32(notifier_page::FS_STAMP)?; let ta_stamp = g.notifier.r32(notifier_page::TA_STAMP)?; - full &= stamp_reached(fs_stamp, f.fs_target, e.fs_target) + full &= stamp_reached(fs_stamp, f.fs_target, e.fs_target[pair]) && (fs_stamp != f.fs_target || g.notifier .r32(notifier_page::FS_RECORD + notifier::CONTEXT)? == f.job.vm.slot) - && stamp_reached(ta_stamp, f.ta_target, e.ta_target) + && stamp_reached(ta_stamp, f.ta_target, e.ta_target[pair]) && (ta_stamp != f.ta_target || g.notifier.r32(notifier::CONTEXT)? == f.job.vm.slot) && f.job @@ -1363,20 +1449,12 @@ impl Firmware { // Check FS (terminal stage) before TA so running renders fail fast on 1 WC read. if g.fw_stamp[1].r32(0)? != f.fs_target || g.fw_stamp[0].r32(0)? != f.ta_target - || !self.queue_receipt( - Channel::Ta, - &g.qstate[0], - &g.qinfo[0], - f.ta_head, - f.rec[0], - )? - || !self.queue_receipt( - Channel::Fs, - &g.qstate[1], - &g.qinfo[1], - f.fs_head, - f.rec[1], - )? + || !self.queue_ring_receipt(&g.qstate[0], &g.qinfo[0], f.ta_head)? + || !self.queue_ring_receipt(&g.qstate[1], &g.qinfo[1], f.fs_head)? + || !(f.render_chan_settled[0] + || self.channel_receipt(Channel::Ta, f.rec[0], chan_behind)?) + || !(f.render_chan_settled[1] + || self.channel_receipt(Channel::Fs, f.rec[1], chan_behind)?) { return Ok(Retirement::Pending); } @@ -1536,17 +1614,20 @@ impl Firmware { } } if f.renders != 0 { + let pair = f.render_pair as usize; + let stage = super::recovery::logic::retired_render_stage; for m in 0..(f.renders as usize).min(f.r_ta_stamp.len()) { self.recovery .last_retired - .push(super::hw::sizes::COMPUTE_PIPES, f.r_ta_stamp[m]); + .push(stage(pair, 0), f.r_ta_stamp[m]); self.recovery .last_retired - .push(super::hw::sizes::COMPUTE_PIPES + 1, f.r_fs_stamp[m]); + .push(stage(pair, 1), f.r_fs_stamp[m]); } let committed = f.pb.as_ref().ok_or(EINVAL).and_then(|epoch| { self.pools.retire_flight( f.pb_slot as usize, + f.pb_seq, epoch, f.pb_binding, result.is_ok(), @@ -1661,7 +1742,7 @@ impl Firmware { self.power.utilization.idle(self.engine.stats.idle_from_ns); self.power.report_work(false); } - // The next prefix on the retired flight's pipe/class starts executing about now. + // The next prefix on the retired flight's pipe/pair starts executing about now. if f.renders != 0 { self.renew_render_deadline(); } @@ -1788,9 +1869,10 @@ impl Firmware { return; } const CP: usize = super::hw::sizes::COMPUTE_PIPES; + const RP: usize = super::hw::sizes::RENDER_PAIRS; let (g, r, e) = (&self.graph.compute, &self.graph.render, &self.engine); let mut fc: [Option<&Flight>; CP] = [None; CP]; - let mut fr = None; + let mut fr: [Option<&Flight>; RP] = [None; RP]; for f in e.flights.iter() { if f.computes != 0 { let p = (f.compute_pipe as usize).min(CP - 1); @@ -1798,16 +1880,19 @@ impl Firmware { fc[p] = Some(f); } } - if fr.is_none() && f.renders != 0 { - fr = Some(f); + if f.renders != 0 { + let q = (f.render_pair as usize).min(RP - 1); + if fr[q].is_none() { + fr[q] = Some(f); + } } } // None denotes an inactive/reached stage. A real unreached stamp may be zero // immediately after native wrap and must remain distinguishable from completion. let pending = |observed, own, tail| (!stamp_reached(observed, own, tail)).then_some(observed); - let mut next_progress = [None; CP + 2]; - let mut published = [0u64; CP + 1]; + let mut next_progress = [None; CP + 2 * RP]; + let mut published = [0u64; CP + RP]; for p in 0..CP { if let Some(f) = fc[p] { next_progress[p] = pending( @@ -1818,15 +1903,20 @@ impl Firmware { published[p] = f.published_ns; } } - if let Some(fr) = fr { - next_progress[CP] = pending( - r.fw_stamp[0].r32(0).unwrap_or(0), - fr.ta_target, - e.ta_target, - ); - next_progress[CP + 1] = - pending(r.fw_stamp[1].r32(0).unwrap_or(0), fr.fs_target, e.fs_target); - published[CP] = fr.published_ns; + for q in 0..RP { + if let Some(fr) = fr[q] { + next_progress[CP + 2 * q] = pending( + r[q].fw_stamp[0].r32(0).unwrap_or(0), + fr.ta_target, + e.ta_target[q], + ); + next_progress[CP + 2 * q + 1] = pending( + r[q].fw_stamp[1].r32(0).unwrap_or(0), + fr.fs_target, + e.fs_target[q], + ); + published[CP + q] = fr.published_ns; + } } let mut compute_moved = [false; CP]; for p in 0..CP { @@ -1834,9 +1924,14 @@ impl Firmware { && e.progress_flight[p] == published[p] && next_progress[p] != e.progress[p]; } - let render_moved = fr.is_some() - && e.progress_flight[CP] == published[CP] - && [next_progress[CP], next_progress[CP + 1]] != [e.progress[CP], e.progress[CP + 1]]; + // One render deadline covers every render pair: a render can wait on another pair's + // (`prefix_render` orders them), so a stall on any pair holds the others. + let render_moved = (0..RP).any(|q| { + let (ta, fs) = (CP + 2 * q, CP + 2 * q + 1); + fr[q].is_some() + && e.progress_flight[CP + q] == published[CP + q] + && [next_progress[ta], next_progress[fs]] != [e.progress[ta], e.progress[fs]] + }); for (p, moved) in compute_moved.into_iter().enumerate() { if moved { self.renew_compute_pipe_deadline(p); @@ -2043,8 +2138,9 @@ impl Firmware { s.span_ticks = s.span_ticks.saturating_add(hi - lo); } if f.renders != 0 { + let pair = (f.render_pair as usize).min(super::hw::sizes::RENDER_PAIRS - 1); for b in 0..2 { - let t = self.events.event_ns[b]; + let t = self.events.event_ns[super::hw::sizes::render_stage(pair, b)]; first = first.min(t); last = last.max(t); } @@ -2073,7 +2169,7 @@ impl Firmware { /// readiness and Flags words). #[allow(dead_code)] pub(crate) fn report(&self, what: &str) { - let (r, e) = (&self.graph.render, &self.engine); + let e = &self.engine; let ch = &self.channels; let rd = |o: &super::object::FwObject, off| o.r32(off).unwrap_or(0xdeadbeef); let state = self @@ -2119,32 +2215,39 @@ impl Firmware { state.fault(), ms ); - if f.is_some_and(|f| f.renders != 0) { - dev_info!( - self.graph.dev.as_ref(), - "G16: render: draw={} ta {:#x}/{:#x}/{:#x} done={} read={} write={} head={} ch0={}/{}; fs {:#x}/{:#x}/{:#x} done={} read={} write={} head={} ch1={}/{}; stage events={}/{}\n", - e.draw, - e.ta_target, - rd(&r.user_stamp[0], 0), - rd(&r.fw_stamp[0], 0), - rd(&r.qstate[0], qstate::DONE), - rd(&r.qstate[0], qstate::READ), - rd(&r.qstate[0], qstate::WRITE), - e.ta_head, - ch.read(Channel::Ta).unwrap_or(0xdeadbeef), - ch.write_cell(Channel::Ta).unwrap_or(0xdeadbeef), - e.fs_target, - rd(&r.user_stamp[1], 0), - rd(&r.fw_stamp[1], 0), - rd(&r.qstate[1], qstate::DONE), - rd(&r.qstate[1], qstate::READ), - rd(&r.qstate[1], qstate::WRITE), - e.fs_head, - ch.read(Channel::Fs).unwrap_or(0xdeadbeef), - ch.write_cell(Channel::Fs).unwrap_or(0xdeadbeef), - self.events.stage_events, - e.stage_seen - ); + if e.flights.iter().any(|f| f.renders != 0) { + for (pair, r) in self.graph.render.iter().enumerate() { + if !e.flights.iter().any(|f| f.renders != 0 && f.render_pair as usize == pair) { + continue; + } + dev_info!( + self.graph.dev.as_ref(), + "G16: render pair {}: draw={}/{} ta {:#x}/{:#x}/{:#x} done={} read={} write={} head={} ch0={}/{}; fs {:#x}/{:#x}/{:#x} done={} read={} write={} head={} ch1={}/{}; stage events={}/{}\n", + pair, + e.pair_draw[pair], + e.draw, + e.ta_target[pair], + rd(&r.user_stamp[0], 0), + rd(&r.fw_stamp[0], 0), + rd(&r.qstate[0], qstate::DONE), + rd(&r.qstate[0], qstate::READ), + rd(&r.qstate[0], qstate::WRITE), + e.ta_head[pair], + ch.read(Channel::Ta).unwrap_or(0xdeadbeef), + ch.write_cell(Channel::Ta).unwrap_or(0xdeadbeef), + e.fs_target[pair], + rd(&r.user_stamp[1], 0), + rd(&r.fw_stamp[1], 0), + rd(&r.qstate[1], qstate::DONE), + rd(&r.qstate[1], qstate::READ), + rd(&r.qstate[1], qstate::WRITE), + e.fs_head[pair], + ch.read(Channel::Fs).unwrap_or(0xdeadbeef), + ch.write_cell(Channel::Fs).unwrap_or(0xdeadbeef), + self.events.stage_events, + e.stage_seen + ); + } } } @@ -2308,6 +2411,11 @@ impl Firmware { write!(f, " {} {}", name, n)?; } writeln!(f)?; + write!(f, "render_pairs: publications")?; + for n in s.render_pair_publications { + write!(f, " {}", n)?; + } + writeln!(f, " cross_pair {}", s.cross_pair_renders)?; } let p = &self.engine.prof; writeln!( diff --git a/drivers/gpu/drm/asahi/g16/pools.rs b/drivers/gpu/drm/asahi/g16/pools.rs index 0af1660bf2579..432bf3ef01c19 100644 --- a/drivers/gpu/drm/asahi/g16/pools.rs +++ b/drivers/gpu/drm/asahi/g16/pools.rs @@ -496,8 +496,12 @@ pub(crate) struct Pools { keep: [bool; sizes::PB_SLOTS], /// Most recently published allocator slot (`0..PB_SLOTS`). active: Option, - /// Most recently cleanly retired allocator slot (proves every other slot is displaced). - last_clean_retired: Option, + /// Publication sequence of the newest render, and per allocator slot the sequence of its + /// newest render and whether a later render of another slot has yet to retire + /// ([`Self::retire_flight`]). + pub_seq: u64, + slot_seq: [u64; sizes::PB_SLOTS], + undisplaced: [bool; sizes::PB_SLOTS], /// Live in-flight render count per allocator slot. inflight: [u32; sizes::PB_SLOTS], /// Permanently quarantined allocator slots after an aborted receipt. @@ -532,7 +536,9 @@ impl Pools { binds: [0; sizes::PB_SLOTS], keep: [false; sizes::PB_SLOTS], active: None, - last_clean_retired: None, + pub_seq: 0, + slot_seq: [0; sizes::PB_SLOTS], + undisplaced: [false; sizes::PB_SLOTS], inflight: [0; sizes::PB_SLOTS], quarantined: [false; sizes::PB_SLOTS], quarantined_epochs: [const { None }; sizes::PB_SLOTS], @@ -560,7 +566,9 @@ impl Pools { binds: [0; sizes::PB_SLOTS], keep: [false; sizes::PB_SLOTS], active: None, - last_clean_retired: None, + pub_seq: 0, + slot_seq: [0; sizes::PB_SLOTS], + undisplaced: [false; sizes::PB_SLOTS], inflight: [0; sizes::PB_SLOTS], quarantined: [false; sizes::PB_SLOTS], quarantined_epochs: [const { None }; sizes::PB_SLOTS], @@ -594,13 +602,12 @@ impl Pools { pub(crate) fn slot_inflight(&self, k: usize) -> u32 { self.inflight.get(k).copied().unwrap_or(0) } - /// Whether slot `k` is healthy, idle, not active, and either fresh or displaced by a clean - /// retirement of some other slot. + /// Whether slot `k` is healthy, idle, and either fresh or displaced: a render of another + /// slot published after `k`'s newest render retired normally ([`Self::retire_flight`]). fn slot_displaced(&self, k: usize) -> bool { !self.quarantined[k] && self.inflight[k] == 0 - && self.active != Some(k) - && (self.owners[k].is_none() || self.last_clean_retired.is_some_and(|r| r != k)) + && (self.owners[k].is_none() || !self.undisplaced[k]) } /// Whether at least one displaced physical PB allocator slot exists in `0..limit`. fn has_displaced_slot_within(&self, limit: usize) -> bool { @@ -955,19 +962,35 @@ impl Pools { self.pending_uma[k] = None; } } - /// Records a render reaching firmware visibility on allocator slot `k`. + /// Records a render reaching firmware visibility on allocator slot `k`. Returns its + /// publication sequence, which the render retires with ([`Self::retire_flight`]). #[allow(dead_code)] - pub(crate) fn publish_flight(&mut self, k: usize) { - if k < sizes::PB_SLOTS { - self.active = Some(k); - self.inflight[k] = self.inflight[k].saturating_add(1); + pub(crate) fn publish_flight(&mut self, k: usize) -> u64 { + if k >= sizes::PB_SLOTS { + return 0; } - } - /// Retires one render flight on allocator slot `k` after a full normal receipt. + self.pub_seq += 1; + self.active = Some(k); + self.slot_seq[k] = self.pub_seq; + self.undisplaced[k] = true; + self.inflight[k] = self.inflight[k].saturating_add(1); + self.pub_seq + } + /// Retires one render flight on allocator slot `k`, published as `seq`, after a full normal + /// receipt. + /// + /// After its last render retires a slot stays the TA and FS engines' current allocator + /// (UMA slot `RENDER_UMA_SLOT + k`, `pb_mgr_table[k]`) until they run a render of another + /// slot: until then no other VM's fresh epoch may rebind it, and its closed owner's arena + /// stays mapped. Renders run on those engines in publication order, so this retirement + /// displaces every other slot whose newest render was published before it. Retirements are + /// observed in publication order only within one render queue pair; the sequence, not the + /// order they are observed in, decides. #[allow(dead_code)] pub(crate) fn retire_flight( &mut self, k: usize, + seq: u64, epoch: &Arc, binding: u64, completed: bool, @@ -998,7 +1021,11 @@ impl Pools { if let Some(uma) = self.pending_uma[k].take() { self.retained_uma[k] = Some(uma); } - self.last_clean_retired = Some(k); + for j in 0..sizes::PB_SLOTS { + if j != k && self.slot_seq[j] < seq { + self.undisplaced[j] = false; + } + } self.retire_epoch(k, binding, completed); Ok(()) } diff --git a/drivers/gpu/drm/asahi/g16/pools/lifetime.rs b/drivers/gpu/drm/asahi/g16/pools/lifetime.rs index d3cf6caf6084d..7356a8c9eda0b 100644 --- a/drivers/gpu/drm/asahi/g16/pools/lifetime.rs +++ b/drivers/gpu/drm/asahi/g16/pools/lifetime.rs @@ -11,6 +11,11 @@ //! in flight (the compute queue); without it, publication stays serialized against every //! owner (the render pass slots). //! +//! With `ordered` pipes, the owners of every pipe run on the engines that load them in +//! publication order (the render queue pairs, ordered by their stage barriers): an owner is +//! then reusable once any owner published after it retired, on any pipe. Retirement is still +//! observed in order only per pipe. +//! //! Core-only so the transition system is executable in host tests. #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -47,6 +52,8 @@ pub(crate) struct Lifetime { units: [Unit; N], sequence: u64, pipelined: bool, + /// Owners of every pipe run in publication order (module documentation). + ordered: bool, } impl Lifetime { pub(crate) const fn new(pipelined: bool) -> Self { @@ -61,8 +68,14 @@ impl Lifetime { units: [unit; N], sequence: 0, pipelined, + ordered: false, } } + /// The owners of every pipe run in publication order (module documentation). + pub(crate) const fn ordered(mut self) -> Self { + self.ordered = true; + self + } #[allow(dead_code)] pub(crate) fn generation(&self, k: usize) -> u8 { self.units[k].generation @@ -96,10 +109,11 @@ impl Lifetime { State::Fresh => true, // A later publication on the same hardware pipe retired: it started only after this // owner finished on that pipe, and its load displaced this owner from the slot. + // A later publication retired: with `ordered` pipes on any pipe, else on this one. State::Retired => self.units.iter().enumerate().any(|(b, other)| { b != k && other.state == State::Retired - && other.pipe == u.pipe + && (self.ordered || other.pipe == u.pipe) && other.publication > u.publication }), _ => false, @@ -172,6 +186,7 @@ impl Lifetime { }; } } + #[allow(dead_code)] pub(crate) fn publish(&mut self, k: usize) -> bool { self.publish_on(k, 0) } @@ -225,6 +240,28 @@ impl Lifetime { mod tests { use super::*; #[test] + fn ordered_pipes_displace_by_publication_on_any_pipe() { + // Owner 0 on pipe 0, then owner 1 on pipe 1; pipe 1 retires first. + let mut l = Lifetime::<3>::new(true).ordered(); + assert!(l.claim(0) && l.publish_on(0, 0)); + assert!(l.claim(1) && l.publish_on(1, 1)); + assert!(l.retire(1)); + assert!(!l.available(1)); + assert!(l.retire(0)); + // The later publication displaced the earlier one across pipes, not the reverse. + assert!(l.available(0) && !l.available(1)); + // Each pipe still retires its own owners in order. + assert!(l.claim(0) && l.publish_on(0, 0)); + assert!(l.claim(2) && l.publish_on(2, 0)); + assert!(!l.retire(2)); + assert!(l.retire(0) && l.retire(2)); + // Without ordered pipes only the same pipe displaces (the compute pipes). + let mut c = Lifetime::<3>::new(true); + assert!(c.claim(0) && c.publish_on(0, 0) && c.retire(0)); + assert!(c.claim(2) && c.publish_on(2, 1) && c.retire(2)); + assert!(!c.available(0)); + } + #[test] fn distinct_retired_displacement_is_required() { let mut l = Lifetime::<2>::new(false); assert!(l.claim(0)); diff --git a/drivers/gpu/drm/asahi/g16/recovery.rs b/drivers/gpu/drm/asahi/g16/recovery.rs index ee64e0e687698..6d5f7384b1786 100644 --- a/drivers/gpu/drm/asahi/g16/recovery.rs +++ b/drivers/gpu/drm/asahi/g16/recovery.rs @@ -51,6 +51,7 @@ pub(crate) fn push_completion(done: &mut Completions, job: &Arc, result: Re } const _: () = assert!(logic::RETIRED_COMPUTE_PIPES == super::hw::sizes::COMPUTE_PIPES); +const _: () = assert!(logic::RETIRED_RENDER_PAIRS == super::hw::sizes::RENDER_PAIRS); pub(crate) struct Recovery { /// Render host deadlines, ordinary and long-job ([`logic::Deadlines`]). @@ -435,7 +436,7 @@ impl Firmware { /// owner prevents acknowledgement: its failure cannot safely be attributed. fn mark_recovery( &mut self, - stage: [u32; 2 + super::hw::sizes::COMPUTE_PIPES], + stage: [u32; super::hw::sizes::STAGES], event: u32, asid: Option, ) -> Result { @@ -540,18 +541,25 @@ impl Firmware { // Which side stalled, and whether tiling or fragment work was left behind. let stage = self .recovery_snapshot() - .unwrap_or([0; 2 + super::hw::sizes::COMPUTE_PIPES]); + .unwrap_or([0; super::hw::sizes::STAGES]); dev_err!( self.dev(), - "M4 GPU recovery exceeded 1000 ms: {} (phase {}, TA {:#x}/{:#x}, FS {:#x}/{:#x}, {} flights)\n", + "M4 GPU recovery exceeded 1000 ms: {} (phase {}, {} flights)\n", logic::Stall::of(last_phase, answered).describe(), last_phase, - stage[0], - self.engine.ta_target, - stage[1], - self.engine.fs_target, self.engine.flights.len() ); + for pair in 0..super::hw::sizes::RENDER_PAIRS { + dev_err!( + self.dev(), + "M4 GPU recovery: render pair {} TA {:#x}/{:#x}, FS {:#x}/{:#x}\n", + pair, + stage[super::hw::sizes::render_stage(pair, 0)], + self.engine.ta_target[pair], + stage[super::hw::sizes::render_stage(pair, 1)], + self.engine.fs_target[pair] + ); + } return Err(ETIMEDOUT); } let phase = self.firmware_r32(self.init.firmware_data().phase)?; diff --git a/drivers/gpu/drm/asahi/g16/recovery/logic.rs b/drivers/gpu/drm/asahi/g16/recovery/logic.rs index a205d213bd221..e44bbf98b303a 100644 --- a/drivers/gpu/drm/asahi/g16/recovery/logic.rs +++ b/drivers/gpu/drm/asahi/g16/recovery/logic.rs @@ -160,8 +160,17 @@ impl SnapshotEntry { pub(crate) const RETIRED_STAMPS_CAP: usize = 64; /// Number of compute pipes tracked by [`RetiredStamps`] (matches `hw::sizes::COMPUTE_PIPES`). pub(crate) const RETIRED_COMPUTE_PIPES: usize = 8; -/// Total retired-stamp stages: compute pipes `0..RETIRED_COMPUTE_PIPES`, TA, FS. -pub(crate) const RETIRED_STAGES: usize = RETIRED_COMPUTE_PIPES + 2; +/// Number of TA/FS render queue pairs tracked by [`RetiredStamps`] (matches +/// `hw::sizes::RENDER_PAIRS`). +pub(crate) const RETIRED_RENDER_PAIRS: usize = 8; +/// Total retired-stamp stages: compute pipes `0..RETIRED_COMPUTE_PIPES`, then TA and FS of each +/// render pair ([`retired_render_stage`]). +pub(crate) const RETIRED_STAGES: usize = RETIRED_COMPUTE_PIPES + 2 * RETIRED_RENDER_PAIRS; + +/// The [`RetiredStamps`] stage of render pair `pair`'s TA (`stage` 0) or FS (`stage` 1). +pub(crate) const fn retired_render_stage(pair: usize, stage: usize) -> usize { + RETIRED_COMPUTE_PIPES + 2 * pair + stage +} /// Bounded per-stage ring of recently retired compute pipe and TA/FS firmware stamps /// so a late recovery snapshot arriving after pipelined retirement resolves any recently @@ -206,8 +215,10 @@ impl RetiredStamps { pub(crate) fn contains(&self, event: u32, target: u32) -> bool { let stage = match event { e if (15..15 + RETIRED_COMPUTE_PIPES as u32).contains(&e) => (e - 15) as usize, - 0x70 => RETIRED_COMPUTE_PIPES, - 0x71 => RETIRED_COMPUTE_PIPES + 1, + // Render pair p: TA 0x70 + 2p, FS 0x71 + 2p. + e if (0x70..0x70 + 2 * RETIRED_RENDER_PAIRS as u32).contains(&e) => { + RETIRED_COMPUTE_PIPES + (e - 0x70) as usize + } _ => return false, }; let len = self.len[stage] as usize; @@ -336,6 +347,15 @@ mod tests { assert!(!retired.contains(event, target.wrapping_add(0x100))); } assert!(!retired.contains(0x72, 0)); + // Render pair 1 (0x72/0x73) keeps its own history; dense per-pair stamps collide + // across pairs, so a pair-1 stamp never names a pair-0 owner. + retired.push(retired_render_stage(1, 1), 0x400); + assert!(retired.contains(0x73, 0x400)); + assert!(!retired.contains(0x71, 0x400)); + assert!(!retired.contains(0x72, 0x400)); + retired.push(retired_render_stage(7, 0), 0x500); + assert!(retired.contains(0x7e, 0x500)); + assert!(!retired.contains(0x80, 0x500)); // Pipelined bursts retain all recent stamps up to RETIRED_STAMPS_CAP and evict oldest. let mut ring = RetiredStamps::new(); for i in 0..(RETIRED_STAMPS_CAP as u32 + 4) { diff --git a/drivers/gpu/drm/asahi/g16/slots.rs b/drivers/gpu/drm/asahi/g16/slots.rs index f938866ba2eb9..0d78699350d5a 100644 --- a/drivers/gpu/drm/asahi/g16/slots.rs +++ b/drivers/gpu/drm/asahi/g16/slots.rs @@ -660,6 +660,8 @@ pub(crate) struct Claims { pub(crate) slot: [u32; sizes::COMPUTE_SLOTS], pub(crate) slot_count: u32, pub(crate) compute_pipe: u8, + /// Render queue pair the pass slots are published on. + pub(crate) render_pair: u8, pub(crate) pass: [u32; sizes::RENDER_SLOTS], pub(crate) pass_count: u32, pub(crate) pass_mask: u64, @@ -678,6 +680,7 @@ impl Claims { slot: [0; sizes::COMPUTE_SLOTS], slot_count: 0, compute_pipe: 0, + render_pair: 0, pass: [0; sizes::RENDER_SLOTS], pass_count: 0, pass_mask: 0, @@ -1017,7 +1020,8 @@ impl Slots { )?, render: KBox::init( init!(RenderOwners { - lifetime: Lifetime::new(true), + // Every render queue pair feeds the TA and FS engines in publication order. + lifetime: Lifetime::new(true).ordered(), owner: [const { None }; sizes::RENDER_SLOTS], pending_retarget: [None; sizes::RENDER_SLOTS], pending_owner: [const { None }; sizes::RENDER_SLOTS], @@ -2025,7 +2029,7 @@ impl Slots { return Err(EINVAL); } for &k in &f.pass[..f.pass_count as usize] { - if k as usize >= sizes::RENDER_SLOTS || !p.publish(k as usize) { + if k as usize >= sizes::RENDER_SLOTS || !p.publish_on(k as usize, f.render_pair) { return Err(EBUSY); } } @@ -2034,7 +2038,7 @@ impl Slots { while mask != 0 { let k = mask.trailing_zeros() as usize; mask &= mask - 1; - if !p.publish(k) { + if !p.publish_on(k, f.render_pair) { return Err(EBUSY); } } diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs index a06623ffaa9f2..0b9199cac7015 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs @@ -131,7 +131,7 @@ fn render(out: &std::path::Path) { uma_mgr: [f + 0x300000, f + 0x300000], uma_aux: [f + 0x300100, f + 0x300200], uma_gpu: g + 0x6000000, pb_mgr: f + 0x3000000, scene_list: g + 0x500000, parameter_id: 3, generation: 254, activity: [f + 0x900004, f + 0xa00008], - counter: [4, 3], uma_submitted: 4, uuid: 0x123401, usc_base: 1 << 40, + counter: [4, 3], uma_submitted: 4, uuid: 0x123401, usc_base: 1 << 40, event: [0x70, 0x71], ..Default::default() }; let p = encode::PassRefs { @@ -397,7 +397,7 @@ fn g15s_26b123() { uma_gpu: g + 0x6000000, pb_mgr: f + 0x3000000, scene_list: g + 0x500000, pb_init_blocks: 512, parameter_id: 6, generation: 254, activity: [f + 0x900004, f + 0xa00008], counter: [4, 3], uma_submitted: 4, - uuid: 0x123401, usc_base: 1 << 40, ..Default::default() + uuid: 0x123401, usc_base: 1 << 40, event: [0x70, 0x71], ..Default::default() }; let p = encode::PassRefs { ta_work: f + 0xb00000, ta_work_gva: g + 0x7000000, fs_work: f + 0xc00000, diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-render.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-render.rs index d93aa65b30fee..e647ce1082a9c 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-render.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-render.rs @@ -47,7 +47,7 @@ fn main() { uma_mgr:[f+0x300000,f+0x300000],uma_aux:[f+0x300100,f+0x300200],uma_gpu:g+0x6000000,pb_mgr:f+0x3000000, scene_list:g+0x500000,parameter_id:[0,3,31,15][v],generation:[1,2,254,127][v], activity:[f+0x900004,f+0xa00008],counter:[2+v as u64*2,1+v as u64*2], - uma_submitted:2+v as u64*2,uuid:0x123400+v as u32,usc_base:1<<40, + uma_submitted:2+v as u64*2,uuid:0x123400+v as u32,usc_base:1<<40, event: [0x70, 0x71], ..Default::default() }; let p=encode::PassRefs { 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 93f34ddc4fa5d..56a74111a4f38 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,6 +66,7 @@ def item(declaration, text=source): mod hw { pub mod sizes { pub const COMPUTE_PIPES: usize = 8; + pub const RENDER_PAIRS: usize = 2; pub const COALESCE_WINDOW_US: u32 = 18; } } @@ -127,7 +128,7 @@ def item(declaration, text=source): } struct Graph { compute: [ComputeGraph; hw::sizes::COMPUTE_PIPES], - render: RenderGraph, + render: [RenderGraph; hw::sizes::RENDER_PAIRS], } #[derive(Default)] @@ -146,6 +147,7 @@ def item(declaration, text=source): computes: u32, compute_pipe: u8, renders: u32, + render_pair: u8, target: u32, fs_target: u32, } @@ -155,7 +157,7 @@ def item(declaration, text=source): flights: Vec, pending: Vec>, target: [u32; hw::sizes::COMPUTE_PIPES], - fs_target: u32, + fs_target: [u32; hw::sizes::RENDER_PAIRS], chan_wait: bool, slot_wait: bool, short_repoll: bool, @@ -346,16 +348,16 @@ def item(declaration, text=source): compute: core::array::from_fn(|_| ComputeGraph { fw_stamp: Cell32::new(0), }), - render: RenderGraph { + render: core::array::from_fn(|_| RenderGraph { fw_stamp: [Cell32::new(0), Cell32::new(0)], - }, + }), }, engine: Engine { shared: None, flights: vec![], pending: vec![], target: [0; hw::sizes::COMPUTE_PIPES], - fs_target: 0, + fs_target: [0; hw::sizes::RENDER_PAIRS], chan_wait: false, slot_wait: false, short_repoll: false, @@ -579,6 +581,7 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); fw.engine.target[0] = 0x100; fw.graph.compute[0].fw_stamp.set(0x100); @@ -607,8 +610,9 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; let mut done = vec![]; shared @@ -629,8 +633,9 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw_ta.engine.fs_target = 0x100; + fw_ta.engine.fs_target[0] = 0x100; fw_ta.drain_stage_delta = 1; fw_ta.drain_fs_delta = 0; shared_ta @@ -656,6 +661,7 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); fw.engine.flights.push(Flight { computes: 1, @@ -663,6 +669,7 @@ def item(declaration, text=source): renders: 0, target: 0x200, fs_target: 0, + render_pair: 0, }); fw.engine.target[0] = 0x200; @@ -707,6 +714,7 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); fw.engine.target[0] = 0x100; let mut retry_tail = false; @@ -741,6 +749,7 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); let mut done = vec![]; @@ -778,8 +787,9 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; // Simulate draining a TA (0x70) stage event with no FS (0x71) event and FS stamp unreached. fw.drain_stage_delta = 1; fw.drain_fs_delta = 0; @@ -805,8 +815,9 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; fw.drain_stage_delta = 1; fw.drain_fs_delta = 1; @@ -838,6 +849,7 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x200, + render_pair: 0, }); fw.engine.flights.push(Flight { computes: 1, @@ -845,15 +857,16 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); - fw.engine.fs_target = 0x200; + fw.engine.fs_target[0] = 0x200; fw.engine.target[0] = 0x100; // Render still running, compute reached its stamp. - fw.graph.render.fw_stamp[1].set(0x100); + fw.graph.render[0].fw_stamp[1].set(0x100); fw.graph.compute[0].fw_stamp.set(0x100); assert!(fw.oldest_stamp_reached()); assert_eq!(fw.graph.compute[0].fw_stamp.reads.get(), 1); - assert_eq!(fw.graph.render.fw_stamp[1].reads.get(), 0); + assert_eq!(fw.graph.render[0].fw_stamp[1].reads.get(), 0); assert_eq!(fw.oldest_terminal_events(), Some((Some(0), Some(0)))); // Pipe 1 reaching its stamp behind a pending pipe 0 flight also wakes inline retirement. @@ -864,6 +877,7 @@ def item(declaration, text=source): renders: 0, target: 0x200, fs_target: 0, + render_pair: 0, }); fw2.engine.flights.push(Flight { computes: 1, @@ -871,6 +885,7 @@ def item(declaration, text=source): renders: 0, target: 0x100, fs_target: 0, + render_pair: 0, }); fw2.engine.target[0] = 0x200; fw2.engine.target[1] = 0x100; @@ -879,7 +894,7 @@ def item(declaration, text=source): assert!(fw2.oldest_stamp_reached()); assert_eq!(fw2.graph.compute[0].fw_stamp.reads.get(), 1); assert_eq!(fw2.graph.compute[1].fw_stamp.reads.get(), 1); - assert_eq!(fw2.graph.render.fw_stamp[1].reads.get(), 0); + assert_eq!(fw2.graph.render[0].fw_stamp[1].reads.get(), 0); } #[test] @@ -892,14 +907,15 @@ def item(declaration, text=source): renders: 0, target: 0x200, fs_target: 0, + render_pair: 0, }); fc.engine.target[0] = 0x200; fc.graph.compute[0].fw_stamp.set(0x100); assert!(!fc.oldest_stamp_reached()); assert_eq!(fc.graph.compute[0].fw_stamp.reads.get(), 1); assert_eq!(fc.graph.compute[1].fw_stamp.reads.get(), 0); - assert_eq!(fc.graph.render.fw_stamp[0].reads.get(), 0); - assert_eq!(fc.graph.render.fw_stamp[1].reads.get(), 0); + assert_eq!(fc.graph.render[0].fw_stamp[0].reads.get(), 0); + assert_eq!(fc.graph.render[0].fw_stamp[1].reads.get(), 0); // Render-only workload never reads compute fw_stamp. let mut fr = Firmware::new(); @@ -909,14 +925,15 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x200, + render_pair: 0, }); - fr.engine.fs_target = 0x200; - fr.graph.render.fw_stamp[1].set(0x100); + fr.engine.fs_target[0] = 0x200; + fr.graph.render[0].fw_stamp[1].set(0x100); assert!(!fr.oldest_stamp_reached()); assert_eq!(fr.graph.compute[0].fw_stamp.reads.get(), 0); assert_eq!(fr.graph.compute[1].fw_stamp.reads.get(), 0); - assert_eq!(fr.graph.render.fw_stamp[0].reads.get(), 0); - assert_eq!(fr.graph.render.fw_stamp[1].reads.get(), 1); + assert_eq!(fr.graph.render[0].fw_stamp[0].reads.get(), 0); + assert_eq!(fr.graph.render[0].fw_stamp[1].reads.get(), 1); } #[test] @@ -929,9 +946,10 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); fw.engine.pending.push(Arc::new(Job { id: 2 })); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; fw.drain_stage_delta = 1; let mut retry_tail = false; let mut deferred = false; @@ -998,8 +1016,9 @@ def item(declaration, text=source): renders: 11, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; let mut retry_tail = false; let mut deferred = false; let mut done = vec![]; @@ -1053,8 +1072,9 @@ def item(declaration, text=source): renders: 2, target: 0, fs_target: 0x200, + render_pair: 0, }); - fw.engine.fs_target = 0x200; + fw.engine.fs_target[0] = 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![]); @@ -1098,8 +1118,9 @@ def item(declaration, text=source): renders: 4, target: 0, fs_target: 0x400, + render_pair: 0, }); - fw.engine.fs_target = 0x400; + fw.engine.fs_target[0] = 0x400; fw.engine.pending.push(Arc::new(Job { id: 2 })); fw.drain_stage_delta = 1; fw.drain_fs_delta = 0; @@ -1135,8 +1156,9 @@ def item(declaration, text=source): renders: 1, target: 0, fs_target: 0x100, + render_pair: 0, }); - fw.engine.fs_target = 0x100; + fw.engine.fs_target[0] = 0x100; fw.engine.frozen = frozen; fw.publish_waits = Some((slot_wait, held_wait)); let mut done = vec![]; @@ -1162,6 +1184,7 @@ def item(declaration, text=source): renders: 0, target: 0x200, fs_target: 0, + render_pair: 0, }); fw.engine.target[0] = 0x200; fw.coalesce_us = Some(18); @@ -1219,11 +1242,24 @@ def item(declaration, text=source): const RING_SLOTS: u32 = 128; const RECORD_WORDS: usize = 18; const COMPUTE_PIPES: usize = 8; - const STAGE_COUNT: usize = 2 + COMPUTE_PIPES; + mod sizes { + pub const COMPUTE_PIPES: usize = 8; + pub const RENDER_PAIRS: usize = 2; + pub const STAGES: usize = 2 + COMPUTE_PIPES + 2 * (RENDER_PAIRS - 1); + pub const fn render_stage(pair: usize, stage: usize) -> usize { + if pair == 0 { stage } else { 2 + COMPUTE_PIPES + 2 * (pair - 1) + stage } + } + } + const STAGE_COUNT: usize = sizes::STAGES; mod compute { pub const EVENT: u32 = 15; } + mod render_pair { + pub const TA_EVENT: u32 = 0x70; + } const COMPUTE_EVENT_MASK: u32 = ((1u32 << COMPUTE_PIPES) - 1) << compute::EVENT; + const RENDER_EVENT_MASK: u32 = + ((1u32 << (2 * sizes::RENDER_PAIRS)) - 1) << (render_pair::TA_EVENT % 32); mod rings { pub const EVENT_RECORD: usize = 0x48; } @@ -1387,6 +1423,37 @@ def item(declaration, text=source): assert_eq!(ring.ring.reads.get(), 15); } + #[test] + fn event_drain_decodes_render_pair_1_events() { + // Render pair 1 posts TA 0x72 (word 4 bit 18) and FS 0x73 (bit 19); both land + // in their own stage cells after the compute pipes, and FS counts as a terminal event. + let ring = Ring::new(); + let mut r0 = [0u32; RECORD_WORDS]; + r0[0] = 1; + r0[4] = 1 << 18; + let mut r1 = [0u32; RECORD_WORDS]; + r1[0] = 1; + r1[4] = (1 << 19) | (1 << 17); + let mut r2 = [0u32; RECORD_WORDS]; + r2[0] = 1; + r2[4] = 1 << 20; + ring.put_record(0, &r0); + ring.put_record(1, &r1); + ring.put_record(2, &r2); + ring.set_indices(0, 3); + let mut ev = Events::default(); + ev.drain(&device::Device, &ring).unwrap(); + assert_eq!(sizes::render_stage(1, 0), 10); + assert_eq!(ev.event_ns[0], 0); + assert_eq!(ev.event_ns[1], 12345); + assert_eq!(ev.event_ns[sizes::render_stage(1, 0)], 12345); + assert_eq!(ev.event_ns[sizes::render_stage(1, 1)], 12345); + // 0x74 names no configured pair. + assert_eq!(ev.stage_events, 3); + assert_eq!(ev.fs_events, 2); + assert_eq!(ev.compute_events, 0); + } + #[test] fn event_drain_flushes_progress_on_mid_burst_error() { let ring = Ring::new(); @@ -1814,7 +1881,7 @@ def item(declaration, text=source): json.dumps( { 'passed': True, - 'tests': 25, + 'tests': 26, '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-progress-wrap.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-progress-wrap.py index 19ebbe49508af..8fb768177ddef 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-progress-wrap.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-progress-wrap.py @@ -9,7 +9,7 @@ def function(text,name): marker=text.index('fn '+name+'(');start=text.rfind('\n',0,marker)+1;at=text.index('{',marker);depth,end=1,at+1 while depth:depth+=(text[end]=='{')-(text[end]=='}');end+=1 return text[start:end] -option='progress: [Option; sizes::COMPUTE_PIPES + 2]' in engine +option='progress: [Option; sizes::COMPUTE_PIPES + 2 * sizes::RENDER_PAIRS]' in engine harness=r''' #![allow(dead_code)] use std::cell::Cell; @@ -18,7 +18,7 @@ def function(text,name): #[derive(Copy,Clone,Debug,PartialEq,Eq)]struct Error(i32); const EIO:Error=Error(5);const ETIMEDOUT:Error=Error(110); type Result=core::result::Result; -mod hw{pub mod sizes{pub const COMPUTE_PIPES:usize=8;}} +mod hw{pub mod sizes{pub const COMPUTE_PIPES:usize=8;pub const RENDER_PAIRS:usize=2;}} mod command{pub const RENDER:usize=0;pub const COMPUTE:usize=1;} mod params{ pub fn recovery()->bool{true} @@ -31,11 +31,11 @@ def function(text,name): macro_rules! dev_warn{($($tt:tt)*)=>{};} macro_rules! dev_err{($($tt:tt)*)=>{};} struct Object(Cell);impl Object{fn r32(&self,_off:usize)->core::result::Result{Ok(self.0.get())}} -struct Compute{fw_stamp:Object}struct Render{fw_stamp:[Object;2]}struct Graph{compute:[Compute;hw::sizes::COMPUTE_PIPES],render:Render} +struct Compute{fw_stamp:Object}struct Render{fw_stamp:[Object;2]}struct Graph{compute:[Compute;hw::sizes::COMPUTE_PIPES],render:[Render;hw::sizes::RENDER_PAIRS]} struct Job{long:bool} impl Job{fn long(&self)->bool{self.long}} -struct Flight{job:Job,computes:u32,compute_pipe:u8,renders:u32,target:u32,ta_target:u32,fs_target:u32,published_ns:u64} -struct Engine{flights:Vec,target:[u32;hw::sizes::COMPUTE_PIPES],ta_target:u32,fs_target:u32,progress_flight:[u64;hw::sizes::COMPUTE_PIPES+1],progress:[__TYPE__;hw::sizes::COMPUTE_PIPES+2]} +struct Flight{render_pair:u8,job:Job,computes:u32,compute_pipe:u8,renders:u32,target:u32,ta_target:u32,fs_target:u32,published_ns:u64} +struct Engine{flights:Vec,target:[u32;hw::sizes::COMPUTE_PIPES],ta_target:[u32;hw::sizes::RENDER_PAIRS],fs_target:[u32;hw::sizes::RENDER_PAIRS],progress_flight:[u64;hw::sizes::COMPUTE_PIPES+hw::sizes::RENDER_PAIRS],progress:[__TYPE__;hw::sizes::COMPUTE_PIPES+2*hw::sizes::RENDER_PAIRS]} impl Engine{fn oldest(&self)->Option<&Flight>{self.flights.first()}} struct Recovery{deadlines:logic::Deadlines,compute_deadlines:[logic::Deadlines;hw::sizes::COMPUTE_PIPES],warning_deadline_ns:[u64;2],compute_warning_deadline_ns:[u64;hw::sizes::COMPUTE_PIPES],long_commands:u64,receipt_fault:bool,failed:Option} struct Firmware{graph:Graph,engine:Engine,recovery:Recovery,render_renewed:u32,compute_renewed:u32,pipe_renewed:[u32;hw::sizes::COMPUTE_PIPES],fail_stops:Vec} @@ -75,8 +75,8 @@ def function(text,name): fn firmware(render:bool,target:u32,previous:u32)->Firmware{ set_now_ns(1_000_000_000); let mut t=[0u32;hw::sizes::COMPUTE_PIPES];t[0]=target; - let mut f=Firmware{graph:Graph{compute:core::array::from_fn(|_|Compute{fw_stamp:Object(Cell::new(previous))}),render:Render{fw_stamp:[Object(Cell::new(previous)),Object(Cell::new(previous))]}}, - engine:Engine{flights:vec![Flight{job:Job{long:false},computes:u32::from(!render),compute_pipe:0,renders:u32::from(render),target,ta_target:target,fs_target:target,published_ns:1}],target:t,ta_target:target,fs_target:target,progress_flight:[0;hw::sizes::COMPUTE_PIPES+1],progress:[__ZERO__;hw::sizes::COMPUTE_PIPES+2]}, + let mut f=Firmware{graph:Graph{compute:core::array::from_fn(|_|Compute{fw_stamp:Object(Cell::new(previous))}),render:core::array::from_fn(|_|Render{fw_stamp:[Object(Cell::new(previous)),Object(Cell::new(previous))]})}, + engine:Engine{flights:vec![Flight{render_pair:0,job:Job{long:false},computes:u32::from(!render),compute_pipe:0,renders:u32::from(render),target,ta_target:target,fs_target:target,published_ns:1}],target:t,ta_target:[target;hw::sizes::RENDER_PAIRS],fs_target:[target;hw::sizes::RENDER_PAIRS],progress_flight:[0;hw::sizes::COMPUTE_PIPES+hw::sizes::RENDER_PAIRS],progress:[__ZERO__;hw::sizes::COMPUTE_PIPES+2*hw::sizes::RENDER_PAIRS]}, recovery:Recovery{deadlines:logic::Deadlines::EXPIRED,compute_deadlines:[logic::Deadlines::EXPIRED;hw::sizes::COMPUTE_PIPES],warning_deadline_ns:[u64::MAX;2],compute_warning_deadline_ns:[u64::MAX;hw::sizes::COMPUTE_PIPES],long_commands:0,receipt_fault:false,failed:None}, render_renewed:0,compute_renewed:0,pipe_renewed:[0;hw::sizes::COMPUTE_PIPES],fail_stops:vec![]}; f.renew_render_deadline();f.renew_compute_deadline();f.render_renewed=0;f.compute_renewed=0;f.pipe_renewed=[0;hw::sizes::COMPUTE_PIPES];f @@ -90,8 +90,8 @@ def function(text,name): #[test]fn paired_ta_fs_zero_each_renews_once_without_lending_other_engine_progress(){ let mut f=firmware(true,0x100,0);f.progress(); f.graph.compute[0].fw_stamp.0.set(0x100);f.progress();assert_eq!(f.render_renewed,0);assert_eq!(f.compute_renewed,0); - f.graph.render.fw_stamp[0].0.set(0x100);f.progress();assert_eq!(f.render_renewed,1);assert_eq!(f.compute_renewed,0); - f.graph.render.fw_stamp[1].0.set(0x100);f.progress();assert_eq!(f.render_renewed,2);assert_eq!(f.compute_renewed,0); + f.graph.render[0].fw_stamp[0].0.set(0x100);f.progress();assert_eq!(f.render_renewed,1);assert_eq!(f.compute_renewed,0); + f.graph.render[0].fw_stamp[1].0.set(0x100);f.progress();assert_eq!(f.render_renewed,2);assert_eq!(f.compute_renewed,0); f.progress();assert_eq!(f.render_renewed,2); } #[test]fn before_at_and_after_zero_completions_have_the_same_progress_contract(){ @@ -103,15 +103,15 @@ def function(text,name): } #[test]fn concurrent_compute_and_render_renew_deadlines_independently(){ let mut f=firmware(true,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); + f.engine.flights.push(Flight{render_pair:0,job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); f.engine.target[0]=0x300; f.progress();assert_eq!((f.render_renewed,f.compute_renewed),(0,0)); f.graph.compute[0].fw_stamp.0.set(0x300);f.progress();assert_eq!((f.render_renewed,f.compute_renewed),(0,1)); - f.graph.render.fw_stamp[0].0.set(0x200);f.progress();assert_eq!((f.render_renewed,f.compute_renewed),(1,1)); + f.graph.render[0].fw_stamp[0].0.set(0x200);f.progress();assert_eq!((f.render_renewed,f.compute_renewed),(1,1)); } #[test]fn two_concurrent_compute_pipes_sample_progress_independently(){ let mut f=firmware(false,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:false},computes:1,compute_pipe:1,renders:0,target:0x200,ta_target:0,fs_target:0,published_ns:2}); + f.engine.flights.push(Flight{render_pair:0,job:Job{long:false},computes:1,compute_pipe:1,renders:0,target:0x200,ta_target:0,fs_target:0,published_ns:2}); f.engine.target[0]=0x200;f.engine.target[1]=0x200; f.progress();assert_eq!(f.compute_renewed,0); // Pipe 1 advances while pipe 0 stays pending -> renews compute deadline once. @@ -124,7 +124,7 @@ def function(text,name): } #[test]fn stuck_render_times_out_while_compute_keeps_advancing_and_retiring(){ let mut f=firmware(true,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); + f.engine.flights.push(Flight{render_pair:0,job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); f.engine.target[0]=0x300; let mut done=(); assert_eq!(f.check_hangs(&mut done),Ok(())); @@ -149,21 +149,21 @@ def function(text,name): } #[test]fn stuck_compute_times_out_while_render_keeps_advancing_and_retiring(){ let mut f=firmware(false,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:false},computes:0,compute_pipe:0,renders:1,target:0,ta_target:0x300,fs_target:0x300,published_ns:2}); - f.engine.ta_target=0x300;f.engine.fs_target=0x300; + f.engine.flights.push(Flight{render_pair:0,job:Job{long:false},computes:0,compute_pipe:0,renders:1,target:0,ta_target:0x300,fs_target:0x300,published_ns:2}); + f.engine.ta_target[0]=0x300;f.engine.fs_target[0]=0x300; let mut done=(); assert_eq!(f.check_hangs(&mut done),Ok(())); // Render keeps advancing and retiring every 2 s across 6 s while compute stays stuck at 0x100. for step in 1u64..=3 { set_now_ns(1_000_000_000 + step * 2_000_000_000); let next_target = 0x300 + (step as u32) * 0x100; - f.graph.render.fw_stamp[0].0.set(next_target - 0x100); - f.graph.render.fw_stamp[1].0.set(next_target - 0x100); + f.graph.render[0].fw_stamp[0].0.set(next_target - 0x100); + f.graph.render[0].fw_stamp[1].0.set(next_target - 0x100); f.engine.flights[1].ta_target = next_target; f.engine.flights[1].fs_target = next_target; f.engine.flights[1].published_ns = 2 + step; - f.engine.ta_target = next_target; - f.engine.fs_target = next_target; + f.engine.ta_target[0] = next_target; + f.engine.fs_target[0] = next_target; f.renew_render_deadline(); let res = f.check_hangs(&mut done); if step < 3 { @@ -180,7 +180,7 @@ def function(text,name): // keeps advancing and retiring every 2s across 6s. Pipe 1 progress/retirement must never // renew pipe 0's deadline or grant pipe 0 the 10s long-job allowance. let mut f=firmware(false,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:true},computes:1,compute_pipe:1,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); + f.engine.flights.push(Flight{render_pair:0,job:Job{long:true},computes:1,compute_pipe:1,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); f.engine.target[1]=0x300; let mut done=(); assert_eq!(f.check_hangs(&mut done),Ok(())); @@ -208,7 +208,7 @@ def function(text,name): // on the same pipe (10s allowance). Only the oldest active flight on a pipe selects its // deadline, so the stalled normal head still times out at 6s instead of inheriting 10s. let mut f=firmware(false,0x200,0x100); - f.engine.flights.push(Flight{job:Job{long:true},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); + f.engine.flights.push(Flight{render_pair:0,job:Job{long:true},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); f.engine.target[0]=0x300; let mut done=(); set_now_ns(1_000_000_000 + 6_000_000_000); @@ -218,15 +218,25 @@ def function(text,name): // queued behind it on the same pipe, pipe 0 keeps its 10s long-job allowance at 6s. let mut fl=firmware(false,0x200,0x100); fl.engine.flights[0].job.long=true; - fl.engine.flights.push(Flight{job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); + fl.engine.flights.push(Flight{render_pair:0,job:Job{long:false},computes:1,compute_pipe:0,renders:0,target:0x300,ta_target:0,fs_target:0,published_ns:2}); fl.engine.target[0]=0x300; set_now_ns(1_000_000_000 + 6_000_000_000); assert_eq!(fl.check_hangs(&mut done), Ok(())); assert!(fl.fail_stops.is_empty()); } +#[test]fn progress_on_any_render_pair_renews_the_render_deadline(){ + // Each pair's oldest flight has its own progress cells; the pairs share one deadline. + let mut f=firmware(true,0x200,0x100); + f.engine.flights.push(Flight{render_pair:1,job:Job{long:false},computes:0,compute_pipe:0,renders:1,target:0,ta_target:0x200,fs_target:0x200,published_ns:2}); + f.progress();assert_eq!(f.render_renewed,0); + f.graph.render[1].fw_stamp[0].0.set(0x200);f.progress();assert_eq!(f.render_renewed,1); + f.graph.render[0].fw_stamp[1].0.set(0x200);f.progress();assert_eq!(f.render_renewed,2); + f.progress();assert_eq!(f.render_renewed,2); + assert_eq!(f.compute_renewed,0); +} '''.replace('__LOGIC__',str(backend/'recovery/logic.rs')).replace('__PROGRESS__',function(source,'progress').replace('super::hw::','hw::')).replace('__CHECK_HANGS__',function(recovery_src,'check_hangs').replace('super::command::','command::').replace('super::hw::','hw::')).replace('__TYPE__','Option' if option else 'u32').replace('__ZERO__','None' if option else '0') unit=out/'progress-wrap.rs';unit.write_text(harness);log='' for command in [rustc()+['--edition=2021','--test',str(unit),'-o',str(out/'progress-wrap')],[str(out/'progress-wrap'),'--nocapture']]: result=subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True);log+=result.stdout;print(result.stdout,end='');(out/'progress-wrap.log').write_text(log) if result.returncode:raise SystemExit(result.returncode) -(out/'progress-wrap.json').write_text(json.dumps({'passed':True,'cpu_only':True,'tests':11,'scope':'Copied production progress and modular comparison logic; mapped-register reads and deadline renewal mocked. No GPU or real deadline expiration.','source_sha256':{name:sha(backend/name)for name in ['engine.rs','poll.rs','recovery/logic.rs']}},indent=2)+'\n') +(out/'progress-wrap.json').write_text(json.dumps({'passed':True,'cpu_only':True,'tests':12,'scope':'Copied production progress and modular comparison logic; mapped-register reads and deadline renewal mocked. No GPU or real deadline expiration.','source_sha256':{name:sha(backend/name)for name in ['engine.rs','poll.rs','recovery/logic.rs']}},indent=2)+'\n') 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 50611556c8718..1d2ccdff019c2 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -3,6 +3,7 @@ """Execute production M4 publication/error isolation with a CPU-only transport recorder.""" from common import kernel_root, output_dir, rustc, sha import json +import re import subprocess production = kernel_root() / 'drivers/gpu/drm/asahi/g16/engine.rs' @@ -49,8 +50,18 @@ def item(declaration): 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);') - < prefix_render_fn.index('if plan.ta_prev_wait') + < prefix_render_fn.index('if let Some((stamp, wait_ta, event)) = ta_prev') ), 'render_bar must be hoisted ahead of barrier emission' +# Renders reach TA and FS in publication order across render pairs: a prefix's first pass waits +# for the newest in-flight render when it is on another pair, in place of its own pair's +# prev_barrier / fs_dep, so a pass keeps at most MAX_RENDER_RING_ENTRIES ring entries. +prior_slice = prefix_render_fn[prefix_render_fn.index('let prior = if member == 0'):prefix_render_fn.index('let producer_initbm')] +assert '.rev()' in prior_slice and '.find(|fl| fl.renders != 0)' in prior_slice, prior_slice +assert '.filter(|fl| fl.render_pair as usize != pair)' in prior_slice, prior_slice +pair_slice = prefix_render_fn[prefix_render_fn.index('let (ta_prev, fs_prev) = match prior'):prefix_render_fn.index('if let Some((stamp, wait_ta, event)) = ta_prev')] +assert 'Some((other.fw_stamp[0].va, ta, ta_event))' in pair_slice and 'Some((other.fw_stamp[1].va, fs, fs_event))' in pair_slice, pair_slice +assert 'plan.ta_prev_wait' in pair_slice and 'plan.fs_render_wait' in pair_slice, pair_slice +assert 'prior.is_some_and(|(_, _, _, initbm)| initbm)' in prefix_render_fn assert prefix_render_fn.count('render_bar,') == 5, prefix_render_fn assert 'p.prev_barrier.write(0, &prev)?;' in prefix_render_fn assert 'p.ta_fs_barrier.write(0, &ta_fs)?;' in prefix_render_fn @@ -77,8 +88,9 @@ def item(declaration): assert 'let waits_for_timestamps = c.query_access' in can_queue_behind_fn assert 'DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2' in params_src publish_prefix_body_fn = item('fn publish_prefix_body(') -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 +# Each render pair's thresholds follow its own dense draw ordinal. +assert 'r.threshold.w32(0, prefix.pair_draw as u32)?;' in publish_prefix_body_fn +assert 'r.threshold.w32(8, prefix.pair_draw as u32)?;' in publish_prefix_body_fn assert 'earliest_unfinished_ta_draw' not in source and 'rearm_ta_threshold' not in source 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' @@ -135,14 +147,25 @@ def item(declaration): __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} -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,render_pair: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,render_pair:0,rt_compute:false,doomed:false,recovery_suspect:false,initbm:false}}} __SCS_COMPUTE_CONFLICT__ __CROSS_VM_RENDER_CONFLICT__ -struct Engine{ordinal:u64,draw:u64,pending:Vec>,flights:Vec,frozen:bool,turn:u64,stats:Stats,chan_wait:bool,slot_wait:bool,held_wait:bool,handoff_avoid_pipes:u32,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,held_wait:bool,handoff_avoid_pipes:u32,handoff_avoid_pairs:u8,coalesce_deadline_ns:u64} impl Engine { __PICK__ __UNPEND__ + fn render_pair_hint(&self,vm:&Vm)->Option{crate::pair_hint::get(vm.id)} +} +impl QueueBehindEngine { + fn render_pair_hint(&self,vm:&Vm)->Option{crate::pair_hint::get(vm.id)} +} +// `Engine::render_pair_hint` stand-in: the pair of a VM's newest render, per test thread. +mod pair_hint { + thread_local!{static HINTS:std::cell::RefCell>=const{std::cell::RefCell::new(Vec::new())};} + pub fn get(id:u64)->Option{HINTS.with(|h|h.borrow().iter().find(|(v,_)|*v==id).map(|&(_,p)|p))} + pub fn set(id:u64,pair:usize){HINTS.with(|h|{let mut h=h.borrow_mut();h.retain(|(v,_)|*v!=id);h.push((id,pair));});} + pub fn clear(){HINTS.with(|h|h.borrow_mut().clear());} } struct Checks;impl Checks{fn check(&self)->Result{Ok(())}fn health(&self)->Result{Ok(())}} struct Shared{sleeping:AtomicBool} @@ -185,7 +208,7 @@ def item(declaration): // containment branch below decides whether the unit becomes claimable again. pub fn validate_compute_descriptor(refs:&ComputeRefs,_old:&[u8;160],_before:u64)->Result<(),()>{if refs.invalid{Err(())}else{Ok(())}} } -mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const COMPUTE_PIPES:usize=8; pub const MAX_VM_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 hw { pub mod sizes { pub const RENDER_PAIRS:usize=2; pub const STAGES:usize=2+COMPUTE_PIPES+2*(RENDER_PAIRS-1); pub const fn render_stage(pair:usize,stage:usize)->usize{if pair==0{stage}else{2+COMPUTE_PIPES+2*(pair-1)+stage}} pub const FLIGHTS:usize=32; pub const COMPUTE_PIPES:usize=8; pub const MAX_VM_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())} @@ -230,6 +253,8 @@ def item(declaration): fn mark_class_unavailable(&mut self,class:usize,error:Error){self.unavailable.push((class,error));} fn sync_quarantine_hints(&self){} fn compute_handoff_pipe(&self,_job:&Arc)->Option{None} + __RENDER_PAIR_FOR__ + __RENDER_HANDOFF_PAIR__ __NEEDS_ENGINE_DRAIN__ __RENDER_CAN_PIPELINE__ __HOLD_CAUSE_FN__ @@ -297,7 +322,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,held_wait:false,handoff_avoid_pipes:0,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,held_wait:false,handoff_avoid_pipes:0,handoff_avoid_pairs:0,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, @@ -528,9 +553,9 @@ def item(declaration): 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,true); - // Another VM's render in flight: a render drains on a VM switch (linux#3201), no short - // repoll. - run(r(1,&vm2,Ok(())),1,false,false,r(2,&vm1,Ok(())),false,None,false,HoldCause::DrainCross,false); + // Another VM's render in flight is no drain: the render takes another render pair + // (linux#3201 keeps two VMs' renders off one pair), 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); } @@ -557,8 +582,8 @@ def item(declaration): assert_eq!(f.attempted,[2]); assert_eq!(f.engine.pending.len(),1); - // A warm render of another VM never queues behind an active render (linux#3201): it - // waits for the engine to drain, then publishes. + // A warm render of another VM queues behind an active render on another render pair + // (two VMs' renders never share one, linux#3201). let vm1_r=job_on_vm(10,vm1.clone(),true,0,Ok(())); let vm2_warm_r=job_on_vm(11,vm2.clone(),true,0,Ok(())); let mut fw=firmware(vec![vm2_warm_r],vec![(Ok(()),true)]); @@ -567,11 +592,8 @@ def item(declaration): fw.engine.flights.push(fl); fw.allow_behind=true; assert_eq!(fw.publish_checked(&mut done),Ok(())); - assert!(fw.attempted.is_empty()); - assert_eq!(fw.engine.stats.hold[0],1); - fw.engine.flights.clear(); - assert_eq!(fw.publish_checked(&mut done),Ok(())); assert_eq!(fw.attempted,[11]); + assert_eq!(fw.engine.stats.hold[0],0); // Cross-VM non-SCS compute queues behind another VM's active compute on a disjoint pipe. let vm1_c=job_on_vm(12,vm1.clone(),false,0,Ok(())); @@ -706,8 +728,8 @@ 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,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,pipe_last_vm:[Option;hw::sizes::COMPUTE_PIPES],pipe_last_used:[u64;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:u32,flights:Vec} +struct QueueBehindFlight{render_pair:u8,job:Arc,group:Vec>,first:usize,count:usize,computes:u32,renders:u32,compute_pipe:u8,rt_compute: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,pipe_last_vm:[Option;hw::sizes::COMPUTE_PIPES],pipe_last_used:[u64;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:u32,handoff_avoid_pairs:u8,flights:Vec} struct QueueBehindSlots{compute_exhausted:bool,render_exhausted:bool,compute_available:bool,pass_available:bool} impl QueueBehindSlots{ fn compute_exhausted(&self)->bool{self.compute_exhausted} @@ -768,6 +790,8 @@ def item(declaration): __SCS_COMPUTE_CONFLICT__ __CROSS_VM_RENDER_CONFLICT__ impl QueueBehindHost { + __RENDER_PAIR_FOR__ + __RENDER_HANDOFF_PAIR__ __NEEDS_ENGINE_DRAIN__ __RENDER_CAN_PIPELINE__ __BLOCKED_ON_SLOT_HEADROOM__ @@ -797,7 +821,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,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0,job:j1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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}, }; @@ -838,7 +862,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,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 flight=|job:Arc,rt_compute:bool,compute_pipe:u8|QueueBehindFlight{render_pair:0,job,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe,rt_compute,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); @@ -846,7 +870,7 @@ def item(declaration): let rq_vm2=mk(5,vm2.clone(),q2.clone(),true); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![flight(rq.clone(),true,0)]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![flight(rq.clone(),true,0)]}, 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}, }; @@ -902,7 +926,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,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0,job:timed,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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}, }; @@ -920,7 +944,7 @@ def item(declaration): }); let pr=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0,job:timed_render,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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}, }; @@ -944,14 +968,16 @@ 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,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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}]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0,job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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}, }; assert!(p.can_queue_behind(&r2)); - // A render of another VM never queues behind a render (linux#3201), warm or cold. - assert!(!p.can_queue_behind(&r_other_vm)); - assert!(p.needs_engine_drain(&r_other_vm)); + // A warm render of another VM queues behind a render only on another pair (linux#3201); + // a cold one still drains for its InitBM. + assert_eq!(p.render_pair_for(&vm2),Some(1)); + assert!(p.can_queue_behind(&r_other_vm)); + assert!(!p.needs_engine_drain(&r_other_vm)); p.pools.block_pipeline_vm=Some(vm2.slot); assert!(!p.can_queue_behind(&r_other_vm)); assert!(p.needs_engine_drain(&r_other_vm)); @@ -988,22 +1014,22 @@ def item(declaration): let vm1_c=mk(2,vm1.clone(),q1.clone(),false); 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{ + let mk_flight=|job:Arc,c:u32,r:u32|QueueBehindFlight{render_pair:0, job,group:vec![],first:0,count:1,computes:c,renders:r,compute_pipe:0,rt_compute: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, }; let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![mk_flight(vm1_r.clone(),0,1)]}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![mk_flight(vm1_r.clone(),0,1)]}, 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}, }; - // Active VM1 Render: same-VM R & C allowed; cross-VM R and C blocked + drain - // (linux#3201 for R). + // Active VM1 Render: same-VM R & C allowed; cross-VM R on the other render pair + // (linux#3201 keeps it off VM1's); cross-VM C blocked + drain. assert!(p.can_queue_behind(&vm1_r) && !p.needs_engine_drain(&vm1_r)); assert!(p.can_queue_behind(&vm1_c) && !p.needs_engine_drain(&vm1_c)); - assert!(!p.can_queue_behind(&vm2_r) && p.needs_engine_drain(&vm2_r)); + assert!(p.can_queue_behind(&vm2_r) && !p.needs_engine_drain(&vm2_r)); assert!(!p.can_queue_behind(&vm2_c) && p.needs_engine_drain(&vm2_c)); // Active VM1 Compute: same-VM R & C allowed; cross-VM non-SCS C allowed on a disjoint // pipe; cross-VM R blocked + drains. @@ -1017,6 +1043,81 @@ def item(declaration): assert!(!p.can_queue_behind(&vm2_r) && p.needs_engine_drain(&vm2_r)); assert!(!p.can_queue_behind(&vm2_c) && p.needs_engine_drain(&vm2_c)); } + #[test]fn render_pairs_lease_one_vm_each_and_hand_off_when_all_are_taken(){ + // Two render pairs in this harness. VM ids are deliberately not their pair parity. + crate::pair_hint::clear(); + let mkvm=|id:u64,slot:u32|Arc::new(Vm{id,status:Status(AtomicU32::new(0)),slot}); + let (vm1,vm2,vm3)=(mkvm(4,1),mkvm(6,2),mkvm(8,3)); + let mk=|id:u32,vm:Arc,render:bool|Arc::new(QueueBehindJob{ + id,vm,queue:Queue::new(0,0),progress:Progress{sent:AtomicU32::new(0),count:1,pending:AtomicBool::new(true)}, + commands:vec![if render{Command::Render(RenderCommand)}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![], + }); + let (r1,r2,r3)=(mk(1,vm1.clone(),true),mk(2,vm2.clone(),true),mk(3,vm3.clone(),true)); + let fl=|job:Arc,pair:u8,renders:u32|QueueBehindFlight{render_pair:pair, + job,group:vec![],first:0,count:1,computes:0,renders,compute_pipe:0,rt_compute: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, + }; + let mut p=QueueBehindHost{ + graph:QueueBehindGraph::new(), + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs: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}, + }; + // Idle: the lowest free pair, or the VM's last pair while it is free. + assert_eq!(p.render_pair_for(&vm1),Some(0)); + crate::pair_hint::set(vm1.id,1); + assert_eq!(p.render_pair_for(&vm1),Some(1)); + crate::pair_hint::clear(); + // VM1 renders on pair 0: it keeps that pair; VM2 takes the free pair 1 and overlaps. + p.engine.flights=vec![fl(r1.clone(),0,1)]; + assert_eq!(p.render_pair_for(&vm1),Some(0)); + assert_eq!(p.render_pair_for(&vm2),Some(1)); + assert!(p.can_queue_behind(&r1) && p.can_queue_behind(&r2)); + // A last pair held by another VM is not taken again (linux#3201). + crate::pair_hint::set(vm2.id,0); + assert_eq!(p.render_pair_for(&vm2),Some(1)); + crate::pair_hint::clear(); + // Every pair held by another VM: VM3 has no pair, waits without an engine drain, and + // the pair with the fewest render passes in flight is handed off to it. + p.engine.flights=vec![fl(r1.clone(),0,3),fl(r2.clone(),1,1)]; + assert_eq!(p.render_pair_for(&vm3),None); + assert!(!p.can_queue_behind(&r3)); + assert!(!p.needs_engine_drain(&r3)); + assert_eq!(p.render_handoff_pair(&r3),Some(1)); + assert_eq!(p.render_handoff_pair(&r1),None,"VM1 has its pair"); + // While pair 1 drains for the handoff its VM publishes nothing more there; pair 0 goes on. + p.engine.handoff_avoid_pairs=1<<1; + assert!(!p.can_queue_behind(&r2)); + assert!(p.can_queue_behind(&r1)); + assert_eq!(p.render_pair_for(&vm3),None); + // Pair 1 drained: VM3 takes it while VM2 has no pair until one frees. + p.engine.handoff_avoid_pairs=0; + p.engine.flights=vec![fl(r1.clone(),0,3)]; + assert_eq!(p.render_pair_for(&vm3),Some(1)); + p.engine.flights.push(fl(r3.clone(),1,1)); + assert_eq!(p.render_pair_for(&vm2),None); + assert!(!p.can_queue_behind(&r2)); + // Two VMs' renders never share a pair, also when one's flights are on it already. + for f in &p.engine.flights { + for vm in [&vm1,&vm2,&vm3] { + let pair=f.render_pair as usize; + if !Arc::ptr_eq(&f.job.vm,vm) { + assert!(cross_vm_render_conflict(f,vm,pair)); + } + } + } + // Another VM's compute still drains a render, and a render still drains compute of + // another VM, whatever the pairs. + let c1=mk(4,vm1.clone(),false); + p.engine.flights=vec![fl(r1.clone(),0,1)]; + assert!(!p.can_queue_behind(&mk(5,vm2.clone(),false)) && p.needs_engine_drain(&mk(5,vm2.clone(),false))); + let mut cf=fl(c1.clone(),0,0);cf.computes=1;cf.renders=0; + p.engine.flights=vec![cf]; + assert!(!p.can_queue_behind(&r2) && p.needs_engine_drain(&r2)); + } #[test]fn cross_engine_wait_resolves_barriers_and_skips_no_barrier_or_retired(){ let vm1=Arc::new(Vm{id:1,status:Status(AtomicU32::new(0)),slot:1}); let q1=Queue::new(0,0); @@ -1035,16 +1136,16 @@ def item(declaration): let c_other_q=mk(5,q2.clone(),false,1,[None,None]); let p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![ - QueueBehindFlight{job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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,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}, + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![ + QueueBehindFlight{render_pair:0,job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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{render_pair:0,job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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}, }; // Same-queue FS -> CDM barrier resolves render's fs_target; CDM -> TA resolves compute's target. - assert_eq!(p.cross_engine_wait(&c1,0,command::RENDER),Ok(Some(WaitTarget{stamp:0x500,initbm:false}))); - assert_eq!(p.cross_engine_wait(&r2_after_c1,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x700,initbm:false}))); + assert_eq!(p.cross_engine_wait(&c1,0,command::RENDER),Ok(Some(WaitTarget{stamp:0x500,initbm:false,pair:0}))); + assert_eq!(p.cross_engine_wait(&r2_after_c1,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x700,initbm:false,pair:0}))); // No-barrier / independent-queue submits emit no cross-engine barrier. assert_eq!(p.cross_engine_wait(&c_nobarrier,0,command::RENDER),Ok(None)); assert_eq!(p.cross_engine_wait(&c_other_q,0,command::RENDER),Ok(None)); @@ -1072,14 +1173,14 @@ def item(declaration): cstamp[0]=0x100;cstamp[1]=0x200;cstamp[2]=0x300; let pm=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:3,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![ - QueueBehindFlight{job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute: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}, + engine:QueueBehindEngine{ordinal:3,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![ + QueueBehindFlight{render_pair:0,job:multi_c,group:vec![],first:0,count:3,computes:3,renders:0,compute_pipe:0,rt_compute: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}, }; - assert_eq!(pm.cross_engine_wait(&r_wait_c2,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x200,initbm:false}))); - assert_eq!(pm.cross_engine_wait(&r_wait_c3,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x300,initbm:false}))); + assert_eq!(pm.cross_engine_wait(&r_wait_c2,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x200,initbm:false,pair:0}))); + assert_eq!(pm.cross_engine_wait(&r_wait_c3,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x300,initbm:false,pair:0}))); assert_eq!(pm.cross_engine_wait(&r_wait_missing,0,command::COMPUTE),Err(EAGAIN)); } #[test]fn cross_engine_barrier_keeps_hold_when_producer_or_consumer_carries_initbm(){ @@ -1105,7 +1206,7 @@ def item(declaration): let r_after_r=mk(3,true,2,[Some(1),None]); let host=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:r_initbm,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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, @@ -1114,10 +1215,10 @@ def item(declaration): pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; let fs2c = host.cross_engine_wait(&c_after_r, 0, command::RENDER).unwrap().unwrap(); - assert_eq!(fs2c, WaitTarget { stamp: 0x900, initbm: true }); + assert_eq!(fs2c, WaitTarget { stamp: 0x900, initbm: true, pair: 0 }); assert_eq!(cross_engine_barrier_type(fs2c.initbm, false), BarrierType::Hold); let r2r = host.wait_stamp_for(&r_after_r, command::RENDER, Some(1)).unwrap().unwrap(); - assert_eq!(r2r, WaitTarget { stamp: 0x900, initbm: true }); + assert_eq!(r2r, WaitTarget { stamp: 0x900, initbm: true, pair: 0 }); assert_eq!(cross_engine_barrier_type(r2r.initbm, false), BarrierType::Hold); } #[test]fn publish_checked_uses_transport_without_repeating_session_check(){ @@ -1151,7 +1252,7 @@ def item(declaration): }); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:1,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:c_job.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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, }]}, @@ -1162,7 +1263,7 @@ def item(declaration): assert!(p.can_queue_behind(&r_job)); 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{ + p.engine.flights[0]=QueueBehindFlight{render_pair:0, job:r_job,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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, }; @@ -1189,15 +1290,15 @@ def item(declaration): cstamp[0]=0x100;cstamp[1]=0x200;cstamp[2]=0x300; let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:3,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:3,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:c1,group:vec![c2,c3],first:0,count:1,computes:3,renders:0,compute_pipe:0,rt_compute: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}, }; - assert_eq!(p.cross_engine_wait(&r_wait_c2,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x200,initbm:false}))); - assert_eq!(p.cross_engine_wait(&r_wait_c3,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x300,initbm:false}))); + assert_eq!(p.cross_engine_wait(&r_wait_c2,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x200,initbm:false,pair:0}))); + assert_eq!(p.cross_engine_wait(&r_wait_c3,0,command::COMPUTE),Ok(Some(WaitTarget{stamp:0x300,initbm:false,pair:0}))); // Active computes sum flight.computes: 16 batched computes saturates compute_flights(). assert!(p.can_queue_behind(&c4)); p.engine.flights[0].computes=16; @@ -1229,7 +1330,7 @@ def item(declaration): r_fs[0]=0x100;r_fs[1]=0x200;r_fs[2]=0x300; let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:0,draw:3,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:0,draw:3,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:multi.clone(),group:vec![],first:0,count:3,computes:0,renders:3,compute_pipe:0,rt_compute: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, }]}, @@ -1237,18 +1338,18 @@ def item(declaration): pools:QueueBehindPools{exhausted:false,can_pipeline:true,block_pipeline_vm:None}, }; // Lookup into published multi-pass render flight resolves interior and tail passes. - assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(1)),Ok(Some(WaitTarget{stamp:0x100,initbm:false}))); - assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(2)),Ok(Some(WaitTarget{stamp:0x200,initbm:false}))); - assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(3)),Ok(Some(WaitTarget{stamp:0x300,initbm:false}))); + assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(1)),Ok(Some(WaitTarget{stamp:0x100,initbm:false,pair:0}))); + assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(2)),Ok(Some(WaitTarget{stamp:0x200,initbm:false,pair:0}))); + assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(3)),Ok(Some(WaitTarget{stamp:0x300,initbm:false,pair:0}))); assert_eq!(p.wait_stamp_for(&next_r,command::RENDER,Some(4)),Err(EAGAIN)); // Lookup against an in-progress same-batch flight resolves earlier pass before publish. let mut cur_fs=[0u32;16]; cur_fs[0]=0x400; - let cur=QueueBehindFlight{ + let cur=QueueBehindFlight{render_pair:0, job:next_r.clone(),group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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}))); + assert_eq!(p.wait_stamp_for_with(&next_r,command::RENDER,Some(4),Some(&cur)),Ok(Some(WaitTarget{stamp:0x400,initbm:false,pair:0}))); // Cross-job render horizon flight resolves folded flight.group member stamps too. let r_fold_a=Arc::new(QueueBehindJob{ id:10,vm:vm1.clone(),queue:q1.clone(), @@ -1266,13 +1367,13 @@ 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{ + let cur_grp=QueueBehindFlight{render_pair:0, 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,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}))); - assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(5),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x500,initbm:false}))); - assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(6),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x600,initbm: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,pair:0}))); + assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(5),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x500,initbm:false,pair:0}))); + assert_eq!(p.wait_stamp_for_with(&r_fold_b,command::RENDER,Some(6),Some(&cur_grp)),Ok(Some(WaitTarget{stamp:0x600,initbm:false,pair:0}))); // Active renders sum flight.renders: 44 passes (4x11-pass postfx) still pipelines // behind once TA has finished, while 47 batched renders saturates render_flights(). assert!(p.can_queue_behind(&next_r)); @@ -1299,7 +1400,7 @@ def item(declaration): } let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:0,draw:16,ta_target:0x1000,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:0,draw:16,ta_target:0x1000,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:r_live,group:vec![],first:0,count:16,computes:0,renders:4,compute_pipe:0,rt_compute:false,published_ns:0,target:0,cstamp:[0;16], r_ta_stamp:r_ta,r_fs_stamp:r_ta,fs_target:0x1000, initbm:false,has_timestamps:false,doomed:false,recovery_suspect:false, @@ -1337,7 +1438,7 @@ def item(declaration): let c_ts_wait=mk(5,vm1.clone(),false,Ok(()),true,[Some(1),None]); let mut p=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![QueueBehindFlight{render_pair:0, job:r_live,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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, @@ -1353,9 +1454,9 @@ def item(declaration): // Render pass slot exhaustion IS a slot-headroom block for a ready same-VM render... p.slots.pass_available=false; assert!(p.blocked_on_slot_headroom(&r_same)); - // ...but NOT for a render of another VM (it drains, linux#3201), warm or cold InitBM, - // nor for external-fence or live-InitBM jobs. - assert!(!p.blocked_on_slot_headroom(&r_cross_vm)); + // ...and for a warm render of another VM on another render pair, but NOT for a cold + // one (it drains for its InitBM), nor for external-fence or live-InitBM jobs. + assert!(p.blocked_on_slot_headroom(&r_cross_vm)); p.pools.block_pipeline_vm=Some(vm2.slot); assert!(!p.blocked_on_slot_headroom(&r_cross_vm)); p.pools.block_pipeline_vm=None; @@ -1638,14 +1739,14 @@ def item(declaration): 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,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![]}, + engine:QueueBehindEngine{ordinal:0,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs: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 starts on pipe 0. let no_w = [None; sizes::COMPUTE_PIPES]; assert_eq!(host.choose_compute_pipe(&q1, &vm1, no_w, (1u32 << 24) - 1, false, false), Some(0)); - host.engine.flights.push(QueueBehindFlight{ + host.engine.flights.push(QueueBehindFlight{render_pair:0, job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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, @@ -1684,7 +1785,7 @@ def item(declaration): assert!(host.can_queue_behind(&c2)); // Add second concurrent flight on pipe 1 from VM2 (q2): VM1 stays on pipe 0 (or expands to // pipe 2 for heavy compute, capped at MAX_VM_COMPUTE_PIPES=2), VM2 stays on pipe 1. - host.engine.flights.push(QueueBehindFlight{ + host.engine.flights.push(QueueBehindFlight{render_pair:0, job:c_vm2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:1,rt_compute: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, @@ -1695,7 +1796,7 @@ def item(declaration): assert_eq!(host.choose_compute_pipe(&q1, &vm1, no_w, (1u32 << 24) - 1, false, true), Some(2)); assert_eq!(host.choose_compute_pipe(&q3, &vm1, no_w, (1u32 << 24) - 1, false, false), Some(2)); // Once VM1 has 2 active pipes (0 and 2), MAX_VM_COMPUTE_PIPES=2 keeps VM1 on {0, 2}. - host.engine.flights.push(QueueBehindFlight{ + host.engine.flights.push(QueueBehindFlight{render_pair:0, job:c2.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:2,rt_compute: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, @@ -1713,7 +1814,7 @@ def item(declaration): let vp = mk_vm((p + 10) as u32); let qp = Queue::new(0, 2); let jp = mk((p + 10) as u32, vp, qp, 1); - host.engine.flights.push(QueueBehindFlight{ + host.engine.flights.push(QueueBehindFlight{render_pair:0, job:jp,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:p as u8,rt_compute: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, @@ -1739,7 +1840,7 @@ def item(declaration): // pipe 0: avoiding pipe 0 moves VM1 onto pipe 1 while pipe 0 drains, then VM2 gets pipe 0! host.engine.handoff_avoid_pipes = 0; host.engine.flights.clear(); - host.engine.flights.push(QueueBehindFlight{ + host.engine.flights.push(QueueBehindFlight{render_pair:0, job:c1.clone(),group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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, @@ -1773,13 +1874,13 @@ def item(declaration): let c4=mk(4,4,Some(2)); let mut host=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:2,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![ - QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:2,draw:0,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![ + QueueBehindFlight{render_pair:0, job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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{ + QueueBehindFlight{render_pair:0, job:c2,group:vec![],first:0,count:1,computes:2,renders:0,compute_pipe:1,rt_compute: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, @@ -1790,9 +1891,9 @@ def item(declaration): }; // Barrier-free compute resolves all None. let mut exp1 = [None; sizes::COMPUTE_PIPES]; - exp1[0] = Some(WaitTarget{stamp:0x100,initbm:false}); + exp1[0] = Some(WaitTarget{stamp:0x100,initbm:false,pair:0}); let mut exp2 = exp1; - exp2[1] = Some(WaitTarget{stamp:0x200,initbm:false}); + exp2[1] = Some(WaitTarget{stamp:0x200,initbm:false,pair:0}); assert_eq!(host.wait_compute_stamps_for(&c3, None), Ok([None; sizes::COMPUTE_PIPES])); // 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(); @@ -1856,13 +1957,13 @@ def item(declaration): }); let host=QueueBehindHost{ graph:QueueBehindGraph::new(), - engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,flights:vec![ - QueueBehindFlight{ + engine:QueueBehindEngine{ordinal:1,draw:1,ta_target:0,next_compute_pipe:0,pipe_last_vm:[None;hw::sizes::COMPUTE_PIPES],pipe_last_used:[0;hw::sizes::COMPUTE_PIPES],handoff_avoid_pipes:0,handoff_avoid_pairs:0,flights:vec![ + QueueBehindFlight{render_pair:0, job:c1,group:vec![],first:0,count:1,computes:1,renders:0,compute_pipe:0,rt_compute: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{ + QueueBehindFlight{render_pair:0, job:r1,group:vec![],first:0,count:1,computes:0,renders:1,compute_pipe:0,rt_compute: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, @@ -1873,12 +1974,12 @@ def item(declaration): }; // Cross-queue compute wait resolves pipe 0 stamp 0x100 and keeps q2 on pipe 0 (zero c2c). let mut exp_cw = [None; sizes::COMPUTE_PIPES]; - exp_cw[0] = Some(WaitTarget{stamp:0x100,initbm:false}); + exp_cw[0] = Some(WaitTarget{stamp:0x100,initbm:false,pair:0}); let cw=host.wait_compute_stamps_for(&c2_wait_q1,None).unwrap(); assert_eq!(cw,exp_cw); assert_eq!(host.choose_compute_pipe(&q2,&vm1,cw,(1u32<<24)-1,false,false),Some(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}))); + assert_eq!(host.wait_stamp_for(&c2_wait_q1,command::RENDER,None),Ok(Some(WaitTarget{stamp:0x200,initbm:false,pair:0}))); // query_access compute waiting via fw_waits on a timestamped q1 flight must wait to retire; // non-query compute queues directly behind q1 in firmware. assert!(!host.can_queue_behind(&c2_query_wait_q1)); @@ -2225,6 +2326,7 @@ def item(declaration): pub fn stamp_reached(obs: u32, own: u32, _tail: u32) -> bool { obs >= own } } mod work { + __RENDER_PAIR_MOD__ pub mod ta { pub const TPC_BYTES: usize = 0; } pub mod compute { pub const fn pipe_of_event(event: u32) -> Option { @@ -2265,6 +2367,7 @@ def item(declaration): computes: u32, renders: u32, compute_pipe: u8, + render_pair: u8, target: u32, ta_target: u32, fs_target: u32, @@ -2277,11 +2380,11 @@ def item(declaration): gate_passed_ns: Option, unsettled_polls: u32, } - struct RecEngine { flights: Vec, target: [u32; sizes::COMPUTE_PIPES], ta_target: u32, fs_target: u32 } + struct RecEngine { flights: Vec, target: [u32; sizes::COMPUTE_PIPES], ta_target: [u32; sizes::RENDER_PAIRS], fs_target: [u32; sizes::RENDER_PAIRS] } struct RecState { last_retired: recovery::logic::RetiredStamps } struct RecFirmware { engine: RecEngine, recovery: RecState } - fn st(ta: u32, fs: u32, c0: u32, c1: u32) -> [u32; 2 + sizes::COMPUTE_PIPES] { - let mut s = [0u32; 2 + sizes::COMPUTE_PIPES]; + fn st(ta: u32, fs: u32, c0: u32, c1: u32) -> [u32; sizes::STAGES] { + let mut s = [0u32; sizes::STAGES]; s[0] = ta; s[1] = fs; s[2] = c0; @@ -2302,7 +2405,7 @@ def item(declaration): target[0] = 0x300; let mut fw = RecFirmware { engine: RecEngine { - flights: vec![RecFlight { + flights: vec![RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 1 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 3, @@ -2321,8 +2424,8 @@ def item(declaration): unsettled_polls: 0, }], target, - ta_target: 0, - fs_target: 0, + ta_target: [0; sizes::RENDER_PAIRS], + fs_target: [0; sizes::RENDER_PAIRS], }, recovery: RecState { last_retired: recovery::logic::RetiredStamps::new() }, }; @@ -2345,7 +2448,7 @@ def item(declaration): pass[0] = 0; pass[1] = 1; pass[2] = 2; let mut fw = RecFirmware { engine: RecEngine { - flights: vec![RecFlight { + flights: vec![RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 1 }, resources: Resources { @@ -2369,8 +2472,8 @@ def item(declaration): unsettled_polls: 0, }], target: [0; sizes::COMPUTE_PIPES], - ta_target: 0x300, - fs_target: 0x300, + ta_target: [0x300; sizes::RENDER_PAIRS], + fs_target: [0x300; sizes::RENDER_PAIRS], }, recovery: RecState { last_retired: recovery::logic::RetiredStamps::new() }, }; @@ -2386,6 +2489,55 @@ def item(declaration): assert_eq!(fw.recovery_prepare(1, 0x71, 0x400, st(0x300, 0x100, 0, 0)), Err(ENOENT)); } #[test] + fn render_pair_events_blame_only_flights_of_their_pair() { + // Per-pair stamps are dense, so both pairs can hold stamp 0x200. A pair-1 + // event (0x72/0x73) names only the pair-1 flight, and its TPC cleanup reads pair 1's TA + // stage; pair 0's 0x70/0x71 never reach the pair-1 flight. + let mk_pass = |size: usize| Pass { + ta_work: PassBuf { size: 0, tpc_bytes: size as u64, cleared: std::cell::Cell::new(0) }, + tpc: PassBuf { size: 0x10000, tpc_bytes: 0, cleared: std::cell::Cell::new(0) }, + }; + let mut stamps = [0u32; 16]; + stamps[0] = 0x200; + let mk = |pair: u8, slot: u32| RecFlight { render_pair: pair, + job: RecJob { vm: RecVm { slot }, resources: Resources { passes: vec![mk_pass(0x1000)] } }, + claims: RecClaims { pass: [0; 16] }, + computes: 0, renders: 1, compute_pipe: 0, target: 0, ta_target: 0x200, fs_target: 0x200, + cstamp: [0; 16], r_ta_stamp: stamps, r_fs_stamp: stamps, doomed: false, + recovery_suspect: false, recovery_started_ns: 0, gate_passed_ns: None, unsettled_polls: 0, + }; + let mut fw = RecFirmware { + engine: RecEngine { + flights: vec![mk(0, 1), mk(1, 2)], + target: [0; sizes::COMPUTE_PIPES], + ta_target: [0x200; sizes::RENDER_PAIRS], + fs_target: [0x200; sizes::RENDER_PAIRS], + }, + recovery: RecState { last_retired: recovery::logic::RetiredStamps::new() }, + }; + // Pair 0's TA finished, pair 1's TA did not: stage cells follow `render_stage`. + let mut stage = st(0x200, 0x100, 0, 0); + stage[sizes::render_stage(1, 0)] = 0x100; + stage[sizes::render_stage(1, 1)] = 0x100; + assert_eq!(fw.recovery_prepare(9, 0x72, 0x200, stage), Ok(())); + assert!(!fw.engine.flights[0].doomed && fw.engine.flights[1].doomed); + assert_eq!(fw.engine.flights[0].job.resources.passes[0].tpc.cleared.get(), 0); + assert_eq!(fw.engine.flights[1].job.resources.passes[0].tpc.cleared.get(), 0x1000); + fw.engine.flights[1].doomed = false; + assert_eq!(fw.recovery_prepare(1, 0x71, 0x200, stage), Ok(())); + assert!(fw.engine.flights[0].doomed && !fw.engine.flights[1].doomed); + fw.engine.flights[0].doomed = false; + assert_eq!(fw.recovery_prepare(1, 0x73, 0x200, stage), Ok(())); + assert!(!fw.engine.flights[0].doomed && fw.engine.flights[1].doomed); + // 0x74 names no configured pair. + assert_eq!(fw.recovery_prepare(1, 0x74, 0x200, stage), Err(ENOENT)); + // Suspects: pair 0 finished both stages; pair 1's FS did not. + for f in fw.engine.flights.iter_mut() { f.recovery_suspect = false; } + stage[1] = 0x200; + assert_eq!(fw.recovery_prepare_suspects(stage, 0, None), Ok(())); + assert!(!fw.engine.flights[0].recovery_suspect && fw.engine.flights[1].recovery_suspect); + } + #[test] fn cross_vm_recovery_prepare_isolates_blame_to_faulting_vm() { let mut r_ta = [0u32; 16]; let mut r_fs = [0u32; 16]; @@ -2397,7 +2549,7 @@ def item(declaration): let mut fw = RecFirmware { engine: RecEngine { flights: vec![ - RecFlight { + RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 1 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 0, @@ -2415,7 +2567,7 @@ def item(declaration): gate_passed_ns: None, unsettled_polls: 0, }, - RecFlight { + RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 2 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 1, @@ -2435,8 +2587,8 @@ def item(declaration): }, ], target, - ta_target: 0x100, - fs_target: 0x100, + ta_target: [0x100; sizes::RENDER_PAIRS], + fs_target: [0x100; sizes::RENDER_PAIRS], }, recovery: RecState { last_retired: recovery::logic::RetiredStamps::new() }, }; @@ -2455,7 +2607,7 @@ def item(declaration): r2_ta[0] = 0x200; r2_fs[0] = 0x200; fw.engine.flights[0].doomed = false; fw.engine.flights[0].recovery_suspect = false; - fw.engine.flights[1] = RecFlight { + fw.engine.flights[1] = RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 2 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 0, @@ -2473,8 +2625,8 @@ def item(declaration): gate_passed_ns: None, unsettled_polls: 0, }; - fw.engine.ta_target = 0x200; - fw.engine.fs_target = 0x200; + fw.engine.ta_target[0] = 0x200; + fw.engine.fs_target[0] = 0x200; assert_eq!(fw.recovery_prepare(1, 0x71, 0x100, st(0x200, 0, 0, 0)), Ok(())); assert_eq!(fw.recovery_prepare_suspects(st(0x200, 0, 0, 0), 0x71, Some(1)), Ok(())); assert!(fw.engine.flights[0].doomed); @@ -2498,7 +2650,7 @@ def item(declaration): let mut fw = RecFirmware { engine: RecEngine { flights: vec![ - RecFlight { + RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 1 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 1, @@ -2516,7 +2668,7 @@ def item(declaration): gate_passed_ns: None, unsettled_polls: 0, }, - RecFlight { + RecFlight { render_pair: 0, job: RecJob { vm: RecVm { slot: 2 }, resources: Resources { passes: vec![] } }, claims: RecClaims { pass: [0; 16] }, computes: 1, @@ -2536,8 +2688,8 @@ def item(declaration): }, ], target, - ta_target: 0, - fs_target: 0, + ta_target: [0; sizes::RENDER_PAIRS], + fs_target: [0; sizes::RENDER_PAIRS], }, recovery: RecState { last_retired }, }; @@ -2749,6 +2901,8 @@ def item(declaration): } ''' harness = harness.replace('__LOGIC__', str(production.parent / 'recovery/logic.rs')) +work_src = (production.parent / 'fw/work.rs').read_text() +harness = harness.replace('__RENDER_PAIR_MOD__', item_in(work_src, 'pub(crate) mod render_pair {')) harness = harness.replace('__USAGE__', str(production.parent.parent / 'usage.rs')) harness = harness.replace('__FLIGHTS_LINE__', flights_line.strip()) harness = harness.replace('__MAX_QUEUES_LINE__', max_queues_line.strip()) @@ -2823,12 +2977,18 @@ def item(declaration): '__CHOOSE_COMPUTE_PIPE__': 'fn choose_compute_pipe(', '__SCS_COMPUTE_CONFLICT__': 'fn scs_compute_conflict(', '__CROSS_VM_RENDER_CONFLICT__': 'fn cross_vm_render_conflict(', + '__RENDER_PAIR_FOR__': 'pub(crate) fn render_pair_for(', + '__RENDER_HANDOFF_PAIR__': 'fn render_handoff_pair(', '__WAIT_TARGET__': 'struct WaitTarget {', '__CROSS_ENGINE_BARRIER_TYPE__': 'const fn cross_engine_barrier_type(', '__RENDER_BARRIER_PLAN__': 'struct RenderBarrierPlan {', '__PLAN_RENDER_BARRIERS__': 'fn plan_render_barriers(', }.items(): - harness = harness.replace(token, item(declaration).replace("super::command::", "crate::command::").replace("super::recovery::", "crate::recovery::").replace("super::hw::", "crate::hw::").replace("super::resources::", "crate::resources::").replace("super::queue::QueueState", "crate::Queue").replace("super::vm::VmState", "crate::Vm").replace("super::fence::", "crate::fence::")) + text = item(declaration) + # The render pair lease runs at the crate root here, which has no `sizes` import. + if token in ('__RENDER_PAIR_FOR__', '__RENDER_HANDOFF_PAIR__'): + text = re.sub(r'(?2),Some(0)); let refs=pools.prepare_in_flight(0,draw,draw>2).unwrap(); assert_eq!(refs.uma_submitted,draw*2); pools.publish_batch(0,refs.uma_submitted,1).unwrap(); - p.publish_flight(0); + seqs.push(p.publish_flight(0)); } assert!(!pools.retired_at(0,4).unwrap()); d0.w64(0x54,4).unwrap(); assert!(pools.retired_at(0,4).unwrap()); assert!(!pools.retired_at(0,6).unwrap()); - p.retire_flight(0,&e1,b1,true).unwrap(); + p.retire_flight(0, seqs[0],&e1,b1,true).unwrap(); d0.w64(0x54,6).unwrap(); assert!(pools.retired_at(0,6).unwrap()); - p.retire_flight(0,&e1,b1,true).unwrap(); + p.retire_flight(0, seqs[1],&e1,b1,true).unwrap(); d0.w64(0x54,8).unwrap(); assert!(pools.retired(0).unwrap()); - p.retire_flight(0,&e1,b1,true).unwrap(); + p.retire_flight(0, seqs[2],&e1,b1,true).unwrap(); // Cross-VM switch drains and switches to slot 1 (displacing slot 0 upon clean retirement). assert_eq!(p.pick_slot(&vm2,false),Some(1)); let b2=p.bind(1,false); - p.publish_flight(1); - p.retire_flight(1,&e2,b2,true).unwrap(); + let sq=p.publish_flight(1); + p.retire_flight(1, sq,&e2,b2,true).unwrap(); assert!(!p.exhausted()); assert_eq!(p.needed_slots(),g16::hw::sizes::BASE_PB_SLOTS); // Normal cross-VM switch back to VM1 reuses displaced slot 0 rather than claiming slot 2. @@ -1254,6 +1255,38 @@ def module(text, name): } } + #[test]fn pb_slots_displace_in_publication_order_not_retirement_order(){ + // Renders on different render pairs can be observed retiring out of publication order. + // Displacement follows the publication sequence: the later render displaces the + // earlier slot, never the reverse. + let vm1=vm(1);let vm2=vm(2);let vm3=vm(3); + let factory=g16::object::Factory;let budget=g16::budget::Budget::new().unwrap(); + let mk_epoch=|owner:&sync::Arc,slot:usize|{ + let e=g16::pools::PbEpoch::new(&factory,owner,g16::budget::Budget::reserve(&budget,1).unwrap().take().unwrap()).unwrap(); + e.prepare(slot,0x70c0000000,2048).unwrap();e.check_assignment(slot).unwrap();e.expose(); + e + }; + let mut p=g16::pools::Pools::new(&driver::AsahiDrmDevice(device::Device)); + let e1=mk_epoch(&vm1,0); + let b1=p.bind(0,false);let s1=p.publish_flight(0); + let e2=mk_epoch(&vm2,1); + let b2=p.bind(1,false);let s2=p.publish_flight(1); + assert!(s2>s1); + // The later render is observed first; the earlier slot is still in flight. + p.retire_flight(1, s2, &e2, b2, true).unwrap(); + assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm3,false,0b11,0,0,false),None); + p.retire_flight(0, s1, &e1, b1, true).unwrap(); + // Slot 0 ran before slot 1's render: displaced. Slot 1 holds the newest render. + assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm3,false,0b11,0,0,false),Some(0)); + assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm3,false,0b10,1,0,false),None); + assert!(!p.exhausted_for_mask_mode(&vm3,0b11,0,false)); + // A render published after both displaces slot 1 too. + let e3=mk_epoch(&vm3,2); + let b3=p.bind(2,false);let s3=p.publish_flight(2); + p.retire_flight(2, s3, &e3, b3, true).unwrap(); + assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm3,false,0b10,1,0,false),Some(1)); + } + #[test]fn multi_active_pools_allow_warm_cross_vm_reuse_and_gate_cold_initbm(){ let vm1=vm(1);let vm2=vm(2);let vm3=vm(3); let factory=g16::object::Factory;let budget=g16::budget::Budget::new().unwrap(); @@ -1266,14 +1299,14 @@ def module(text, name): // Prime VM1 on slot 0 and VM2 on slot 1 (drained InitBM). let e1=mk_epoch(&vm1,0); assert_eq!(p.pick_slot_within(&vm1,false,2),Some(0)); - let b1=p.bind(0,false);p.publish_flight(0);p.retire_flight(0,&e1,b1,true).unwrap(); + let b1=p.bind(0,false);let sq=p.publish_flight(0);p.retire_flight(0, sq,&e1,b1,true).unwrap(); let e2=mk_epoch(&vm2,1); assert_eq!(p.pick_slot_within(&vm2,false,2),Some(1)); - let b2=p.bind(1,false);p.publish_flight(1);p.retire_flight(1,&e2,b2,true).unwrap(); + let b2=p.bind(1,false);let sq=p.publish_flight(1);p.retire_flight(1, sq,&e2,b2,true).unwrap(); // VM1 starts a render on warm slot 0 (no InitBM). assert_eq!(p.pick_slot_within(&vm1,false,2),Some(0)); assert!(p.reusable(0,&vm1).is_some()); - let b1=p.bind(0,true);p.publish_flight(0); + let b1=p.bind(0,true);let s1=p.publish_flight(0); assert_eq!(p.slot_inflight(0),1); assert_eq!(p.slot_inflight(1),0); // While VM1 is live on slot 0 (behind=true): @@ -1284,16 +1317,16 @@ def module(text, name): assert!(!p.can_pipeline_within(&vm3,2)); assert_eq!(p.pick_slot_within(&vm3,true,2),None); // VM2 publishes on slot 1 concurrently with VM1 on slot 0. - let b2=p.bind(1,true);p.publish_flight(1); + let b2=p.bind(1,true);let s2=p.publish_flight(1); assert_eq!(p.slot_inflight(0),1); assert_eq!(p.slot_inflight(1),1); // Neither in-flight slot is displaced while live. assert!(!p.exhausted()); // Both retire cleanly in order. - p.retire_flight(0,&e1,b1,true).unwrap(); + p.retire_flight(0, s1,&e1,b1,true).unwrap(); assert_eq!(p.slot_inflight(0),0); assert_eq!(p.slot_inflight(1),1); - p.retire_flight(1,&e2,b2,true).unwrap(); + p.retire_flight(1, s2,&e2,b2,true).unwrap(); assert_eq!(p.slot_inflight(1),0); // Recovery invalidation clears warm reuse for BOTH slots so both VMs drain for InitBM. p.invalidate(); @@ -1313,13 +1346,13 @@ def module(text, name): // Exact live cross-VM sequence: VM1 on slot 0 -> VM2 on slot 1 -> VM1 on slot 0. let e1=mk_epoch(&vm1,0); assert_eq!(p.pick_slot_within(&vm1,false,2),Some(0)); - let b=p.bind(0,false);p.publish_flight(0);p.retire_flight(0,&e1,b,true).unwrap(); + let b=p.bind(0,false);let sq=p.publish_flight(0);p.retire_flight(0, sq,&e1,b,true).unwrap(); let e2=mk_epoch(&vm2,1); assert_eq!(p.pick_slot_within(&vm2,false,2),Some(1)); - let b=p.bind(1,false);p.publish_flight(1);p.retire_flight(1,&e2,b,true).unwrap(); + let b=p.bind(1,false);let sq=p.publish_flight(1);p.retire_flight(1, sq,&e2,b,true).unwrap(); let e1b=mk_epoch(&vm1,0); assert_eq!(p.pick_slot_within(&vm1,false,2),Some(0)); - let b=p.bind(0,false);p.publish_flight(0);p.retire_flight(0,&e1b,b,true).unwrap(); + let b=p.bind(0,false);let sq=p.publish_flight(0);p.retire_flight(0, sq,&e1b,b,true).unwrap(); // VM3 switches to slot 1 with a fresh epoch and hangs: recovery invalidates epochs // and quarantines slot 1 while retaining BOTH the prior owner (e2) and fresh epoch (e3). let e3=mk_epoch(&vm3,1); @@ -1339,12 +1372,12 @@ def module(text, name): assert!(!p.exhausted_for_within(&vm4,3)); assert_eq!(p.pick_slot_within(&vm4,false,3),Some(2)); let e4=mk_epoch(&vm4,2); - let b=p.bind(2,false);p.publish_flight(2);p.retire_flight(2,&e4,b,true).unwrap(); + let b=p.bind(2,false);let sq=p.publish_flight(2);p.retire_flight(2, sq,&e4,b,true).unwrap(); // Clean retirement on slot 2 displaces surviving slot 0 back to reusable! assert!(!p.exhausted_for_within(&vm1,3)); assert_eq!(p.pick_slot_within(&vm1,false,3),Some(0)); let e1c=mk_epoch(&vm1,0); - let b=p.bind(0,false);p.publish_flight(0);p.retire_flight(0,&e1c,b,true).unwrap(); + let b=p.bind(0,false);let sq=p.publish_flight(0);p.retire_flight(0, sq,&e1c,b,true).unwrap(); // Subsequent cross-VM render reuses displaced slot 2 (does not consume slot 3). assert_eq!(p.pick_slot_within(&vm2,false,3),Some(2)); // An unrelated compute hang calling invalidate() does not wedge render either. @@ -1382,10 +1415,10 @@ def module(text, name): let s_a=warm+2;let s_b=warm+3; assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm1,false,vm_mask,0,0,false),Some(s_a)); let ea=mk_epoch(&vm1,s_a); - let b=p.bind(s_a,false);p.publish_flight(s_a);p.retire_flight(s_a,&ea,b,true).unwrap(); + let b=p.bind(s_a,false);let sq=p.publish_flight(s_a);p.retire_flight(s_a, sq,&ea,b,true).unwrap(); assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm2,false,vm_mask,0,0,false),Some(s_b)); let eb=mk_epoch(&vm2,s_b); - let b=p.bind(s_b,false);p.publish_flight(s_b);p.retire_flight(s_b,&eb,b,true).unwrap(); + let b=p.bind(s_b,false);let sq=p.publish_flight(s_b);p.retire_flight(s_b, sq,&eb,b,true).unwrap(); assert_eq!(p.pick_slot_in_mask_blocks_mode(&vm1,false,vm_mask,0,0,false),Some(s_a)); // 5th hang quarantines s_a: only s_b survives (reuse-only for VM2; VM1/VM3 exhausted). p.publish_flight(s_a); @@ -1410,9 +1443,9 @@ def module(text, name): assert_eq!(q.pick_slot(&vm2,false),Some(last)); let qlast=mk_epoch(&vm2,last); let qb=q.bind(last,false); - q.publish_flight(last); + let sq=q.publish_flight(last); assert!(!q.exhausted_for(&vm3)); // in-flight: waits for drain first - q.retire_flight(last,&qlast,qb,true).unwrap(); + q.retire_flight(last, sq,&qlast,qb,true).unwrap(); assert!(!q.exhausted()); assert!(!q.exhausted_for(&vm2)); assert_eq!(q.pick_slot(&vm2,false),Some(last)); @@ -2406,8 +2439,8 @@ def module(text, name): assert_eq!(e512.heap_blocks(), 512); e512.expose(); let b0 = p.bind(0, false); - p.publish_flight(0); - p.retire_flight(0, &e512, b0, true).unwrap(); + let sq=p.publish_flight(0); + p.retire_flight(0, sq, &e512, b0, true).unwrap(); // At 512 blocks VM1 pipelines cleanly on slot 0. assert!(p.can_pipeline_within_blocks(&vm1, 2, 512)); @@ -2425,8 +2458,8 @@ def module(text, name): assert_eq!(e1024.heap_blocks(), 1024); e1024.expose(); let b1 = p.bind(1, false); - p.publish_flight(1); - p.retire_flight(1, &e1024, b1, true).unwrap(); + let sq=p.publish_flight(1); + p.retire_flight(1, sq, &e1024, b1, true).unwrap(); // Slot 1 now pipelines at 1024 blocks; expanding to 2048 rotates cleanly back to displaced slot 0. assert!(p.can_pipeline_within_blocks(&vm1, 2, 1024)); @@ -2540,8 +2573,8 @@ def module(text, name): assert_eq!(slot, home, "VM {i} must claim its home slot {home} despite reverse arrival"); let e = mk_epoch(&vms[i], slot); let b = p.bind(slot, false); - p.publish_flight(slot); - p.retire_flight(slot, &e, b, true).unwrap(); + let sq=p.publish_flight(slot); + p.retire_flight(slot, sq, &e, b, true).unwrap(); epochs.push((i, e)); } // All 16 VMs now pipeline concurrently (behind=true) on 16 disjoint warm slots with 0 InitBM. @@ -2553,12 +2586,12 @@ def module(text, name): assert_eq!(slot, home); assert!(p.reusable_for_mask_mode(slot, &vms[i], mask, 512, false).is_some()); let b = p.bind(slot, true); - p.publish_flight(slot); - binds.push((i, slot, b)); + let sq = p.publish_flight(slot); + binds.push((i, slot, b, sq)); } - for (idx, (i, slot, b)) in binds.into_iter().enumerate() { + for (idx, (i, slot, b, sq)) in binds.into_iter().enumerate() { assert_eq!(p.slot_inflight(slot), 1); - p.retire_flight(slot, &epochs[idx].1, b, true).unwrap(); + p.retire_flight(slot, sq, &epochs[idx].1, b, true).unwrap(); assert_eq!(p.slot_inflight(slot), 0); let _ = i; } @@ -2570,8 +2603,8 @@ def module(text, name): assert_ne!(mask & (1u32 << slot), 0); let e = mk_epoch(&vms[i], slot); let b = p.bind(slot, false); - p.publish_flight(slot); - p.retire_flight(slot, &e, b, true).unwrap(); + let sq=p.publish_flight(slot); + p.retire_flight(slot, sq, &e, b, true).unwrap(); } } @@ -2739,8 +2772,8 @@ def module(text, name): e.expose(); let b = p.bind(pb_slot, false); p.hold_alloc(pb_slot, &v, Some(PbOwnerArena::Base(pb_arena.clone())), None).unwrap(); - p.publish_flight(pb_slot); - p.retire_flight(pb_slot, &e, b, true).unwrap(); + let sq=p.publish_flight(pb_slot); + p.retire_flight(pb_slot, sq, &e, b, true).unwrap(); // 2) Render pass slot i let pk = s.pick_pass_in_for(&r_prep, &geo, 0, Some(v.id)).unwrap(); @@ -2824,8 +2857,8 @@ def module(text, name): live_e.expose(); let lb = p.bind(live_slot, false); p.hold_alloc(live_slot, &live, Some(PbOwnerArena::Base(live_r_arena.clone())), None).unwrap(); - p.publish_flight(live_slot); - p.retire_flight(live_slot, &live_e, lb, true).unwrap(); + let sq=p.publish_flight(live_slot); + p.retire_flight(live_slot, sq, &live_e, lb, true).unwrap(); let lpk = s.pick_pass_in_for(&live_r_prep, &geo, 0, Some(live.id)).unwrap(); s.claim_pass_in(&live_r_prep, lpk, Some(live.id), geo.tilemap_bytes).unwrap(); @@ -2869,8 +2902,8 @@ def module(text, name): e.expose(); let b = p.bind(i, false); p.hold_alloc(i, &next, None, None).unwrap(); - p.publish_flight(i); - p.retire_flight(i, &e, b, true).unwrap(); + let sq=p.publish_flight(i); + p.retire_flight(i, sq, &e, b, true).unwrap(); assert_eq!(sync::Arc::strong_count(&epochs[i]), 1, "replaced PB epoch {i} released"); } assert!(!p.reclaim_closed()); @@ -3053,8 +3086,8 @@ def module(text, name): e1.expose(); let b1 = p.bind(0, false); p.hold_alloc(0, &vm1, Some(PbOwnerArena::Base(r_arena1.clone())), Some(uma1.clone())).unwrap(); - p.publish_flight(0); - p.retire_flight(0, &e1, b1, true).unwrap(); + let sq=p.publish_flight(0); + p.retire_flight(0, sq, &e1, b1, true).unwrap(); let pools2 = PoolSet::new_with_slots(&mut o, &factory, [1, 2]).unwrap(); let uma2 = pools2.unit(0).unwrap().uma_lease(); @@ -3068,8 +3101,8 @@ def module(text, name): e2.expose(); let b2 = p.bind(1, false); p.hold_alloc(1, &vm2, Some(PbOwnerArena::Base(r_arena2.clone())), Some(uma2.clone())).unwrap(); - p.publish_flight(1); - p.retire_flight(1, &e2, b2, true).unwrap(); + let sq=p.publish_flight(1); + p.retire_flight(1, sq, &e2, b2, true).unwrap(); // Compute unit 0 owned by VM1, displaced by VM2 on unit 1. let mut units1 = KVec::new(); @@ -3153,8 +3186,8 @@ def module(text, name): e3.expose(); let b3 = p.bind(0, false); p.hold_alloc(0, &vm3, Some(PbOwnerArena::Base(r_arena3)), Some(uma3.clone())).unwrap(); - p.publish_flight(0); - p.retire_flight(0, &e3, b3, true).unwrap(); + let sq=p.publish_flight(0); + p.retire_flight(0, sq, &e3, b3, true).unwrap(); assert_eq!(sync::Arc::strong_count(&pb_lease1), 1, "overwritten pb_mgr_table[0] lease dropped"); assert_eq!(sync::Arc::strong_count(&vm1), 1, "replaced PB epoch releases VM1's TTBAT slot"); assert_eq!(sync::Arc::strong_count(&uma1), 1, "overwritten render uma_mgr_table[33] lease dropped"); @@ -3199,14 +3232,14 @@ def module(text, name): let x_records = ex.records_lease(); let bx = p.bind(3, false); p.hold_alloc(3, &x, Some(PbOwnerArena::Base(x_arena.clone())), None).unwrap(); - p.publish_flight(3); - p.retire_flight(3, &ex, bx, true).unwrap(); + let sq=p.publish_flight(3); + p.retire_flight(3, sq, &ex, bx, true).unwrap(); let y = vm(47); let ey = epoch(&y, 4); let by = p.bind(4, false); p.hold_alloc(4, &y, None, None).unwrap(); - p.publish_flight(4); - p.retire_flight(4, &ey, by, true).unwrap(); + let sq=p.publish_flight(4); + p.retire_flight(4, sq, &ey, by, true).unwrap(); // X closes. Its arena and PB heap go, but not the epoch firmware still names. x.vm.close(); @@ -3225,11 +3258,11 @@ def module(text, name): let ez = epoch(&z, 3); let bz = p.bind(3, false); p.hold_alloc(3, &z, None, None).unwrap(); - p.publish_flight(3); + let sq = p.publish_flight(3); assert!(p.reclaim_closed(), "rebinding render still in flight"); assert_eq!(sync::Arc::strong_count(&ex), 2); assert_eq!(sync::Arc::strong_count(&x), 2); - p.retire_flight(3, &ez, bz, true).unwrap(); + p.retire_flight(3, sq, &ez, bz, true).unwrap(); assert_eq!(sync::Arc::strong_count(&ex), 1, "replaced epoch released"); drop(ex); assert_eq!(sync::Arc::strong_count(&x), 1, "closed VM released after replacement"); @@ -3260,8 +3293,8 @@ def module(text, name): e: &sync::Arc, completed: bool| { let b = p.bind(k, false); p.hold_alloc(k, v, None, None).unwrap(); - p.publish_flight(k); - p.retire_flight(k, e, b, completed).unwrap(); + let sq=p.publish_flight(k); + p.retire_flight(k, sq, e, b, completed).unwrap(); }; let a = vm(62); @@ -3279,9 +3312,9 @@ def module(text, name): let ea2 = epoch(&a, 4); let b2 = p.bind(4, false); p.hold_alloc(4, &a, None, None).unwrap(); - p.publish_flight(4); + let sq = p.publish_flight(4); assert_eq!(sync::Arc::strong_count(&ea1), 2); - p.retire_flight(4, &ea2, b2, false).unwrap(); + p.retire_flight(4, sq, &ea2, b2, false).unwrap(); assert_eq!(sync::Arc::strong_count(&ea1), 2, "a failed render released the old list"); let ea3 = epoch(&a, 4); run(&mut p, &a, 4, &ea3, true); @@ -3317,8 +3350,8 @@ def module(text, name): e: &sync::Arc| { let b = p.bind(k, false); p.hold_alloc(k, v, None, None).unwrap(); - p.publish_flight(k); - p.retire_flight(k, e, b, true).unwrap(); + let sq=p.publish_flight(k); + p.retire_flight(k, sq, e, b, true).unwrap(); }; let a = vm(20); @@ -3339,10 +3372,10 @@ def module(text, name): let ea2 = epoch(&a, 4); let b2 = p.bind(4, false); p.hold_alloc(4, &a, None, None).unwrap(); - p.publish_flight(4); + let sq = p.publish_flight(4); assert!(p.reclaim_closed(), "render of the closed VM in flight"); assert_eq!(sync::Arc::strong_count(&ea1), 2); - p.retire_flight(4, &ea2, b2, true).unwrap(); + p.retire_flight(4, sq, &ea2, b2, true).unwrap(); assert_eq!(sync::Arc::strong_count(&ea1), 1, "older epoch released after the InitBM"); assert!(p.take_closed_vm_last(), "a closed VM's entry asks for another reclaim pass"); assert!(!p.take_closed_vm_last()); diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py index a06beb782943b..02b7283d9de0a 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py @@ -28,7 +28,7 @@ def function(text, name): #[path="__LOGIC__"]mod logic; use logic::{Retirement, ABORT_GRACE_NS}; mod encode { __STAMP_SEED__ __STAMP__ } -mod hw { pub mod sizes { pub const COMPUTE_PIPES: usize = 8; } } +mod hw { pub mod sizes { pub const COMPUTE_PIPES: usize = 8; pub const RENDER_PAIRS: usize = 2; } } struct Object{cells:BTreeMap,va:u64,unstable:bool,reads:Cell} impl Default for Object{fn default()->Self{Self{cells:BTreeMap::new(),va:0x1234,unstable:false,reads:Cell::new(0)}}} impl Object { @@ -43,13 +43,13 @@ def function(text, name): mod manager {pub const COUNTER:usize=0x4c;pub const COMPLETED:usize=0x54;} #[derive(Default)]struct CGraph{fw_stamp:Object,qstate:Object,qinfo:Object,notifier:Object} struct RGraph{fw_stamp:[Object;2],qstate:[Object;2],qinfo:[Object;2],notifier:Object} -struct Graph{compute:[CGraph;hw::sizes::COMPUTE_PIPES],render:RGraph} +struct Graph{compute:[CGraph;hw::sizes::COMPUTE_PIPES],render:[RGraph;hw::sizes::RENDER_PAIRS]} struct Vm{slot:u32}struct Job{vm:Vm,resources:Resources} struct Resources{compute:Vec,passes:Vec,pools:Pools} impl Resources{fn compute(&self)->Result<&Self>{Ok(self)}fn render(&self)->Result<&Self>{Ok(self)}fn compute_unit(&self,k:usize)->Result<&CUnit>{self.compute.get(k).ok_or(EINVAL)}fn render_pass(&self,k:usize)->Result<&RUnit>{self.passes.get(k).ok_or(EINVAL)}fn pb_retired(&self,k:usize)->Result{self.pools.retired(k)}fn pb_retired_at(&self,k:usize,target:u64)->Result{self.pools.retired_at(k,target)}} struct Claims{slot:[u32;16],slot_count:u32,pass:[u32;4]} -struct Flight{computes:u32,renders:u32,compute_pipe:u8,target:u32,ta_target:u32,fs_target:u32,job:Job,claims:Claims,head:u32,ta_head:u32,fs_head:u32,rec:[u32;3],chan_settled:bool,pb_slot:u32,uma_submitted:u64,csubmitted:[u64;16],recovery_suspect:bool,recovery_started_ns:u64,gate_passed_ns:Option,unsettled_polls:u32,doomed:bool} -struct Engine{flights:Vec,target:[u32;hw::sizes::COMPUTE_PIPES],ta_target:u32,fs_target:u32,retired_ticks:[u64;4]} +struct Flight{computes:u32,renders:u32,compute_pipe:u8,render_pair:u8,render_chan_settled:[bool;2],target:u32,ta_target:u32,fs_target:u32,job:Job,claims:Claims,head:u32,ta_head:u32,fs_head:u32,rec:[u32;3],chan_settled:bool,pb_slot:u32,uma_submitted:u64,csubmitted:[u64;16],recovery_suspect:bool,recovery_started_ns:u64,gate_passed_ns:Option,unsettled_polls:u32,doomed:bool} +struct Engine{flights:Vec,target:[u32;hw::sizes::COMPUTE_PIPES],ta_target:[u32;hw::sizes::RENDER_PAIRS],fs_target:[u32;hw::sizes::RENDER_PAIRS],retired_ticks:[u64;4]} fn stamp_reached(observed:u32,own:u32,tail:u32)->bool{logic::stamp_reached(observed,own,tail)} impl Engine{fn oldest(&self)->Option<&Flight>{self.flights.first()}} struct CUnit{counter:Object,descriptor:Object,its:Object,work:Object} @@ -83,8 +83,8 @@ def function(text, name): let mut target_arr=[0u32;hw::sizes::COMPUTE_PIPES];target_arr[0]=target; let mut f=Firmware{ graph:Graph{compute:core::array::from_fn(|_|CGraph::default()), - render:RGraph{fw_stamp:Default::default(),qstate:Default::default(),qinfo:Default::default(),notifier:Object::default()}}, - engine:Engine{flights:vec![Flight{computes:u32::from(!render),renders:u32::from(render),compute_pipe:0,target,ta_target:target,fs_target:target,job:Job{vm:Vm{slot:2},resources:Resources{compute:vec![CUnit{counter:Object::default(),descriptor:Object::default(),its:Object::default(),work:Object::default()}],passes:vec![RUnit{scene:Object::default()}],pools:Pools{full:true,completed:2}}},claims:Claims{slot:[0;16],slot_count:u32::from(!render),pass:[0;4]},head:1,ta_head:1,fs_head:1,rec:[1;3],chan_settled:false,pb_slot:0,uma_submitted:2,csubmitted:{let mut a=[0u64;16];if !render{a[0]=ordinal;}a},recovery_suspect:false,recovery_started_ns:0,gate_passed_ns:None,unsettled_polls:0,doomed:false}],target:target_arr,ta_target:target,fs_target:target,retired_ticks:[0;4]}, + render:core::array::from_fn(|_|RGraph{fw_stamp:Default::default(),qstate:Default::default(),qinfo:Default::default(),notifier:Object::default()})}, + engine:Engine{flights:vec![Flight{computes:u32::from(!render),renders:u32::from(render),compute_pipe:0,render_pair:0,render_chan_settled:[false;2],target,ta_target:target,fs_target:target,job:Job{vm:Vm{slot:2},resources:Resources{compute:vec![CUnit{counter:Object::default(),descriptor:Object::default(),its:Object::default(),work:Object::default()}],passes:vec![RUnit{scene:Object::default()}],pools:Pools{full:true,completed:2}}},claims:Claims{slot:[0;16],slot_count:u32::from(!render),pass:[0;4]},head:1,ta_head:1,fs_head:1,rec:[1;3],chan_settled:false,pb_slot:0,uma_submitted:2,csubmitted:{let mut a=[0u64;16];if !render{a[0]=ordinal;}a},recovery_suspect:false,recovery_started_ns:0,gate_passed_ns:None,unsettled_polls:0,doomed:false}],target:target_arr,ta_target:[target;hw::sizes::RENDER_PAIRS],fs_target:[target;hw::sizes::RENDER_PAIRS],retired_ticks:[0;4]}, slots:Slots{scrub:Scrub{compute:vec![CUnit{counter:Object::default(),descriptor:Object::default(),its:Object::default(),work:Object::default()}],passes:vec![RUnit{scene:Object::default()}]}}, pools:Pools{full:true,completed:2},channels:TopChannels{compute_producer:1},queue_passed:true,last_chan_passed:Cell::new(None), }; @@ -95,11 +95,11 @@ def function(text, name): f.engine.flights[0].job.resources.compute[0].its.set(0,100);f.engine.flights[0].job.resources.compute[0].its.set(8,101); f.engine.flights[0].job.resources.compute[0].descriptor.set(manager::COMPLETED,ordinal); f.engine.flights[0].job.resources.compute[0].descriptor.set(manager::COUNTER,0x1234); - for stage in 0..2{f.graph.render.fw_stamp[stage].set(0,u64::from(target));} - f.graph.render.notifier.set(notifier_page::TA_STAMP,u64::from(target)); - f.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(target)); - f.graph.render.notifier.set(notifier::CONTEXT,2); - f.graph.render.notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,2); + for stage in 0..2{f.graph.render[0].fw_stamp[stage].set(0,u64::from(target));} + f.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(target)); + f.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(target)); + f.graph.render[0].notifier.set(notifier::CONTEXT,2); + f.graph.render[0].notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,2); for (off,time) in [(0x600,100),(0x608,101),(0x620,102),(0x628,103)]{f.engine.flights[0].job.resources.passes[0].scene.set(off,time);} f } @@ -118,12 +118,12 @@ def function(text, name): f.queue_passed=false;assert_eq!(f.retired(),Ok(Retirement::Pending)); f.queue_passed=true; if render { - f.graph.render.fw_stamp[0].set(0,u64::from(encode::stamp(n-1))); + f.graph.render[0].fw_stamp[0].set(0,u64::from(encode::stamp(n-1))); assert_eq!(f.retired(),Ok(Retirement::Pending)); - f.graph.render.fw_stamp[0].set(0,u64::from(encode::stamp(n))); - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(n-1))); + f.graph.render[0].fw_stamp[0].set(0,u64::from(encode::stamp(n))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n-1))); assert_eq!(f.retired(),Ok(Retirement::Pending)); - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(n))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n))); f.engine.flights[0].job.resources.pools.full=false;assert_eq!(f.retired(),Ok(Retirement::Pending)); }else{ f.engine.flights[0].job.resources.compute[0].its.set(8,0); @@ -156,20 +156,20 @@ def function(text, name): let mut later=firmware(true,n+1).engine.flights.remove(0); later.uma_submitted=4; f.engine.flights.push(later); - f.engine.ta_target=encode::stamp(n+1); - f.engine.fs_target=encode::stamp(n+1); + f.engine.ta_target[0]=encode::stamp(n+1); + f.engine.fs_target[0]=encode::stamp(n+1); // The render behind it finished too: shared TA/FS stamps and notifier moved on. - for stage in 0..2 { f.graph.render.fw_stamp[stage].set(0,u64::from(encode::stamp(n+1))); } - f.graph.render.notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(n+1))); - f.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(n+1))); - f.graph.render.notifier.set(notifier::CONTEXT,9); - f.graph.render.notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,9); + for stage in 0..2 { f.graph.render[0].fw_stamp[stage].set(0,u64::from(encode::stamp(n+1))); } + f.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(n+1))); + f.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(n+1))); + f.graph.render[0].notifier.set(notifier::CONTEXT,9); + f.graph.render[0].notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,9); f.engine.flights[0].job.resources.pools.completed=4; assert_eq!(f.retired(),Ok(Retirement::Full)); // Unreached FS stamp keeps it pending. - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(n-1))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n-1))); assert_eq!(f.retired(),Ok(Retirement::Pending)); - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(n))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n))); assert_eq!(f.retired(),Ok(Retirement::Full)); // Unreached UMA completion keeps it pending. f.engine.flights[0].job.resources.pools.completed=1; @@ -202,22 +202,22 @@ def function(text, name): f.graph.compute[0].notifier.set(notifier_page::COMPUTE_STAMP,u64::from(encode::stamp(20))); f.graph.compute[0].notifier.set(notifier_page::COMPUTE_CONTEXT,2); // Keep render FS stamp unreached so render at index 0 stays pending. - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(9))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(9))); assert_eq!(f.retired_flight(),Ok(Some((1,Retirement::Full)))); f.engine.flights.remove(1); assert_eq!(f.retired_flight(),Ok(None)); // Now finish render: render retires cleanly with exact single-class receipt. - f.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(10))); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(10))); assert_eq!(f.retired_flight(),Ok(Some((0,Retirement::Full)))); // Reverse order: Compute at index 0 (pending) + Render at index 1 (complete). let mut f2=firmware(false,30); let r=firmware(true,40).engine.flights.remove(0); f2.engine.flights.push(r); - f2.engine.ta_target=encode::stamp(40); - f2.engine.fs_target=encode::stamp(40); - for stage in 0..2 { f2.graph.render.fw_stamp[stage].set(0,u64::from(encode::stamp(40))); } - f2.graph.render.notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(40))); - f2.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(40))); + f2.engine.ta_target[0]=encode::stamp(40); + f2.engine.fs_target[0]=encode::stamp(40); + for stage in 0..2 { f2.graph.render[0].fw_stamp[stage].set(0,u64::from(encode::stamp(40))); } + f2.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(40))); + f2.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(40))); f2.graph.compute[0].fw_stamp.set(0,u64::from(encode::stamp(29))); assert_eq!(f2.retired_flight(),Ok(Some((1,Retirement::Full)))); } @@ -252,9 +252,9 @@ def function(text, name): // Compute-only retirement performs zero render WC reads. let mut fc=firmware(false,5); assert_eq!(fc.retired_flight(),Ok(Some((0,Retirement::Full)))); - assert_eq!(fc.graph.render.fw_stamp[0].reads.get(),0); - assert_eq!(fc.graph.render.fw_stamp[1].reads.get(),0); - assert_eq!(fc.graph.render.notifier.reads.get(),0); + assert_eq!(fc.graph.render[0].fw_stamp[0].reads.get(),0); + assert_eq!(fc.graph.render[0].fw_stamp[1].reads.get(),0); + assert_eq!(fc.graph.render[0].notifier.reads.get(),0); // Render-only retirement performs zero compute WC reads. let mut fr=firmware(true,5); assert_eq!(fr.retired_flight(),Ok(Some((0,Retirement::Full)))); @@ -264,14 +264,14 @@ def function(text, name): assert_eq!(fr.graph.compute[1].notifier.reads.get(),0); // In-progress render (TA done, FS still running) fails fast on FS stamp without reading TA or scene. let mut fp=firmware(true,7); - fp.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(6))); + fp.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(6))); assert_eq!(fp.retired_flight(),Ok(None)); - assert_eq!(fp.graph.render.fw_stamp[1].reads.get(),1); - assert_eq!(fp.graph.render.fw_stamp[0].reads.get(),0); + assert_eq!(fp.graph.render[0].fw_stamp[1].reads.get(),1); + assert_eq!(fp.graph.render[0].fw_stamp[0].reads.get(),0); assert_eq!(fp.engine.flights[0].job.resources.passes[0].scene.reads.get(),0); // Unsettled notifier skips scene WC timestamp reads. - fp.graph.render.fw_stamp[1].set(0,u64::from(encode::stamp(7))); - fp.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(6))); + fp.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(7))); + fp.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(6))); assert_eq!(fp.retired_flight(),Ok(None)); assert_eq!(fp.engine.flights[0].job.resources.passes[0].scene.reads.get(),0); // Mixed flight pending is polled once, not twice. @@ -280,28 +280,98 @@ def function(text, name): fm.graph.compute[0].fw_stamp.set(0,u64::from(encode::stamp(8))); assert_eq!(fm.retired_flight(),Ok(None)); assert_eq!(fm.graph.compute[0].fw_stamp.reads.get(),1); - assert_eq!(fm.graph.render.fw_stamp[1].reads.get(),0); + assert_eq!(fm.graph.render[0].fw_stamp[1].reads.get(),0); // Pending compute class is not re-polled while retiring a burst of render flights. let mut fmix=firmware(false,30); let r1=firmware(true,40).engine.flights.remove(0); let r2=firmware(true,41).engine.flights.remove(0); fmix.engine.flights.push(r1); fmix.engine.flights.push(r2); - fmix.engine.ta_target=encode::stamp(41); - fmix.engine.fs_target=encode::stamp(41); - for stage in 0..2 { fmix.graph.render.fw_stamp[stage].set(0,u64::from(encode::stamp(41))); } - fmix.graph.render.notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(41))); - fmix.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(41))); + fmix.engine.ta_target[0]=encode::stamp(41); + fmix.engine.fs_target[0]=encode::stamp(41); + for stage in 0..2 { fmix.graph.render[0].fw_stamp[stage].set(0,u64::from(encode::stamp(41))); } + fmix.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(41))); + fmix.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(41))); fmix.graph.compute[0].fw_stamp.set(0,u64::from(encode::stamp(29))); - let (mut check_c,mut check_r)=([true;hw::sizes::COMPUTE_PIPES],true); + let (mut check_c,mut check_r)=([true;hw::sizes::COMPUTE_PIPES],[true;hw::sizes::RENDER_PAIRS]); assert_eq!(fmix.retired_flight_classes(&mut check_c,&mut check_r),Ok(Some((1,Retirement::Full)))); - assert!(!check_c[0] && !check_c[1] && check_r); + assert!(!check_c[0] && !check_c[1] && check_r[0] && !check_r[1]); fmix.engine.flights.remove(1); assert_eq!(fmix.retired_flight_classes(&mut check_c,&mut check_r),Ok(Some((1,Retirement::Full)))); fmix.engine.flights.remove(1); assert_eq!(fmix.retired_flight_classes(&mut check_c,&mut check_r),Ok(None)); assert_eq!(fmix.graph.compute[0].fw_stamp.reads.get(),1); } +/// A render flight of ordinal `n` on render pair 1 whose pair-1 cells show it done. +fn pair1_render(f:&mut Firmware,n:u64){ + let mut fl=firmware(true,n).engine.flights.remove(0); + fl.render_pair=1; + f.engine.flights.push(fl); + let t=encode::stamp(n); + f.engine.ta_target[1]=t;f.engine.fs_target[1]=t; + for stage in 0..2 { f.graph.render[1].fw_stamp[stage].set(0,u64::from(t)); } + f.graph.render[1].notifier.set(notifier_page::TA_STAMP,u64::from(t)); + f.graph.render[1].notifier.set(notifier_page::FS_STAMP,u64::from(t)); + f.graph.render[1].notifier.set(notifier::CONTEXT,2); + f.graph.render[1].notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,2); +} +#[test]fn render_pairs_retire_out_of_order_on_their_own_cells(){ + // Pair 0 render (older, FS still running) + pair 1 render (newer, finished): pair 1 retires + // first, from pair 1's stamps and notifier alone. Dense per-pair stamps may be equal. + for n in [1u64,0x7fffff,0xffffff,0x1000000] { + let mut f=firmware(true,n); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n-1))); + pair1_render(&mut f,n); + assert_eq!(f.retired_flight(),Ok(Some((1,Retirement::Full)))); + // Another render flight is in flight on the shared TA/FS channels: passed channel proof. + assert_eq!(f.last_chan_passed.get(),Some(true)); + f.engine.flights.remove(1); + assert_eq!(f.retired_flight(),Ok(None)); + // Pair 1's cells never stand in for pair 0's. + assert_eq!(f.graph.render[1].fw_stamp[1].reads.get(),1); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(n))); + f.last_chan_passed.set(None); + assert_eq!(f.retired_flight(),Ok(Some((0,Retirement::Full)))); + // Alone again with the newest channel record: exact channel proof. + assert_eq!(f.last_chan_passed.get(),Some(false)); + } +} +#[test]fn render_pair_progress_does_not_retire_the_other_pair(){ + // Pair 1 finished, pair 0 pending with its own FS stamp unreached: only pair 1 retires, + // and a later pair-0 flight keeps pair 0 in order with "passed" receipts. + let mut f=firmware(true,5); + f.graph.render[0].fw_stamp[1].set(0,u64::from(encode::stamp(4))); + pair1_render(&mut f,5); + f.graph.render[1].fw_stamp[1].set(0,u64::from(encode::stamp(4))); + assert_eq!(f.retired_flight(),Ok(None)); + let mut later=firmware(true,6).engine.flights.remove(0); + later.uma_submitted=4; + f.engine.flights.push(later); + f.engine.ta_target[0]=encode::stamp(6);f.engine.fs_target[0]=encode::stamp(6); + f.engine.flights[0].job.resources.pools.completed=4; + for stage in 0..2 { f.graph.render[0].fw_stamp[stage].set(0,u64::from(encode::stamp(6))); } + f.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(encode::stamp(6))); + f.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(encode::stamp(6))); + // Pair 0's oldest retires in order (index 0); pair 1 stays pending. + assert_eq!(f.retired_flight(),Ok(Some((0,Retirement::Full)))); + f.engine.flights.remove(0); + assert_eq!(f.retired_flight(),Ok(Some((1,Retirement::Full)))); + f.engine.flights.remove(1); + assert_eq!(f.retired_flight(),Ok(None)); +} +#[test]fn latched_render_channel_receipt_stands_in_for_a_lapped_channel_proof(){ + // A long pair-0 render whose TA/FS records the other pair's records have lapped: once the + // channel proof was latched, the queue and stamp receipts alone retire it. + let mut f=firmware(true,9); + f.queue_passed=true; + f.last_chan_passed.set(None); + f.engine.flights[0].render_chan_settled=[true;2]; + assert_eq!(f.retired(),Ok(Retirement::Full)); + assert_eq!(f.last_chan_passed.get(),None,"no channel cursor read once latched"); + f.engine.flights[0].render_chan_settled=[true,false]; + assert_eq!(f.retired(),Ok(Retirement::Full)); + assert_eq!(f.last_chan_passed.get(),Some(false)); +} #[test]fn innocent_suspect_flight_does_not_false_abort_after_recovery_grace(){ let mut f=firmware(true,15); f.engine.flights[0].recovery_suspect=true; @@ -396,13 +466,13 @@ def function(text, name): f.engine.flights.push(innocent); let t31=encode::stamp(31); - f.engine.ta_target=t31; - f.engine.fs_target=t31; - for stage in 0..2 { f.graph.render.fw_stamp[stage].set(0,u64::from(t31)); } - f.graph.render.notifier.set(notifier_page::TA_STAMP,u64::from(t31)); - f.graph.render.notifier.set(notifier_page::FS_STAMP,u64::from(t31)); - f.graph.render.notifier.set(notifier::CONTEXT,2); - f.graph.render.notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,2); + f.engine.ta_target[0]=t31; + f.engine.fs_target[0]=t31; + for stage in 0..2 { f.graph.render[0].fw_stamp[stage].set(0,u64::from(t31)); } + f.graph.render[0].notifier.set(notifier_page::TA_STAMP,u64::from(t31)); + f.graph.render[0].notifier.set(notifier_page::FS_STAMP,u64::from(t31)); + f.graph.render[0].notifier.set(notifier::CONTEXT,2); + f.graph.render[0].notifier.set(notifier_page::FS_RECORD+notifier::CONTEXT,2); // First unsettled poll records gate_passed_ns on hanging VM A; after ABORT_GRACE_NS, VM A aborts. assert_eq!(f.retired_flight(),Ok(None)); @@ -537,8 +607,8 @@ def function(text, name): } fn producer(&self, ch: Channel) -> u32 { self.channel(ch).write } } - struct Engine { head: [u32; hw::sizes::COMPUTE_PIPES], ta_head: u32, fs_head: u32, flights: Vec } - struct Flight { computes: u32, compute_pipe: u8, c_start: u32, head: u32, ta_start: u32, ta_head: u32, fs_start: u32, fs_head: u32, rec: [u32; 3], chan_settled: bool } + struct Engine { head: [u32; hw::sizes::COMPUTE_PIPES], ta_head: [u32; hw::sizes::RENDER_PAIRS], fs_head: [u32; hw::sizes::RENDER_PAIRS], flights: Vec } + struct Flight { computes: u32, compute_pipe: u8, render_pair: u8, c_start: u32, head: u32, ta_start: u32, ta_head: u32, fs_start: u32, fs_head: u32, rec: [u32; 3], chan_settled: bool } struct Firmware { init: Init, channels: Channels, engine: Engine } mod inner { use super::*; @@ -561,7 +631,7 @@ def function(text, name): ta: Pipe { read: 7, completion: 7, write: 7 }, fs: Pipe { read: 9, completion: 9, write: 9 }, }, - engine: Engine { head: { let mut h = [0u32; hw::sizes::COMPUTE_PIPES]; h[0] = 10; h[1] = 12; h }, ta_head: 20, fs_head: 30, flights: vec![] }, + engine: Engine { head: { let mut h = [0u32; hw::sizes::COMPUTE_PIPES]; h[0] = 10; h[1] = 12; h }, ta_head: [20; hw::sizes::RENDER_PAIRS], fs_head: [30; hw::sizes::RENDER_PAIRS], flights: vec![] }, }; let mut state = Object::default(); let mut info = Object::default(); @@ -596,16 +666,16 @@ def function(text, name): assert_eq!(fw.queue_ring_receipt(&state, &info, 12), Ok(true)); assert_eq!(fw.channel_receipt(Channel::Compute, 5, false), Ok(false)); assert_eq!(fw.channel_receipt(Channel::Compute, 5, true), Ok(true)); - let f_p1 = Flight { computes: 1, compute_pipe: 1, c_start: 10, head: 11, ta_start: 0, ta_head: 1, fs_start: 0, fs_head: 1, rec: [1, 1, 5], chan_settled: false }; + let f_p1 = Flight { render_pair: 0, computes: 1, compute_pipe: 1, c_start: 10, head: 11, ta_start: 0, ta_head: 1, fs_start: 0, fs_head: 1, rec: [1, 1, 5], chan_settled: false }; assert_eq!(fw.queue_ring_passed(Channel::Compute, &state, &info, &f_p1), Ok(true)); state.set(qstate::READ, 10); assert_eq!(fw.queue_ring_passed(Channel::Compute, &state, &info, &f_p1), Ok(false)); assert_eq!(info.reads.get(), 0); // queue_passed with queued work behind flight (including wrap-around) never reads qinfo. - fw.engine.ta_head = 2; + fw.engine.ta_head[0] = 2; fw.channels.ta = Pipe { read: 2, completion: 2, write: 3 }; - let f = Flight { computes: 0, compute_pipe: 0, c_start: 0, head: 10, ta_start: 254, ta_head: 0, fs_start: 0, fs_head: 1, rec: [1, 1, 5], chan_settled: false }; + let f = Flight { render_pair: 0, computes: 0, compute_pipe: 0, c_start: 0, head: 10, ta_start: 254, ta_head: 0, fs_start: 0, fs_head: 1, rec: [1, 1, 5], chan_settled: false }; state.set(qstate::READ, 1); assert_eq!(fw.queue_passed(Channel::Ta, &state, &info, &f), Ok(true)); assert_eq!(info.reads.get(), 0); @@ -633,9 +703,10 @@ def function(text, name): }, engine: Engine { head: [0u32; hw::sizes::COMPUTE_PIPES], - ta_head: 0, - fs_head: 0, + ta_head: [0; hw::sizes::RENDER_PAIRS], + fs_head: [0; hw::sizes::RENDER_PAIRS], flights: vec![Flight { + render_pair: 0, computes: 1, compute_pipe: 0, c_start: 0,