diff --git a/drivers/gpu/drm/asahi/g17/buffer.rs b/drivers/gpu/drm/asahi/g17/buffer.rs index fd0aace6a4262..0d9bdd33ba1ed 100644 --- a/drivers/gpu/drm/asahi/g17/buffer.rs +++ b/drivers/gpu/drm/asahi/g17/buffer.rs @@ -9,6 +9,7 @@ use super::fw::buffer as fw; use crate::hw::t8140::resources as cfg; pub(crate) mod target; +pub(crate) mod compact; mod geometry; pub(crate) use geometry::BlockGeometry; mod layout; @@ -414,6 +415,18 @@ impl Tvb { } geometry.backing_bytes(blocks) } + /// Backing for `blocks` blocks to be mapped into `vm`. M5 blocks are mapped one by one in + /// the compact window, which is checked for room for all of them first, and the client's + /// passes and geometry size them, so they are charged to the client. + fn allocate(dev: &AsahiDrmDevice, vm: &mmu::Vm, geometry: BlockGeometry, blocks: usize) + -> Result { + let bytes = Self::backing_bytes(geometry, blocks)?; + if geometry == BlockGeometry::NEO { + return KernelObject::backing(dev, bytes, CpuMap::WriteCombined); + } + compact::PairObject::ParameterBlock.check_room(vm, geometry.block_bytes, blocks)?; + KernelObject::client_backing(dev, bytes, vm.memory_client()) + } fn map_block( object: &KernelObject, vm: &mmu::Vm, @@ -423,9 +436,8 @@ impl Tvb { if geometry != BlockGeometry::NEO { let start = relative.checked_mul(geometry.backing_stride).ok_or(EOVERFLOW)?; let source = start..start.checked_add(geometry.block_bytes).ok_or(EOVERFLOW)?; - let guard = geometry.stride - geometry.block_bytes; - let mapping = object.map_range(vm, source, geometry.base..geometry.end, - BlockGeometry::PAGE as u64, mmu::PROT_GPU_SHARED_RW, guard)?; + let mapping = compact::PairObject::ParameterBlock.map(object, vm, source, + mmu::PROT_GPU_SHARED_RW)?; geometry.compact_page(mapping.iova())?; return Ok(mapping); } @@ -458,8 +470,7 @@ impl Tvb { if blocks == 0 || blocks > geometry.max_blocks() { return Err(ERANGE); } - let backing = KernelObject::backing(dev, Self::backing_bytes(geometry, blocks)?, - CpuMap::WriteCombined)?; + let backing = Self::allocate(dev, vm, geometry, blocks)?; let mut mappings = KVec::with_capacity(blocks, GFP_KERNEL)?; let mut addresses = KVec::with_capacity(blocks, GFP_KERNEL)?; for index in 0..blocks { @@ -511,8 +522,7 @@ impl Tvb { let added = target - self.blocks(); self.extensions.reserve(1, GFP_KERNEL)?; self.addresses.reserve(added, GFP_KERNEL)?; - let backing = KernelObject::backing(dev, Self::backing_bytes(self.geometry, added)?, - CpuMap::WriteCombined)?; + let backing = Self::allocate(dev, vm, self.geometry, added)?; let mut mappings = KVec::with_capacity(added, GFP_KERNEL)?; let mut addresses = KVec::with_capacity(added, GFP_KERNEL)?; for relative in 0..added { @@ -568,15 +578,18 @@ impl MetricsIds { /// backing each lease is taken from. pub(crate) fn with_stride(scene_stride: usize) -> Result { if scene_stride < 4 || scene_stride % 4 != 0 { return Err(EINVAL); } - let entry_pitch = scene_stride.checked_mul(fw::SCENES) - .and_then(|bytes| bytes.checked_next_multiple_of(mmu::UAT_PGSZ)) - .ok_or(EOVERFLOW)?; Ok(Self { used: [AtomicU64::new(0), AtomicU64::new(0)], scene_stride, - entry_pitch, + entry_pitch: Self::entry_pitch(scene_stride)?, }) } + /// The pitch of entries of `scene_stride`-byte scenes: each starts its own pages. + pub(crate) fn entry_pitch(scene_stride: usize) -> Result { + scene_stride.checked_mul(fw::SCENES) + .and_then(|bytes| bytes.checked_next_multiple_of(mmu::UAT_PGSZ)) + .ok_or(EOVERFLOW) + } /// Backing required for every entry owned by this allocator. pub(crate) fn storage_bytes(&self) -> Result { self.entry_pitch.checked_mul(self.used.len() * u64::BITS as usize) @@ -607,14 +620,14 @@ impl MetricsLease { // window's start (InitData::bind_m5_metrics), so place the entry where its offset puts // it there. let fixed = super::J813_FORMS.load(Ordering::Relaxed).then(|| { - let at = BlockGeometry::M5_COMPACT.start + offset as u64; - self.backing.map_range(vm, offset..offset + pitch, at..at + pitch as u64, - mmu::UAT_PGSZ as u64, mmu::PROT_GPU_SHARED_RW, 0).ok() + let at = compact::WINDOW.start + offset as u64; + compact::PairObject::Metrics.map_at(&self.backing, vm, offset..offset + pitch, at, + mmu::PROT_GPU_SHARED_RW).ok() }).flatten(); let client = match fixed { Some(client) => client, - None => self.backing.map_range(vm, offset..offset + pitch, BlockGeometry::M5_COMPACT, - mmu::UAT_PGSZ as u64, mmu::PROT_GPU_SHARED_RW, 0)?, + None => compact::PairObject::Metrics.map(&self.backing, vm, offset..offset + pitch, + mmu::PROT_GPU_SHARED_RW)?, }; self.addresses.client = client.iova(); self.client = Some(client); @@ -822,8 +835,7 @@ impl Manager { mmu::UAT_PGSZ, )? } else { - graph.map_range(vm, source, geometry.base..geometry.end, - cfg::TVB_PAGE, mmu::PROT_GPU_FW_SHARED_RW, mmu::UAT_PGSZ)? + compact::PairObject::PageList.map(&graph, vm, source, mmu::PROT_GPU_FW_SHARED_RW)? }; let address = graph.gpu_va(); let graph_args = fw::GraphArgs { diff --git a/drivers/gpu/drm/asahi/g17/buffer/compact.rs b/drivers/gpu/drm/asahi/g17/buffer/compact.rs new file mode 100644 index 0000000000000..af491dc8c7167 --- /dev/null +++ b/drivers/gpu/drm/asahi/g17/buffer/compact.rs @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! The objects a render pair maps in its client's M5 compact window. +//! +//! The firmware addresses the window with 32-bit offsets, so it is 4 GiB, and every render pair +//! of the client maps its objects there. [`PairObject`] names each such object and fixes how it +//! is placed: every mapping of one goes through [`PairObject::map`] (or +//! [`PairObject::placement`]), and every room check before allocating one through +//! [`PairObject::check_room`]. SUBMIT's bound ([`PairSizes::window_bytes`]) counts the same +//! objects with the same placement, so an object cannot be mapped there without a size in the +//! bound, and the bound cannot disagree with a mapping on its alignment or guard. + +use super::BlockGeometry; +use crate::g17::object::{KernelObject, Placement}; +use crate::{ + hw::t8140::{queues, resources as cfg}, + mmu, +}; +use core::ops::Range; +use kernel::prelude::*; + +/// The client's M5 compact window. +pub(crate) const WINDOW: Range = BlockGeometry::M5_COMPACT; +/// Its size: 4 GiB. +pub(crate) const WINDOW_BYTES: u64 = WINDOW.end - WINDOW.start; + +const DEPTH: usize = queues::RENDER_DEPTH as usize; + +/// The task-stage mesh storage chunk: chunk bases are 64 KiB aligned, and the storage register +/// counts 64 KiB chunks. +pub(crate) const MESH_STORAGE_CHUNK: usize = 0x10000; + +/// The task-stage mesh storage a render pair maps on its first task-stage kick and keeps, as +/// (chunks, bytes); `None` when the module parameter disables the binding. +pub(crate) fn mesh_storage() -> Result> { + let chunks = crate::module_parameters::m5_mesh_storage_chunks.value(); + if chunks == 0 { + return Ok(None); + } + if chunks > 0xffff { + return Err(EINVAL); + } + let bytes = (chunks as usize).checked_mul(MESH_STORAGE_CHUNK).ok_or(EOVERFLOW)?; + Ok(Some((chunks, bytes))) +} + +/// Bytes of a pair's parameter-buffer scene scratch for `geometry`. +pub(crate) fn scratch_bytes(geometry: BlockGeometry) -> Result { + use crate::g17::fw::m5::pool; + pool::parameter_scratch_stride(geometry.capacity, 0) + .map_err(|_| EINVAL)? + .checked_mul(pool::SCENE_TABLE_ENTRIES) + .ok_or(EOVERFLOW) +} + +/// Bytes of the page list of a pair's block manager for `geometry`. +pub(crate) fn page_list_bytes(geometry: BlockGeometry) -> Result { + Ok(super::layout::Layout::m5(geometry)?.page_bytes) +} + +/// Bytes of a pair's metrics entry for `geometry`. +fn metrics_bytes(geometry: BlockGeometry) -> Result { + super::MetricsIds::entry_pitch(super::layout::Layout::m5(geometry)?.metric_stride) +} + +/// An object a render pair maps in its client's M5 compact window. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum PairObject { + /// The target records: one record stride for each command slot. + Records = 0, + /// The TPC object. + Tpc, + /// One parameter block, initial or grown, mapped at the M5 block stride. + ParameterBlock, + /// The context state of one command slot. + SlotState, + /// The parameter buffer's scene scratch. + Scratch, + /// The parameter buffer's discard. + Discard, + /// The block manager's page list. + PageList, + /// The pair's metrics entry. + Metrics, + /// The task-stage mesh storage, mapped on the pair's first task-stage kick and kept for the + /// pair's lifetime. + MeshStorage, +} + +impl PairObject { + /// Every object, in declaration order. + pub(crate) const ALL: [Self; 9] = [ + Self::Records, + Self::Tpc, + Self::ParameterBlock, + Self::SlotState, + Self::Scratch, + Self::Discard, + Self::PageList, + Self::Metrics, + Self::MeshStorage, + ]; + + /// The alignment it is placed at. + pub(crate) const fn align(self) -> u64 { + match self { + Self::MeshStorage => MESH_STORAGE_CHUNK as u64, + Self::Metrics => mmu::UAT_PGSZ as u64, + Self::ParameterBlock => BlockGeometry::PAGE as u64, + Self::Records + | Self::Tpc + | Self::SlotState + | Self::Scratch + | Self::Discard + | Self::PageList => cfg::TVB_PAGE, + } + } + + /// The unmapped guard that follows it. + pub(crate) const fn guard(self) -> usize { + match self { + Self::Metrics => 0, + Self::ParameterBlock => BlockGeometry::M5_BLOCK_STRIDE - BlockGeometry::M5_BLOCK_BYTES, + Self::Records + | Self::Tpc + | Self::SlotState + | Self::Scratch + | Self::Discard + | Self::PageList + | Self::MeshStorage => mmu::UAT_PGSZ, + } + } + + /// The bytes one mapping of an object of `bytes` takes in one hole: its pages and its guard. + fn mapped_bytes(self, bytes: usize) -> Result { + bytes + .checked_next_multiple_of(mmu::UAT_PGSZ) + .and_then(|n| n.checked_add(self.guard())) + .ok_or(EOVERFLOW) + } + + /// The window bytes an object of `bytes` can take: its pages and its guard, rounded up to + /// its alignment and at least to the 32 KiB most of these objects are placed at, plus, for + /// an object aligned beyond 32 KiB, the hole that alignment can leave before it. + pub(crate) fn window_bytes(self, bytes: usize) -> Result { + let base = cfg::TVB_PAGE as usize; + let align = (self.align() as usize).max(base); + self.mapped_bytes(bytes)? + .checked_next_multiple_of(align) + .and_then(|n| n.checked_add(align - base)) + .ok_or(EOVERFLOW) + } + + /// Maps `source` of `object` into `vm`'s window as this object. + pub(crate) fn map( + self, + object: &KernelObject, + vm: &mmu::Vm, + source: Range, + prot: mmu::Prot, + ) -> Result { + let mapping = object.map_range(vm, source, WINDOW, self.align(), prot, self.guard())?; + if mapping.iova() % self.align() != 0 { + return Err(EINVAL); + } + Ok(mapping) + } + + /// [`Self::map`] at `at`, where the firmware expects this object. + pub(crate) fn map_at( + self, + object: &KernelObject, + vm: &mmu::Vm, + source: Range, + at: u64, + prot: mmu::Prot, + ) -> Result { + let end = at.checked_add(self.mapped_bytes(source.len())? as u64).ok_or(EOVERFLOW)?; + if at < WINDOW.start || end > WINDOW.end { + return Err(EINVAL); + } + object.map_range(vm, source, at..end, self.align(), prot, self.guard()) + } + + /// The [`Placement`] of a [`KernelObject::new`] of this object in the window, whose guard is + /// one page. + pub(crate) fn placement(self) -> Result { + if self.guard() != mmu::UAT_PGSZ { + return Err(EINVAL); + } + Ok(Placement::In(WINDOW, self.align())) + } + + /// Refuses with ENOSPC, as the mapping would and before any backing is allocated, `count` + /// of this object of `bytes` each that `vm`'s window has no room for: a hole for one, and + /// room for all of them. The window is shared, so room seen here is no placement promise: + /// the mapping can still fail, but only after allocating backing that could fit. + pub(crate) fn check_room(self, vm: &mmu::Vm, bytes: usize, count: usize) -> Result { + let (used, largest) = vm.capacity(WINDOW)?; + let one = self.mapped_bytes(bytes)?; + let all = one.checked_mul(count).ok_or(EOVERFLOW)?; + if one as u64 > largest || all as u64 > WINDOW_BYTES.saturating_sub(used) { + return Err(ENOSPC); + } + Ok(()) + } +} + +// `PairObject::ALL` holds every object once, in order. +const _: () = { + let mut index = 0; + while index < PairObject::ALL.len() { + assert!(PairObject::ALL[index] as usize == index); + index += 1; + } + assert!(PairObject::ALL.len() == PairObject::MeshStorage as usize + 1); +}; + +/// The sizes of the objects a render pair built for one layout maps in the window. +pub(crate) struct PairSizes { + /// The target records object: one record stride for each command slot. + pub(crate) records: usize, + /// The TPC object. + pub(crate) tpc: usize, + /// The initial parameter blocks, of `geometry`'s block size. + pub(crate) blocks: usize, + /// The parameter-buffer geometry, which sizes the blocks, scratch, page list and metrics. + pub(crate) geometry: BlockGeometry, + /// One command slot's context state. + pub(crate) state: usize, + /// The task-stage mesh storage the pair may map ([`mesh_storage`]). + pub(crate) mesh_storage: Option, +} + +impl PairSizes { + /// How many of `object` the pair maps, and the bytes of each. + fn of(&self, object: PairObject) -> Result<(usize, usize)> { + Ok(match object { + PairObject::Records => (1, self.records), + PairObject::Tpc => (1, self.tpc), + PairObject::ParameterBlock => (self.blocks, self.geometry.block_bytes), + PairObject::SlotState => (DEPTH, self.state), + PairObject::Scratch => (1, scratch_bytes(self.geometry)?), + PairObject::Discard => (1, crate::g17::fw::m5::pool::DISCARD_BYTES), + PairObject::PageList => (1, page_list_bytes(self.geometry)?), + PairObject::Metrics => (1, metrics_bytes(self.geometry)?), + PairObject::MeshStorage => match self.mesh_storage { + Some(bytes) => (1, bytes), + None => (0, 0), + }, + }) + } + + /// The window bytes of `object` in the pair. + pub(crate) fn object_bytes(&self, object: PairObject) -> Result { + let (count, bytes) = self.of(object)?; + object.window_bytes(bytes)?.checked_mul(count).ok_or(EOVERFLOW) + } + + /// The window bytes of every object of the pair. + pub(crate) fn window_bytes(&self) -> Result { + PairObject::ALL.into_iter().try_fold(0usize, |sum, object| { + sum.checked_add(self.object_bytes(object)?).ok_or(EOVERFLOW) + }) + } +} diff --git a/drivers/gpu/drm/asahi/g17/buffer/geometry.rs b/drivers/gpu/drm/asahi/g17/buffer/geometry.rs index c871f470c1a15..71c5e18dc48f1 100644 --- a/drivers/gpu/drm/asahi/g17/buffer/geometry.rs +++ b/drivers/gpu/drm/asahi/g17/buffer/geometry.rs @@ -20,6 +20,9 @@ impl BlockGeometry { pub(crate) const PAGE: usize = 0x8000; /// M5 parameter resources use 32-bit offsets from this compact base. pub(crate) const M5_COMPACT: core::ops::Range = 0x10_0000_0000..0x11_0000_0000; + /// An M5 parameter block, and the stride it is mapped at, its guard included. + pub(crate) const M5_BLOCK_BYTES: usize = 0x80000; + pub(crate) const M5_BLOCK_STRIDE: usize = 0x88000; pub(crate) const NEO: Self = Self { base: cfg::USER_BASE, end: cfg::USER_END, @@ -40,9 +43,9 @@ impl BlockGeometry { Ok(Self { base: Self::M5_COMPACT.start, end: Self::M5_COMPACT.end, - block_bytes: 0x80000, - backing_stride: 0x80000, - stride: 0x88000, + block_bytes: Self::M5_BLOCK_BYTES, + backing_stride: Self::M5_BLOCK_BYTES, + stride: Self::M5_BLOCK_STRIDE, capacity, }) } diff --git a/drivers/gpu/drm/asahi/g17/buffer/target.rs b/drivers/gpu/drm/asahi/g17/buffer/target.rs index c17e6c3643f2e..c037c9f7914d7 100644 --- a/drivers/gpu/drm/asahi/g17/buffer/target.rs +++ b/drivers/gpu/drm/asahi/g17/buffer/target.rs @@ -4,6 +4,7 @@ //! Larger targets replace only the objects that need more capacity. Every old //! backing keeps the exact commands that still reference it until retirement. +use super::compact::PairObject; use super::compact_alias; use crate::g17::{ fw::render::{RegisterPrograms, RenderPass}, @@ -237,14 +238,22 @@ struct Object { backing: KernelObject, } impl Object { - fn new(dev: &AsahiDrmDevice, vm: &mmu::Vm, size: usize, m5: bool) -> Result { - let backing = KernelObject::backing(dev, size, CpuMap::WriteCombined)?; - let prot = mmu::PROT_GPU_FW_SHARED_RW; - let mapping = if m5 { - backing.map_range(vm, 0..size, super::BlockGeometry::M5_COMPACT, - cfg::TVB_PAGE, prot, mmu::UAT_PGSZ)? + /// An object of `size` bytes, on M5 mapped in the client's compact window as `m5`. + fn new(dev: &AsahiDrmDevice, vm: &mmu::Vm, size: usize, m5: Option) + -> Result { + if let Some(object) = m5 { + object.check_room(vm, size, 1)?; + } + // An M5 target is sized by the client's pass: charge it to the client. + let backing = if m5.is_some() { + KernelObject::client_backing(dev, size, vm.memory_client())? } else { - compact_alias(&backing, vm, 0..size, cfg::TVB_PAGE, prot, mmu::UAT_PGSZ)? + KernelObject::backing(dev, size, CpuMap::WriteCombined)? + }; + let prot = mmu::PROT_GPU_FW_SHARED_RW; + let mapping = match m5 { + Some(object) => object.map(&backing, vm, 0..size, prot)?, + None => compact_alias(&backing, vm, 0..size, cfg::TVB_PAGE, prot, mmu::UAT_PGSZ)?, }; Ok(Self { address: mapping.iova(), @@ -281,8 +290,8 @@ impl Target { let stride = layout.record_stride()?; layout.check_capacity(stride)?; let m5 = layout.m5.is_some(); - let records = Object::new(dev, vm, stride * DEPTH, m5)?; - let tpc = Object::new(dev, vm, tpc, m5)?; + let records = Object::new(dev, vm, stride * DEPTH, m5.then_some(PairObject::Records))?; + let tpc = Object::new(dev, vm, tpc, m5.then_some(PairObject::Tpc))?; KBox::new( Self { records, @@ -387,7 +396,8 @@ impl Target { layout.check_capacity(stride)?; let mut grew = false; if tpc > self.tpc.backing.size() { - Self::replace(&mut self.retired, &mut self.tpc, dev, vm, tpc, owners, self.m5)?; + Self::replace(&mut self.retired, &mut self.tpc, dev, vm, tpc, owners, + self.m5.then_some(PairObject::Tpc))?; grew = true; } if stride > self.stride { @@ -398,7 +408,7 @@ impl Target { vm, stride * DEPTH, owners, - self.m5, + self.m5.then_some(PairObject::Records), )?; self.stride = stride; self.slots = [None; DEPTH]; @@ -413,7 +423,7 @@ impl Target { vm: &mmu::Vm, size: usize, owners: &[Option; DEPTH], - m5: bool, + m5: Option, ) -> Result { let retain = owners.iter().any(Option::is_some); if retain { diff --git a/drivers/gpu/drm/asahi/g17/command.rs b/drivers/gpu/drm/asahi/g17/command.rs index 86e9c5464a680..deeb5bd50833a 100644 --- a/drivers/gpu/drm/asahi/g17/command.rs +++ b/drivers/gpu/drm/asahi/g17/command.rs @@ -486,6 +486,9 @@ pub(crate) enum Validated { ray_query: [RayQueryStage; 2], resources: Option>, plan: Option, + /// Bytes of the client's M5 compact window that each render pair built for this render + /// reserves, from the layout SUBMIT derives with the plan (`None` without an M5 plan). + pair_window: Option, attachments: [Attachments; 2], timestamps: [uapi::drm_asahi_timestamps; 2], }, @@ -531,6 +534,14 @@ impl Validated { Self::Render { long_job, .. } | Self::Compute { long_job, .. } => *long_job, } } + /// The compact-window bytes of each render pair kept by SUBMIT (`Render::pair_window`); + /// `None` for a compute command. + pub(crate) fn pair_window(&self) -> Option { + match self { + Self::Render { pair_window, .. } => *pair_window, + Self::Compute { .. } => None, + } + } pub(crate) fn allow_long_job(&mut self) { match self { Self::Render { long_job, .. } | Self::Compute { long_job, .. } => *long_job = true, @@ -759,6 +770,7 @@ impl Payload { ray_query: *ray_query, resources: resources.clone(), plan: None, + pair_window: None, attachments: *attachments, timestamps: [cmd.ts_vtx, cmd.ts_frag], }) diff --git a/drivers/gpu/drm/asahi/g17/fw/m5/pool.rs b/drivers/gpu/drm/asahi/g17/fw/m5/pool.rs index 7a457322fb64e..6c1283f988b1c 100644 --- a/drivers/gpu/drm/asahi/g17/fw/m5/pool.rs +++ b/drivers/gpu/drm/asahi/g17/fw/m5/pool.rs @@ -54,6 +54,8 @@ pub(crate) const SAVED_FIELDS: [usize; 8] = [0x28, 0x20, 0x24, 0x2c, 0x3c, 0x48, const GPU_PAGE: usize = 0x4000; const PRIVATE_TOP: u64 = 1 << 42; pub(crate) const SCENE_TABLE_ENTRIES: usize = 0x50; +/// Bytes of a render pair's parameter-buffer discard object. +pub(crate) const DISCARD_BYTES: usize = 0x8000; pub(crate) const SCENE_STRIDE: usize = 0x80; pub(crate) const SCENE_TRAILER_SIZE: usize = 0x40; diff --git a/drivers/gpu/drm/asahi/g17/object.rs b/drivers/gpu/drm/asahi/g17/object.rs index de422808e8e66..6899b2743f1cf 100644 --- a/drivers/gpu/drm/asahi/g17/object.rs +++ b/drivers/gpu/drm/asahi/g17/object.rs @@ -58,6 +58,8 @@ pub(crate) struct KernelObject { obj: gem::ObjectRef, ptr: NonNull, size: usize, + /// The client charge of backing from [`Self::client_backing`], released with the object. + charge: Option, } // SAFETY: The object only refers to kernel memory; concurrent access goes through `&self` @@ -108,6 +110,29 @@ impl KernelObject { }, size) } + /// Write-combined [`Self::backing`] that a client's commands size, charged to that client + /// (`client`) as a user buffer of the same size would be: admitted against its and the + /// device's memory limits before it is allocated, failing with ENOMEM over either, and then + /// counted as its held memory instead of kernel memory, until the object is dropped. + /// Without a client (a kernel VM's object) it is kernel memory, as [`Self::backing`]. + pub(crate) fn client_backing( + dev: &AsahiDrmDevice, + size: usize, + client: Option<&kernel::sync::Arc>, + ) -> Result { + let Some(client) = client else { + return Self::backing(dev, size, CpuMap::WriteCombined); + }; + let bytes = gem::checked_object_size(size)? as u64; + let commit = crate::memacct::LEDGER.admit(client, bytes)?; + let mut object = + Self::with_object(gem::new_kernel_object_wc_user_charged(dev, size)?, size)?; + let charge = crate::memacct::Charge::user(commit, None); + charge.set_held(true); + object.charge = Some(charge); + Ok(object) + } + fn with_object(mut obj: gem::ObjectRef, size: usize) -> Result { let vmap = obj.vmap()?; let ptr = NonNull::new(vmap.addr.cast::()).ok_or(ENOMEM)?; @@ -121,6 +146,7 @@ impl KernelObject { obj, ptr, size, + charge: None, }) } diff --git a/drivers/gpu/drm/asahi/g17/pairs.rs b/drivers/gpu/drm/asahi/g17/pairs.rs index 405718f78bf4a..756a842faa1fe 100644 --- a/drivers/gpu/drm/asahi/g17/pairs.rs +++ b/drivers/gpu/drm/asahi/g17/pairs.rs @@ -58,3 +58,42 @@ pub(crate) fn sibling_backlog() -> u8 { pub(crate) fn set_sibling_backlog(renders: u8) { BACKLOG.store(renders, Relaxed); } + + +/// The pairs a queue of `queue` pairs uses for a render each of whose pairs reserves +/// `window_bytes` of the client's M5 compact window of `window` bytes (`None`: no M5 footprint). +/// Each pair maps its own copy of a layout's objects in that one window, so a second pair is +/// built and used only for a layout the window holds twice. Any other layout runs on one of the +/// queue's pairs, always the same one, as on a part with one pair per queue +/// (`Pool::acquire_render`). SUBMIT has already refused a layout that one pair cannot hold. +pub(crate) fn for_window(queue: u8, window_bytes: Option, window: u64) -> u8 { + match window_bytes { + Some(bytes) if queue > 1 && bytes.saturating_mul(u64::from(queue)) > window => 1, + _ => queue, + } +} + +#[kernel::macros::kunit_tests(asahi_g17_pair_count)] +mod tests { + use super::*; + + const WINDOW: u64 = 1 << 32; + + #[test] + fn a_layout_the_window_holds_twice_keeps_both_pairs() { + assert_eq!(for_window(2, Some(WINDOW / 2), WINDOW), 2); + assert_eq!(for_window(2, Some(64 << 20), WINDOW), 2); + } + + #[test] + fn a_larger_layout_runs_on_one_pair() { + assert_eq!(for_window(2, Some(WINDOW / 2 + 1), WINDOW), 1); + assert_eq!(for_window(2, Some(WINDOW), WINDOW), 1); + } + + #[test] + fn a_one_pair_queue_and_a_render_without_footprint_are_unchanged() { + assert_eq!(for_window(1, Some(WINDOW), WINDOW), 1); + assert_eq!(for_window(2, None, WINDOW), 2); + } +} diff --git a/drivers/gpu/drm/asahi/g17/queue/admission.rs b/drivers/gpu/drm/asahi/g17/queue/admission.rs index 07198cb2b1039..44f937de18f6f 100644 --- a/drivers/gpu/drm/asahi/g17/queue/admission.rs +++ b/drivers/gpu/drm/asahi/g17/queue/admission.rs @@ -65,6 +65,7 @@ fn wait_slice_ms(deadline_ns: u64, now_ns: u64) -> Result { struct State { active: u64, refs: [u8; cfg::RENDER_SLOTS], + /// The owner of each slot. Written only by [`Self::set_owner`], which keeps `wide` with it. owners: [u64; cfg::RENDER_SLOTS], epochs: [u64; cfg::RENDER_SLOTS], quarantined: u64, @@ -90,6 +91,11 @@ struct State { /// The physical queue table still has room for a pair built in an unowned slot. The /// runtime updates this whenever the table changes. build_room: bool, + /// Slots that take their owner's renders that run on one of a two-pair queue's pairs + /// ([`crate::g17::pairs::for_window`]), so the objects of a layout too large for two pairs + /// exist in that pair only: at most one per owner ([`Self::mark_wide`]). A mark belongs to its + /// owner's tenure of the slot: [`Self::set_owner`] drops it whenever the slot changes hands. + wide: u64, /// Total dedicated render pairs the QID table can hold (installed plus buildable). /// Updated alongside `build_room` so sibling admission preserves first-pair capacity. render_capacity: usize, @@ -120,6 +126,7 @@ impl State { killed_at: [0; cfg::RENDER_SLOTS], held: 0, build_room: true, + wide: 0, render_capacity: cfg::RENDER_SLOTS - 1, published: 0, released: 0, @@ -212,6 +219,14 @@ impl State { self.epoch = self.epoch.wrapping_add(1); self.epochs[slot] = self.epoch; } + /// Gives `slot` to `owner` (0: to nobody): the one writer of `owners`. A new owner starts + /// without the slot's one-pair mark. + fn set_owner(&mut self, slot: usize, owner: u64) { + if self.owners[slot] != owner { + self.wide &= !(1u64 << slot); + } + self.owners[slot] = owner; + } fn take_idle(&mut self, slot: usize, owner: u64) -> u8 { if self.owners[slot] != owner || self.released & (1u64 << slot) != 0 { if self.owners[slot] != owner { @@ -228,7 +243,7 @@ impl State { self.refs[slot] += 1; self.active |= 1u64 << slot; self.released &= !(1u64 << slot); - self.owners[slot] = owner; + self.set_owner(slot, owner); self.advance(slot); slot as u8 } @@ -461,7 +476,7 @@ impl State { if let Some(slot) = sibling { self.released &= !(1u64 << slot); self.published &= !(1u64 << slot); - self.owners[slot] = owner; + self.set_owner(slot, owner); // A speculative sibling has no GPU-use recency yet. self.epochs[slot] = 0; } @@ -513,7 +528,7 @@ impl State { } let slot = usize::from(slot); let bit = 1u64 << slot; - self.owners[slot] = owner.unwrap_or(0); + self.set_owner(slot, owner.unwrap_or(0)); self.released &= !bit; self.published &= !bit; self.epochs[slot] = 0; @@ -543,26 +558,33 @@ impl State { if keep_installed { self.released |= bit; } else { - self.owners[index] = 0; + self.set_owner(index, 0); self.released &= !bit; } + self.wide &= !bit; self.published &= !bit; self.epochs[index] = 0; true } /// Takes back one idle live sibling in `eligible`, preferring unpublished - /// siblings before published ones. Slots in `installed` or `published` keep - /// `released` set so their installed QIDs are reused first. + /// siblings before published ones and non-wide siblings before wide-marked + /// ones. Slots in `installed` or `published` keep `released` set so their + /// installed QIDs are reused first. fn reclaim_sibling(&mut self, eligible: u64, installed: u64) -> Option { for allow_published in [false, true] { - for slot in 1..cfg::RENDER_SLOTS { - let bit = 1u64 << slot; - if eligible & bit == 0 || (!allow_published && self.published & bit != 0) { - continue; - } - let keep_installed = (installed | self.published) & bit != 0; - if self.release_unused_sibling(slot as u8, None, keep_installed) { - return Some(slot as u8); + for allow_wide in [false, true] { + for slot in 1..cfg::RENDER_SLOTS { + let bit = 1u64 << slot; + if eligible & bit == 0 + || (!allow_published && self.published & bit != 0) + || (!allow_wide && self.wide & bit != 0) + { + continue; + } + let keep_installed = (installed | self.published) & bit != 0; + if self.release_unused_sibling(slot as u8, None, keep_installed) { + return Some(slot as u8); + } } } } @@ -595,7 +617,7 @@ impl State { && self.refs[slot] == 1 && (self.quarantined | self.kill_hold | self.held) & bit == 0 { - self.owners[slot] = 0; + self.set_owner(slot, 0); self.released &= !bit; self.published &= !bit; self.epochs[slot] = 0; @@ -652,6 +674,56 @@ impl State { } } + /// The one pair a one-pair render (`pairs` 1) of an owner holding two pairs goes to: the pair + /// its previous one-pair render took, while the owner holds it (`wide`). Its layout's objects + /// then exist in that pair only. + fn wide(&self, owner: u64, pairs: usize) -> Option { + if pairs != 1 + || (1..cfg::RENDER_SLOTS) + .filter(|slot| self.owns_live(owner, *slot)) + .count() + < 2 + { + return None; + } + (1..cfg::RENDER_SLOTS) + .find(|slot| self.wide & (1u64 << slot) != 0 && self.owns_live(owner, *slot)) + } + + /// Marks `slot` as taking its owner's one-pair renders, instead of any other slot. + fn mark_wide(&mut self, slot: usize) { + for other in 1..cfg::RENDER_SLOTS { + if self.owners[other] == self.owners[slot] { + self.wide &= !(1u64 << other); + } + } + self.wide |= 1u64 << slot; + } + + /// [`Self::can_pick`] for a render that may use `pairs` of the owner's pairs. + #[cfg(CONFIG_KUNIT = "y")] + fn can_pick_render(&self, owner: u64, pairs: usize, plan: Plan) -> bool { + self.can_pick_render_for(owner, pairs, 0, plan) + } + + /// [`Self::can_pick_for`] for a render that may use `pairs` of the owner's pairs. + fn can_pick_render_for( + &self, + owner: u64, + pairs: usize, + open_queues: usize, + plan: Plan, + ) -> bool { + match (self.wide(owner, pairs), plan) { + (None, plan) => self.can_pick_for(owner, open_queues, plan), + (Some(_), Plan::Wait) => false, + (Some(wide), Plan::Pair(slot)) if usize::from(slot) != wide => false, + (Some(wide), _) => { + self.usable(owner, wide) && self.can_lease_slot(owner, wide, open_queues) + } + } + } + #[cfg(CONFIG_KUNIT = "y")] fn pick(&mut self, owner: u64, pairs: usize, plan: Plan) -> Option { self.pick_for(owner, pairs, 0, plan) @@ -664,7 +736,19 @@ impl State { open_queues: usize, plan: Plan, ) -> Option { - match plan { + // A one-pair render of an owner holding two pairs goes only to the pair its previous + // one-pair render took, while the owner holds it (see `wide`). + if let Some(wide) = self.wide(owner, pairs) { + return match plan { + Plan::Wait => None, + Plan::Pair(slot) if usize::from(slot) != wide => None, + // The publication barrier orders a Join's overlap from this pair. + Plan::Any | Plan::Pair(_) | Plan::Join(_) => { + self.join_for(owner, wide, open_queues) + } + }; + } + let slot = match plan { Plan::Any => self.acquire_for(owner, pairs, open_queues), Plan::Wait => None, Plan::Pair(slot) => self.join_for(owner, usize::from(slot), open_queues), @@ -682,7 +766,11 @@ impl State { .min_by_key(|other| (self.refs[*other], u64::MAX - self.epochs[*other]))?; self.join_for(owner, other, open_queues) }), + }?; + if pairs == 1 { + self.mark_wide(usize::from(slot)); } + Some(slot) } fn usable(&self, owner: u64, slot: usize) -> bool { self.owns_live(owner, slot) @@ -1004,7 +1092,8 @@ impl Pool { self.state.lock().owner_quarantine(owner) == Some(true) } - /// For an owner that may hold `pairs` render pairs. + /// For an owner that may hold `pairs` render pairs: its queue's count, or 1 for a render + /// that runs on one of a two-pair queue's pairs ([`crate::g17::pairs::for_window`]). pub(crate) fn acquire_render( self: &Arc, owner: u64, @@ -1125,7 +1214,7 @@ impl Pool { } /// Whether `acquire_render` would admit this request now, without /// admitting it: the scheduler's prepare step waits for this. - pub(crate) fn admits_render(&self, owner: u64, request: Option>) -> bool { + pub(crate) fn admits_render(&self, owner: u64, pairs: usize, request: Option>) -> bool { let state = self.state.lock(); if owner == 0 || state.refusal(owner).is_err() { return false; @@ -1135,7 +1224,7 @@ impl Pool { } let plan = state.plan(owner, request, None); let open_queues = self.queues.load(Ordering::Acquire) as usize; - state.can_pick_for(owner, open_queues, plan) + state.can_pick_render_for(owner, pairs, open_queues, plan) } pub(crate) fn warmable_sibling( self: &Arc, @@ -1198,6 +1287,10 @@ impl Pool { pub(crate) fn owns_live_slot(&self, owner: u64) -> bool { self.state.lock().has_live_owner(owner) } + pub(crate) fn is_wide(&self, slot: u8) -> bool { + let index = usize::from(slot); + index < cfg::RENDER_SLOTS && self.state.lock().wide & (1u64 << index) != 0 + } pub(crate) fn note_published(&self, slot: u8) { self.state.lock().mark_published(slot); } @@ -1207,6 +1300,7 @@ impl Pool { if state.owners[slot] == owner { let bit = 1u64 << slot; state.released |= bit; + state.wide &= !bit; state.published &= !bit; } } @@ -1220,7 +1314,7 @@ impl Pool { let released = state.released & !state.active; for slot in 1..cfg::RENDER_SLOTS { if released & (1u64 << slot) != 0 { - state.owners[slot] = 0; + state.set_owner(slot, 0); state.epochs[slot] = 0; } } @@ -1868,16 +1962,16 @@ mod owner_pair_tests { state.owners[1] = 1; state.owners[2] = 1; for _ in 0..cfg::RENDER_DEPTH { - assert_eq!(state.pick(1, 1, Plan::Pair(1)), Some(1)); + assert_eq!(state.pick(1, 2, Plan::Pair(1)), Some(1)); } assert!(!state.can_pick(1, Plan::Pair(1))); - assert_eq!(state.pick(1, 1, Plan::Pair(1)), None); + assert_eq!(state.pick(1, 2, Plan::Pair(1)), None); assert!(state.can_pick(1, Plan::Join(1))); - assert_eq!(state.pick(1, 1, Plan::Join(1)), Some(2)); + assert_eq!(state.pick(1, 2, Plan::Join(1)), Some(2)); // With one pair a preference is the pair. state.owners[2] = 0; assert!(!state.can_pick(1, Plan::Join(1))); - assert_eq!(state.pick(1, 1, Plan::Join(1)), None); + assert_eq!(state.pick(1, 2, Plan::Join(1)), None); } #[test] @@ -1996,6 +2090,176 @@ mod two_pair_tests { assert!(state.reassign_unused_spare(6, Some(3), Some(2))); } + #[test] + fn a_one_pair_render_of_a_two_pair_owner_stays_on_one_pair() { + crate::g17::pairs::set_sibling_backlog(1); + let mut state = State::new(); + // Small renders take the first pair and, with a backlog there, the sibling. + let first = state.pick(1, 2, Plan::Any).unwrap(); + assert_eq!(state.pick(1, 2, Plan::Any), Some(first)); + let sibling = state.pick(1, 2, Plan::Any).unwrap(); + assert_ne!(sibling, first); + // A render whose layout the window holds once takes one of them, and every later such + // render goes there too, even when the other pair is idle or less loaded. + let wide = state.pick(1, 1, Plan::Any).unwrap(); + let other = if wide == first { sibling } else { first }; + state.release(other); + for _ in state.refs[usize::from(wide)]..cfg::RENDER_DEPTH { + assert_eq!(state.pick(1, 1, Plan::Any), Some(wide)); + } + // At full depth it waits for that pair instead of taking the other. + assert!(state.can_pick(1, Plan::Any)); + assert!(!state.can_pick_render(1, 1, Plan::Any)); + assert!(state.can_pick_render(1, 2, Plan::Any)); + assert_eq!(state.pick(1, 1, Plan::Any), None); + assert_eq!(state.pick(1, 1, Plan::Join(other)), None); + state.release(wide); + assert_eq!(state.pick(1, 1, Plan::Join(other)), Some(wide)); + assert_eq!(state.pick(1, 1, Plan::Pair(other)), None); + state.release(wide); + assert_eq!(state.pick(1, 1, Plan::Pair(wide)), Some(wide)); + // A small render may still use either pair. + assert_eq!(state.pick(1, 2, Plan::Pair(other)), Some(other)); + } + + #[test] + fn a_two_pair_owner_whose_first_render_needs_one_pair_claims_no_sibling() { + let mut state = State::new(); + // Two large renders in flight on a new queue share its one pair. + let first = state.pick(1, 1, Plan::Any).unwrap(); + assert_eq!(state.pick(1, 1, Plan::Any), Some(first)); + assert_eq!(state.owners.iter().filter(|id| **id == 1).count(), 1); + } + + #[test] + fn a_slot_lost_and_claimed_back_drops_its_one_pair_mark() { + let mut state = State::new(); + // A one-pair render of owner 1 takes slot `a`; its build fails before publication and + // the slot goes back unowned. + let a = state.pick(1, 1, Plan::Any).unwrap(); + assert!(state.cancel_empty_slot(a, 1)); + state.release(a); + // Owner 2 takes `a` meanwhile, so owner 1's next one-pair render, which builds its + // large layout's objects there, takes a slot `b` above it. + state.build_room = false; + assert_eq!(state.pick(2, 2, Plan::Any), Some(a)); + state.build_room = true; + let b = state.pick(1, 1, Plan::Any).unwrap(); + assert!(b > a); + state.release(b); + // Owner 2 closes, and a small render of owner 1 claims `a` back as its sibling. + state.release(a); + state.released |= 1u64 << a; + assert_eq!(state.pick(1, 2, Plan::Any), Some(b)); + assert_eq!(state.owners[usize::from(a)], 1); + state.release(b); + // The large layout's objects are in `b` alone, and its one-pair renders stay there. + assert_eq!(state.pick(1, 1, Plan::Any), Some(b)); + assert!(state.can_pick_render(1, 1, Plan::Pair(b))); + assert!(!state.can_pick_render(1, 1, Plan::Pair(a))); + assert_eq!(state.pick(1, 1, Plan::Join(a)), Some(b)); + } + + #[test] + fn a_slot_given_to_another_owner_drops_its_one_pair_mark() { + let mut state = State::new(); + // Owner 1 holds two pairs, and its one-pair renders went to the lower one. + state.owners[1] = 1; + state.owners[2] = 1; + assert_eq!(state.pick(1, 1, Plan::Pair(1)), Some(1)); + state.release(1); + // That pair is given to owner 2 as its spare, and owner 1's next one-pair render, with + // one pair left, builds its layout in the other. + assert!(state.reassign_unused_spare(1, Some(1), Some(2))); + assert_eq!(state.pick(1, 1, Plan::Any), Some(2)); + state.release(2); + // Owner 2 closes, owner 1 claims the pair back, and its one-pair renders stay on the + // pair that holds the layout. + state.released |= 1u64 << 1; + assert_eq!(state.pick(1, 2, Plan::Any), Some(2)); + assert_eq!(state.owners[1], 1); + state.release(2); + assert_eq!(state.pick(1, 1, Plan::Any), Some(2)); + assert!(!state.can_pick_render(1, 1, Plan::Pair(1))); + } + + #[test] + fn reclaim_prefers_non_wide_sibling_and_clears_wide_on_detach() { + let mut state = State::new(); + // Owner 1 holds two published pairs; slot 1 holds its one-pair wide mark. + state.set_owner(1, 1); + state.set_owner(2, 1); + state.published = (1u64 << 1) | (1u64 << 2); + assert_eq!(state.pick(1, 1, Plan::Pair(1)), Some(1)); + state.release(1); + assert_ne!(state.wide & (1u64 << 1), 0); + // Reclaiming a sibling takes the non-wide slot (slot 2) instead of slot 1. + assert_eq!(state.reclaim_sibling(State::MASK, State::MASK), Some(2)); + assert_ne!(state.released & (1u64 << 2), 0); + assert_ne!(state.wide & (1u64 << 1), 0); + // Reattach slot 2 and explicitly detach the wide slot with keep_installed=true: + // the wide mark clears so reclaiming/re-acquiring slot 1 does not leave a stale mark. + state.released &= !(1u64 << 2); + assert!(state.release_unused_sibling(1, Some(1), true)); + assert_eq!(state.wide & (1u64 << 1), 0); + assert_ne!(state.released & (1u64 << 1), 0); + assert_eq!(state.owners[1], 1); + // With only slot 2 live, the next one-pair render moves to slot 2. + assert_eq!(state.pick(1, 1, Plan::Any), Some(2)); + state.release(2); + // Detach with keep_installed=false also clears the wide mark and owner. + state.set_owner(1, 1); + state.released &= !(1u64 << 1); + assert!(state.release_unused_sibling(2, Some(1), false)); + assert_eq!(state.owners[2], 0); + assert_eq!(state.wide & (1u64 << 2), 0); + } + + #[test] + fn wide_render_respects_open_queue_capacity_gate_and_release_owner() { + let pool = Pool::new(MAX_EXECUTION_CONTEXTS).unwrap(); + pool.note_build_room(true, 4); + let q1 = pool.try_reserve_queue(4).unwrap(); + let q2 = pool.try_reserve_queue(4).unwrap(); + let q3 = pool.try_reserve_queue(4).unwrap(); + // Owner 1 gets two pairs; mark `wide_slot` for one-pair renders, then leave it idle + // while the other pair stays busy and capacity shrinks to 3 (= open queues). + let a = pool.acquire_render(1, 2, None, u64::MAX, || Ok(())).unwrap(); + let b = pool.acquire_render(1, 1, None, u64::MAX, || Ok(())).unwrap(); + let wide_slot = b.slot(); + assert!(pool.is_wide(wide_slot)); + drop(b); + drop(a); + let other = { + let mut state = pool.state.lock(); + let other = (1..cfg::RENDER_SLOTS) + .find(|s| *s != usize::from(wide_slot) && state.owns_live(1, *s)) + .unwrap(); + state.refs[other] = 1; + state.active |= 1u64 << other; + other as u8 + }; + pool.note_build_room(false, 3); + { + let mut state = pool.state.lock(); + // Promoting idle `wide_slot` would push pair_demand from 3 to 4 > cap 3. + assert!(!state.can_pick_render_for(1, 1, 3, Plan::Any)); + assert_eq!(state.pick_for(1, 1, 3, Plan::Any), None); + // With capacity 4, the marked slot is picked again. + state.render_capacity = 4; + assert!(state.can_pick_render_for(1, 1, 3, Plan::Any)); + assert_eq!(state.pick_for(1, 1, 3, Plan::Any), Some(wide_slot)); + state.release(wide_slot); + state.release(other); + } + // release_owner clears the wide mark. + pool.release_owner(1); + assert!(!pool.is_wide(wide_slot)); + drop(q3); + drop(q2); + drop(q1); + } + #[test] fn a_one_pair_owner_claims_no_sibling() { let mut state = State::new(); diff --git a/drivers/gpu/drm/asahi/g17/queue/render.rs b/drivers/gpu/drm/asahi/g17/queue/render.rs index 3d2d0ddd7fff8..58a05278448ef 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render.rs @@ -347,7 +347,8 @@ impl Pair { if word == u32::MAX { return Err(EINVAL); } - let layout = m5_render_submission::layout(&first.command, clusters, variant.programs)?; + let layout = + m5_render_submission::layout(&first.command, clusters, variant.programs, board)?; let storage = KBox::::new_uninit(GFP_KERNEL)?; let (tiling, ta_alias) = kick::Queue::render(alloc, ids[0], context.vm(), rings)?; let (fragment, fragment_alias) = kick::Queue::render(alloc, ids[1], context.vm(), rings)?; @@ -539,7 +540,8 @@ impl Pair { let node = work.node_va()?; let word = work.word(); let layout = - m5_render_submission::layout(&packet.command, self.clusters, self.variant.programs)?; + m5_render_submission::layout(&packet.command, self.clusters, self.variant.programs, + self.board)?; let deflake_layout = self.deflake; let owners = self.memory.owners(); self.memory @@ -1831,7 +1833,8 @@ impl Pair { /// keeps its current capacity and lets firmware request growth as needed. pub(crate) fn host_growth_target(&mut self, packet: &Packet) -> Result> { let mut required = - m5_render_submission::layout(&packet.command, self.clusters, self.variant.programs)? + m5_render_submission::layout(&packet.command, self.clusters, self.variant.programs, + self.board)? .tvb_blocks; // A mesh workgroup whose output is in flight when the tiler heap runs out loses part of // it, whether the firmware then grows the heap or partial-renders, and the tile-count @@ -3288,7 +3291,8 @@ impl Pair { let buffer_id = buffer_id.ok_or(EINVAL)?; let pm_generation = pm_generation.ok_or(EINVAL)?; let layout = - m5_render_submission::layout(&first.command, self.clusters, self.variant.programs)?; + m5_render_submission::layout(&first.command, self.clusters, self.variant.programs, + self.board)?; // A context of another VM gets the rings cleared before its VM is given its view, // so it cannot read the entries earlier owners' commands left, as for a parked pair. // The pair is bindable, hence idle: the firmware consumed every entry. diff --git a/drivers/gpu/drm/asahi/g17/queue/render/generation.rs b/drivers/gpu/drm/asahi/g17/queue/render/generation.rs index fb4be12b71f6a..b2848b35b418b 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/generation.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/generation.rs @@ -4,7 +4,7 @@ //! their backing owners; a generation is reusable only after paired retirement. use crate::g17::{ - buffer::{self, BlockGeometry}, + buffer::{self, compact::PairObject}, fw::{ m5::{initdata::Board, render_registers::ContextStore}, render::{storage, RenderPass}, @@ -101,10 +101,10 @@ pub(in crate::g17) struct Generation { impl Generation { pub(in crate::g17) fn allocate_state(alloc: &Allocator<'_>, vm: &mmu::Vm, board: Option<&'static Board>) -> Result { - let (range, layout) = if alloc.uat.is_m5() { - (BlockGeometry::M5_COMPACT, Layout::m5(board.ok_or(EINVAL)?)) - } else { (vm.client_private_range(), Layout::NEO) }; - KernelObject::new(alloc.dev, vm, Placement::In(range, cfg::TVB_PAGE), layout.bytes, + let (placement, layout) = if alloc.uat.is_m5() { + (PairObject::SlotState.placement()?, Layout::m5(board.ok_or(EINVAL)?)) + } else { (Placement::In(vm.client_private_range(), cfg::TVB_PAGE), Layout::NEO) }; + KernelObject::new(alloc.dev, vm, placement, layout.bytes, mmu::PROT_GPU_FW_SHARED_RW, CpuMap::WriteCombined) } diff --git a/drivers/gpu/drm/asahi/g17/queue/render/m5_render_submission.rs b/drivers/gpu/drm/asahi/g17/queue/render/m5_render_submission.rs index 333846d3f83c6..5b2afea2a8ca7 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/m5_render_submission.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/m5_render_submission.rs @@ -3,7 +3,7 @@ use kernel::prelude::*; use crate::g17::fw::m5::{render as cmd, render_registers as regs}; -use crate::g17::{buffer::target, command::Validated, fw::render::{RenderArgs, RenderPass, RegisterPrograms}}; +use crate::g17::{buffer::{compact, target}, command::Validated, fw::render::{RenderArgs, RenderPass, RegisterPrograms}}; /// Compressed single-layer MSAA ZLS admission: D32 depth with optional plain /// stencil, and the compressed Z/S form. @@ -120,25 +120,83 @@ pub(crate) fn parameter_geometry(blocks: usize) -> Result Result { +/// The target layout of a render: G17P's for a command without an M5 plan. `board` is the M5 +/// board, which an M5 plan needs. +pub(crate) fn layout(command: &Validated, clusters: u32, programs: RegisterPrograms, + board: Option<&'static crate::g17::fw::m5::initdata::Board>) -> Result { + Ok(layout_and_window(command, clusters, programs, board)?.0) +} + +/// The target layout of a render and, for an M5 render, the bytes of the client's compact +/// window that each render pair built for it reserves. +pub(crate) fn layout_and_window(command: &Validated, clusters: u32, programs: RegisterPrograms, + board: Option<&'static crate::g17::fw::m5::initdata::Board>) + -> Result<(target::Layout, Option)> { let Validated::Render { pass, plan, .. } = command else { return Err(EINVAL); }; let layout = target::Layout::new(pass, clusters, programs)?; - if plan.is_none() { return Ok(layout); } + if plan.is_none() { return Ok((layout, None)); } validate(pass)?; + let geometry = parameter_geometry(layout.tvb_blocks)?; + let mesh_storage = compact::mesh_storage()?.map(|(_, bytes)| bytes); + // The context state a pair allocates for each command slot (`Generation::allocate_state`). + let state = super::generation::Layout::m5(board.ok_or(EINVAL)?).bytes; + let (layout, reserved) = m5_layout(layout, pass, clusters, geometry, mesh_storage, state)?; + Ok((layout, Some(reserved))) +} + +/// The M5 layout of `pass` from its G17P layout, and the compact-window bytes a pair built for +/// it reserves ([`pair_window_bytes`]) with `mesh_storage` bytes of task-stage mesh storage. +fn m5_layout(layout: target::Layout, pass: &RenderPass, clusters: u32, + geometry: crate::g17::buffer::BlockGeometry, mesh_storage: Option, state: usize) + -> Result<(target::Layout, usize)> { // One target group per cluster unless the pass asks for few primitives. // Both target storage and the segment controls use the physical cluster count. - let geometry = parameter_geometry(layout.tvb_blocks)?; // The auxiliary tables cover the complete parameter inventory, including // future growth, rather than just the initially resident physical blocks. let bytes = geometry.capacity.checked_mul(geometry.block_bytes).ok_or(EOVERFLOW)?; let groups = if pass.few_primitives { 1 } else { clusters }; - layout.with_m5_slices(pass, clusters, groups, 64, bytes) + let layout = layout.with_m5_slices(pass, clusters, groups, 64, bytes)?; + // A pair maps its objects in the client's compact window, whose 32-bit offsets make it + // 4 GiB. A layout whose pair does not fit there on its own can never be mapped: refuse it + // as memory that cannot be had, before any of it is allocated. SUBMIT derives the layout, + // so the refusal is the ioctl's. + let reserved = pair_window_bytes(&layout, geometry, state, mesh_storage)?; + if reserved as u64 > compact::WINDOW_BYTES { + return Err(ENOMEM); + } + Ok((layout, reserved)) +} + +/// The objects a render pair built for `layout` maps in the client's M5 compact window +/// ([`compact::PairObject`]): its target records (a page-rounded record for each command slot), +/// its TPC object and its initial parameter blocks, which the layout sizes, the context state +/// of each command slot (`state` bytes each), the parameter buffer's scratch, discard and page +/// list, its metrics entry, and, while the binding is enabled, the task-stage mesh storage. A +/// pair maps that storage on its first task-stage kick and keeps it for the passes that follow, +/// so every pair counts it, whether or not this pass has a task stage. +fn pair_sizes(layout: &target::Layout, geometry: crate::g17::buffer::BlockGeometry, + state: usize, mesh_storage: Option) -> Result { + let depth = crate::hw::t8140::queues::RENDER_DEPTH as usize; + Ok(compact::PairSizes { + records: layout.record_stride()?.checked_mul(depth).ok_or(EOVERFLOW)?, + tpc: layout.tpc_capacity()?, + blocks: layout.tvb_blocks, + geometry, + state, + mesh_storage, + }) +} + +/// Bytes of the client's M5 compact window that a render pair built for `layout` reserves +/// ([`pair_sizes`]). +fn pair_window_bytes(layout: &target::Layout, geometry: crate::g17::buffer::BlockGeometry, + state: usize, mesh_storage: Option) -> Result { + pair_sizes(layout, geometry, state, mesh_storage)?.window_bytes() } pub(crate) fn controls( @@ -216,3 +274,122 @@ pub(crate) fn inputs(args: &RenderArgs<'_>, usage: [u64; 2]) -> Result = Some(0x200 * compact::MESH_STORAGE_CHUNK); + /// The J775D's context state per command slot. + const STATE: usize = + super::super::generation::Layout::m5(&crate::g17::fw::m5::initdata::J775D).bytes; + + /// A single-sample pass as Borealis sends it: `utile` tiles, and few-primitives for a pass + /// of at most four primitives. + fn pass(size: u32, layers: u16, utile: u8, few: bool) -> RenderPass { + // SAFETY: RenderPass and its nested surfaces/programs contain only + // integers and bools, for which the all-zero representation is valid. + let mut pass: RenderPass = unsafe { core::mem::zeroed() }; + pass.width = size; + pass.height = size; + pass.layers = layers; + pass.utile_width = utile; + pass.utile_height = utile; + pass.few_primitives = few; + pass + } + + /// The window bytes of a pair for that pass with `mesh` bytes of mesh storage. + fn reserved_with(size: u32, layers: u16, utile: u8, few: bool, mesh: Option) + -> Result { + let pass = pass(size, layers, utile, few); + let layout = target::Layout::new(&pass, 8, RegisterPrograms::G17P)?; + let geometry = BlockGeometry::m5(RAM, + (layout.tvb_blocks * BlockGeometry::M5_BLOCK_BYTES) as u64)?; + m5_layout(layout, &pass, 8, geometry, mesh, STATE).map(|(_, bytes)| bytes) + } + + /// The same with the default mesh storage. + fn reserved(size: u32, layers: u16, utile: u8, few: bool) -> Result { + reserved_with(size, layers, utile, few, MESH) + } + + /// The pairs a two-pair queue uses for that pass. + fn pairs(size: u32, layers: u16, utile: u8, few: bool, mesh: Option) -> u8 { + let bytes = reserved_with(size, layers, utile, few, mesh).unwrap() as u64; + crate::g17::pairs::for_window(2, Some(bytes), compact::WINDOW_BYTES) + } + + #[test] + fn borealis_32x32_passes_of_more_than_four_primitives() { + assert!(reserved(16384, 21, 32, false).unwrap() <= WINDOW); + assert_eq!(reserved(16384, 22, 32, false), Err(ENOMEM)); + assert!(reserved(512, 2048, 32, false).unwrap() <= WINDOW); + assert!(reserved(1024, 2048, 32, false).unwrap() <= WINDOW); + assert_eq!(reserved(1152, 2048, 32, false), Err(ENOMEM)); + } + + #[test] + fn borealis_32x32_passes_of_few_primitives() { + assert!(reserved(16384, 53, 32, true).unwrap() <= WINDOW); + assert_eq!(reserved(16384, 54, 32, true), Err(ENOMEM)); + assert!(reserved(2048, 2047, 32, true).unwrap() <= WINDOW); + assert!(reserved(2048, 2048, 32, true).unwrap() <= WINDOW); + assert_eq!(reserved(2112, 2048, 32, true), Err(ENOMEM)); + assert!(reserved(1152, 2048, 32, true).unwrap() <= WINDOW); + } + + #[test] + fn passes_with_16x16_tiles() { + assert!(reserved(16384, 5, 16, false).unwrap() <= WINDOW); + assert_eq!(reserved(16384, 6, 16, false), Err(ENOMEM)); + assert!(reserved(512, 2048, 16, false).unwrap() <= WINDOW); + assert_eq!(reserved(1024, 2048, 16, false), Err(ENOMEM)); + } + + #[test] + fn mesh_storage_counts_at_the_4_gib_edge() { + // A pass that fits only without the mesh storage a pair keeps once it has run a + // task-stage pass is refused while the binding is enabled. + assert!(reserved_with(16384, 22, 32, false, None).unwrap() <= WINDOW); + assert_eq!(reserved_with(16384, 22, 32, false, MESH), Err(ENOMEM)); + let with = reserved_with(16384, 21, 32, false, MESH).unwrap(); + let without = reserved_with(16384, 21, 32, false, None).unwrap(); + assert_eq!(with - without, PairObject::MeshStorage.window_bytes(MESH.unwrap()).unwrap()); + assert!(with - without >= 32 * MIB); + } + + #[test] + fn mesh_storage_counts_at_the_2_gib_edge() { + // A pass whose pair the window holds twice only without mesh storage runs on one pair. + assert_eq!(pairs(16384, 17, 32, true, None), 2); + assert_eq!(pairs(16384, 17, 32, true, MESH), 1); + assert_eq!(pairs(16384, 16, 32, true, MESH), 2); + } + + #[test] + fn a_pair_counts_the_objects_its_layout_does_not_size() { + // A trace of a pair on the J775D found 3824 KiB of these objects, guards included and + // alignment holes not. + let geometry = BlockGeometry::m5(RAM, 32 * BlockGeometry::M5_BLOCK_BYTES as u64).unwrap(); + let sizes = compact::PairSizes { + records: 0, tpc: 0, blocks: 0, geometry, + state: STATE, mesh_storage: None, + }; + let sized = [PairObject::Records, PairObject::Tpc, PairObject::ParameterBlock] + .into_iter().map(|object| sizes.object_bytes(object).unwrap()).sum::(); + let fixed = sizes.window_bytes().unwrap() - sized; + assert!(fixed >= 3824 * 1024); + assert!(fixed <= 5 * MIB); + // Each block takes its stride, guard included. + assert_eq!(PairObject::ParameterBlock.window_bytes(geometry.block_bytes).unwrap(), + geometry.stride); + } +} diff --git a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs index 4cc04e2ac23e9..b6f2b07f961de 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs @@ -5,7 +5,7 @@ use super::retirement::Cursors; use crate::g17::{ - buffer::{self, target}, + buffer::{self, compact::PairObject, target}, context::Context, fw::{ self, queue, @@ -319,23 +319,19 @@ struct Compact { address: u64, _backing: KernelObject, } -/// The mesh storage chunk: chunk bases are 64 KiB aligned and the storage -/// register counts 64 KiB chunks. -const MESH_STORAGE_CHUNK: usize = 0x10000; impl Compact { - /// M5 shared-RW object in the compact window with an explicit VA alignment. - fn new_aligned(alloc: &Allocator<'_>, vm: &mmu::Vm, size: usize, align: u64) -> Result { - let size = size.checked_add(mmu::UAT_PGSZ - 1).ok_or(EOVERFLOW)? & !(mmu::UAT_PGSZ - 1); + /// M5: a shared-RW object of `size` bytes mapped in the client's compact window as `object`. + fn m5(alloc: &Allocator<'_>, vm: &mmu::Vm, object: PairObject, size: usize) -> Result { + let size = size.checked_next_multiple_of(mmu::UAT_PGSZ).ok_or(EOVERFLOW)?; let backing = KernelObject::backing(alloc.dev, size, CpuMap::WriteCombined)?; - let mapping = backing.map_range(vm, 0..size, buffer::BlockGeometry::M5_COMPACT, - align, mmu::PROT_GPU_SHARED_RW, mmu::UAT_PGSZ)?; - if mapping.iova() % align != 0 { return Err(EINVAL); } + let mapping = object.map(&backing, vm, 0..size, mmu::PROT_GPU_SHARED_RW)?; Ok(Self { address: mapping.iova(), mapping: Some(mapping), _backing: backing }) } + /// Off M5: a shared-RW object of `size` bytes in a compact alias range. fn new(alloc: &Allocator<'_>, vm: &mmu::Vm, size: usize) -> Result { if alloc.uat.is_m5() { - return Self::new_aligned(alloc, vm, size, cfg::TVB_PAGE); + return Err(EINVAL); } let backing = KernelObject::backing(alloc.dev, size, CpuMap::WriteCombined)?; let mapping = buffer::compact_alias( @@ -560,12 +556,10 @@ impl Memory { let state = Generation::allocate_state(alloc, vm, board)?; let (tvb, mappings, scratch, discard) = if m5 { let geometry = super::m5_render_submission::parameter_geometry(layout.tvb_blocks)?; - let bytes = fw::m5::pool::parameter_scratch_stride(geometry.capacity, 0) - .map_err(|_| EINVAL)?.checked_mul(fw::m5::pool::SCENE_TABLE_ENTRIES) - .ok_or(EOVERFLOW)?; + let bytes = buffer::compact::scratch_bytes(geometry)?; let (tvb, mappings) = buffer::Tvb::with_geometry(alloc.dev, vm, layout.tvb_blocks, geometry)?; - let scratch = Compact::new(alloc, vm, bytes)?; - let discard = Compact::new(alloc, vm, 0x8000)?; + let scratch = Compact::m5(alloc, vm, PairObject::Scratch, bytes)?; + let discard = Compact::m5(alloc, vm, PairObject::Discard, fw::m5::pool::DISCARD_BYTES)?; (tvb, mappings, scratch, discard) } else { let scratch = Compact::new(alloc, vm, cfg::SCENE_SIZE as usize)?; @@ -667,18 +661,17 @@ impl Memory { )) } /// The mesh storage register value of a task-stage kick. The buffer is - /// allocated on the queue's first such kick and kept for the queue's lifetime, + /// allocated on the pair's first such kick and kept for the pair's lifetime, /// so other contexts pay nothing. A failed allocation leaves no partial state. - /// A zero chunk parameter disables the binding. + /// A zero chunk parameter disables the binding. SUBMIT's compact-window bound + /// counts this buffer in every pair while the binding is enabled, since a pair + /// keeps it for the passes that follow. pub(super) fn mesh_storage_register(&mut self, alloc: &Allocator<'_>) -> Result { if self.mesh_storage.is_none() { - let chunks = crate::module_parameters::m5_mesh_storage_chunks.value(); - if chunks == 0 { return Ok(0); } - if chunks > 0xffff { return Err(EINVAL); } - let bytes = (chunks as usize).checked_mul(MESH_STORAGE_CHUNK).ok_or(EOVERFLOW)?; - let storage = Compact::new_aligned(alloc, self.context.vm(), bytes, - MESH_STORAGE_CHUNK as u64)?; - self.mesh_storage = Some(storage); + let Some((chunks, bytes)) = buffer::compact::mesh_storage()? else { return Ok(0); }; + let vm = self.context.vm(); + PairObject::MeshStorage.check_room(vm, bytes, 1)?; + self.mesh_storage = Some(Compact::m5(alloc, vm, PairObject::MeshStorage, bytes)?); self.mesh_storage_chunks = chunks; } let storage = self.mesh_storage.as_ref().ok_or(ENOMEM)?; diff --git a/drivers/gpu/drm/asahi/g17/queue/render/parked.rs b/drivers/gpu/drm/asahi/g17/queue/render/parked.rs index 35e39e2130b85..60935d5795aca 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/parked.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/parked.rs @@ -220,6 +220,7 @@ impl ParkedPair { &first.command, self.clusters, self.variant.programs, + self.board, )?; let aliases = [ kicks[0].prepare_client_alias(context.vm())?, diff --git a/drivers/gpu/drm/asahi/g17/runtime/backend.rs b/drivers/gpu/drm/asahi/g17/runtime/backend.rs index f12626e7039b0..19bdf733ea088 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/backend.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/backend.rs @@ -207,9 +207,15 @@ impl job::Backend for Backend { let programs = resources.as_deref().ok_or(EINVAL)?; *plan = Some(policy.plan(programs, priority)?); // The M5 target layout refuses the passes the M5 path cannot run. Derive it - // here, so that SUBMIT returns the refusal before anything is queued. - crate::g17::queue::render::m5_render_submission::layout( - command, self.shared.clusters, self.shared.variant.programs)?; + // here, so that SUBMIT returns the refusal before anything is queued, and keep + // the window its pairs reserve for choosing their count (`render_pairs`). + let (_, window) = + crate::g17::queue::render::m5_render_submission::layout_and_window( + command, self.shared.clusters, self.shared.variant.programs, + self.shared.m5_board)?; + if let Validated::Render { pair_window, .. } = command { + *pair_window = window; + } } Validated::Compute { resources, plan, m5_scratch, cdm_auxiliary_allocation, .. } => { if let Some(programs) = resources { diff --git a/drivers/gpu/drm/asahi/g17/runtime/render.rs b/drivers/gpu/drm/asahi/g17/runtime/render.rs index 0a0a527ac1bf8..228f114aead8b 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render.rs @@ -291,13 +291,16 @@ impl Registry { } // Prefer an empty reservation or an already parked channel, then a // reusable or warmed unpublished pair, then an idle drained published - // sibling (render only). - for pass in 0..3u8 { - if pass == 2 && owner.is_none() { + // sibling (render only), preferring non-wide siblings before wide ones. + for pass in 0..4u8 { + if pass >= 2 && owner.is_none() { break; } let with_backing = pass != 0; for slot in 1..RENDER_SLOTS { + if pass == 2 && self.admission.is_wide(slot as u8) { + continue; + } if with_backing && self.render.entries[slot].as_ref().is_some_and(|entry| { entry.pair.is_some() @@ -454,9 +457,12 @@ impl Registry { /// only that slot's owner so the next queue reuses them via `bind_owner()`. /// The caller destroys any returned backing after dropping the device lock. pub(super) fn reclaim_unused_render_sibling(&mut self) -> Result> { - for pass in 0..3u8 { + for pass in 0..4u8 { let with_backing = pass != 0; for slot in 1..RENDER_SLOTS { + if pass == 2 && self.admission.is_wide(slot as u8) { + continue; + } if with_backing && self.render.entries[slot].as_ref().is_some_and(|entry| { entry.pair.is_some() diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/prepare.rs b/drivers/gpu/drm/asahi/g17/runtime/render/prepare.rs index 406497094979e..1da5c2c70ad71 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/prepare.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/prepare.rs @@ -823,8 +823,8 @@ impl super::super::Backend { pub(super) fn ensure_render(&self, packet: &Arc, slot: u8, sleep: bool) -> Result { self.build_render_pair(slot, packet, false, sleep)?; - // An owner held to one pair has no sibling to warm. - if self.pairs == 1 { + // An owner held to one pair, or running this layout on one, has no sibling to warm. + if self.render_pairs(packet) == 1 { return Ok(()); } let sibling = { @@ -841,8 +841,15 @@ impl super::super::Backend { // construction and its final device-locked install have finished. // An optional sibling may be borrowed or waiting for recovery. // The selected pair is revalidated by prepare_render before publication. + // A sibling for which the client's window or memory limit has no room now, as the + // queue's other objects hold it, is not built either: this render runs on its pair. match self.build_render_pair(sibling.slot(), packet, true, sleep) { - Err(error) if error == EBUSY || error == EAGAIN || error == super::submit::FALLBACK => {} + Err(error) + if error == EBUSY + || error == EAGAIN + || error == super::submit::FALLBACK + || error == ENOSPC + || error == ENOMEM => {} result => result?, } } diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs index dda6ebf5b9eb7..4a56d4eff67e5 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs @@ -37,6 +37,16 @@ impl Backend { }) } + /// The render pairs this queue uses for `packet`: its own count, or one for an M5 layout + /// whose pairs the client's compact window cannot hold side by side + /// ([`crate::g17::pairs::for_window`]). + pub(in crate::g17::runtime) fn render_pairs(&self, packet: &Packet) -> u8 { + // SUBMIT derived the layout and kept its window bytes on the command. + crate::g17::pairs::for_window(self.pairs, + packet.command.pair_window().map(|bytes| bytes as u64), + crate::g17::buffer::compact::WINDOW_BYTES) + } + pub(in crate::g17) fn render_packet( &self, packet: &Arc, @@ -87,7 +97,7 @@ impl Backend { if !sleep { return Err(FALLBACK); } - match pool.acquire_render(self.owner, self.pairs.into(), Request::of(packet), deadline_ns, || { + match pool.acquire_render(self.owner, self.render_pairs(packet).into(), Request::of(packet), deadline_ns, || { // Atomics only: the callback runs under the pool mutex. if packet.cancel_requested() || self.closed.load(Ordering::Acquire) { return Err(ECANCELED); @@ -190,11 +200,12 @@ impl Backend { Ok(_) => {} } let request = Request::of(packet); - if self.admission.admits_render(self.owner, request) { + let pairs = self.render_pairs(packet).into(); + if self.admission.admits_render(self.owner, pairs, request) { return None; } let observed = self.shared.renders.observe(); - if self.admission.admits_render(self.owner, request) { + if self.admission.admits_render(self.owner, pairs, request) { return None; } self.shared.queue_events(); @@ -411,7 +422,7 @@ impl Backend { Some(lease) => Some(lease), None if known != 0 => self .admission - .try_acquire_render(self.owner, self.pairs.into(), Request::of(packet)) + .try_acquire_render(self.owner, self.render_pairs(packet).into(), Request::of(packet)) .ok() .flatten(), None => None, @@ -574,7 +585,7 @@ impl Backend { if !self.traversal_inline(packet) { return false; } - let admission = match self.admission.try_acquire_render(self.owner, self.pairs.into(), Request::of(packet)) { + let admission = match self.admission.try_acquire_render(self.owner, self.render_pairs(packet).into(), Request::of(packet)) { Ok(Some(lease)) => lease, _ => return false, }; diff --git a/tools/asahi/g17-admission-order-tests.py b/tools/asahi/g17-admission-order-tests.py index 2cdcf55a0d87a..a55d4c7fbe6f9 100644 --- a/tools/asahi/g17-admission-order-tests.py +++ b/tools/asahi/g17-admission-order-tests.py @@ -161,12 +161,13 @@ def held_fixture(): backlog = pairs[at:pairs.index('\n}\n', pairs.index('fn sibling_backlog', at)) + 3] state = '\n'.join(item(source, name) for name in [ 'const fn new(', 'fn owns_live(', 'fn has_live_owner(', 'fn exhausted(', 'fn owner_quarantine(', 'fn refusal(', 'fn advance(', - 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', + 'fn set_owner(', 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', 'fn reclaimable_siblings_in(', 'fn reclaimable_siblings(', 'fn promotes_reclaimable_sibling(', 'fn can_lease_slot(', 'fn unavailable_released(', 'fn total_pair_demand(', 'fn pair_demand(', 'fn claim_sibling(', 'fn can_reassign_unused_spare(', 'fn reassign_unused_spare(', - 'fn cancel_empty_slot(', 'fn can_pick(', - 'fn can_pick_for(', 'fn pick(', 'fn pick_for(', 'fn usable(', 'fn join(', 'fn join_for(', + 'fn cancel_empty_slot(', 'fn can_pick(', 'fn can_pick_for(', + 'fn wide(', 'fn mark_wide(', 'fn can_pick_render(', 'fn can_pick_render_for(', + 'fn pick(', 'fn pick_for(', 'fn usable(', 'fn join(', 'fn join_for(', 'fn release(', 'fn set_held(', 'fn retained(', 'fn used(']) pool = '\n'.join(item(source, name) for name in [ 'pub(crate) fn set_held(', 'pub(crate) fn release_retained_owners_after_processor_stop(', @@ -370,7 +371,7 @@ def release_fixture(): backlog = pairs[at:pairs.index('\n}\n', pairs.index('fn sibling_backlog', at)) + 3] state = '\n'.join(item(source, name) for name in [ 'const fn new(', 'fn owns_live(', 'fn has_live_owner(', 'fn exhausted(', 'fn owner_quarantine(', 'fn refusal(', 'fn advance(', - 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', + 'fn set_owner(', 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', 'fn reclaimable_siblings_in(', 'fn reclaimable_siblings(', 'fn promotes_reclaimable_sibling(', 'fn can_lease_slot(', 'fn unavailable_released(', 'fn total_pair_demand(', 'fn pair_demand(', 'fn claim_sibling(', 'fn usable(', 'fn can_reassign_unused_spare(', 'fn reassign_unused_spare(', @@ -378,7 +379,7 @@ def release_fixture(): pool = '\n'.join(item(source, name) for name in [ 'pub(crate) fn can_reassign_unused_spare(', 'pub(crate) fn reassign_unused_spare(', 'pub(crate) fn release_unused_sibling(', 'pub(crate) fn owns_live_slot(', - 'pub(crate) fn hold_render_slots_for_exit_kill(', + 'pub(crate) fn is_wide(', 'pub(crate) fn hold_render_slots_for_exit_kill(', 'pub(crate) fn set_held(', 'pub(crate) fn sync_held(', 'pub(crate) fn release_owner(']) pending = '\n'.join(item(teardown, name) for name in [ 'pub(crate) fn new(', 'pub(crate) fn releasing(', 'fn find(', 'fn insert(', diff --git a/tools/asahi/g17-quarantine-drain-tests.py b/tools/asahi/g17-quarantine-drain-tests.py index 2faff3ad00fac..1126e95451e4d 100644 --- a/tools/asahi/g17-quarantine-drain-tests.py +++ b/tools/asahi/g17-quarantine-drain-tests.py @@ -85,7 +85,7 @@ def fixture(): backlog = pairs[at:pairs.index('\n}\n', pairs.index('fn sibling_backlog', at)) + 3] state = '\n'.join(item(admission, name) for name in [ 'const fn new(', 'fn owns_live(', 'fn has_live_owner(', 'fn exhausted(', 'fn owner_quarantine(', 'fn refusal(', 'fn advance(', - 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', + 'fn set_owner(', 'fn take_idle(', 'fn acquire(', 'fn acquire_for(', 'fn live_owners(', 'fn live_siblings(', 'fn reclaimable_siblings_in(', 'fn reclaimable_siblings(', 'fn promotes_reclaimable_sibling(', 'fn can_lease_slot(', 'fn unavailable_released(', 'fn total_pair_demand(', 'fn pair_demand(', 'fn claim_sibling(', 'fn usable(', 'fn position(', 'fn release(', diff --git a/tools/asahi/g17-resource-tests.py b/tools/asahi/g17-resource-tests.py index b68d2285fff86..31d24d19afee2 100644 --- a/tools/asahi/g17-resource-tests.py +++ b/tools/asahi/g17-resource-tests.py @@ -39,7 +39,7 @@ def item(start): macro_rules! resource_exhausted { ($s:literal)=>{ENOSPC}; } type KVec = Vec; struct InFlight; mod cfg {\n'''+constants+'}\n'+limits+'\n' - methods=['const fn new','fn owns_live','fn has_live_owner','fn live_owners','fn live_siblings','fn reclaimable_siblings_in','fn reclaimable_siblings(','fn promotes_reclaimable_sibling','fn can_lease_slot','fn exhausted','fn owner_quarantine','fn refusal','fn advance','fn take_idle','fn acquire(','fn acquire_for','fn unavailable_released','fn total_pair_demand','fn pair_demand','fn usable','fn claim_sibling','fn can_reassign_unused_spare','fn reassign_unused_spare','fn release_unused_sibling','fn reclaim_sibling','fn warmable_sibling','fn borrow_warm_sibling','fn cancel_empty_slot','fn release('] + methods=['const fn new','fn owns_live','fn has_live_owner','fn live_owners','fn live_siblings','fn reclaimable_siblings_in','fn reclaimable_siblings(','fn promotes_reclaimable_sibling','fn can_lease_slot','fn exhausted','fn owner_quarantine','fn refusal','fn advance','fn set_owner','fn take_idle','fn acquire(','fn acquire_for','fn unavailable_released','fn total_pair_demand','fn pair_demand','fn usable','fn claim_sibling','fn can_reassign_unused_spare','fn reassign_unused_spare','fn release_unused_sibling','fn reclaim_sibling','fn warmable_sibling','fn borrow_warm_sibling','fn cancel_empty_slot','fn release('] code=header+item('struct State')+'\nimpl State {\n'+re.search(r' const MASK: u64 = .*;',s).group(0)+'\n'+'\n'.join(item(n) for n in methods)+'\n}\n'+''' // A queue holds g17::pairs::per_owner() pairs (Backend::pairs): one, or // RENDER_PAIRS_MAX on G17D. Both admissions run.