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)}}