Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4bee746
drm/asahi: g17: enable direct compute submission on M5
DjDeveloperr Nov 23, 2026
9723957
drm/asahi: g17: throttle M5 report drain and coalesce event locks
DjDeveloperr Nov 23, 2026
73103a8
drm/asahi: g17: enable direct render submission on M5
DjDeveloperr Nov 23, 2026
8a1ec93
drm/asahi: g17: reduce M5 direct submit and event lock overhead
DjDeveloperr Nov 23, 2026
d13f235
drm/asahi: g17: reduce M5 multi-queue cluster pinning and outer-lock …
DjDeveloperr Nov 23, 2026
173110e
drm/asahi: g17: single-lock render completion fast path and doorbell …
DjDeveloperr Nov 23, 2026
70c48d2
drm/asahi: g17: run M5 event work beside the submitter, not on its CPU
DjDeveloperr Nov 23, 2026
93f3a20
drm/asahi: g17: retire a lent render pair's completions when it is re…
DjDeveloperr Nov 23, 2026
d10e12a
Merge branch 'main' into perf/asahi-g17-m5-direct-compute
DjDeveloperr Nov 24, 2026
2744163
Merge branch 'perf/asahi-g17-m5-direct-compute' into perf/asahi-g17-m…
DjDeveloperr Nov 24, 2026
2d44b5e
Merge branch 'perf/asahi-g17-m5-direct-render-and-locks' into perf/as…
DjDeveloperr Nov 24, 2026
d268c69
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 24, 2026
64a40b8
Merge branch 'perf/asahi-g17-m5-render-fast-done' into perf/asahi-g17…
DjDeveloperr Nov 24, 2026
5a44dc6
Merge branch 'main' into perf/asahi-g17-m5-direct-compute
DjDeveloperr Nov 25, 2026
889e839
Merge branch 'perf/asahi-g17-m5-direct-compute' into perf/asahi-g17-m…
DjDeveloperr Nov 25, 2026
e967978
Merge branch 'perf/asahi-g17-m5-direct-render-and-locks' into perf/as…
DjDeveloperr Nov 25, 2026
ffc9834
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 25, 2026
539a8fa
Merge branch 'perf/asahi-g17-m5-render-fast-done' into perf/asahi-g17…
DjDeveloperr Nov 25, 2026
61af6c4
drm/asahi: g17: drop the unused unlocked M5 history update
DjDeveloperr Nov 25, 2026
8926e89
Merge branch 'perf/asahi-g17-m5-direct-render-and-locks' into perf/as…
DjDeveloperr Nov 25, 2026
beb9656
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 25, 2026
69f46da
Merge branch 'perf/asahi-g17-m5-render-fast-done' into perf/asahi-g17…
DjDeveloperr Nov 25, 2026
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
32 changes: 23 additions & 9 deletions drivers/gpu/drm/asahi/g17/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! lock round trip.

