Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ impl Completion {
match class {
Class::Spared => 1,
Class::Guilty => 2,
Class::Forfeited => 3,
},
Ordering::Release,
);
Expand All @@ -781,6 +782,11 @@ impl Completion {
self.class.load(Ordering::Acquire) == 2
}

/// See [`Class::Forfeited`].
pub(crate) fn forfeited(&self) -> bool {
self.class.load(Ordering::Acquire) == 3
}

/// A recovery blamed this command, whatever class it keeps: it may have caused the fault,
/// so it is never published again.
pub(crate) fn note_blamed(&self) {
Expand Down
90 changes: 68 additions & 22 deletions drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ pub(crate) struct Packet {
/// When the job's watchdog allowance ends (host ns, [`super::timeout::Allowance::end`]):
/// zero under the default allowance, `u64::MAX` for a longer one not yet placed.
allowance_end: AtomicU64,
/// Another VM's watchdog took the rest of the allowance away
/// ([`super::timeout::Verdict::forfeits`]).
forfeited: AtomicBool,
/// The publication of the command this job was first excused behind
/// ([`super::timeout::Verdict::first_excuse`]); zero before that.
first_excuse: AtomicU64,
/// The command's place in the order both engines publish in
/// ([`super::port::Port::next_publication`]), zero until it is published. The watchdog
/// compares it with the newest publication that retired ([`super::timeout::overtaken`]).
Expand Down Expand Up @@ -177,6 +183,8 @@ impl Packet {
early: AtomicI32::new(0),
backlog: AtomicBool::new(false),
allowance_end: AtomicU64::new(0),
forfeited: AtomicBool::new(false),
first_excuse: AtomicU64::new(0),
ordinal: AtomicU64::new(0),
}));
Ok(packet.into())
Expand All @@ -185,7 +193,30 @@ impl Packet {
/// Its own watchdog still renews the job for the allowance its queue asked for at `now`
/// ([`super::timeout::Head::excused`]).
pub(crate) fn within_allowance(&self, now: u64) -> bool {
now < self.allowance_end.load(Ordering::Relaxed)
!self.forfeited.load(Ordering::Relaxed) && now < self.allowance_end.load(Ordering::Relaxed)
}

/// Ends the job's allowance and every other renewal its own watchdog would grant it
/// ([`super::timeout::Verdict::forfeits`]): its next expiry goes straight to the
/// attribution. Returns whether the job had not lost them already.
pub(crate) fn forfeit_allowance(&self) -> bool {
!self.forfeited.swap(true, Ordering::Relaxed)
}

/// Whether another VM's watchdog took the job's allowance away.
pub(crate) fn allowance_forfeited(&self) -> bool {
self.forfeited.load(Ordering::Relaxed)
}

/// Records the command the job was first excused behind (`published`), once.
pub(crate) fn note_first_excuse(&self, published: u64) {
let _ = self.first_excuse.compare_exchange(0, published, Ordering::Relaxed,
Ordering::Relaxed);
}

/// The command the job was first excused behind; zero if none.
pub(crate) fn first_excuse(&self) -> u64 {
self.first_excuse.load(Ordering::Relaxed)
}

pub(crate) fn engine(&self) -> Engine {
Expand Down Expand Up @@ -437,6 +468,35 @@ impl PublishedExpiry {
}
}

impl<B: Backend> Timeout<B> {
/// Attributes an expiry that no renewal of the job's own covered: deferred or excused
/// behind other work, or given up. `renews_shared` and `since_retired` are the sharing
/// inputs the renewals were decided on, for the log line.
fn settle(&mut self, renews_shared: bool, since_retired: Option<u64>) -> bool {
match self.backend.defer_timeout(&self.packet, self.victim_renewals, self.excused) {
super::timeout::Decision::Defer => {
self.victim_renewals = self.victim_renewals.saturating_add(1);
true
}
super::timeout::Decision::Excuse => {
self.excused = self.excused.saturating_add(1);
true
}
// The backend retired the job on its completion record: its fence has signalled.
super::timeout::Decision::Retire => true,
decision @ (super::timeout::Decision::Own | super::timeout::Decision::Spare) => {
// The sharing inputs are the ones the renewal above was decided on.
self.backend.gave_up(&self.packet, &super::timeout::GaveUp::new(
&self.allowance, super::now_ns(), self.packet.command.long_job(),
self.execution_renewals, renews_shared, self.shared_renewals, since_retired,
self.victim_renewals, self.excused, decision,
));
false
}
}
}
}

impl<B: Backend> Drop for Job<B> {
fn drop(&mut self) {
// Entity teardown can free a queued job without invoking cancel.
Expand Down Expand Up @@ -470,6 +530,12 @@ impl<B: Backend> sched::JobImpl for Job<B> {
if finished || job.packet.completion.take_replay_timeout() {
return true;
}
// A job whose allowance another VM's watchdog took away gets no renewal of its own
// left; only the attribution below decides between failing it and deferring it.
if job.packet.allowance_forfeited() {
let since_retired = super::recovery::since_retired(super::now_ns());
return job.settle(true, since_retired);
}
// Within the allowance its queue asked for. Past it, the deferrals below still apply;
// the shared renewals run alongside an allowance rather than after it.
let placing = job.allowance.placing_after_wait(job.packet.is_published());
Expand Down Expand Up @@ -505,27 +571,7 @@ impl<B: Backend> sched::JobImpl for Job<B> {
if super::timeout::renew_shared(job.packet.is_published(), shared, &mut job.shared_renewals) {
return true;
}
match job.backend.defer_timeout(&job.packet, job.victim_renewals, job.excused) {
super::timeout::Decision::Defer => {
job.victim_renewals = job.victim_renewals.saturating_add(1);
true
}
super::timeout::Decision::Excuse => {
job.excused = job.excused.saturating_add(1);
true
}
// The backend retired the job on its completion record: its fence has signalled.
super::timeout::Decision::Retire => true,
decision @ (super::timeout::Decision::Own | super::timeout::Decision::Spare) => {
// The sharing inputs are the ones the renewal above was decided on.
job.backend.gave_up(&job.packet, &super::timeout::GaveUp::new(
&job.allowance, super::now_ns(), job.packet.command.long_job(),
job.execution_renewals, true, job.shared_renewals, since_retired,
job.victim_renewals, job.excused, decision,
));
false
}
}
job.settle(true, since_retired)
}

fn prepare(job: &mut Self) -> Option<Fence> {
Expand Down
20 changes: 19 additions & 1 deletion drivers/gpu/drm/asahi/g17/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,20 @@ impl Queue {
})
}

/// Takes the rest of its allowance from the command at [`Self::timeout_head`] if that is
/// `head` ([`crate::g17::timeout::Verdict::forfeits`]). Returns whether it lost one. The
/// whole head is compared, so a command whose allowance ended since the verdict (its
/// `excused` changed) keeps nothing to lose and is skipped.
pub(crate) fn forfeit_head(&self, head: crate::g17::timeout::Head) -> bool {
if self.timeout_head() != Some(head) {
return false;
}
self.active
.iter()
.find(|active| !active.stamps_owed)
.is_some_and(|active| active.packet.forfeit_allowance())
}

pub(crate) fn can_classify_timeout(&self, packet: &Arc<Packet>) -> bool {
!self.quarantined && self.owns_packet(packet)
}
Expand Down Expand Up @@ -1487,7 +1501,11 @@ impl Queue {
for active in self.active.iter_mut() {
let completion = &active.packet.completion;
// A command whose stamp is owed ran and has its result.
if active.stamps_owed || completion.spared() || completion.guilty() {
if active.stamps_owed
|| completion.spared()
|| completion.guilty()
|| completion.forfeited()
{
continue;
}
if dropped {
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/queue/compute/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ impl Queue {
/// how long ago the watchdog failed it. The owner's VM has already failed, so it loses
/// nothing it could still use; without the kill a command that never terminates keeps
/// running, and keeps this queue, until the owner closes.
///
/// That holds for a command whose allowance another VM's waiting work took
/// ([`crate::g17::recovery::Class::Forfeited`]) too: only spared work keeps its VM through
/// [`Self::timeout`], so the timeout of a forfeited command fails its VM as it does any
/// command past its allowance. The kill names every queue of the context, sibling
/// channels included, so it must not reach a VM that can still submit to them.
pub(crate) fn open_timeout_kill(&self, now: u64) -> Option<(Arc<Context>, u64)> {
if self.released || self.timed_out_at == 0 || !self.timed_out() {
return None;
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ pub(super) enum Class {
Spared,
/// This VM owns guilty work.
Guilty,
/// The watchdog failed this compute work because another VM's waiting work took the rest
/// of its allowance ([`super::timeout::Verdict::forfeits`]), not because a recovery dropped
/// it. Unlike spared work it fails as a command past its allowance does: its VM fails, and
/// its queue's quarantine is not a spared one, so the queue never returns to service and on
/// M5 its context is killed ([`super::queue::compute::Queue::timed_out`]).
Forfeited,
}

/// Queue operations under the device mutex. Completion signalling belongs to the caller after
Expand Down
11 changes: 11 additions & 0 deletions drivers/gpu/drm/asahi/g17/runtime/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ impl job::Backend for Backend {
decision, blocker.vm, blocker.published, u8::from(blocker.failed),
u8::from(blocker.excused));
}
if let Some(published) = verdict.first_excuse(excuse) {
packet.note_first_excuse(published);
}
if let Some(blocker) =
firmware.queues.forfeit_blocker(&verdict, excuse, packet.first_excuse())
{
dev_warn!(self.shared.dev.as_ref(),
"Render watchdog owner={} vm={} publication={} excused for the longest allowance: blocker_vm={} blocker_publication={} loses its allowance\n",
self.owner, verdict.own.vm, verdict.own.published, blocker.vm,
blocker.published);
}
}
Ok(decision)
})();
Expand Down
22 changes: 20 additions & 2 deletions drivers/gpu/drm/asahi/g17/runtime/compute_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ impl Backend {
verdict.decision = self.retire_on_record(firmware, packet, &mut deferred)?;
}
let decision = verdict.decision;
if decision == Decision::Spare {
// A command that lost its allowance to another VM's waiting work
// ([`timeout::Verdict::forfeits`]) is failed for that. It is not spared: a spared
// quarantine is never killed, and a forfeited command may be one that never ends.
let class = match decision {
Decision::Spare => Some(Class::Spared),
Decision::Own if packet.allowance_forfeited() => Some(Class::Forfeited),
_ => None,
};
if let Some(class) = class {
firmware.queues.compute_for_packet(self.owner, packet).ok_or(EIO)?
.classify(&|_| Class::Spared);
.classify(&|_| class);
}
if let Some(blocker) = verdict.reported_blocker(renewals, excuse) {
dev_warn!(self.shared.dev.as_ref(),
Expand All @@ -58,6 +66,16 @@ impl Backend {
blocker.vm, blocker.published, u8::from(blocker.failed),
u8::from(blocker.excused));
}
if let Some(published) = verdict.first_excuse(excuse) {
packet.note_first_excuse(published);
}
if let Some(blocker) =
firmware.queues.forfeit_blocker(&verdict, excuse, packet.first_excuse())
{
dev_warn!(self.shared.dev.as_ref(),
"Compute watchdog owner={} vm={} publication={} excused for the longest allowance: blocker_vm={} blocker_publication={} loses its allowance\n",
self.owner, own.vm, own.published, blocker.vm, blocker.published);
}
Ok(decision)
})();
deferred.finish();
Expand Down
26 changes: 26 additions & 0 deletions drivers/gpu/drm/asahi/g17/runtime/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,32 @@ impl Registry {
)
})
}

/// Takes the rest of its allowance from the compute command a waiting job's `verdict`
/// charges ([`crate::g17::timeout::Verdict::forfeits`]; only compute commands have one),
/// given the job's excuse and the command it was first excused behind. Returns that
/// command if it lost its allowance here.
pub(in crate::g17) fn forfeit_blocker(
&self,
verdict: &crate::g17::timeout::Verdict,
excuse: crate::g17::timeout::Excuse,
first: u64,
) -> Option<crate::g17::timeout::Head> {
let computes = self
.compute
.iter()
.flatten()
.filter_map(|entry| entry.queue.as_deref())
.filter_map(|queue| queue.timeout_head());
let blocker = verdict.forfeits(excuse, first,
Iterator::chain(self.render_timeout_heads(), computes))?;
self.compute
.iter()
.flatten()
.filter_map(|entry| entry.queue.as_deref())
.any(|queue| queue.forfeit_head(blocker))
.then_some(blocker)
}
}

impl RenderState {
Expand Down
Loading
Loading