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
176 changes: 139 additions & 37 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,46 @@ enum PublicationError {
Uncertain(Error),
}

/// Why a publication pass stopped at a ready job without publishing it (`Stats::hold_causes`).
///
/// A drain cause means the job waits for an empty engine; the others wait behind in-flight
/// work for headroom or ordering.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) enum HoldCause {
/// The job's VM failed, or a flight is doomed or suspect in a recovery.
DrainFailed,
/// A cold `InitBM` render is in flight.
DrainInitbm,
/// Compute behind any flight of another VM, render behind compute of another VM, or an
/// SCS compute conflict.
DrainCross,
/// No warm PB/UMA allocator slot of the VM can take the render behind active flights.
DrainPb,
/// The TA wave window is full.
TaWave,
/// Flight, render pass or compute unit headroom.
Slot,
/// The job's dependency check failed: it fails once it reaches publication.
/// (`Engine::pick()` skips jobs still waiting for a dependency.)
Dependency,
/// Any other admission refusal behind in-flight work.
Other,
}

impl HoldCause {
pub(crate) const COUNT: usize = 8;
pub(crate) const NAMES: [&'static str; Self::COUNT] = [
"drain_failed",
"drain_initbm",
"drain_cross",
"drain_pb",
"ta_wave",
"slot",
"dependency",
"other",
];
}

/// Engine statistics, printed by `aurora-g16/stats`.
#[derive(Default, Zeroable)]
pub(crate) struct Stats {
Expand Down Expand Up @@ -474,6 +514,8 @@ pub(crate) struct Stats {
/// Why ready jobs stayed unpublished: both flights published, a channel record unconsumed,
/// no free slot.
pub(crate) hold: [u64; 3],
/// `hold[0]` split by [`HoldCause`].
pub(crate) hold_causes: [u64; HoldCause::COUNT],
/// Compute commands published behind in-flight ones.
pub(crate) behind: u64,
/// Most flights in flight at once.
Expand Down Expand Up @@ -610,6 +652,13 @@ pub(crate) struct Engine {
pub(crate) ta_wave_wait: bool,
/// An EP 0x20 event arrived with a flight still settling its final receipt: repoll sooner.
pub(crate) short_repoll: bool,
/// An idle poll pass inside the housekeeping cadence skipped housekeeping: queue a backup
/// poll so it runs once the cadence elapses.
pub(crate) housekeeping_owed: bool,
/// A ready job is held behind flights that all belong to its own VM, for any cause but a
/// failure, a cross-VM overlap or a failed dependency: one of those flights retiring is
/// what releases it, so repoll soon instead of after `resnap_us`.
pub(crate) held_wait: bool,
/// Absolute deadline (`ktime_get_ns`) for busy-state same-queue horizon micro-coalescing
/// (0 when no batch is held).
pub(crate) coalesce_deadline_ns: u64,
Expand Down Expand Up @@ -657,6 +706,8 @@ impl Engine {
slot_wait: false,
ta_wave_wait: false,
short_repoll: false,
housekeeping_owed: false,
held_wait: false,
coalesce_deadline_ns: 0,
progress_flight: [0; 3],
progress: [None; 4],
Expand Down Expand Up @@ -1006,6 +1057,7 @@ impl Firmware {
self.engine.chan_wait = false;
self.engine.slot_wait = false;
self.engine.ta_wave_wait = false;
self.engine.held_wait = false;
self.engine.coalesce_deadline_ns = 0;
while self.recovery.failed().is_none()
&& !self.engine.frozen
Expand All @@ -1028,7 +1080,7 @@ impl Firmware {
&& !self.can_queue_behind_with_ta(&job, &mut ta_pending)
{
if self.needs_engine_drain(&job) {
self.engine.stats.hold[0] += 1;
self.note_hold(&job, true, 0);
break;
}
let ta_val = *ta_pending.get_or_insert_with(|| self.ta_pending_passes());
Expand Down Expand Up @@ -1115,7 +1167,7 @@ impl Firmware {
.check_command_dependencies(cand.progress.sent())
.is_ok()
});
self.engine.stats.hold[0] += 1;
self.note_hold(&job, false, ta_val);
break;
}
}
Expand Down Expand Up @@ -1350,23 +1402,83 @@ impl Firmware {
|| f.recovery_suspect
|| f.initbm
|| (is_compute && scs_compute_conflict(f, &job.vm, is_rt_compute))
|| (((is_compute && f.renders != 0) || (is_render && f.computes != 0))
|| ((is_compute || (is_render && f.computes != 0))
&& !Arc::ptr_eq(&f.job.vm, &job.vm))
})
|| (is_render
&& !job
.resources
.pb_slot_mask()
.and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?)))
.is_ok_and(|(mask, home, blocks)| {
self.pools.can_pipeline_in_mask_blocks_mode(
&job.vm,
mask,
home,
blocks,
job.resources.render_scs(),
)
}))
|| (is_render && !self.render_can_pipeline(job))
}

