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
15 changes: 14 additions & 1 deletion drivers/gpu/drm/asahi/g17/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ pub(crate) struct Context {
/// 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.
/// Whether this logical queue has submitted render work (so compute may have a render prefix).
render_seen: AtomicBool,
/// Number of currently active (published and unretired) render entries for this context.
render_active: AtomicU32,
qos: Arc<QosLease>,
owner_pid: u32,
states: WorkStates,
Expand Down Expand Up @@ -386,6 +388,7 @@ impl Context {
compute_bindings: AtomicU32::new(0),
compute_ordinal: AtomicU32::new(0),
render_seen: AtomicBool::new(false),
render_active: AtomicU32::new(0),
qos,
owner_pid,
states: match &share {
Expand Down Expand Up @@ -428,6 +431,16 @@ impl Context {
self.render_seen.store(true, Ordering::Release);
}
}
/// Active (published and unretired) render count for this context.
pub(crate) fn render_active(&self) -> u32 {
self.render_active.load(Ordering::Acquire)
}
pub(crate) fn inc_render_active(&self) {
self.render_active.fetch_add(1, Ordering::AcqRel);
}
pub(crate) fn dec_render_active(&self) {
self.render_active.fetch_sub(1, Ordering::AcqRel);
}
pub(crate) fn note_compute_binding(&self, owned: bool) {
if owned {
self.compute_bindings.fetch_add(1, Ordering::AcqRel);
Expand Down
65 changes: 48 additions & 17 deletions drivers/gpu/drm/asahi/g17/queue/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ struct Active {
stamps_owed: bool,
}

impl Drop for Active {
fn drop(&mut self) {
self.packet.context.dec_render_active();
}
}

/// A render packet parked for replay after GPU recovery. Holds the context's
/// `render_active` count across `active -> replay -> republish/fail/drop` so
/// `compute_direct()` never mistakes a context with parked replay renders for
/// render-idle.
struct ParkedReplay {
packet: Arc<Packet>,
}

impl ParkedReplay {
fn new(packet: Arc<Packet>) -> Self {
packet.context.inc_render_active();
Self { packet }
}
}

impl Drop for ParkedReplay {
fn drop(&mut self) {
self.packet.context.dec_render_active();
}
}

/// A firmware-retired, unexecuted group must hold on two observations this far
/// apart before it is republished; a single sample may straddle an update.
const ABANDON_GRACE_NS: u64 = 2_000_000;
Expand Down Expand Up @@ -257,7 +284,7 @@ pub(crate) struct Pair {
context_update: bool,
/// Retired, never-executed groups awaiting republication on this pair, in
/// their original order. Nothing else is prepared on the pair before them.
replay: Tracker<Arc<Packet>>,
replay: Tracker<ParkedReplay>,
/// Recovery generation of this pair's last executed retirement.
executed_generation: Option<u64>,
/// When the oldest parked group was parked or the last one republished.
Expand Down Expand Up @@ -484,13 +511,13 @@ impl Pair {
self.replay.len() != 0 && crate::g17::timeout::background_stalled(self.replay_since, now)
}
pub(crate) fn replay_front(&self) -> Option<Arc<Packet>> {
self.replay.front().cloned()
self.replay.front().map(|parked| parked.packet.clone())
}
pub(crate) fn finish_replay(&mut self, packet: &Arc<Packet>) -> Result {
if !self
.replay
.front()
.is_some_and(|front| Arc::ptr_eq(front, packet))
.is_some_and(|front| Arc::ptr_eq(&front.packet, packet))
{
return Err(EIO);
}
Expand Down Expand Up @@ -522,7 +549,7 @@ impl Pair {
|| self
.replay
.front()
.is_some_and(|front| !Arc::ptr_eq(front, packet))
.is_some_and(|front| !Arc::ptr_eq(&front.packet, packet))
|| !Arc::ptr_eq(&self.memory.context, &packet.context)
|| !packet.context.is_current()
{
Expand Down Expand Up @@ -1272,6 +1299,7 @@ impl Pair {
let pm_submission = memory.manager.prepare_submission()?;
let published = host.next_publication()?;
packet.note_ordinal(published);
packet.context.inc_render_active();
self.active
.push(Active {
published,
Expand Down Expand Up @@ -1867,7 +1895,9 @@ impl Pair {
.any(|active| active.stamps_owed && Arc::ptr_eq(&active.packet, packet))
}
pub(crate) fn replay_contains(&self, packet: &Arc<Packet>) -> bool {
self.replay.iter().any(|replay| Arc::ptr_eq(replay, packet))
self.replay
.iter()
.any(|replay| Arc::ptr_eq(&replay.packet, packet))
}
pub(crate) fn take_deferred_timeout(&self) -> Option<(Arc<Packet>, Error)> {
self.active.iter().find_map(|active| {
Expand Down Expand Up @@ -2418,9 +2448,9 @@ impl Pair {
}
/// The oldest parked group precedes a command waiting through `through`.
pub(crate) fn replay_through(&self, through: Option<u64>) -> bool {
self.replay
.front()
.is_some_and(|packet| crate::g17::job::Order::contains(through, packet.order.sequence))
self.replay.front().is_some_and(|parked| {
crate::g17::job::Order::contains(through, parked.packet.order.sequence)
})
}

/// Every retained group was retired and unlinked by firmware without
Expand Down Expand Up @@ -2587,11 +2617,12 @@ impl Pair {
self.active.pop().ok_or(EIO)?;
continue;
}
let parked = ParkedReplay::new(packet.clone());
self.memory.retire(ordinal)?;
self.active.pop().ok_or(EIO)?;
packet.reset_publication_for_replay();
self.published_completions = None;
self.replay.push(packet).map_err(|_| EIO)?;
self.replay.push(parked).map_err(|_| EIO)?;
}
Ok(true)
}
Expand Down Expand Up @@ -2723,7 +2754,7 @@ impl Pair {
self.replay_since = None;
// A descriptor prepared for the front and never published goes with it, or the pair
// would take no work again.
if let Some(front) = self.replay.front().cloned() {
if let Some(front) = self.replay.front().map(|parked| parked.packet.clone()) {
if self
.prepared
.as_ref()
Expand All @@ -2732,8 +2763,8 @@ impl Pair {
self.discard_prepared(&front)?;
}
}
while let Some(packet) = self.replay.pop() {
defer(Deferred::Retired(packet.completion.clone(), Err(error)))?;
while let Some(parked) = self.replay.pop() {
defer(Deferred::Retired(parked.packet.completion.clone(), Err(error)))?;
}
Ok(())
}
Expand All @@ -2752,9 +2783,9 @@ impl Pair {
self.slot,
self.replay.len()
);
for packet in self.replay.iter() {
if !packet.completion.guilty() {
packet.completion.classify(recovery::Class::Spared);
for parked in self.replay.iter() {
if !parked.packet.completion.guilty() {
parked.packet.completion.classify(recovery::Class::Spared);
}
}
self.fail_replay(ENODATA, defer)
Expand Down Expand Up @@ -3132,8 +3163,8 @@ impl Pair {
self.active.pop().ok_or(EIO)?;
}
self.replay_since = None;
while let Some(packet) = self.replay.pop() {
defer(Deferred::Drained(packet.completion.clone(), Err(EIO)))?;
while let Some(parked) = self.replay.pop() {
defer(Deferred::Drained(parked.packet.completion.clone(), Err(EIO)))?;
}
if let Some(previous) = self.previous.as_mut() {
previous.ready = true;
Expand Down
35 changes: 32 additions & 3 deletions drivers/gpu/drm/asahi/g17/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3303,8 +3303,7 @@ impl Backend {
let m5 = self.context.is_m5();
let has_sources = packet.completion.sources().is_some();
let bound_count = self.context.compute_binding_count() as usize;
if self.context.render_seen()
|| bound_count == 0
if bound_count == 0
|| bound_count > super::pairs::COMPUTE_CHANNELS_MAX
|| (bound_count > 1 && packet.order.wait_through[1].is_some())
|| packet.cancel_requested()
Expand All @@ -3313,6 +3312,9 @@ impl Backend {
{
return None;
}
if let Err(error) = packet.check_firmware_producers() {
return Some(Err(error));
}
let cells = self.direct.lock().clone();
let cached_count = cells.iter().filter(|cell| cell.is_some()).count();
if cached_count != bound_count || cells[0].is_none() {
Expand All @@ -3325,12 +3327,39 @@ impl Backend {
return None;
}
let generation = port.generation();
let (direct_frontier, direct_native, direct_holds, cross_qid_mask) =
let (mut direct_frontier, direct_native, direct_holds, cross_qid_mask) =
if let Some(sources) = packet.completion.sources() {
self.resolve_direct_sources(port, generation, target_qid, m5, sources)?
} else {
(super::dependency::Frontier::new(), KVec::new(), KVec::new(), 0)
};
// Mixed-engine contexts resolve any active render prefix briefly under the device mutex
// (and skip the mutex altogether when no render of this context is in flight), then keep
// compute descriptor encoding, cache maintenance, and doorbell rings off the device mutex.
if self.context.render_seen()
&& packet.order.wait_through[0].is_some()
&& self.context.render_active() != 0
{
let render_frontier = {
let state = self.shared.state.lock();
let firmware = (*state).as_deref()?;
if !lease.is_current()
|| firmware.recovery.pending()
|| firmware.queues.render.replay_parked()
{
return None;
}
match firmware.queues.render_prefix(self.owner, packet) {
Ok(frontier) => frontier,
Err(error) => return Some(Err(error)),
}
};
for dep in render_frontier.as_slice() {
if direct_frontier.insert(0, *dep).is_err() {
return None;
}
}
}
// Only an independent kick without input sources of an owner whose primary channel runs
// sustained heavy work may leave the primary ring ([`Self::fans_out`]); the primary
// cell's lock-free hint answers that without a lock.
Expand Down
Loading
Loading