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
11 changes: 11 additions & 0 deletions drivers/gpu/drm/asahi/g17/fw/m5/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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<Self> {
use super::super::{kick::QID_MAX,queue::{Policy,DataMaster}};
const ADDRESS_MASK:u64=0x0000_07ff_ffff_ffe0;
Expand Down
52 changes: 51 additions & 1 deletion drivers/gpu/drm/asahi/g17/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,38 @@ 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.
pub(super) struct Admission<'a> {
deadline: Cell<u64>,
started: u64,
check: &'a dyn Fn() -> Result,
/// Nanoseconds spent in each [`AdmissionWait`] (diagnostics).
spent: [Cell<u64>; ADMISSION_WAITS],
}

/// Bound for a compute publication's waits: a physical compute queue, or room on the shared
Expand All @@ -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<T>(&self, wait: AdmissionWait, f: impl FnOnce() -> Result<T>) -> Result<T> {
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
Expand Down
43 changes: 43 additions & 0 deletions drivers/gpu/drm/asahi/g17/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
consumer: Option<u32>,
configuration: bool,
ordinal: u32,
quarantined: bool,
awaiting_witness: bool,
}

pub(crate) struct Queue {
owner: Option<u64>,
/// Scheduler/work pages of an exited last owner whose context was dropped;
Expand Down Expand Up @@ -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<Packet>, 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.
Expand Down Expand Up @@ -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)
})();
Expand Down
Loading
Loading