Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
550b955
drm/asahi: g17: deduplicate sync-input chains and resolve M5 cross-QI…
DjDeveloperr Nov 23, 2026
7bb65ce
drm/asahi: g17: fan M5 Pro compute out to sibling channels for sustai…
DjDeveloperr Nov 23, 2026
5eb4df2
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 24, 2026
d61af75
Merge branch 'perf/asahi-g17-m5-direct-cross-qid-sources' into perf/a…
DjDeveloperr Nov 24, 2026
e5c2f09
drm/asahi: g17: count render-pair demand for a fresh sibling compute QID
DjDeveloperr Nov 24, 2026
e5b20d9
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 25, 2026
5af9de5
Merge branch 'perf/asahi-g17-m5-direct-cross-qid-sources' into perf/a…
DjDeveloperr Nov 25, 2026
b15be7d
drm/asahi: g17: wrap the submission state initializer to 100 columns
DjDeveloperr Nov 25, 2026
cfcfd4e
Merge branch 'perf/asahi-g17-m5-direct-cross-qid-sources' into perf/a…
DjDeveloperr Nov 25, 2026
d60d7b9
drm/asahi: g17: wrap the sibling compute lines to 100 columns
DjDeveloperr Nov 25, 2026
e35ddb5
Merge branch 'perf/asahi-g17-m5-multiqueue-contention' into perf/asah…
DjDeveloperr Nov 25, 2026
9b419de
Merge branch 'perf/asahi-g17-m5-direct-cross-qid-sources' into perf/a…
DjDeveloperr Nov 25, 2026
df36284
drm/asahi: g17: collect given-up compute channels without allocating …
DjDeveloperr Nov 25, 2026
c9d9d6b
Merge branch 'main' into perf/asahi-g17-m5-direct-cross-qid-sources
DjDeveloperr Nov 25, 2026
75774d0
Merge branch 'perf/asahi-g17-m5-direct-cross-qid-sources' into perf/a…
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
4 changes: 4 additions & 0 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub(crate) const DRM_ASAHI_COMPUTE_VISIBLE_COMPLETION: u32 =
/// (`drm_asahi_queue_create::compute_timeout_ms`).
pub(crate) const DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT: u64 =
uapi::DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT as u64;
/// The kernel spreads one compute queue's independent commands over several firmware compute
/// queues itself.
pub(crate) const DRM_ASAHI_FEATURE_COMPUTE_MULTI_CHANNEL: u64 =
uapi::DRM_ASAHI_FEATURE_COMPUTE_MULTI_CHANNEL as u64;
/// The tiling half waits only on the render and compute prefixes of the command's stage-prefix
/// fields, its fragment half on the whole ones.
#[allow(dead_code)]
Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/asahi/g17/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ impl Completion {
pub(super) fn is_input_source(&self, source: &Arc<super::fence::Submission>) -> bool {
self.output.output().member.is_source(source)
}
pub(crate) fn note_source_published(&self, published: super::fence::PublishedSource) {
self.output.output().member.note_published(published);
}
pub(crate) fn clear_source_published(&self) {
self.output.output().member.clear_published();
}
pub(super) fn set_source_ready(&self, ready: Fence) {
self.output.output().member.set_source_ready(ready);
}
Expand Down Expand Up @@ -682,6 +688,7 @@ impl Completion {
})
.is_ok();
if accepted {
self.clear_source_published();
self.replay_timeout.store(true, Ordering::Release);
// Callers replay only work proven not to have started; the new
// publication runs from the beginning and reports its own result.
Expand All @@ -700,6 +707,7 @@ impl Completion {

pub(crate) fn has_firmware_consumer(&self) -> bool {
self.firmware_consumer.load(Ordering::Acquire)
|| self.output.output().member.has_firmware_consumer()
}

pub(crate) fn take_replay_timeout(&self) -> bool {
Expand Down
40 changes: 34 additions & 6 deletions drivers/gpu/drm/asahi/g17/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,12 @@ pub(crate) struct Context {
/// A kill of this context was published, through a compute queue or on its render pairs'
/// behalf. A context is killed at most once.
kill_published: AtomicBool,
/// Advisory only: publication still checks the physical binding under the
/// device mutex. False skips an inline attempt known to need admission.
compute_binding_hint: AtomicBool,
/// Advisory count of bound compute channels: publication still checks the physical binding
/// under the device mutex. Zero skips an inline attempt known to need admission.
compute_bindings: AtomicU32,
/// Shared monotonic compute completion ordinal / submit sequence across an M5 multi-channel
/// context's physical compute queues.
compute_ordinal: AtomicU32,
/// Mixed-engine contexts keep the original inline publication path.
render_seen: AtomicBool,
qos: Arc<QosLease>,
Expand Down Expand Up @@ -349,7 +352,8 @@ impl Context {
scheduler_generation,
published: AtomicBool::new(false),
kill_published: AtomicBool::new(false),
compute_binding_hint: AtomicBool::new(false),
compute_bindings: AtomicU32::new(0),
compute_ordinal: AtomicU32::new(0),
render_seen: AtomicBool::new(false),
qos,
owner_pid,
Expand All @@ -376,7 +380,11 @@ impl Context {
}
pub(crate) fn compute_binding_hint(&self) -> bool {
self.render_seen.load(Ordering::Acquire)
|| self.compute_binding_hint.load(Ordering::Relaxed)
|| self.compute_bindings.load(Ordering::Relaxed) != 0
}
/// Advisory count of physical compute channels currently bound to this context.
pub(crate) fn compute_binding_count(&self) -> u32 {
self.compute_bindings.load(Ordering::Acquire)
}
/// This logical queue has submitted render work, so its compute may have a render prefix.
pub(crate) fn render_seen(&self) -> bool {
Expand All @@ -388,7 +396,27 @@ impl Context {
}
}
pub(crate) fn note_compute_binding(&self, owned: bool) {
self.compute_binding_hint.store(owned, Ordering::Relaxed);
if owned {
self.compute_bindings.fetch_add(1, Ordering::AcqRel);
} else {
let _ = self
.compute_bindings
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |n| {
Some(n.saturating_sub(1))
});
}
}
/// Atomically allocates the next 1-based shared compute ordinal and packed
/// `(predecessor_id << 32) | current_id` descriptor object_ids pair for a multi-channel
/// M5 context, so concurrent direct submissions across sibling QIDs never collide on
/// `submit_sequence`, `completion_ordinal`, or `object_ids`.
pub(crate) fn next_compute_identity(&self) -> (u32, u64) {
let prev = self.compute_ordinal.fetch_add(1, Ordering::AcqRel);
let next = prev.wrapping_add(1);
let predecessor_id = if prev == 0 { 1 } else { prev };
let current_id = if next == 0 { 1 } else { next };
let object_ids = (u64::from(predecessor_id) << 32) | u64::from(current_id);
(next, object_ids)
}
pub(crate) fn compute_timestamps(&self) -> &Arc<super::completion::ComputeTimestampCache> {
&self.compute_timestamps
Expand Down
93 changes: 87 additions & 6 deletions drivers/gpu/drm/asahi/g17/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,20 @@ pub(super) unsafe fn exported_source_raw(raw: *mut bindings::dma_fence) -> Optio
.cloned()
}

/// Immutable cross-QID kick metadata published once a compute source is committed in firmware.
/// Consumers on the same VM read this without acquiring the global device mutex.
#[derive(Clone)]
pub(crate) struct PublishedSource {
pub(crate) epoch: u64,
pub(crate) published: u64,
pub(crate) dependency: super::fw::kick::KickDependency,
pub(crate) readers: Arc<core::sync::atomic::AtomicU32>,
}

struct State {
work: Option<Arc<WorkStateLease>>,
ready: Option<Fence>,
published: Option<PublishedSource>,
}

// One Member per parsed command, plus the enqueue guard. Exported references
Expand All @@ -236,6 +247,8 @@ kernel::static_assert!(crate::file::MAX_COMMANDS_PER_SUBMISSION < u8::MAX as u32
pub(crate) struct Submission {
#[pin]
state: Mutex<State>,
/// Immutable VM status of this submission, stored outside `state` so `same_vm()` is lock-free.
vm_status: Option<Arc<super::status::VmStatus>>,
remaining: AtomicU8,
error: AtomicI32,
/// Live Member objects, plus the enqueue guard, independently of signalling.
Expand All @@ -245,22 +258,38 @@ pub(crate) struct Submission {
/// is queued, before its fence is signalled off-lock: a consumer published
/// in between needs no wait on it.
retired: AtomicBool,
/// Non-zero encoded recovery epoch (`epoch.wrapping_add(1)`) while `state.published` holds a
/// live `PublishedSource` snapshot, or `0` when unpublished.
published_epoch: AtomicU64,
/// Set atomically when a firmware kick depends on this source so replay/retirement
/// observes consumers without scanning producer queues under the device mutex.
firmware_consumer: AtomicBool,
}

impl Submission {
fn encode_epoch(epoch: u64) -> u64 {
epoch.wrapping_add(1)
}
fn new(context: Arc<Context>, firmware_source: bool) -> Result<Arc<Self>> {
let work = Arc::new(WorkStateLease::deferred(context)?, GFP_KERNEL)?;
Self::with_work(Some(work), firmware_source)
}
fn with_work(work: Option<Arc<WorkStateLease>>, firmware_source: bool) -> Result<Arc<Self>> {
let vm_status = work.as_ref().map(|work| work.status().clone());
Arc::pin_init(
pin_init!(Self {
state <- new_mutex!(State { work, ready: None }, "G17 submission work state"),
state <- new_mutex!(
State { work, ready: None, published: None },
"G17 submission work state"
),
vm_status,
remaining: AtomicU8::new(1),
error: AtomicI32::new(0),
owners: AtomicU8::new(1),
firmware_source,
retired: AtomicBool::new(false),
published_epoch: AtomicU64::new(0),
firmware_consumer: AtomicBool::new(false),
}),
GFP_KERNEL,
)
Expand All @@ -275,15 +304,55 @@ impl Submission {
Ok(complete)
}
pub(super) fn same_vm(&self, status: &Arc<super::status::VmStatus>) -> bool {
self.state
.lock()
.work
self.vm_status
.as_ref()
.is_some_and(|work| Arc::ptr_eq(work.status(), status))
.is_some_and(|vm| Arc::ptr_eq(vm, status))
}
pub(super) fn ready(&self) -> Option<Fence> {
self.state.lock().ready.clone()
}
pub(super) fn set_published(&self, source: PublishedSource) {
if !self.firmware_source {
return;
}
let tag = Self::encode_epoch(source.epoch);
let mut state = self.state.lock();
if state.work.is_some()
&& self.error.load(Ordering::Acquire) == 0
&& !self.retired.load(Ordering::Acquire)
{
state.published = Some(source);
self.published_epoch.store(tag, Ordering::Release);
}
}
pub(super) fn clear_published(&self) {
if self.published_epoch.swap(0, Ordering::AcqRel) == 0 {
return;
}
let old = self.state.lock().published.take();
drop(old);
}
pub(super) fn published_source(&self, epoch: u64) -> Option<PublishedSource> {
if !self.has_published_epoch(epoch) {
return None;
}
let state = self.state.lock();
state
.published
.as_ref()
.filter(|source| source.epoch == epoch)
.cloned()
}
pub(super) fn has_published_epoch(&self, epoch: u64) -> bool {
let tag = Self::encode_epoch(epoch);
self.firmware_source && tag != 0 && self.published_epoch.load(Ordering::Acquire) == tag
}
pub(super) fn note_firmware_consumer(&self) {
self.firmware_consumer.store(true, Ordering::Release);
}
pub(super) fn has_firmware_consumer(&self) -> bool {
self.firmware_consumer.load(Ordering::Acquire)
}
fn set_ready(&self, ready: Fence) {
if !self.firmware_source {
return;
Expand All @@ -294,14 +363,16 @@ impl Submission {
}
}
fn note_error(&self, error: Error) -> bool {
self.clear_published();
self.error
.compare_exchange(0, error.to_errno(), Ordering::AcqRel, Ordering::Acquire)
.is_ok()
}
fn release_state(&self) {
self.published_epoch.store(0, Ordering::Release);
let old = {
let mut state = self.state.lock();
(state.work.take(), state.ready.take())
(state.work.take(), state.ready.take(), state.published.take())
};
drop(old);
}
Expand Down Expand Up @@ -406,8 +477,18 @@ impl Member {
let source = self.aggregate.source();
if source.firmware_source {
source.retired.store(true, Ordering::Release);
source.clear_published();
}
}
pub(super) fn note_published(&self, published: PublishedSource) {
self.aggregate.source().set_published(published);
}
pub(super) fn clear_published(&self) {
self.aggregate.source().clear_published();
}
pub(super) fn has_firmware_consumer(&self) -> bool {
self.aggregate.source().has_firmware_consumer()
}
pub(crate) fn complete(&self, result: Result) {
if !self.complete.swap(true, Ordering::AcqRel) {
self.aggregate
Expand Down
23 changes: 18 additions & 5 deletions drivers/gpu/drm/asahi/g17/fw/m5/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ pub(crate) fn explicit_dependency(board: &Board) -> u8 {
/// Dependency class of a compute kick's implicit parent (the previous kick of its queue) on
/// `board`. With the counted forms ([`counted_forms`]) it is class 1, which holds the kick until
/// its parent has completed. On boards whose explicit waits take the completion class
/// ([`Board::completion_inputs`]) a parent the host has already retired (`parent_retired`) takes
/// the pipelined class instead, as macOS's late-published M5 Pro kicks do: there is nothing left
/// to hold for. Otherwise it is the pipelined class, with which a kick may start while its parent
/// still runs.
/// ([`Board::completion_inputs`]), a parent the host has already retired (`parent_retired`) takes
/// the pipelined class instead: there is nothing left on that physical QID to hold for.
/// Otherwise it is the pipelined class, with which a kick may start while its parent still runs.
pub(crate) fn parent_dependency(board: &Board, parent_retired: bool) -> u8 {
if !counted_forms(board) || (parent_retired && board.completion_inputs()) {
COMPUTE_PIPELINED_DEPENDENCY
Expand All @@ -60,6 +59,16 @@ pub(crate) fn parent_dependency(board: &Board, parent_retired: bool) -> u8 {
}
}

/// Whether `board` spreads a logical compute queue across multiple physical compute channels
/// ([`Board::compute_channels`]) sharing one context, QoS slot, scheduler page, and work-state
/// table, each with its own dedicated compute pool. Each physical QID still holds a
/// completion-class implicit parent while its own prior kick is active, preventing two kicks
/// from overlapping on one QID's single preemption/operand/usage state; concurrency comes
/// strictly from independent kicks running across distinct sibling QIDs.
pub(crate) fn multi_channel(board: &Board) -> bool {
board.compute_channels() > 1
}

/// Whether compute kicks on `board` count their completion ordinal and hold for their parent:
/// with the G17D forms, on boards whose explicit waits take the completion class
/// ([`Board::completion_inputs`]), as macOS encodes M5 Pro compute, and on the J813, whose
Expand Down Expand Up @@ -465,6 +474,8 @@ pub(crate) struct DescriptorArgs {
pub(crate) stamp_va: [u64; 2],
pub(crate) stamp_value: u32,
pub(crate) qid: u32,
/// Per-context compute channel index (0, 1, 2 for a multi-channel owner; 0 otherwise).
pub(crate) channel_index: u32,
pub(crate) kick_timestamp: u64,
pub(crate) completion_ordinal: u32,
pub(crate) status_va: [u64; 2],
Expand Down Expand Up @@ -503,7 +514,8 @@ pub(crate) struct Descriptor {
stamp_va: [u64; 2],
stamp_value: u32,
qid: u32,
reserved_f58: u64,
channel_index: u32,
reserved_f5c: u32,
kick_timestamp: u64,
current_id: u64,
completion_ordinal: u32,
Expand Down Expand Up @@ -574,6 +586,7 @@ impl Descriptor {
self.stamp_va = args.stamp_va;
self.stamp_value = args.stamp_value;
self.qid = args.qid;
self.channel_index = args.channel_index;
self.kick_timestamp = args.kick_timestamp;
self.current_id = args.registers.object_ids as u32 as u64;
self.completion_ordinal = args.completion_ordinal;
Expand Down
Loading
Loading