/// Whether `job`'s render can reuse a warm PB/UMA allocator slot of its VM behind active
/// flights, without the drain that a fresh `InitBM` epoch needs.
fn render_can_pipeline(&self, job: &Arc<Job>) -> bool {
job.resources
.pb_slot_mask()
.and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?)))
.is_ok_and(|(mask, home, blocks)| {
self.pools.can_pipeline_in_mask_blocks_mode(
&job.vm,
mask,
home,
blocks,
job.resources.render_scs(),
)
})
}

/// Why a publication pass stopped at `job`: `drain` when [`Self::needs_engine_drain`]
/// held it, otherwise the first refusal of [`Self::can_queue_behind_with_ta`] that
/// applies, with `ta_pending` from that check. Of the drain causes, a failure, an `InitBM`
/// flight and the PB check are tested directly; what remains of `needs_engine_drain()` is a
/// cross-VM or SCS overlap.
fn hold_cause(&self, job: &Arc<Job>, drain: bool, ta_pending: usize) -> HoldCause {
let render = command(job, job.progress.sent());
if drain {
if job.vm.status.get() != 0
|| self
.engine
.flights
.iter()
.any(|f| f.doomed || f.recovery_suspect)
{
HoldCause::DrainFailed
} else if self.engine.flights.iter().any(|f| f.initbm) {
HoldCause::DrainInitbm
} else if matches!(render, Some(Command::Render(_))) && !self.render_can_pipeline(job) {
HoldCause::DrainPb
} else {
HoldCause::DrainCross
}
} else if job.check_command_dependencies(job.progress.sent()).is_err() {
HoldCause::Dependency
} else if matches!(render, Some(Command::Render(r))
if ta_pending >= self.ta_wave_cap_for(r.is_heavy_ta()))
{
HoldCause::TaWave
} else if self.blocked_on_slot_headroom(job) {
HoldCause::Slot
} else {
HoldCause::Other
}
}

/// Counts a publication pass that stopped at the ready `job` behind in-flight work, and
/// marks it [`Engine::held_wait`] when only its own VM's flights hold it.
fn note_hold(&mut self, job: &Arc<Job>, drain: bool, ta_pending: usize) {
let cause = self.hold_cause(job, drain, ta_pending);
let s = &mut self.engine.stats;
s.hold[0] += 1;
s.hold_causes[cause as usize] += 1;
if !matches!(
cause,
HoldCause::DrainFailed | HoldCause::DrainCross | HoldCause::Dependency
) && self
.engine
.flights
.iter()
.all(|f| Arc::ptr_eq(&f.job.vm, &job.vm))
{
self.engine.held_wait = true;
}
}

