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
11 changes: 11 additions & 0 deletions drivers/gpu/drm/asahi/g17/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,17 @@ impl WorkStateLease {
ordinal,
})
}
/// An additional lease for splitting a multi-command ioctl, returning `None` once
/// `identity::Order` reaches its split cap so new ioctls keep full headroom.
pub(crate) fn deferred_split(context: Arc<Context>) -> Option<Self> {
let ordinal = context.order.lock().assign_split()?;
Some(Self {
context,
word: AtomicU32::new(FREE),
engine: AtomicU8::new(0),
ordinal,
})
}
/// The ioctl's node, taking one for `engine`'s admission if it has none yet. EBUSY: an older
/// ioctl still waits for its node (see `identity::Order`), or no node may be taken now
/// (see `identity::may_take`); an older ioctl's admission or a return lets it try again.
Expand Down
27 changes: 26 additions & 1 deletion drivers/gpu/drm/asahi/g17/context/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ impl WorkStates {

/// How far past the oldest waiting ioctl a new ioctl may be ordered: the ordinals past the
/// turn remembered for ioctls that left early.
pub(super) const ORDER_WINDOW: u64 = 1024;
pub(super) const ORDER_WINDOW: u64 = 2048;

/// Cap for extra work-state splits inside multi-command ioctls, keeping the upper half of
/// [`ORDER_WINDOW`] permanently reserved for new ioctls.
pub(super) const ORDER_SPLIT_LIMIT: u64 = ORDER_WINDOW / 2;

/// The order in which a context's ioctls take work-state nodes.
///
Expand Down Expand Up @@ -147,6 +151,14 @@ impl Order {
self.next += 1;
Some(ordinal)
}
/// The ordinal of an extra work-state split within a multi-command ioctl. None once
/// [`ORDER_SPLIT_LIMIT`] ordinals are ahead of the turn so new ioctls keep full headroom.
pub(super) fn assign_split(&mut self) -> Option<u64> {
if self.next - self.turn >= ORDER_SPLIT_LIMIT {
return None;
}
self.assign()
}
/// Whether the ioctl `ordinal` may take its node now: only at its turn. A refusal is
/// remembered until the turn next moves, so that move wakes the refused publisher.
pub(super) fn admits(&mut self, ordinal: u64) -> bool {
Expand Down Expand Up @@ -390,6 +402,19 @@ mod tests {
assert!(order.assign().is_some());
}

#[test]
fn split_ordinals_reserve_half_the_window_for_new_ioctls() {
let mut order = Order::new();
for _ in 0..ORDER_SPLIT_LIMIT {
assert!(order.assign_split().is_some());
}
assert!(order.assign_split().is_none());
for _ in ORDER_SPLIT_LIMIT..ORDER_WINDOW {
assert!(order.assign().is_some());
}
assert!(order.assign().is_none());
}

#[test]
fn single_engine_admission_wakes_nobody() {
let mut order = Order::new();
Expand Down
98 changes: 98 additions & 0 deletions drivers/gpu/drm/asahi/g17/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ impl Submission {
}
fn with_work(work: Option<Arc<WorkStateLease>>, firmware_source: bool) -> Result<Arc<Self>> {
let vm_status = work.as_ref().map(|work| work.status().clone());
Self::with_work_and_status(work, vm_status, firmware_source)
}
fn with_work_and_status(
work: Option<Arc<WorkStateLease>>,
vm_status: Option<Arc<super::status::VmStatus>>,
firmware_source: bool,
) -> Result<Arc<Self>> {
Arc::pin_init(
pin_init!(Self {
state <- new_mutex!(
Expand Down Expand Up @@ -406,6 +413,61 @@ impl Submission {
}
}

#[pin_data]
pub(crate) struct ChunkWork {
#[pin]
work: Mutex<Option<Arc<WorkStateLease>>>,
remaining: AtomicU32,
owners: AtomicU32,
error: AtomicBool,
}
impl ChunkWork {
pub(crate) fn new(work: Arc<WorkStateLease>) -> Result<Arc<Self>> {
Arc::pin_init(
pin_init!(Self {
work <- new_mutex!(Some(work), "G17 chunk work state"),
// Initial enqueue guard matching Submission's lifecycle so an
// early-retiring or dropped member cannot release the work
// state before later commands in the same chunk attach.
remaining: AtomicU32::new(1),
owners: AtomicU32::new(1),
error: AtomicBool::new(false),
}),
GFP_KERNEL,
)
}
fn attach(&self) {
self.remaining.fetch_add(1, Ordering::Relaxed);
self.owners.fetch_add(1, Ordering::Relaxed);
}
fn work_state(&self) -> Result<Arc<WorkStateLease>> {
self.work.lock().clone().ok_or(ECANCELED)
}
fn release(&self) {
let old = self.work.lock().take();
drop(old);
}
fn member_done(&self, result: Result) {
if result.is_err() {
self.error.store(true, Ordering::Release);
}
if self.remaining.fetch_sub(1, Ordering::AcqRel) == 1
&& !self.error.load(Ordering::Acquire)
{
self.release();
}
}
fn owner_done(&self) {
if self.owners.fetch_sub(1, Ordering::AcqRel) == 1 {
self.release();
}
}
pub(crate) fn finish_enqueue(&self, result: Result) {
self.member_done(result);
self.owner_done();
}
}

#[derive(Clone)]
pub(crate) struct Aggregate(UserFence<ExportFence>);
impl Aggregate {
Expand All @@ -420,10 +482,18 @@ impl Aggregate {
Fence::from_fence(&self.0)
}
pub(crate) fn member(&self) -> Member {
self.member_inner(None)
}
pub(crate) fn member_with_work(&self, work: Arc<ChunkWork>) -> Member {
work.attach();
self.member_inner(Some(work))
}
fn member_inner(&self, work: Option<Arc<ChunkWork>>) -> Member {
self.source().remaining.fetch_add(1, Ordering::Relaxed);
self.source().owners.fetch_add(1, Ordering::Relaxed);
Member {
aggregate: self.clone(),
work,
complete: AtomicBool::new(false),
}
}
Expand All @@ -449,13 +519,17 @@ impl Aggregate {

pub(crate) struct Member {
aggregate: Aggregate,
work: Option<Arc<ChunkWork>>,
complete: AtomicBool,
}
impl Member {
pub(super) fn needs_source_ready(&self) -> bool {
self.aggregate.source().firmware_source
}
pub(crate) fn work_state(&self) -> Result<Arc<WorkStateLease>> {
if let Some(work) = &self.work {
return work.work_state();
}
self.aggregate
.source()
.state
Expand Down Expand Up @@ -491,6 +565,9 @@ impl Member {
}
pub(crate) fn complete(&self, result: Result) {
if !self.complete.swap(true, Ordering::AcqRel) {
if let Some(work) = &self.work {
work.member_done(result);
}
self.aggregate
.source()
.member_done(&self.aggregate.0, result);
Expand Down Expand Up @@ -591,6 +668,9 @@ mod tests {
impl Drop for Member {
fn drop(&mut self) {
self.complete(Err(ECANCELED));
if let Some(work) = &self.work {
work.owner_done();
}
self.aggregate.source().owner_done();
}
}
Expand All @@ -610,6 +690,7 @@ pub(crate) struct Outputs {
syncs: KVVec<SyncItem>,
input_count: usize,
submission: Option<Aggregate>,
chunks: KVec<Arc<ChunkWork>>,
result: Result,
cumulative: Option<super::sync_output::SignalBundle>,
}
Expand Down Expand Up @@ -640,6 +721,7 @@ impl Outputs {
syncs,
input_count,
submission: None,
chunks: KVec::new(),
result: Err(ECANCELED),
cumulative,
})
Expand All @@ -661,6 +743,19 @@ impl Outputs {
compute_only: bool,
) -> Result<Aggregate> {
let source = Submission::new(context, firmware_source)?;
self.publish_source(source, compute_only)
}
pub(crate) fn publish_with_status(
&mut self,
vm_status: Arc<super::status::VmStatus>,
chunks: KVec<Arc<ChunkWork>>,
compute_only: bool,
) -> Result<Aggregate> {
self.chunks = chunks;
let source = Submission::with_work_and_status(None, Some(vm_status), false)?;
self.publish_source(source, compute_only)
}
fn publish_source(&mut self, source: Arc<Submission>, compute_only: bool) -> Result<Aggregate> {
let mut fence = self.fallback.take().ok_or(EINVAL)?;
fence.source = Some(source);
fence.scoped = self.cumulative.is_some();
Expand All @@ -682,6 +777,9 @@ impl Outputs {
}
impl Drop for Outputs {
fn drop(&mut self) {
for chunk in &self.chunks {
chunk.finish_enqueue(self.result);
}
if let Some(submission) = self.submission.take() {
if let Some(bundle) = &mut self.cumulative {
bundle.fail(&submission.fence());
Expand Down
6 changes: 5 additions & 1 deletion drivers/gpu/drm/asahi/g17/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,10 @@ impl Queue {
/// A completion hint can require a second visibility/recordless pass even
/// when firmware has no more events to send. Do not poll idle or failed queues.
pub(crate) fn retirement_polling(&self) -> bool {
self.configuration.is_some() || (!self.quarantined && self.retire_pending)
self.configuration.is_some()
|| (!self.quarantined
&& (self.retire_pending
|| self.active.front().is_some_and(|a| a.observed.is_some())))
}

/// A release has no completion event: keep observing the control consumer
Expand Down Expand Up @@ -1140,6 +1143,7 @@ impl Queue {
fn selected(&self, masks: Option<[u64; 2]>) -> bool {
self.retired_by_teardown
|| self.retire_pending
|| self.active.front().is_some_and(|a| a.observed.is_some())
|| masks.is_none_or(|m| m[self.qid() as usize / 64] & (1 << (self.qid() % 64)) != 0)
}

Expand Down
Loading
Loading