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
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g17/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub(crate) struct Context {
/// profile in every record, ring, doorbell and registration.
policy: Policy,
/// This logical queue's use of the execution context its VM's queues share
/// (`super::exec_share`); `None` on M5.
/// (`super::exec_share`).
share: Option<super::exec_share::Use>,
}
impl Context {
Expand Down
11 changes: 6 additions & 5 deletions drivers/gpu/drm/asahi/g17/exec_share.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! Logical queues of one VM share one UAT execution context (G17P).
//! Logical queues of one VM share one UAT execution context.
//!
//! GPU caches are tagged by address and context: queues of one VM in separate contexts see
//! each other's writes only after a memory-scope write-back at the end of each command, so
Expand All @@ -10,8 +10,7 @@
//! The sharers keep their own scheduler pages, QoS identities and work lists; only the
//! TTBAT slot (the context id) is common. Work keys are the context id plus the low six bits
//! of a work-state word, so the sharers draw their work-state indices from one claim map.
//! The root is released by the last sharer's explicit release; a sharer dropped without one
//! leaves the root to the last reference, as an unshared context does.
//! The root is released when the last sharer leaves, whether by explicit release or drop.

use crate::mmu::{ExecutionContext, Vm};
use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
Expand Down Expand Up @@ -72,7 +71,9 @@ impl Use {
impl Drop for Use {
fn drop(&mut self) {
if !self.done.swap(true, Ordering::AcqRel) {
drop(leave(self.vm, &self.execution));
if let Some(last) = leave(self.vm, &self.execution) {
last.release();
}
}
}
}
Expand All @@ -96,7 +97,7 @@ pub(crate) fn join(vm: &Vm) -> Option<(Arc<ExecutionContext>, Use)> {
let mut shares = SHARES.lock();
let entry = shares
.iter_mut()
.find(|entry| entry.vm == vm.id() && entry.execution.is_current())?;
.find(|entry| entry.execution.vm().same_as(vm) && entry.execution.is_current())?;
entry.users = entry.users.checked_add(1)?;
Some((
entry.execution.clone(),
Expand Down
24 changes: 14 additions & 10 deletions drivers/gpu/drm/asahi/g17/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,9 @@ impl Backend {
};
// The new context may reuse a pooled scheduler page: clear released QoS rows first.
firmware.queues.qos_ids.forget_released(|ids| firmware.port.qos_forget(ids));
// G17P queues of one VM join its live execution context (super::exec_share).
let joined = if firmware.uat.is_m5() { None } else { super::exec_share::join(vm) };
// Queues of one VM share its live execution context (super::exec_share)
// so caches tagged by context ID stay coherent across queues of a client.
let joined = super::exec_share::join(vm);
let attempt = if let Some((execution, share)) = joined {
Ok((
execution,
Expand All @@ -1462,7 +1463,16 @@ impl Backend {
reclaimable,
installed,
)?;
firmware.uat.new_execution_context(vm, super::channel::control_witnessed()).map(|execution| (execution, slot, None))
match firmware.uat.new_execution_context(vm, super::channel::control_witnessed()) {
Ok(execution) => match super::exec_share::offer(vm, &execution) {
Ok(share) => Ok((execution, slot, Some(share))),
Err(error) => {
execution.release();
Err(error)
}
},
Err(error) => Err(error),
}
} else {
Err(ENOSPC)
};
Expand All @@ -1483,8 +1493,7 @@ impl Backend {
break result;
}
Err(error) if error == ENOSPC => {
// Every open queue holds one context; this one holds no
// slot or context any more.
// This creator holds no slot or execution context any more.
let open = firmware.queues.admission.queues();
let closing = firmware.uat.execution_contexts_used().saturating_sub(open);
if closing == 0 || now_ns().saturating_sub(started) >= RETAINED_CONTEXT_WAIT_NS {
Expand Down Expand Up @@ -1514,11 +1523,6 @@ impl Backend {
};
let owner_pid =
u32::try_from(kernel::current!().group_leader().pid()).map_err(|_| EOVERFLOW)?;
let share = match share {
Some(share) => Some(share),
None if !uat.is_m5() => Some(super::exec_share::offer(vm, &execution)?),
None => None,
};
let context = Arc::new(
Context::new(
&alloc,
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,11 @@ impl Vm {
self.id
}

/// True when `self` and `other` refer to the same VM instance.
pub(crate) fn same_as(&self, other: &Vm) -> bool {
Arc::ptr_eq(&self.binding, &other.binding)
}

/// Created by an M5 GPU's UAT ([`Uat::is_m5`]).
pub(crate) fn is_m5(&self) -> bool {
self.m5
Expand Down
Loading