/// Whether `job` is ready to run without an engine drain but currently blocked solely on
Expand Down Expand Up @@ -1478,8 +1590,8 @@ impl Firmware {

/// Whether `job`'s next command may be published behind the flights in flight:
///
/// - Compute queues behind healthy non-InitBM compute flights of any VM or same-VM
/// render flights (up to [`params::compute_flights`] active computes), each in its own
/// - Compute queues behind healthy non-InitBM compute and render flights of its own VM
/// (up to [`params::compute_flights`] active computes), each in its own
/// `ComputeSlot` and hardware UMA slot (`COMPUTE_UMA_SLOT + index`), unless `query_access`
/// is set and a same-queue predecessor in its compute or render barrier prefix has
/// CPU-published timestamp outputs that have not retired yet
Expand All @@ -1495,6 +1607,10 @@ impl Firmware {
/// dispatch from one client cannot starve another client's fragment shading into a
/// firmware DM1 timeout. Cold InitBM priming renders and every failure or recovery path
/// still drain the engine first.
/// - Compute never runs beside compute of another VM, on either pipe: with several clients
/// dispatching barrier-free compute, the overlapped dispatches occasionally lost their
/// results without a fault (loads read zero, readbacks came back empty or partial),
/// which one client alone never does. G15 runs one VM at a time for the same reason.
fn can_queue_behind(&self, job: &Arc<Job>) -> bool {
let mut ta_pending = None;
self.can_queue_behind_with_ta(job, &mut ta_pending)
Expand Down Expand Up @@ -1561,17 +1677,14 @@ impl Firmware {
})
})
}));
let cross_vm_render = e
.flights
.iter()
.any(|f| f.renders != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm));
let cross_vm = e.flights.iter().any(|f| !Arc::ptr_eq(&f.job.vm, &job.vm));
let scs = job.resources.compute_scs() || c.is_rt();
let scs_conflict = e
.flights
.iter()
.any(|f| scs_compute_conflict(f, &job.vm, scs));
let compute_count: usize = e.flights.iter().map(|f| f.computes as usize).sum();
!cross_vm_render
!cross_vm
&& !scs_conflict
&& !waits_for_timestamps
&& compute_count < params::compute_flights()
Expand All @@ -1595,19 +1708,7 @@ impl Firmware {
&& !self.slots.render_exhausted()
&& !self.pools.exhausted()
&& super::recovery::logic::next_ordinal(e.draw).is_some()
&& job
.resources
.pb_slot_mask()
.and_then(|(mask, home)| Ok((mask, home, job.resources.pb_heap_blocks()?)))
.is_ok_and(|(mask, home, blocks)| {
self.pools.can_pipeline_in_mask_blocks_mode(
&job.vm,
mask,
home,
blocks,
job.resources.render_scs(),
)
})
&& self.render_can_pipeline(job)
&& job
.resources
.render_passes()
Expand All @@ -1628,6 +1729,7 @@ impl Firmware {
|| self.engine.chan_wait
|| self.engine.slot_wait
|| self.engine.ta_wave_wait
|| self.engine.held_wait
|| self
.engine
.flights
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,9 @@ pub(crate) mod sizes {
pub(crate) const PB_BLOCKS: u32 = 2048;
pub(crate) const PB_LIST_RECORDS: u32 = 4096;
pub(crate) const PB_GROW_STEP: u32 = 10;
/// Published prefixes at most. Warm compute and render commands may pipeline across VMs
/// on disjoint hardware UMA slots while cold `InitBM` renders and recovery paths drain.
/// Published prefixes at most. Warm render commands may pipeline across VMs on disjoint
/// hardware UMA slots, compute only behind its own VM's work, while cold `InitBM` renders
/// and recovery paths drain.
pub(crate) const FLIGHTS: usize = 32;
/// Retained compute units per VM at most; each unit owns its own hardware UMA slot
/// (`COMPUTE_UMA_SLOT + index`, fitting in `1..RENDER_UMA_SLOT = 33`). A unit is reused
Expand Down
Loading