diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 0dfb9a7697df7..4f4848c4988e6 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -1875,6 +1875,7 @@ impl Firmware { || c.is_rt() || head_order.wait_through != [None, None] || !head.fw_waits.is_empty() + || self.engine.flights.iter().any(|fl| fl.renders != 0) || self.compute_queue_is_heavy(&head.queue, now) { return false; @@ -1950,7 +1951,10 @@ impl Firmware { cap > 1 && pending_cmds < cap } Some(Command::Render(_)) => { - if head.resources.render_scs() || !head.fw_waits.is_empty() { + if head.resources.render_scs() + || !head.fw_waits.is_empty() + || self.engine.flights.iter().any(|fl| fl.computes != 0) + { return false; } let queue_active: usize = self diff --git a/drivers/gpu/drm/asahi/g16/job.rs b/drivers/gpu/drm/asahi/g16/job.rs index a5dbc19b7d3e9..5e40081fd2e41 100644 --- a/drivers/gpu/drm/asahi/g16/job.rs +++ b/drivers/gpu/drm/asahi/g16/job.rs @@ -32,8 +32,6 @@ use core::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use kernel::{ c_str, - cpu::CpuId, - cpumask::Cpumask, device, dma_fence::Fence, drm::sched, @@ -794,12 +792,14 @@ pub(crate) struct Scheduler { impl Scheduler { pub(crate) fn new(dev: &device::Device) -> Result { - // Keep drm_sched run/free work in the creating CPU's cluster (matching g17/job.rs). - // Completion work still follows the per-submit submitter_cpu, not queue creation, and - // an unbound workqueue restricted via apply_workqueue_attrs() falls back to - // wq_unbound_cpumask if the cluster goes offline (failing soft if restrict() errors). - let submit = workqueue::OwnedQueue::new_ordered_reclaim(c_str!("aurora_g16"))?; - let _ = submit.restrict(Cpumask::cluster_of(CpuId::current())); + // Run drm_sched's submit worker at WQ_HIGHPRI to cut host-signalled and + // dependency-waited wakeup latency. Do not restrict() this queue to a CPU cluster: + // kernel/workqueue.c clears `ordered` in wqattrs_clear_for_pool() before hashing + // unbound pools by (nice, affn_strict, __pod_cpumask, cpumask), so a cluster-restricted + // nice=-20 submit queue collides with `aurora_g16_events_unbound`'s per-cluster worker + // pools and lets background clients on another cluster pin unpinned submitters across + // clusters via wake-affine. + let submit = workqueue::OwnedQueue::new_ordered_highpri_reclaim(c_str!("aurora_g16"))?; let scheduler = sched::Scheduler::new_with_queues( dev, 1, diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-job-failure.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-job-failure.py index fe6818252cc83..d5fd7b72eab27 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-job-failure.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-job-failure.py @@ -35,6 +35,7 @@ def function(text, name): queue_methods = '\n'.join(function(queue_source, name) for name in ['cancel', 'check', 'cancelled_through', 'is_compute_retired']) methods = '\n'.join(function(source, name) for name in ['latch_failure', 'complete', 'finish', 'is_started', 'try_start_inline', 'start', 'check_command_dependencies', 'command_retired', 'note_full_retirement', 'mark_terminal_retired', 'waits_on_queue']) push_method = function_from(source, 'pub(crate) fn push(&mut self, job: Arc') +sched_new_method = function_from(source, 'pub(crate) fn new(dev: &device::Device)') fence_methods = '\n'.join(function(fence_source, name) for name in ['dependency_status', 'check_dependencies', 'wait_dependencies']) harness = r''' #![allow(dead_code)] @@ -638,7 +639,110 @@ def function(text, name): q1.cancel(&p_orders,0); assert_eq!(cons.check_command_dependencies(0),Err(ECANCELED)); } -'''.replace('QUEUE_METHODS', queue_methods).replace('ORDER_SOURCE', order_source).replace('FENCE_METHODS', fence_methods).replace('METHODS', methods.replace('super::fence::','fence::').replace('super::command::','command::')).replace('PUSH_METHOD', push_method) +mod scheduler_new_check { + use core::sync::atomic::{AtomicUsize, Ordering}; + use std::cell::Cell; + use std::sync::{Arc, Mutex}; + type Result = core::result::Result; + const GFP_KERNEL: u32 = 0; + macro_rules! c_str { ($s:expr) => { $s }; } + thread_local! { + static CLUSTER_WEIGHT: Cell = const { Cell::new(4) }; + static HIGHPRI_CALLS: Cell = const { Cell::new(0) }; + static NORMAL_CALLS: Cell = const { Cell::new(0) }; + static RESTRICT_CALLS: Cell = const { Cell::new(0) }; + } + mod device { pub struct Device; } + mod hw { + pub mod sizes { pub const SCHEDULER_CREDITS: u32 = 64; } + pub mod tuning { pub const SCHED_TIMEOUT_MS: u32 = 1000; } + } + struct CpuId; + impl CpuId { fn current() -> Self { Self } } + struct Cpumask(u32); + impl Cpumask { + fn cluster_of(_cpu: CpuId) -> Self { Self(CLUSTER_WEIGHT.with(Cell::get)) } + fn weight(&self) -> u32 { self.0 } + } + mod workqueue { + use super::*; + pub struct OwnedQueue; + impl OwnedQueue { + pub fn new_ordered_highpri_reclaim(_name: &str) -> Result { + HIGHPRI_CALLS.with(|c| c.set(c.get() + 1)); + Ok(Self) + } + pub fn new_ordered_reclaim(_name: &str) -> Result { + NORMAL_CALLS.with(|c| c.set(c.get() + 1)); + Ok(Self) + } + pub fn restrict(&self, _mask: Cpumask) -> Result { + RESTRICT_CALLS.with(|c| c.set(c.get() + 1)); + Ok(()) + } + } + } + mod sched { + use super::*; + pub enum Priority { Kernel } + pub struct Scheduler(core::marker::PhantomData); + impl Scheduler { + pub fn new_with_queues( + _dev: &device::Device, + _rqs: u32, + _credits: u32, + _hang: u32, + _timeout: u32, + _name: &str, + submit: Option, + _timeout_wq: Option, + ) -> Result { + assert!(submit.is_some()); + Ok(Self(core::marker::PhantomData)) + } + } + pub struct Entity(core::marker::PhantomData); + impl Entity { + pub fn new(_s: &Scheduler, _p: Priority) -> Result { + Ok(Self(core::marker::PhantomData)) + } + } + } + struct SchedJob; + struct Scheduler { + entity: sched::Entity, + _scheduler: sched::Scheduler, + pending_sched: Arc, + } + struct ArcNew; + trait ArcExt { fn new_gfp(v: T, _gfp: u32) -> Result>; } + impl ArcExt for Arc { fn new_gfp(v: T, _gfp: u32) -> Result> { Ok(Arc::new(v)) } } + impl Scheduler { + SCHED_NEW_METHOD + } + #[test] + fn scheduler_new_uses_unrestricted_highpri_wq() { + HIGHPRI_CALLS.with(|c| c.set(0)); + NORMAL_CALLS.with(|c| c.set(0)); + RESTRICT_CALLS.with(|c| c.set(0)); + + // Submit queue uses WQ_HIGHPRI unconditionally without restrict(), keeping its + // unbound worker pool disjoint from aurora_g16_events_unbound's cluster-restricted pools. + CLUSTER_WEIGHT.with(|c| c.set(6)); + let _s = Scheduler::new(&device::Device).unwrap(); + assert_eq!(HIGHPRI_CALLS.with(Cell::get), 1); + assert_eq!(NORMAL_CALLS.with(Cell::get), 0); + assert_eq!(RESTRICT_CALLS.with(Cell::get), 0, "submit wq must not share cluster-restricted pools"); + + CLUSTER_WEIGHT.with(|c| c.set(1)); + let _s2 = Scheduler::new(&device::Device).unwrap(); + assert_eq!(HIGHPRI_CALLS.with(Cell::get), 2); + assert_eq!(NORMAL_CALLS.with(Cell::get), 0); + assert_eq!(RESTRICT_CALLS.with(Cell::get), 0); + let _ = (Mutex::new(()), ArcNew, Ordering::Relaxed, CpuId::current(), Cpumask::cluster_of(CpuId::current()).weight()); + } +} +'''.replace('QUEUE_METHODS', queue_methods).replace('ORDER_SOURCE', order_source).replace('FENCE_METHODS', fence_methods).replace('METHODS', methods.replace('super::fence::','fence::').replace('super::command::','command::')).replace('PUSH_METHOD', push_method).replace('SCHED_NEW_METHOD', sched_new_method.replace('Arc::new(', 'Arc::new_gfp(').replace('core::sync::atomic::AtomicUsize', 'AtomicUsize')) with tempfile.TemporaryDirectory(prefix='m4-rust-job-') as directory: directory=pathlib.Path(directory); test=directory/'test.rs'; test.write_text(harness) @@ -649,6 +753,6 @@ def function(text, name): (OUT/'job-failure-host.log').write_text(result.stdout+result.stderr) (OUT/'job-failure-host.json').write_text(json.dumps({ 'source':str(SOURCE),'sha256':hashlib.sha256(SOURCE.read_bytes()).hexdigest(), - 'result':'pass','test_groups':25, + 'result':'pass','test_groups':26, 'limitations':'Production Job methods with host VM/fence mocks; actual DRM scheduler and firmware publication gates require kernel and execution integration validation.' },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 bd241698a0312..7ba762418125b 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -3193,11 +3193,22 @@ def item(declaration): assert_eq!(h.defer_busy_coalesce(425_000), None); h.engine.flights.pop(); + // Same-queue interleaved render active alongside computes bypasses compute coalescing. + let r_same = mk_job(&vm1, &q1, true, 1, [None, None]); + h.engine.flights.push(Flight { job: r_same, computes: 0, renders: 1, compute_pipe: 0, published_ns: 415_000, doomed: false, recovery_suspect: false, initbm: false }); + assert_eq!(h.defer_busy_coalesce(430_000), None); + h.engine.flights.pop(); + // A render with queue_active == 2 coalesces up to K=6 passes before flushing. let r1 = mk_job(&vm1, &q1, true, 1, [None, None]); h.engine.flights = vec![Flight { job: r1, computes: 0, renders: 2, compute_pipe: 0, published_ns: 490_000, doomed: false, recovery_suspect: false, initbm: false }]; h.engine.pending = vec![mk_job(&vm1, &q1, true, 3, [Some(2), None])]; assert_eq!(h.defer_busy_coalesce(500_000), Some(18)); + // Same-queue interleaved compute active alongside renders bypasses render coalescing. + h.engine.flights.push(Flight { job: c1.clone(), computes: 1, renders: 0, compute_pipe: 0, published_ns: 495_000, doomed: false, recovery_suspect: false, initbm: false }); + assert_eq!(h.defer_busy_coalesce(501_000), None); + h.engine.flights.pop(); + assert_eq!(h.defer_busy_coalesce(500_000), Some(18)); for seq in 4..=7 { h.engine.pending.push(mk_job(&vm1, &q1, true, seq, [Some(seq - 1), None])); assert_eq!(h.defer_busy_coalesce(502_000), Some(16));