use super::fence::{self, CompletionFence};
use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use kernel::{
c_str,
dma_fence::{Fence, FenceContexts, RawDmaFence, UserFence},
Expand All @@ -21,12 +22,13 @@ struct Entry {
}

struct State {
generation: u64,
waiters: Option<KBox<Entry>>,
}

#[pin_data]
pub(crate) struct Availability {
generation: AtomicU64,
has_waiters: AtomicBool,
#[pin]
state: Mutex<State>,
fences: FenceContexts,
Expand All @@ -36,8 +38,10 @@ impl Availability {
pub(crate) fn new() -> Result<Arc<Self>> {
Arc::pin_init(
try_pin_init!(Self {
generation: AtomicU64::new(0),
has_waiters: AtomicBool::new(false),
state <- new_mutex!(
State { generation: 0, waiters: None },
State { waiters: None },
"g17::Availability"
),
fences: FenceContexts::new(1, c_str!("aurora_resource"), kernel::static_lock_class!())?,
Expand All @@ -48,11 +52,11 @@ impl Availability {

/// Sample before checking capacity under the resource's own synchronization.
pub(crate) fn observe(&self) -> u64 {
self.state.lock().generation
self.generation.load(Ordering::Acquire)
}

pub(crate) fn has_waiters(&self) -> bool {
self.state.lock().waiters.is_some()
self.has_waiters.load(Ordering::Acquire)
}

/// A fence the next notification signals. None means capacity changed after the sample:
Expand All @@ -69,7 +73,14 @@ impl Availability {
GFP_KERNEL,
)?;
let mut state = self.state.lock();
if state.generation != observed {
// Publish `has_waiters` with SeqCst before re-checking `generation` (SeqCst),
// pairing with `advance()`'s SeqCst fetch_add on `generation` followed by SeqCst
// load of `has_waiters` so no waiter can be lost on the lock-free fast path.
self.has_waiters.store(true, Ordering::SeqCst);
if self.generation.load(Ordering::SeqCst) != observed {
if state.waiters.is_none() {
self.has_waiters.store(false, Ordering::Release);
}
return Ok(None);
}
entry.next = state.waiters.take();
Expand Down Expand Up @@ -115,11 +126,14 @@ impl Availability {

/// Notifies, returning the generation before this notification.
fn advance(&self) -> u64 {
let (previous, mut waiters) = {
let previous = self.generation.fetch_add(1, Ordering::SeqCst);
if !self.has_waiters.load(Ordering::SeqCst) {
return previous;
}
let mut waiters = {
let mut state = self.state.lock();
let previous = state.generation;
state.generation = previous.wrapping_add(1);
(previous, state.waiters.take())
self.has_waiters.store(false, Ordering::Release);
state.waiters.take()
};
while let Some(mut entry) = waiters {
waiters = entry.next.take();
Expand Down
10 changes: 7 additions & 3 deletions drivers/gpu/drm/asahi/g17/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,17 @@ impl InitData {
}

/// M5 TA, fragment and compute share the compute outer ring per priority.
/// The physical queue claim prevents reassignment while this credit lives.
/// The caller must hold `Port::m5_outer`; the physical queue claim prevents
/// reassignment while this credit lives.
pub(crate) fn reserve_outer(&self, priority: u8, count: u32) -> Result<OuterClaim> {
if !self.m5 { return Err(EINVAL); }
let cursors = self.work_cursors(priority, super::fw::queue::DataMaster::Compute)?;
self.outer_credits.as_ref().ok_or(EIO)?.reserve(priority, count, cursors)
}

/// Hold the device mutex for this scope, including its Drop. The result
/// borrows only the claim, allowing the caller to publish through Firmware.
/// Hold the device mutex for this scope, including its Drop, and serialize entry
/// and Drop under `Port::m5_outer` via `Port::outer_scope`. The result borrows
/// only the claim, allowing the caller to publish through Firmware.
pub(crate) fn outer_scope<'a>(&self, claim: &'a mut OuterClaim) -> Result<OuterScope<'a>> {
self.outer_credits.as_ref().ok_or(EINVAL)?.scope(claim)
}
Expand Down Expand Up @@ -1074,6 +1076,8 @@ impl InitData {
// The word recovery_state() reads: the status block moves with the firmware build.
recovery: self.object(self.cluster)?.word(self.recovery_state_offset())?,
mailbox,
m5_credits: self.outer_credits.clone(),
m5_history: self.m5_history_view()?,
})
}

Expand Down
26 changes: 26 additions & 0 deletions drivers/gpu/drm/asahi/g17/initdata/m5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ impl InitData {
ring(0), ring(1), ring(2), ring(3), page(canonical.start)]
}

/// Direct-port view of the M5 submission-history table (none off M5 or on common 26A428).
pub(super) fn m5_history_view(&self) -> Result<Option<crate::g17::port::M5HistoryView>> {
if !self.m5 || self.graph.is_common26() {
return Ok(None);
}
let private = self.object(self.cluster)?;
let base = self.graph.private.status_config;
let field = |offset| {
self.m5_status_config
.relocate(offset)
.map(|at| base + at)
.ok_or(EINVAL)
};
let history = field(m::M5_STATUS_CONFIG_HISTORY)?;
Ok(Some(crate::g17::port::M5HistoryView {
generation: private.word(field(m::M5_STATUS_CONFIG_HISTORY_GENERATION)?)?,
config: [
private.word(history)?,
private.word(history + 4)?,
private.word(history + 8)?,
private.word(history + 12)?,
],
slots: private.pointer(field(m::M5_STATUS_CONFIG_HISTORY_SLOTS)?, 256)?,
}))
}

/// Selects the power-policy layout of the M5 firmware build `build_m5` encodes for.
pub(in crate::g17) fn set_m5_policy_layouts(
&mut self,
Expand Down
147 changes: 141 additions & 6 deletions drivers/gpu/drm/asahi/g17/initdata/outer_credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use kernel::{prelude::*, sync::Arc};

const PRIORITIES: usize = 4;

pub(super) struct Credits {
pub(crate) struct Credits {
reserved: [AtomicU32; PRIORITIES],
published: [AtomicU64; PRIORITIES],
consumers: [AtomicU64; PRIORITIES],
Expand All @@ -24,7 +24,8 @@ pub(crate) struct OuterClaim {
}

/// Borrows the claim only. The caller must hold the device mutex from entry
/// through Drop: its temporarily lent credits are available to that publisher.
/// through Drop and serialize entry and Drop under `Port::m5_outer` (via
/// `Port::outer_scope`): its temporarily lent credits are available to that publisher.
pub(crate) struct OuterScope<'a> {
claim: &'a mut OuterClaim,
before: u64,
Expand All @@ -49,19 +50,23 @@ impl Credits {
}, GFP_KERNEL)?)
}

pub(super) fn available(&self) -> Arc<Availability> { self.available.clone() }
pub(crate) fn available(&self) -> Arc<Availability> { self.available.clone() }

pub(super) fn waiting(&self) -> bool { self.available.has_waiters() }

pub(super) fn capacity(&self, priority: u8, cursors: [u32; 3]) -> Result<u32> {
pub(crate) fn is_scoped(&self) -> bool {
self.scoped.load(Ordering::Acquire)
}

pub(crate) fn capacity(&self, priority: u8, cursors: [u32; 3]) -> Result<u32> {
let pending = self.reserved.get(usize::from(priority)).ok_or(EINVAL)?
.load(Ordering::Acquire);
Ok(free(cursors)?.saturating_sub(pending))
}

/// Reserve under the sole publisher mutex. Off-lock cancellation may only
/// Reserve under the outer-ring lock. Off-lock cancellation may only
/// reduce reserved counts, so the sampled capacity is conservative.
pub(super) fn reserve(self: &Arc<Self>, priority: u8, count: u32,
pub(crate) fn reserve(self: &Arc<Self>, priority: u8, count: u32,
cursors: [u32; 3]) -> Result<OuterClaim>
{
if count == 0 || count >= WORK_RING_SLOTS { return Err(EINVAL); }
Expand All @@ -75,6 +80,26 @@ impl Credits {
Ok(OuterClaim { domain: self.clone(), priority: index, remaining: count })
}

/// Consumes one reserved slot for a direct M5 publication without touching
/// `published[]`, so an enclosing device-mutex `OuterScope` never debits a direct slot.
pub(crate) fn consume_direct(&self, claim: &mut OuterClaim) -> Result {
self.consume_direct_count(claim, 1)
}

/// Consumes `count` reserved slots for a direct M5 publication without touching
/// `published[]`, so an enclosing device-mutex `OuterScope` never debits direct slots.
pub(crate) fn consume_direct_count(&self, claim: &mut OuterClaim, count: u32) -> Result {
if count == 0 || !core::ptr::eq(self, &*claim.domain) {
return Err(EINVAL);
}
if claim.remaining < count {
return Err(EIO);
}
claim.remaining -= count;
self.reserved[claim.priority].fetch_sub(count, Ordering::AcqRel);
Ok(())
}

pub(super) fn scope<'a>(self: &Arc<Self>, claim: &'a mut OuterClaim) -> Result<OuterScope<'a>> {
if !Arc::ptr_eq(self, &claim.domain) { return Err(EINVAL); }
if self.scoped.swap(true, Ordering::AcqRel) { return Err(EBUSY); }
Expand Down Expand Up @@ -116,6 +141,11 @@ impl OuterClaim {
pub(crate) fn remaining(&self) -> u32 {
self.remaining
}

/// Priority class of the reserved outer work ring.
pub(crate) fn priority(&self) -> usize {
self.priority
}
}

impl Drop for OuterClaim {
Expand All @@ -128,3 +158,108 @@ impl Drop for OuterClaim {
}
}
}

#[kernel::macros::kunit_tests(asahi_g17_outer_credit)]
mod tests {
use super::*;

#[test]
fn direct_consumption_does_not_debit_outer_scope() {
let credits = Credits::new().unwrap();
let cursors = [0, 0, 0];
let full = free(cursors).unwrap();
let mut scoped_claim = credits.reserve(1, 2, cursors).unwrap();
let mut direct_claim = credits.reserve(1, 1, cursors).unwrap();
let mut direct_pair = credits.reserve(1, 2, cursors).unwrap();
assert_eq!(credits.capacity(1, cursors).unwrap(), full - 5);

// Direct publish consumes only its own reserved slots and leaves published[] untouched.
assert!(!credits.is_scoped());
credits.consume_direct(&mut direct_claim).unwrap();
assert_eq!(direct_claim.remaining(), 0);
credits.consume_direct_count(&mut direct_pair, 2).unwrap();
assert_eq!(direct_pair.remaining(), 0);
assert_eq!(credits.capacity(1, cursors).unwrap(), full - 2);
assert_eq!(credits.counter(1).unwrap().load(Ordering::Acquire), 0);

// An OuterScope taken afterward keeps its full 2 credits when nothing published via it.
{
let _scope = credits.scope(&mut scoped_claim).unwrap();
assert!(credits.is_scoped());
assert!(credits.reserve(1, 1, cursors).is_err());
}
assert!(!credits.is_scoped());
assert_eq!(scoped_claim.remaining(), 2);
drop(direct_claim);
drop(direct_pair);
drop(scoped_claim);
assert_eq!(credits.capacity(1, cursors).unwrap(), full);
}

#[test]
fn mixed_render_compute_wrap_and_generation_change_with_queued_claim() {
let credits = Credits::new().unwrap();
let n = WORK_RING_SLOTS;
// Producer sits two slots before wrap while both consumers lag 4 slots behind
// (free = WORK_RING_SLOTS - 5).
let mut consumer_a = n - 6;
let mut consumer_b = n - 6;
let mut producer = n - 2;
let cursors = [consumer_a, consumer_b, producer];
let initial_free = free(cursors).unwrap();
assert_eq!(initial_free, n - 5);

// Interleave a queued 2-slot render claim with 1-slot compute claims across ring wrap.
let mut queued_render = credits.reserve(2, 2, cursors).unwrap();
let mut compute_a = credits.reserve(2, 1, cursors).unwrap();
credits.consume_direct(&mut compute_a).unwrap();
producer = (producer + 1) % n; // n - 1
assert_eq!(
credits.capacity(2, [consumer_a, consumer_b, producer]).unwrap(),
initial_free - 3,
);

let mut compute_b = credits.reserve(2, 1, [consumer_a, consumer_b, producer]).unwrap();
credits.consume_direct(&mut compute_b).unwrap();
producer = (producer + 1) % n; // 0 (wrapped!)
assert_eq!(producer, 0);

// Fill remaining capacity so exactly 1 free slot remains; 2-slot render must fail EBUSY
// while 1-slot compute still succeeds across the wrap boundary.
let rem = credits.capacity(2, [consumer_a, consumer_b, producer]).unwrap();
let filler = credits.reserve(2, rem - 1, [consumer_a, consumer_b, producer]).unwrap();
assert_eq!(credits.capacity(2, [consumer_a, consumer_b, producer]).unwrap(), 1);
assert_eq!(credits.reserve(2, 2, [consumer_a, consumer_b, producer]).err(), Some(EBUSY));
let mut edge_compute = credits.reserve(2, 1, [consumer_a, consumer_b, producer]).unwrap();
credits.consume_direct(&mut edge_compute).unwrap();
producer = (producer + 1) % n; // 1
assert_eq!(credits.capacity(2, [consumer_a, consumer_b, producer]).unwrap(), 0);
drop(filler);

// Consumers advance across the wrap boundary and report progress.
consumer_a = 1;
consumer_b = 1;
let wrapped = [consumer_a, consumer_b, producer];
assert!(credits.progressed(2, wrapped).unwrap());
assert_eq!(credits.capacity(2, wrapped).unwrap(), (n - 1) - 2);

// Simulate locked render / recovery entering OuterScope while a queued compute claim
// waits across a generation change: new reserves fail EBUSY and direct consumption never
// debits OuterScope's published counter; dropping the queued claim after the generation
// change releases its reserved credits cleanly.
let queued_compute = credits.reserve(2, 1, wrapped).unwrap();
{
let _scope = credits.scope(&mut queued_render).unwrap();
assert!(credits.is_scoped());
assert_eq!(credits.reserve(2, 1, wrapped).err(), Some(EBUSY));
credits.counter(2).unwrap().fetch_add(2, Ordering::AcqRel);
}
assert!(!credits.is_scoped());
assert_eq!(queued_render.remaining(), 0);
// Generation changed before queued_compute published: dropping it returns its credit.
assert_eq!(queued_compute.remaining(), 1);
drop(queued_compute);
drop(queued_render);
assert_eq!(credits.capacity(2, wrapped).unwrap(), n - 1);
}
}
Loading
Loading