diff --git a/drivers/gpu/drm/asahi/g17/fw/m5/queue.rs b/drivers/gpu/drm/asahi/g17/fw/m5/queue.rs index 0a0b64b1de05d..2917feca02101 100644 --- a/drivers/gpu/drm/asahi/g17/fw/m5/queue.rs +++ b/drivers/gpu/drm/asahi/g17/fw/m5/queue.rs @@ -166,6 +166,17 @@ impl HardwareSubmission { Ok(Self{writes,count}) } + /// The configuration writes of [`Self::compute`] alone: the queue is configured and marked + /// valid, and no kick is announced. An installation, whose kick ring is still empty, sends + /// them before its doorbell. + pub(crate) fn configure_compute(qid:u8,va:u64,priority:u8)->Result { + let mut submission=Self::compute(qid,va,priority,true)?; + // compute() writes six configuration writes, then the advance pair last. + debug_assert_eq!(submission.count,8); + submission.count-=2; + Ok(submission) + } + pub(crate) fn new(fragment:(u8,u64),tiling:(u8,u64),priority:u8,configured:bool)->Result { use super::super::{kick::QID_MAX,queue::{Policy,DataMaster}}; const ADDRESS_MASK:u64=0x0000_07ff_ffff_ffe0; diff --git a/drivers/gpu/drm/asahi/g17/preparation.rs b/drivers/gpu/drm/asahi/g17/preparation.rs index 85994ab8e6c73..d51083e075027 100644 --- a/drivers/gpu/drm/asahi/g17/preparation.rs +++ b/drivers/gpu/drm/asahi/g17/preparation.rs @@ -21,6 +21,29 @@ const REMOVED: u64 = CLOSED << 1; const FAILED: u64 = CLOSED << 2; const EPOCH: u64 = CLOSED << 3; +/// The waits of a compute publication, by what they wait for. Diagnostics only: the time an +/// admission spends in each is reported when its budget runs out. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(super) enum AdmissionWait { + /// The firmware sources of the packet's dependencies. + Sources = 0, + /// A compute channel for this owner, including its drain-witness waits. + Channel = 1, + /// The preparation gate, which only a recovery closes. + Preparation = 2, + /// A free work state of this context. + WorkState = 3, + /// A pending recovery. + Recovery = 4, + /// Room on the shared work ring. + OuterRoom = 5, + /// Publication backpressure, including the first installation of an M5 queue. + Publication = 6, +} + +/// Number of [`AdmissionWait`] kinds. +pub(super) const ADMISSION_WAITS: usize = 7; + /// One ready packet's monotonic compute-admission budget. The callback checks /// packet cancellation, logical close, VM status and device loss even when no /// capacity/recovery event arrives. Wakes and nested constructors never renew it. @@ -28,6 +51,8 @@ pub(super) struct Admission<'a> { deadline: Cell, started: u64, check: &'a dyn Fn() -> Result, + /// Nanoseconds spent in each [`AdmissionWait`] (diagnostics). + spent: [Cell; ADMISSION_WAITS], } /// Bound for a compute publication's waits: a physical compute queue, or room on the shared @@ -36,7 +61,32 @@ pub(super) const QUEUE_WAIT_NS: u64 = 30_000_000_000; impl<'a> Admission<'a> { pub(super) fn new(deadline: u64, check: &'a dyn Fn() -> Result) -> Self { - Self { deadline: Cell::new(deadline), started: super::now_ns(), check } + Self { + deadline: Cell::new(deadline), + started: super::now_ns(), + check, + spent: core::array::from_fn(|_| Cell::new(0)), + } + } + + /// Runs one wait of kind `wait`, adding its duration to that kind's total. + pub(super) fn timed(&self, wait: AdmissionWait, f: impl FnOnce() -> Result) -> Result { + let start = super::now_ns(); + let result = f(); + let spent = &self.spent[wait as usize]; + spent.set(spent.get().saturating_add(super::now_ns().saturating_sub(start))); + result + } + + /// The budget has run out: an EBUSY from this admission's waits is its deadline. + pub(super) fn expired(&self) -> bool { + super::now_ns() >= self.deadline.get() + } + + /// Milliseconds since the start, and in each [`AdmissionWait`] (diagnostics). + pub(super) fn spent_ms(&self) -> (u64, [u64; ADMISSION_WAITS]) { + let total = super::now_ns().saturating_sub(self.started) / 1_000_000; + (total, core::array::from_fn(|wait| self.spent[wait].get() / 1_000_000)) } /// A recovery is pending or this owner's spared work drains: wait as long as the diff --git a/drivers/gpu/drm/asahi/g17/queue/compute.rs b/drivers/gpu/drm/asahi/g17/queue/compute.rs index 8042e2026451b..515ee73753028 100644 --- a/drivers/gpu/drm/asahi/g17/queue/compute.rs +++ b/drivers/gpu/drm/asahi/g17/queue/compute.rs @@ -615,6 +615,19 @@ pub(crate) struct Growth { phase: PoolPhase, } +/// See [`Queue::admission_state`]. Its fields are read only through `Debug`, by the report. +#[derive(Debug)] +#[allow(dead_code)] +pub(crate) struct AdmissionState { + installed: bool, + m5_install_end: Option, + consumer: Option, + configuration: bool, + ordinal: u32, + quarantined: bool, + awaiting_witness: bool, +} + pub(crate) struct Queue { owner: Option, /// Scheduler/work pages of an exited last owner whose context was dropped; @@ -3060,6 +3073,21 @@ impl Queue { Ok(()) } + /// The installation and health state a timed-out publication reports (diagnostics): + /// whether the queue was installed, the item an M5 installation waits for the firmware to + /// consume and how far it got, an outstanding configuration, and quarantine. + pub(crate) fn admission_state(&self) -> AdmissionState { + AdmissionState { + installed: self.installed, + m5_install_end: self.m5_install, + consumer: self.graph.cursors().ok().map(|cursors| cursors.consumer), + configuration: self.configuration.is_some(), + ordinal: self.ordinal, + quarantined: self.quarantined, + awaiting_witness: self.awaiting_witness, + } + } + fn install_m5(&mut self, packet: &Arc, host: &mut impl Host) -> Result { // Installed, configuration released and a kick published: nothing to check, and no // reads of shared memory under the device mutex. @@ -3097,6 +3125,21 @@ impl Queue { host.publish_outer(policy.priority(), &crate::g17::fw::channels::WorkSlot::new(DataMaster::Compute, self.graph.graph.gpu_va(), self.qid(), producer.try_into()?, true)?)?; self.outer_started = 1 << policy.priority(); + // The queue's host-port configuration and validity go out before the installation's + // doorbell, so that the queue is configured when the firmware acts on it. A + // publication writes its host-port transaction after its doorbell, the work + // notification that wakes gated cores (see the publication path); as we understand + // it, that order matters for the advance the transaction ends with. The + // installation's transaction has no advance: its ring holds no kick yet, and the first + // publication configures the queue again with its kick. The configuration record is + // already visible, so a failed host-port write must not keep the doorbell back: the + // doorbell alone installs the queue, as it did before. + if let Err(error) = crate::g17::fw::m5::queue::HardwareSubmission::configure_compute( + self.qid(), self.kick.low_va(), policy.priority(), + ).and_then(|submission| host.submit_m5(&submission)) { + pr_warn!("asahi: G17: M5 queue {} installs without its host-port configuration: {:?}\n", + self.qid(), error); + } host.notify((0x83 << 48) | 0x02 | u64::from(policy.priority()) << 2)?; Err(EAGAIN) })(); diff --git a/drivers/gpu/drm/asahi/g17/runtime.rs b/drivers/gpu/drm/asahi/g17/runtime.rs index e591c5f99d470..a1f712febcddb 100644 --- a/drivers/gpu/drm/asahi/g17/runtime.rs +++ b/drivers/gpu/drm/asahi/g17/runtime.rs @@ -25,7 +25,7 @@ use super::{ kick, qos, queue::{self, admission, compute}, }; -use super::preparation::Admission; +use super::preparation::{Admission, AdmissionWait, ADMISSION_WAITS}; use core::sync::atomic::{fence, Ordering}; use kernel::{prelude::*, sync::Arc}; @@ -2384,112 +2384,167 @@ impl Backend { let admission = Admission::new(deadline, &check); let progress = &self.shared.progress; let outer = self.outer_domain(); - loop { - admission.check()?; - let observed = progress.observe(); - let claimed = outer.as_ref().map(|domain| domain.observe()); - if !self.sources_published(packet)? { - let recovering = self.shared.state.lock().as_deref().is_some_and(|firmware| { - firmware.recovery.pending() - || super::recovery::Memory::recovery_state(&firmware.init).unwrap_or(0) != 0 - }); - if recovering { - admission.extend_for_recovery(); + // The waits below share one budget. When it runs out, the report names where it went. + let result = (|| -> Result { + loop { + admission.check()?; + let observed = progress.observe(); + let claimed = outer.as_ref().map(|domain| domain.observe()); + if !self.sources_published(packet)? { + let recovering = self.shared.state.lock().as_deref().is_some_and(|firmware| { + firmware.recovery.pending() + || super::recovery::Memory::recovery_state(&firmware.init).unwrap_or(0) != 0 + }); + if recovering { + admission.extend_for_recovery(); + } + self.shared.queue_events(); + let wait = if recovering { AdmissionWait::Recovery } else { AdmissionWait::Sources }; + admission.timed(wait, || self.wait_release(progress, observed, &admission))?; + continue; + } + // All DRM dependencies were satisfied before this scheduler callback. + // Recheck on every retry: pressure may yield an idle binding between + // admission and publication without changing this logical queue. + if !bound { + demand.get_or_insert_with(|| ComputeDemand::new(&self.shared)); + admission.timed(AdmissionWait::Channel, || { + Backend::ensure_compute(self, required, &admission) + })?; + admission.check()?; + } + let lease = admission.timed(AdmissionWait::Preparation, || { + self.shared.preparations.enter_until(&admission) + })?; + // Work states free as this context's earlier commands retire. + match packet.completion.work_state()?.acquire(crate::g17::job::Engine::Compute) { + Err(error) if error == EBUSY => { + drop(lease); + self.shared.queue_events(); + admission.timed(AdmissionWait::WorkState, || { + self.wait_release(progress, observed, &admission) + })?; + continue; + } + result => { + result?; + } + } + let mut state = self.shared.state.lock(); + let firmware = (*state).as_deref_mut().ok_or(ENODEV)?; + if !lease.is_current() { + drop(state); + continue; } - self.shared.queue_events(); - self.wait_release(progress, observed, &admission)?; - continue; - } - // All DRM dependencies were satisfied before this scheduler callback. - // Recheck on every retry: pressure may yield an idle binding between - // admission and publication without changing this logical queue. - if !bound { - demand.get_or_insert_with(|| ComputeDemand::new(&self.shared)); - Backend::ensure_compute(self, required, &admission)?; admission.check()?; - } - let lease = self.shared.preparations.enter_until(&admission)?; - // Work states free as this context's earlier commands retire. - match packet.completion.work_state()?.acquire(crate::g17::job::Engine::Compute) { - Err(error) if error == EBUSY => { + if self + .shared + .crashed + .load(core::sync::atomic::Ordering::Acquire) + { + return Err(EIO); + } + let recovery_state = super::recovery::Memory::recovery_state(&firmware.init)?; + if firmware.recovery.pending() || recovery_state != 0 { + admission.extend_for_recovery(); + drop(state); drop(lease); self.shared.queue_events(); - self.wait_release(progress, observed, &admission)?; + admission.timed(AdmissionWait::Recovery, || { + self.wait_release(progress, observed, &admission) + })?; continue; } - result => { - result?; + firmware.replay_compute(deferred)?; + if !firmware.init.compute_vm_cached(self.context.vm()) + || !firmware.queues.compute_bound(self.owner, &self.context, required)? + { + bound = false; + drop(state); + drop(lease); + continue; } - } - let mut state = self.shared.state.lock(); - let firmware = (*state).as_deref_mut().ok_or(ENODEV)?; - if !lease.is_current() { - drop(state); - continue; - } - admission.check()?; - if self - .shared - .crashed - .load(core::sync::atomic::Ordering::Acquire) - { - return Err(EIO); - } - let recovery_state = super::recovery::Memory::recovery_state(&firmware.init)?; - if firmware.recovery.pending() || recovery_state != 0 { - admission.extend_for_recovery(); - drop(state); - drop(lease); - self.shared.queue_events(); - self.wait_release(progress, observed, &admission)?; - continue; - } - firmware.replay_compute(deferred)?; - if !firmware.init.compute_vm_cached(self.context.vm()) - || !firmware.queues.compute_bound(self.owner, &self.context, required)? - { - bound = false; - drop(state); - drop(lease); - continue; - } - let held = self.claim_outer(firmware, crate::g17::job::Engine::Compute)?; - if let (false, Some(domain), Some(claimed)) = (held, &outer, claimed) { - // The shared work ring has no unclaimed room: consumption or returned claims - // free it. - drop(state); - drop(lease); - self.shared.queue_events(); - self.wait_release(domain, claimed, &admission)?; - continue; - } - let dependencies = firmware.queues.render_prefix(self.owner, packet)?; - admission.check()?; - let result = self.publish_claimed(firmware, packet, dependencies.as_slice(), deferred); - if !packet.is_published() - && (matches!(result, Err(EAGAIN)) - || (matches!(result, Err(EBUSY)) - && (firmware.recovery.pending() - || super::recovery::Memory::recovery_state(&firmware.init)? != 0))) - { - // Recovery or backpressure: nothing is firmware-visible. Other - // queues keep submitting and the event worker retires meanwhile. - if firmware.recovery.pending() - || super::recovery::Memory::recovery_state(&firmware.init)? != 0 + let held = self.claim_outer(firmware, crate::g17::job::Engine::Compute)?; + if let (false, Some(domain), Some(claimed)) = (held, &outer, claimed) { + // The shared work ring has no unclaimed room: consumption or returned claims + // free it. + drop(state); + drop(lease); + self.shared.queue_events(); + admission.timed(AdmissionWait::OuterRoom, || { + self.wait_release(domain, claimed, &admission) + })?; + continue; + } + let dependencies = firmware.queues.render_prefix(self.owner, packet)?; + admission.check()?; + let result = self.publish_claimed(firmware, packet, dependencies.as_slice(), deferred); + if !packet.is_published() + && (matches!(result, Err(EAGAIN)) + || (matches!(result, Err(EBUSY)) + && (firmware.recovery.pending() + || super::recovery::Memory::recovery_state(&firmware.init)? != 0))) { - admission.extend_for_recovery(); + // Recovery or backpressure: nothing is firmware-visible. Other + // queues keep submitting and the event worker retires meanwhile. + let recovering = firmware.recovery.pending() + || super::recovery::Memory::recovery_state(&firmware.init)? != 0; + if recovering { + admission.extend_for_recovery(); + } + drop(state); + drop(lease); + self.shared.queue_events(); + let wait = if recovering { AdmissionWait::Recovery } else { AdmissionWait::Publication }; + admission.timed(wait, || self.wait_release(progress, observed, &admission))?; + continue; } - drop(state); - drop(lease); - self.shared.queue_events(); - self.wait_release(progress, observed, &admission)?; - continue; - } - if result.is_ok() { - self.remember_direct(&firmware.queues); + if result.is_ok() { + self.remember_direct(&firmware.queues); + } + return result; } - return result; + })(); + if matches!(result, Err(error) if error == EBUSY) && !packet.is_published() && admission.expired() { + self.report_admission_expiry(&admission); + } + result + } + + /// Warns about a compute publication whose admission budget ran out, so that the lost + /// device it causes can be attributed: the time spent in each wait, the owner's queue + /// installation state and the recovery state. Rate-limited to the first few per boot. + fn report_admission_expiry(&self, admission: &Admission<'_>) { + static REPORTS: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0); + const ADMISSION_REPORTS: u32 = 8; + const NAMES: [&str; ADMISSION_WAITS] = + ["sources", "channel", "preparation", "work state", "recovery", "outer room", "publication"]; + if REPORTS.load(Ordering::Relaxed) >= ADMISSION_REPORTS { + return; + } + let (total, spent) = admission.spent_ms(); + // Read under the device mutex, print after it is released. + let (queue, pending, recovery_state) = { + let state = self.shared.state.lock(); + let Some(firmware) = (*state).as_deref() else { + return; + }; + ( + firmware.queues.compute(self.owner).map(|queue| queue.admission_state()), + firmware.recovery.pending(), + super::recovery::Memory::recovery_state(&firmware.init), + ) + }; + if REPORTS.fetch_add(1, Ordering::Relaxed) >= ADMISSION_REPORTS { + return; } + pr_warn!( + "asahi: G17: compute publication of owner {} gave up after {} ms; ms by wait: {}={} {}={} {}={} {}={} {}={} {}={} {}={}; queue {:?}; recovery pending {}, state {:?}\n", + self.owner, total, + NAMES[0], spent[0], NAMES[1], spent[1], NAMES[2], spent[2], NAMES[3], spent[3], + NAMES[4], spent[4], NAMES[5], spent[5], NAMES[6], spent[6], + queue, pending, recovery_state, + ); } } diff --git a/tools/asahi/g17-compute-constructor-tests.py b/tools/asahi/g17-compute-constructor-tests.py index 3c96caec2c19a..d5a3bbdeb44d2 100644 --- a/tools/asahi/g17-compute-constructor-tests.py +++ b/tools/asahi/g17-compute-constructor-tests.py @@ -28,6 +28,10 @@ def fixture(): preparation = (ROOT / 'preparation.rs').read_text() admission = (item(preparation, "pub(super) struct Admission<'a>") + '\n' + item(preparation, "impl<'a> Admission<'a>")).replace('pub(super) ', '').replace('super::now_ns()', 'now_ns()').replace('super::timeout::', '') + # The admission's wait kinds and their count, which its struct names. + admission = ('#[derive(Clone,Copy,Debug,PartialEq)]\n' + item(preparation, 'pub(super) enum AdmissionWait').replace('pub(super) ', '') + '\n' + + next(line for line in preparation.splitlines() if 'const ADMISSION_WAITS:' in line).replace('pub(super) ', '') + + '\n' + admission) methods = '\n'.join(item(runtime, sig) for sig in [' fn shared_compute(', ' fn compute_scheduler(']) methods = methods.replace('super::object::Allocator', 'Allocator').replace('super::preparation::Lease', 'Lease').replace('super::initdata::', '') return r''' diff --git a/tools/asahi/g17-compute-deadline-tests.py b/tools/asahi/g17-compute-deadline-tests.py index 45e95c0026ead..a97a3b4021e74 100644 --- a/tools/asahi/g17-compute-deadline-tests.py +++ b/tools/asahi/g17-compute-deadline-tests.py @@ -41,6 +41,8 @@ def fixture(): admission = (item(preparation, "pub(super) struct Admission<'a>") + '\n' + item(preparation, "impl<'a> Admission<'a>")).replace('pub(super) ', '').replace('super::now_ns()', 'now_ns()').replace('super::timeout::', '') gate = item(preparation, 'pub(super) fn enter_until(').replace('pub(super) ', '') + waits = '#[derive(Clone,Copy,Debug,PartialEq)]\n' + item(preparation, 'pub(super) enum AdmissionWait').replace('pub(super) ', '') + waits += '\n' + next(line for line in preparation.splitlines() if 'const ADMISSION_WAITS:' in line).replace('pub(super) ', '') queue_wait = next(line for line in preparation.splitlines() if 'const QUEUE_WAIT_NS:' in line).replace('pub(super) ', '') return r''' #![allow(dead_code,unused_variables,irrefutable_let_patterns)] @@ -56,6 +58,7 @@ def fixture(): static NOW:AtomicU64=AtomicU64::new(0);static CALLS:AtomicUsize=AtomicUsize::new(0); static MODE:AtomicUsize=AtomicUsize::new(0);static CANCEL:AtomicU64=AtomicU64::new(u64::MAX); static STATUS:AtomicU64=AtomicU64::new(u64::MAX);static CLOSED:AtomicBool=AtomicBool::new(false); +static REPORTED:AtomicUsize=AtomicUsize::new(usize::MAX); fn now_ns()->u64{NOW.load(Ordering::SeqCst)} fn advance(ns:u64){NOW.fetch_add(ns,Ordering::SeqCst);assert!(now_ns()<=PUBLICATION_WAIT_NS+4_000_000_000,"admission budget exceeded");} mod kernel{pub mod time{ @@ -63,7 +66,7 @@ def fixture(): pub struct Delta(pub u64);impl Delta{pub fn from_millis(ms:u64)->Self{Self(ms*1_000_000)}pub fn from_micros(us:i64)->Self{Self(us as u64*1_000)}} pub mod delay{pub fn fsleep(d:super::Delta){crate::advance(d.0);}} }} -''' + admission + r''' +''' + waits + '\n' + admission + r''' struct Wait; impl Wait{fn lock(&self){}} struct Changed; @@ -97,7 +100,8 @@ def fixture(): fn release_compute_witness(&self,_:&Init,_:&(),_:u64,_:&mut DeferredBatch)->Result{Ok(MODE.load(Ordering::SeqCst)==2)} } struct Firmware{recovery:Recovery,init:Init,queues:Queues,port:()} -impl Firmware{fn replay_compute(&mut self,_:&mut DeferredBatch)->Result{Ok(())}fn publish_compute(&mut self,_:u64,_:Arc,_:&[()],_:&mut DeferredBatch)->Result{Err(EAGAIN)}} +// Mode 6: the publication itself refuses with EBUSY (no recovery): an immediate error, not a spent budget. +impl Firmware{fn replay_compute(&mut self,_:&mut DeferredBatch)->Result{Ok(())}fn publish_compute(&mut self,_:u64,_:Arc,_:&[()],_:&mut DeferredBatch)->Result{if MODE.load(Ordering::SeqCst)==6{advance(5_000_000);Err(EBUSY)}else{Err(EAGAIN)}}} struct State(Mutex>>);impl State{fn lock(&self)->MutexGuard<'_,Option>>{self.0.lock().unwrap()}} struct Available;impl Available{fn observe(&self)->u64{now_ns()}} struct Shared{preparations:Arc,state:State,crashed:AtomicBool,compute_blocks:usize,active_cores:u32,progress:Available}impl Shared{fn queue_events(&self){}} @@ -120,6 +124,14 @@ def fixture(): admission.check() } fn admission_open(&self)->Result{Ok(())} + // Records the wait the reported budget mostly went to (usize::MAX: no report). + fn report_admission_expiry(&self,admission:&Admission<'_>){ + let (total,spent)=admission.spent_ms(); + // No wait timed: nothing to name (max_by_key would pick the last kind). + let most=if spent.iter().all(|&ms|ms==0){usize::MAX-1}else{(0..ADMISSION_WAITS).max_by_key(|&w|spent[w]).unwrap()}; + assert!(spent.iter().sum::()<=total+1,"waits are timed once each"); + REPORTED.store(most,Ordering::SeqCst); + } // The real ensure_compute forwards the original context into this allocation // boundary. Each success loses its binding before the publication mutex. fn build_compute(&self,_:usize,admission:&Admission<'_>)->Result{ @@ -131,9 +143,11 @@ def fixture(): let b=Backend{owner:1,context:Context,shared:Shared{compute_blocks:21,active_cores:1,progress:Available,preparations:Arc::new(Gate{wait:Wait,changed:Changed}),state:State(Mutex::new(Some(Box::new(Firmware{recovery:Recovery,init:Init,queues:Queues,port:()})))),crashed:AtomicBool::new(false)}}; let p=Arc::new(Packet{command:Validated::Compute{scratch:Scratch},completion:Completion}); for mode in 0..4 { - MODE.store(mode,Ordering::SeqCst);NOW.store(0,Ordering::SeqCst);CALLS.store(0,Ordering::SeqCst); + MODE.store(mode,Ordering::SeqCst);NOW.store(0,Ordering::SeqCst);CALLS.store(0,Ordering::SeqCst);REPORTED.store(usize::MAX,Ordering::SeqCst); let r=b.compute_packet(&p,&mut DeferredBatch); assert_eq!(r,Err(EBUSY),"one admission budget covers binding theft/recovery/publication"); + let named=[AdmissionWait::Channel,AdmissionWait::Recovery,AdmissionWait::Publication,AdmissionWait::Publication][mode]; + assert_eq!(REPORTED.load(Ordering::SeqCst),named as usize,"the report names the wait the budget went to"); let budget=if mode==1{PUBLICATION_WAIT_NS}else{QUEUE_WAIT_NS}; assert!(now_ns()>=budget&&now_ns()<=budget+10_000_000,"admission budget exceeded"); if mode==0{assert_eq!(CALLS.load(Ordering::SeqCst),(QUEUE_WAIT_NS/500_000_000) as usize);assert_eq!(now_ns(),QUEUE_WAIT_NS);} @@ -141,16 +155,26 @@ def fixture(): } // A context without a free work state waits for one under the admission // deadline instead of failing the packet at once. - MODE.store(4,Ordering::SeqCst);NOW.store(0,Ordering::SeqCst);CALLS.store(0,Ordering::SeqCst); + MODE.store(4,Ordering::SeqCst);NOW.store(0,Ordering::SeqCst);CALLS.store(0,Ordering::SeqCst);REPORTED.store(usize::MAX,Ordering::SeqCst); let r=b.compute_packet(&p,&mut DeferredBatch); assert_eq!(r,Err(EBUSY),"a busy work state ends at the admission deadline"); + assert_eq!(REPORTED.load(Ordering::SeqCst),AdmissionWait::WorkState as usize,"the report names the wait the budget went to"); assert!(now_ns()>=QUEUE_WAIT_NS&&now_ns()<=QUEUE_WAIT_NS+10_000_000,"a busy work state waits for the admission deadline"); println!("PASS busy work state waits elapsed_ms={}",now_ns()/1_000_000); + // An EBUSY refusal before the deadline is returned as before and is not a spent budget. + MODE.store(6,Ordering::SeqCst);NOW.store(0,Ordering::SeqCst);REPORTED.store(usize::MAX,Ordering::SeqCst); + let r=b.compute_packet(&p,&mut DeferredBatch); + assert_eq!(r,Err(EBUSY),"a refusal is returned at once"); + assert!(now_ns()= self.deadline.get()', 'if false'), 'admission budget exceeded'), ('render-work-state', source.replace('acquire(crate::g17::job::Engine::Compute)', 'acquire(crate::g17::job::Engine::Render)'), 'compute admission takes a compute work state'), ('omit-gate-check', source.replace(' admission.check()?;\n match self.try_enter()', ' match self.try_enter()').replace('admission.slice_ms()?', '10'), 'gate wake storm'), ('no-recovery-extension', source.replace('admission.extend_for_recovery();', ''), 'recovery extension'), + ('report-every-error', source.replace('if matches!(result, Err(error) if error == EBUSY) && !packet.is_published() && admission.expired() {', 'if result.is_err() {'), 'only a spent budget is reported'), + ('report-without-expiry', source.replace(' && admission.expired() {', ' {'), 'only a spent budget is reported'), + ('untimed-publication', source.replace('admission.timed(wait, || self.wait_release(progress, observed, &admission))?;', 'self.wait_release(progress, observed, &admission)?;'), 'the report names the wait'), ] # Bind the old unbounded mutant with the review's eventual cancellation. mutants[1] = (mutants[1][0], mutants[1][1].replace('for mode in 0..4 {', 'CANCEL.store(PUBLICATION_WAIT_NS+10_000_000_000,Ordering::SeqCst);\n for mode in 0..4 {'), mutants[1][2]) diff --git a/tools/asahi/g17-compute-growth-deadline-tests.py b/tools/asahi/g17-compute-growth-deadline-tests.py index 4cff04e4343e0..1a29447f2f07e 100644 --- a/tools/asahi/g17-compute-growth-deadline-tests.py +++ b/tools/asahi/g17-compute-growth-deadline-tests.py @@ -28,6 +28,10 @@ def fixture(): prep = (ROOT / 'preparation.rs').read_text() admission = (item(prep, "pub(super) struct Admission<'a>") + '\n' + item(prep, "impl<'a> Admission<'a>")).replace('pub(super) ', '').replace('super::now_ns()', 'now_ns()').replace('super::timeout::', '') + # The admission's wait kinds and their count, which its struct names. + admission = ('#[derive(Clone,Copy,Debug,PartialEq)]\n' + item(prep, 'pub(super) enum AdmissionWait').replace('pub(super) ', '') + '\n' + + next(line for line in prep.splitlines() if 'const ADMISSION_WAITS:' in line).replace('pub(super) ', '') + + '\n' + admission) methods = '\n'.join(item(runtime, sig) for sig in [' fn grow_compute(', ' fn finish_uninstalled_compute(']) methods = (methods.replace('super::object::Allocator', 'Allocator').replace('super::freelist::Pages', 'Pages') .replace('super::freelist::ComputeCapacity', 'ComputeCapacity'))