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
14 changes: 14 additions & 0 deletions drivers/gpu/drm/asahi/g17/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,20 @@ impl Completion {
}
}

/// Called under the device mutex and render lock when recovery parks the render for replay.
pub(crate) fn note_render_parked_for_replay(&self) {
if let Some(lease) = self.render.lock().as_ref() {
lease.note_parked_for_replay();
}
}

/// Called under the device mutex and render lock when an executed render retires normally.
pub(crate) fn note_render_executed(&self) {
if let Some(lease) = self.render.lock().as_ref() {
lease.note_executed();
}
}

/// Called under the device mutex before deferring the error signal.
pub(crate) fn quarantine_render(&self) {
if let Some(lease) = self.render.lock().as_ref() {
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,12 @@ impl Packet {
self.publication.load(Ordering::Acquire) == 2
}
/// A published group retired by firmware without executing is published
/// again from the same packet. Publication state returns to "begun".
/// again from the same packet. Publication state returns to "begun", and
/// its admission hazard record drops the discarded fragment kick until it
/// republishes or retires.
pub(crate) fn reset_publication_for_replay(&self) {
self.publication.store(1, Ordering::Release);
self.completion.note_render_parked_for_replay();
}
pub(crate) fn cancel_requested(&self) -> bool {
self.cancelled.load(Ordering::Acquire)
Expand Down
14 changes: 7 additions & 7 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,12 @@ fn compute_channel_features(channels: u8) -> u64 {
}
}

/// Whether the firmware keeps partial renders (tiler-heap overflow fragment passes) strictly
/// ordered behind earlier fragment work: advertised where `fragment_busy` drains an outstanding
/// fragment pass on the pair and each logical render queue uses a single physical render pair.
fn ordered_partial_renders_feature(fragment_busy: bool, render_pairs: u8) -> u64 {
if fragment_busy && render_pairs == 1 {
/// Whether the firmware and queue barrier promotion keep partial renders (tiler-heap overflow
/// fragment passes) strictly ordered behind earlier fragment work: advertised where
/// `fragment_busy` drains an outstanding fragment pass on the same physical render pair and
/// `render_barriers` orders tiling behind any cross-pair fragment dependency.
fn ordered_partial_renders_feature(fragment_busy: bool) -> u64 {
if fragment_busy {
uapi::DRM_ASAHI_FEATURE_ORDERED_PARTIAL_RENDERS as u64
} else {
0
Expand Down Expand Up @@ -3108,8 +3109,7 @@ impl gpu::Gpu for Gpu {
| crate::file::DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT
| compute_channel_features(pairs::compute_channels_per_owner());
let variant = self.shared.variant;
params.features |=
ordered_partial_renders_feature(variant.fragment_busy, pairs::per_owner());
params.features |= ordered_partial_renders_feature(variant.fragment_busy);
// The M5 command set has no AS-build flag: its validation refuses one.
if !variant.m5_commands {
params.features |= u64::from(uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_BOUNDED_AS_BUILD);
Expand Down
151 changes: 143 additions & 8 deletions drivers/gpu/drm/asahi/g17/queue/admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ struct InFlight {
/// Fragment kick of the published render; a later same-VM overlap of
/// another pair waits for it in firmware.
fragment: Option<KickDependency>,
/// Monotonic publication order assigned on first publication, preserved
/// across replays to break mutual waits between overlapping parked renders.
published_order: Option<u64>,
/// True after recovery parks the render for replay and discards its old
/// fragment kick, until it republishes a replacement kick or retires.
parked: bool,
/// True if a later-published overlapping same-VM render executed and
/// retired normally, so replaying this producer would overwrite its output.
later_consumer_executed: bool,
}

const QUARANTINE_WAIT_MS: u32 = 1000;
Expand Down Expand Up @@ -113,6 +122,7 @@ struct State {
epoch: u64,
footprints: KVec<InFlight>,
next_ticket: u64,
next_publication: u64,
}

impl State {
Expand All @@ -139,6 +149,7 @@ impl State {
epoch: 0,
footprints: KVec::new(),
next_ticket: 1,
next_publication: 1,
}
}
fn owns_live(&self, owner: u64, slot: usize) -> bool {
Expand Down Expand Up @@ -835,6 +846,9 @@ impl State {
ticket,
footprint: request.footprint.clone(),
fragment: None,
published_order: None,
parked: false,
later_consumer_executed: false,
},
GFP_KERNEL,
)
Expand Down Expand Up @@ -1639,13 +1653,68 @@ impl RenderLease {
return;
};
if let Some(index) = state.position(self.slot, record) {
state.footprints[index].fragment = Some(fragment);
let order = match state.footprints[index].published_order {
Some(order) => order,
None => {
let order = state.next_publication;
state.next_publication = order.wrapping_add(1).max(1);
order
}
};
let entry = &mut state.footprints[index];
entry.fragment = Some(fragment);
entry.published_order = Some(order);
entry.parked = false;
}
}

/// Called under `port.render_lock()` when recovery parks a previously
/// published render for replay so overlapping renders cannot consume its
/// discarded fragment kick before it republishes or retires.
pub(crate) fn note_parked_for_replay(&self) {
let mut state = self.pool.state.lock();
let Some(record) = self.record else {
return;
};
if let Some(index) = state.position(self.slot, record) {
let entry = &mut state.footprints[index];
entry.fragment = None;
entry.parked = true;
}
}

/// Called under `port.render_lock()` when an executed render retires
/// normally: any earlier-published overlapping same-VM render still in
/// flight can no longer replay ahead of it.
pub(crate) fn note_executed(&self) {
let mut state = self.pool.state.lock();
let Some(record) = self.record else {
return;
};
let Some(index) = state.position(self.slot, record) else {
return;
};
let Some(my_order) = state.footprints[index].published_order else {
return;
};
let my_footprint = state.footprints[index].footprint.clone();
for (other_idx, other) in state.footprints.iter_mut().enumerate() {
if other_idx == index {
continue;
}
if other.published_order.is_some_and(|order| order < my_order)
&& other.footprint.same_vm(&my_footprint)
&& other.footprint.overlaps(&my_footprint)
{
other.later_consumer_executed = true;
}
}
}
}

impl Pool {
/// Under the device mutex, which orders every publication: the newest
/// Under `port.render_lock()`, which orders every device-mutex and direct
/// render publication as well as replay-parking transitions: the newest
/// published fragment kick of each other pair whose live same-VM render
/// overlaps `footprint`. Quarantined pairs are skipped as in admission.
///
Expand All @@ -1660,15 +1729,23 @@ impl Pool {
&self,
owner: u64,
slot: u8,
sequence: u64,
footprint: &Footprint,
prefix: Option<u64>,
barriers: &mut [KickDependency; hazard::PUBLICATION_BARRIERS],
) -> Result<usize> {
let state = self.state.lock();
let self_entry = state
.position(slot, (owner, sequence))
.map(|index| &state.footprints[index]);
if self_entry.is_some_and(|entry| entry.later_consumer_executed) {
return Err(ENODATA);
}
let self_order = self_entry.and_then(|entry| entry.published_order);
let mut slots = [0u8; hazard::PUBLICATION_BARRIERS];
let mut count = 0;
for entry in state.footprints.iter() {
let (Some(other), Some(fragment)) = (entry.slot, entry.fragment) else {
let Some(other) = entry.slot else {
continue;
};
if other == slot
Expand All @@ -1679,6 +1756,32 @@ impl Pool {
{
continue;
}
if let Some(mine) = self_order {
let Some(theirs) = entry.published_order else {
continue;
};
if theirs > mine {
// Preserve original publication direction: never wait on a
// later-published overlapping consumer. If it is already
// parked unexecuted we republish first; if it is still live
// or unobserved, defer until it either parks or retires.
if entry.parked {
continue;
}
if entry.fragment.is_some() {
return Err(EBUSY);
}
continue;
}
if entry.parked {
return Err(EBUSY);
}
} else if entry.parked {
return Err(EBUSY);
}
let Some(fragment) = entry.fragment else {
continue;
};
match slots[..count].iter().position(|known| *known == other) {
// One fragment ring completes in kick order; same QID, so the
// word orders by timestamp.
Expand Down Expand Up @@ -2094,6 +2197,9 @@ mod owner_pair_tests {
ticket: 0,
footprint: footprint.clone(),
fragment: Some(kick(10 + slot, timestamp)),
published_order: Some(sequence),
parked: false,
later_consumer_executed: false,
},
GFP_KERNEL,
)
Expand All @@ -2102,15 +2208,44 @@ mod owner_pair_tests {
}
let mut barriers = [KickDependency::ZERO; hazard::PUBLICATION_BARRIERS];
// On pair 2: pair 1's newest overlapping fragment kick, never its own.
assert_eq!(pool.publication_barriers(1, 2, &footprint, None, &mut barriers).unwrap(), 1);
assert_eq!(pool.publication_barriers(1, 2, 6, &footprint, None, &mut barriers).unwrap(), 1);
assert!(barriers[0] == kick(11, 9));
assert_eq!(pool.publication_barriers(1, 2, &footprint, Some(4), &mut barriers).unwrap(), 1);
assert_eq!(pool.publication_barriers(1, 2, 6, &footprint, Some(4), &mut barriers).unwrap(), 1);
assert!(barriers[0] == kick(11, 9));
// The queue prefix already orders them.
assert_eq!(pool.publication_barriers(1, 2, &footprint, Some(5), &mut barriers).unwrap(), 0);
assert_eq!(pool.publication_barriers(1, 2, 6, &footprint, Some(5), &mut barriers).unwrap(), 0);
// Another owner's render is a barrier whatever the prefix.
assert_eq!(pool.publication_barriers(3, 2, &footprint, Some(9), &mut barriers).unwrap(), 1);
assert_eq!(pool.publication_barriers(3, 3, &footprint, Some(9), &mut barriers).unwrap(), 2);
assert_eq!(pool.publication_barriers(3, 2, 1, &footprint, Some(9), &mut barriers).unwrap(), 1);
assert_eq!(pool.publication_barriers(3, 3, 1, &footprint, Some(9), &mut barriers).unwrap(), 2);

// If an earlier render (seq 4, order 4) parks while a later overlapping
// render (seq 6, order 6) is still live/unobserved, seq 4 defers instead
// of reversing order onto seq 6.
{
let mut state = pool.state.lock();
state.footprints[0].fragment = None;
state.footprints[0].parked = true;
}
assert_eq!(pool.publication_barriers(1, 1, 4, &footprint, None, &mut barriers), Err(EBUSY));
// Once the later render (seq 6) is also parked unexecuted, seq 4 goes first
// while seq 6 and any unrelated new render defer behind seq 4.
{
let mut state = pool.state.lock();
state.footprints[2].fragment = None;
state.footprints[2].parked = true;
}
assert_eq!(pool.publication_barriers(3, 3, 1, &footprint, None, &mut barriers), Err(EBUSY));
assert_eq!(pool.publication_barriers(1, 2, 6, &footprint, None, &mut barriers), Err(EBUSY));
assert_eq!(pool.publication_barriers(1, 1, 4, &footprint, None, &mut barriers).unwrap(), 0);
// If a later overlapping consumer already executed, seq 4 fails with ENODATA.
{
let mut state = pool.state.lock();
state.footprints[0].later_consumer_executed = true;
}
assert_eq!(
pool.publication_barriers(1, 1, 4, &footprint, None, &mut barriers),
Err(ENODATA)
);
}
}

Expand Down
Loading
Loading