From 00f3d43b9640af3071e38137cca3a4512e92dd61 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Tue, 1 Dec 2026 06:26:48 -0500 Subject: [PATCH] drm/asahi: g16: raise standby PB epoch retention ceiling to 64 At render depth 64 (render.light tri d=64), standby.reserved exceeds SPARE_EPOCHS = 32, so every commit_render() -> release_reserved() trims an epoch (deferring client unmap and UAT TLB sync) and the very next ASAHI_SUBMIT -> Cache::prepare() allocates, zero-fills, client-maps, and UAT-syncs a replacement via PbEpoch::new_for(). J773g CPU sampling attributed 55.6% of focused CPU (Window::sync_inner, rust_helper_readq, and cleanup worker mutex contention) and a 249.56 us p95 submit tail to this per-submit churn. Raise SPARE_EPOCHS from 32 to 64 (1/4 of budget::LIMIT = 256, matching d=64 render pipelines) with a compile-time budget assertion: - Shallow VMs (d <= 32) never pre-allocate extra epochs and see zero memory change. - Deep d=64 render VMs retain their standby epochs across steady-state submits without per-submit eviction, zeroing, or UAT syncs. Each extra set has 96 KiB of page-rounded backing, for up to 3 MiB of backing plus metadata and 1.5 MiB of DYNAMIC VA per deep VM. Bursts above 64 still trim back to 64 and Cache::close() still drains all unreserved epochs immediately. - Add a host selftest regression exercising production release_reserved() at steady-state depth 64, above-ceiling trim, and close drain. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/resources.rs | 7 +- .../drivers/gpu/asahi-m4/test-resources.py | 67 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/g16/resources.rs b/drivers/gpu/drm/asahi/g16/resources.rs index 1738847a7dd4f..7184b6c07d000 100644 --- a/drivers/gpu/drm/asahi/g16/resources.rs +++ b/drivers/gpu/drm/asahi/g16/resources.rs @@ -156,7 +156,12 @@ impl ComputeCmds { /// With PB epoch reuse most renders never expose a fresh epoch; keeping a /// shared per-VM standby pool instead of attaching one epoch per queued job /// avoids allocating and mapping fresh epochs whenever submission depth rises. -const SPARE_EPOCHS: usize = 32; +/// Sized to 64 (1/4 of `budget::LIMIT`) so deep d=64 render pipelines retain +/// their standby epochs in steady state without per-submit eviction and +/// client-VA remap churn while shallow VMs still allocate only their actual +/// depth and `Cache::close()` drains all surplus epochs immediately. +const SPARE_EPOCHS: usize = 64; +const _: () = assert!(SPARE_EPOCHS <= super::budget::LIMIT as usize); /// Per-VM shared compute UMA manager descriptor, submission counter, and 32 MiB backing pool. /// diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py index 5fd0cdcfc25f4..e30969dd461f1 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py @@ -686,6 +686,73 @@ def module(text, name): drop(retained); assert_eq!(cache.active_render_passes.load(Ordering::Acquire), 0); } + + #[test] + fn standby_depth_64_retains_without_churn_and_trims_above_ceiling() { + assert_eq!(SPARE_EPOCHS, 64); + let shared = Arc::new(Shared::default(), 0).unwrap(); + let cache = Arc::new(Cache::test_new(shared), 0).unwrap(); + let budget = crate::g16::budget::Budget::new().unwrap(); + let vm = crate::resources::vm(340); + let mut allocs = 0usize; + let prepare_one = |allocs: &mut usize| { + let deficit = { + let s = cache.standby.lock(); + s.compat_deficit(512, 1) + .max((s.reserved as usize + 1).saturating_sub(s.epochs.len())) + }; + if deficit != 0 { + let mut res = crate::g16::budget::Budget::reserve(&budget, deficit as u32) + .unwrap(); + let mut s = cache.standby.lock(); + for _ in 0..deficit { + let epoch = PbEpoch::new_for( + &Factory, + &vm, + res.take().unwrap(), + Some(512), + ) + .unwrap(); + s.epochs.push(epoch, 0).unwrap(); + *allocs += 1; + } + } + cache.standby.lock().add_reserved(512, 1); + }; + + // Ramp to depth 64: allocates 64 standby epochs once. + for _ in 0..64 { + prepare_one(&mut allocs); + } + assert_eq!(allocs, 64); + assert_eq!(cache.standby.lock().epochs.len(), 64); + assert_eq!(cache.standby.lock().reserved, 64); + + // Steady-state d=64 commit_render + prepare loop: zero evictions, zero reallocs. + for _ in 0..128 { + cache.release_reserved(1, 512); + assert_eq!(cache.standby.lock().epochs.len(), 64); + prepare_one(&mut allocs); + } + assert_eq!(allocs, 64); + assert_eq!(cache.standby.lock().epochs.len(), 64); + + // Burst above 64 (to 72) allocates 8 more, and draining trims back to SPARE_EPOCHS. + for _ in 0..8 { + prepare_one(&mut allocs); + } + assert_eq!(allocs, 72); + assert_eq!(cache.standby.lock().epochs.len(), 72); + cache.release_reserved(72, 512); + assert_eq!(cache.standby.lock().reserved, 0); + assert_eq!(cache.standby.lock().epochs.len(), SPARE_EPOCHS); + + // Closing the VM drains all unreserved standby epochs immediately on next release. + cache.standby.lock().add_reserved(512, 1); + cache.closed.store(true, Ordering::Release); + cache.release_reserved(1, 512); + assert_eq!(cache.standby.lock().epochs.len(), 0); + } } } pub mod boot {pub fn eproto()->crate::Error{crate::Error(71)}}