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
16 changes: 8 additions & 8 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl HoldCause {
}

/// Engine statistics, printed by `aurora-g16/stats`.
#[derive(Default, Zeroable)]
#[derive(Zeroable)]
pub(crate) struct Stats {
pub(crate) pub_ns: u64,
pub(crate) idle_from_ns: u64,
Expand Down Expand Up @@ -605,7 +605,7 @@ pub(crate) struct Stats {
/// Host-side phase timers of publication and polling, on with `debug_flags` bit 49
/// (`Debug1`); printed as the `prof:` line of `aurora-g16/stats`. A measurement aid: nothing is
/// timed while the flag is off.
#[derive(Default, Zeroable)]
#[derive(Zeroable)]
pub(crate) struct Prof {
/// Published prefixes timed.
pub(crate) prefixes: u64,
Expand Down Expand Up @@ -993,7 +993,7 @@ impl Firmware {
stage[sizes::render_stage(pair, 1)] = render.user_stamp[1].r32(0)?;
}
for (p, compute) in self.graph.compute.iter().enumerate() {
stage[2 + p] = compute.fw_stamp.r32(0)?;
stage[2 + p] = compute.user_stamp.r32(0)?;
}
Ok(stage)
}
Expand Down Expand Up @@ -2362,7 +2362,7 @@ impl Firmware {
let allowed = if p == 0 {
slot_mask
} else {
slot_mask & !((1u32 << sizes::PIPE1_COMPUTE_START) - 1)
slot_mask & !((1u64 << sizes::PIPE1_COMPUTE_START) - 1)
};
if allowed == 0 || self.slots.compute_exhausted_in_mask(allowed) {
continue;
Expand All @@ -2380,7 +2380,7 @@ impl Firmware {
fn has_compute_pipe_for_vm(
&self,
vm: &Arc<super::vm::VmState>,
slot_mask: u32,
slot_mask: u64,
rt_compute: bool,
) -> bool {
let avoid = self.engine.handoff_avoid_pipes;
Expand Down Expand Up @@ -2424,7 +2424,7 @@ impl Firmware {
&self,
vm: &Arc<super::vm::VmState>,
pipe: usize,
slot_mask: u32,
slot_mask: u64,
) -> Option<usize> {
let mut active_same = [0usize; sizes::COMPUTE_PIPES];
let mut active_other = [false; sizes::COMPUTE_PIPES];
Expand Down Expand Up @@ -2477,7 +2477,7 @@ impl Firmware {
queue: &Arc<super::queue::QueueState>,
vm: &Arc<super::vm::VmState>,
waits: [Option<WaitTarget>; sizes::COMPUTE_PIPES],
slot_mask: u32,
slot_mask: u64,
rt_compute: bool,
heavy_compute: bool,
) -> Option<usize> {
Expand Down Expand Up @@ -2604,7 +2604,7 @@ impl Firmware {
}
None
};
let has_secondary = (slot_mask & !((1u32 << sizes::PIPE1_COMPUTE_START) - 1)) != 0;
let has_secondary = (slot_mask & !((1u64 << sizes::PIPE1_COMPUTE_START) - 1)) != 0;
let prefer_secondary = has_secondary && active_other.iter().any(|&a| a);
if vm_active_pipes < sizes::MAX_VM_COMPUTE_PIPES {
if let Some(p) = pick_idle(prefer_secondary) {
Expand Down
4 changes: 3 additions & 1 deletion drivers/gpu/drm/asahi/g16/fw/work/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ pub(crate) const START_SCS: usize = 0x40;
pub(crate) const EVENT: u32 = 15;
/// Firmware completion events for concurrent compute pipes `0..COMPUTE_PIPES`.
/// All events reside in type-1 event word 1 (`15..32`) so event draining reads only words 1 and 4.
pub(crate) const EVENTS: [u32; 8] = [EVENT, 16, 17, 18, 19, 20, 21, 22];
pub(crate) const EVENTS: [u32; 16] = [
EVENT, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
];

/// Resolves a firmware compute completion event back to its compute pipe index (`0..EVENTS.len()`).
pub(crate) const fn pipe_of_event(event: u32) -> Option<usize> {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g16/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl ComputeGraphSession {
notifier: alloc(o, 0x1000, Class::FwCached, None, 0, false)?,
threshold: alloc(o, 24, Class::Fw, None, 0, false)?,
job_list: alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?,
q: QueueSession::new(o)?,
q: QueueSession::new_with(o, None)?,
})
}
fn finish(self, rings: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<ComputeGraph> {
Expand Down
79 changes: 49 additions & 30 deletions drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,12 +1224,14 @@ pub(crate) mod client {
// pack at a 40 MiB stride from 0x7080000000 up to the SCS compute records (0x70b8000000),
// clear of [`DYNAMIC`] and [`SCS_POOLS`] and leaving 7.25 MiB guard above each unit's
// 32.75 MiB footprint (`0x20c0000`). Every alias is inside Mesa's reserved hole.
pub(crate) const EXT_COMPUTE_STRIDE: u64 = 0x02800000;
pub(crate) const EXT_COMPUTE_POOL_STRIDE: u64 = 0x02100000;
pub(crate) const EXT_COMPUTE_REC_BASE: u64 = 0x70b4000000;
pub(crate) const EXT_COMPUTE_REC_STRIDE: u64 = 0x00100000;
pub(crate) const fn compute_base(k: u64) -> u64 {
if k < 2 {
0x7001000000 + k * 0x04000000
} else {
0x7080000000 + (k - 2) * EXT_COMPUTE_STRIDE
0x7080000000 + (k - 2) * EXT_COMPUTE_POOL_STRIDE
}
}
pub(crate) const fn compute_pool(k: u64) -> u64 {
Expand All @@ -1242,13 +1244,25 @@ pub(crate) mod client {
compute_base(k) + 0x2020000
}
pub(crate) const fn compute_preempt(k: u64) -> u64 {
compute_base(k) + 0x2030000
if k < 2 {
compute_base(k) + 0x2030000
} else {
EXT_COMPUTE_REC_BASE + (k - 2) * EXT_COMPUTE_REC_STRIDE
}
}
pub(crate) const fn compute_aux(k: u64) -> u64 {
compute_base(k) + 0x2040000
if k < 2 {
compute_base(k) + 0x2040000
} else {
EXT_COMPUTE_REC_BASE + (k - 2) * EXT_COMPUTE_REC_STRIDE + 0x10000
}
}
pub(crate) const fn compute_context(k: u64) -> u64 {
compute_base(k) + 0x2080000
if k < 2 {
compute_base(k) + 0x2080000
} else {
EXT_COMPUTE_REC_BASE + (k - 2) * EXT_COMPUTE_REC_STRIDE + 0x40000
}
}
pub(crate) const WORK_PAGE: u64 = 0x7000100000;
pub(crate) const WORK_OFF: u64 = 0;
Expand Down Expand Up @@ -1400,9 +1414,9 @@ pub(crate) mod sizes {
/// `notifier`, `threshold`, `job_list`) and completion event (`work::compute::EVENTS`) so
/// concurrent compute VMs lease disjoint workqueues instead of mixing ASIDs in one active
/// `qinfo`. Pipe 0 exclusively owns `0..PIPE1_COMPUTE_START` for base-only and SCS VMs;
/// secondary pipes `1..COMPUTE_PIPES` share `PIPE1_COMPUTE_START..COMPUTE_UNITS` (18 units
/// for 7 secondary pipes, leaving 11 active units beyond the 7 undisplaced retired leases).
pub(crate) const COMPUTE_PIPES: usize = 8;
/// secondary pipes `1..COMPUTE_PIPES` share `PIPE1_COMPUTE_START..COMPUTE_UNITS` (58 units
/// for 15 secondary pipes, leaving 43 active units beyond the 15 undisplaced retired leases).
pub(crate) const COMPUTE_PIPES: usize = 16;
/// Maximum concurrent compute pipes one VM may occupy at once, preserving the render
/// ring-entry bound (`MAX_RENDER_RING_ENTRIES = 5`) since cross-VM render/compute drains.
pub(crate) const MAX_VM_COMPUTE_PIPES: usize = 2;
Expand Down Expand Up @@ -1480,7 +1494,7 @@ pub(crate) mod sizes {
/// queue/recovery capacities: `47` in-flight passes consume at most `47 * 4 = 188` entries of
/// each 256-entry TA/FS work ring (`QUEUE_CAP = 256`, 255 usable, ring cap `63`), use
/// per-allocator hardware UMA slots `RENDER_UMA_SLOT + slot` (`33..38`, strictly inside the
/// firmware render slot range `33..64`), post at most `FLIGHTS = 32` `SubmitRecord`s (vs
/// firmware render slot range `33..64`), post at most `FLIGHTS = 64` `SubmitRecord`s (vs
/// `AHEAD_RECORDS = 128` / `RING_SLOTS = 256`), and stay far below the firmware recovery
/// `snapshot_entries = 448` limit.
pub(crate) const RENDER_SLOTS: usize = 48;
Expand Down Expand Up @@ -1509,34 +1523,40 @@ pub(crate) mod sizes {
pub(crate) const PB_GROW_STEP: u32 = 10;
/// 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
/// only after a later publication retired (it displaced the unit), so `n` units keep up to
/// `n - 1` compute commands in flight (`23 * 2 = 46` entries of the 256-entry compute work
/// ring `QUEUE_CAP`, well inside `AHEAD_RECORDS = 128`, `RING_SLOTS = 256`, and recovery
/// `snapshot_entries = 448`).
pub(crate) const COMPUTE_UNITS: usize = 24;
/// and recovery paths drain. Bounded by channel ahead limit (`AHEAD_RECORDS = 128`).
pub(crate) const FLIGHTS: usize = 64;
/// Retained compute units per VM at most. Non-SCS compute VMs share one UMA descriptor,
/// pool, and hardware UMA slot (`1..=32`) across all units, so unit count is bounded by
/// the 26B123 compute work ring (`(COMPUTE_UNITS - 1) * MAX_COMPUTE_RING_ENTRIES < 256`,
/// `63 * 3 = 189 < 256`), the `u64` slot mask (`<= 64`), `SCHEDULER_CREDITS = 64`, and
/// recovery `snapshot_entries = 448`. With `COMPUTE_PIPES = 16` holding up to 16
/// undisplaced retired owners, 64 units leave 48 reusable units (3 per VM at 16 processes).
pub(crate) const COMPUTE_UNITS: usize = 64;
/// Disjoint per-VM client VA windows for `SharedComputeUma` pool/freelist/list allocation
/// (2 base windows + 24 extension windows below `EXT_COMPUTE_REC_BASE`).
pub(crate) const COMPUTE_UMA_WINDOWS: usize = 26;
/// Device-wide hardware compute UMA manager slots (`COMPUTE_UMA_SLOT..RENDER_UMA_SLOT`,
/// slots `1..=32`). Non-SCS compute VMs share one UMA descriptor, pool, and hardware slot
/// across all of their compute units and pipes so firmware skips UMA teardown and rebind
/// while any command of the VM remains queued or active.
pub(crate) const COMPUTE_UMA_SLOTS: usize =
(super::engine::RENDER_UMA_SLOT - super::engine::COMPUTE_UMA_SLOT) as usize;
const _: () = assert!(COMPUTE_UMA_SLOTS == 32);
const _: () = assert!(COMPUTE_UNITS >= 2);
const _: () = assert!(COMPUTE_UNITS >= 2 && COMPUTE_UNITS <= 64);
const _: () = assert!((COMPUTE_UNITS - 1) * MAX_COMPUTE_RING_ENTRIES < QUEUE_CAP as usize);
const _: () =
assert!(super::client::compute_list(2) + 0x4000 <= super::client::compute_base(3));
const _: () = assert!(
super::client::compute_context(2) + 0x40000 <= super::client::compute_base(3)
);
const _: () = assert!(
super::client::compute_base(COMPUTE_UNITS as u64) <= super::client::PB_HEAP
super::client::compute_base(COMPUTE_UMA_WINDOWS as u64)
<= super::client::EXT_COMPUTE_REC_BASE
);
const _: () =
assert!(super::client::compute_context(2) + 0x40000 <= super::client::compute_preempt(3));
const _: () = assert!(
super::engine::COMPUTE_UMA_SLOT + (COMPUTE_UNITS as u32)
<= super::engine::RENDER_UMA_SLOT
super::client::compute_context(COMPUTE_UNITS as u64 - 1) + 0x40000
<= super::client::scs_compute_records(0)
);
const _: () = assert!(SCS_COMPUTE_UNITS <= COMPUTE_UMA_SLOTS);
/// SCS-capable compute units per VM, bound dynamically to healthy compute ledger indices
/// (and UMA slots) preferring pipe-0-exclusive indices `0..PIPE1_COMPUTE_START`.
pub(crate) const SCS_COMPUTE_UNITS: usize = 2;
Expand All @@ -1551,11 +1571,10 @@ pub(crate) mod sizes {
/// Bytes of a base UMA pool (its seeds of 4 KiB).
pub(crate) const POOL_BYTES: u64 = 0x2000000;
const _: () = assert!(
super::client::compute_base(COMPUTE_UNITS as u64) <= super::client::scs_compute_records(0)
&& super::client::scs_compute_records(SCS_COMPUTE_UNITS as u64 - 1)
+ super::client::COMPUTE_CONTEXT_OFF
+ 0x40000
<= super::client::scs_compute_records(SCS_COMPUTE_UNITS as u64)
super::client::scs_compute_records(SCS_COMPUTE_UNITS as u64 - 1)
+ super::client::COMPUTE_CONTEXT_OFF
+ 0x40000
<= super::client::scs_compute_records(SCS_COMPUTE_UNITS as u64)
&& super::client::scs_compute_records(SCS_COMPUTE_UNITS as u64)
<= super::client::PB_HEAP
&& super::client::WORK_PAGE
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub(crate) struct Shared {
/// Whether any base compute unit (`0..BASE_COMPUTE_UNITS`) has been quarantined.
pub(crate) base_compute_quarantined: AtomicBool,
/// Bitmask of permanently quarantined device-wide compute units (`0..COMPUTE_UNITS`).
pub(crate) quarantined_compute_mask: AtomicU32,
pub(crate) quarantined_compute_mask: AtomicU64,
/// Bitmask of permanently quarantined device-wide compute UMA slots (`0..COMPUTE_UMA_SLOTS`).
pub(crate) quarantined_compute_uma_mask: AtomicU32,
/// Round-robin cursor assigning each non-SCS compute VM a slot in `0..COMPUTE_UMA_SLOTS`.
Expand Down Expand Up @@ -701,7 +701,7 @@ impl Gpu {
sleep_dark_held: AtomicBool::new(false),
recovering: AtomicBool::new(false),
base_compute_quarantined: AtomicBool::new(false),
quarantined_compute_mask: AtomicU32::new(0),
quarantined_compute_mask: AtomicU64::new(0),
quarantined_compute_uma_mask: AtomicU32::new(0),
next_compute_uma_slot: AtomicU32::new(0),
compute_uma_slot_users,
Expand Down
8 changes: 6 additions & 2 deletions drivers/gpu/drm/asahi/g16/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ pub(crate) fn compute_units() -> usize {
hw::sizes::COMPUTE_UNITS
}

/// Compute commands in flight at most.
/// Compute commands in flight at most: bounded by retained compute units
/// (`COMPUTE_UNITS - 1`, leaving one unit for displacement) and `FLIGHTS`.
pub(crate) fn compute_flights() -> usize {
32usize.clamp(1, hw::sizes::FLIGHTS)
hw::sizes::COMPUTE_UNITS
.saturating_sub(1)
.min(hw::sizes::FLIGHTS)
.max(1)
}

/// Render commands in flight at most: bounded by both retained pass slots
Expand Down
66 changes: 40 additions & 26 deletions drivers/gpu/drm/asahi/g16/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl Firmware {
rmb();
for p in 0..super::hw::sizes::COMPUTE_PIPES {
if let Some(f) = oldest_compute[p] {
if let Ok(obs) = self.graph.compute[p].fw_stamp.r32(0) {
if let Ok(obs) = self.graph.compute[p].user_stamp.r32(0) {
let reached = if compute_behind[p] {
stamp_reached(obs, f.target, self.engine.target[p])
} else {
Expand Down Expand Up @@ -1325,33 +1325,48 @@ impl Firmware {
.is_some()
|| f.rec[2] != self.channels.producer(Channel::Compute);
let g = &self.graph.compute[pipe];
if pipe_behind {
let tail = self.engine.target[pipe];
if !stamp_reached(g.fw_stamp.r32(0)?, f.target, tail)
|| !self.queue_ring_passed(Channel::Compute, &g.qstate, &g.qinfo, f)?
|| !(f.chan_settled
|| self.channel_receipt(Channel::Compute, f.rec[2], chan_behind)?)
{
let tail = self.engine.target[pipe];
let reached = |stamp: u32| {
if pipe_behind {
stamp_reached(stamp, f.target, tail)
} else {
stamp == f.target
}
};
// Compute `fw_stamp` is ASC-cached (`FwCoherent`), matching macOS 26B123. Normal
// flights fail fast on the uncached compute service stamp (`user_stamp`) and never
// read it. The service stamp alone authenticates the receipt: its target is this
// pipe's own ordinal, and the firmware stores it only after updating `fw_stamp` and
// after its last access to the command's work item, microsequence and UMA
// descriptor. The cached notifier record's context word is written back only when
// the record is unlinked, so the host cannot read it reliably. A command a recovery
// aborted may never get its service stamp: a suspect flight whose service stamp is
// stale syncs and checks `fw_stamp` as an independent stage witness, as suspect
// renders do below, so that it reaches the abort grace once its stage and queues
// passed, and not while it still runs.
let served = reached(g.service_stamp().read()?);
if !served {
if !f.recovery_suspect {
return Ok(Retirement::Pending);
}
rmb();
// The service stamp alone authenticates the receipt: its target is this pipe's
// own ordinal, and the firmware stores it only after its last access to the
// command's work item, microsequence and UMA descriptor. The cached notifier
// record's context word is written back only when the record is unlinked, so
// the host cannot read it reliably.
full &= stamp_reached(g.service_stamp().read()?, f.target, tail);
} else {
if g.fw_stamp.r32(0)? != f.target
|| !self.queue_ring_receipt(&g.qstate, &g.qinfo, f.head)?
|| !(f.chan_settled
|| self.channel_receipt(Channel::Compute, f.rec[2], chan_behind)?)
{
g.fw_stamp.sync_for_cpu(0, 4)?;
if !reached(g.fw_stamp.r32(0)?) {
return Ok(Retirement::Pending);
}
rmb();
full &= g.service_stamp().read()? == f.target;
}
let ring = if pipe_behind {
self.queue_ring_passed(Channel::Compute, &g.qstate, &g.qinfo, f)?
} else {
self.queue_ring_receipt(&g.qstate, &g.qinfo, f.head)?
};
if !ring
|| !(f.chan_settled
|| self.channel_receipt(Channel::Compute, f.rec[2], chan_behind)?)
{
return Ok(Retirement::Pending);
}
rmb();
full &= served;
let count = f.claims.slot_count as usize;
full &= count != 0 && count == f.computes as usize;
if full {
Expand Down Expand Up @@ -1986,7 +2001,7 @@ impl Firmware {
for p in 0..CP {
if let Some(f) = fc[p] {
next_progress[p] = pending(
g[p].fw_stamp.r32(0).unwrap_or(0),
g[p].user_stamp.r32(0).unwrap_or(0),
f.target,
e.target[p],
);
Expand Down Expand Up @@ -2283,15 +2298,14 @@ impl Firmware {

dev_info!(
self.graph.dev.as_ref(),
"G16: {}: ctx={} prefixes={} n={} pipe={} target={:#x} user={:#x} fw={:#x} done={} read={} write={} head={} ch={}/{} events={}/{} errors={} busy={} fault={:#x} {}ms\n",
"G16: {}: ctx={} prefixes={} n={} pipe={} target={:#x} user={:#x} done={} read={} write={} head={} ch={}/{} events={}/{} errors={} busy={} fault={:#x} {}ms\n",
what,
f.map_or(0, |f| f.job.vm.slot),
e.flights.len(),
e.ordinal,
pipe,
e.target[pipe],
rd(&g.user_stamp, 0),
rd(&g.fw_stamp, 0),
rd(&g.qstate, qstate::DONE),
rd(&g.qstate, qstate::READ),
rd(&g.qstate, qstate::WRITE),
Expand Down
Loading
Loading