Skip to content
Closed
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
12 changes: 8 additions & 4 deletions drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ pub(crate) enum Engine {
}

impl Engine {
pub(crate) fn of(command: &Validated) -> Self {
match command {
Validated::Render { .. } => Self::Render,
Validated::Compute { .. } => Self::Compute,
}
}

pub(crate) fn index(self) -> usize {
match self {
Self::Render => 0,
Expand Down Expand Up @@ -176,10 +183,7 @@ impl Packet {
}

pub(crate) fn engine(&self) -> Engine {
match &self.command {
Validated::Render { .. } => Engine::Render,
Validated::Compute { .. } => Engine::Compute,
}
Engine::of(&self.command)
}

/// Replay holds the device mutex. Its original inputs were satisfied before
Expand Down
34 changes: 20 additions & 14 deletions drivers/gpu/drm/asahi/g17/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ pub(crate) struct Queue<B: Backend> {
variant: &'static crate::g17::fw::Variant,
proof: Proof,
sequence: [u64; 2],
frontiers: [KVec<(u64, Fences)>; 2],
/// One entry per unfinished command, so as long as userspace keeps work queued
/// (thousands under vkd3d-proton). Neither it nor `finished` needs
/// contiguous pages, and their growth must not fail a submit on fragmentation.
frontiers: [KVVec<(u64, Fences)>; 2],
/// Finished frontier entries pruned during this ioctl. Their last references
/// can tear a whole completion down; that waits until the ioctl has published.
finished: KVec<Fences>,
finished: KVVec<Fences>,
failures: [FailureRecord<Fences>; 2],
// Closing the userspace queue releases admission even if firmware still
// retains one of its execution contexts or installed physical graphs.
Expand Down Expand Up @@ -152,8 +155,8 @@ impl<B: Backend> Queue<B> {
variant,
proof: Proof::new(),
sequence: [0; 2],
frontiers: core::array::from_fn(|_| KVec::new()),
finished: KVec::new(),
frontiers: core::array::from_fn(|_| KVVec::new()),
finished: KVVec::new(),
failures: [FailureRecord::new(), FailureRecord::new()],
_slot: slot,
})
Expand All @@ -179,7 +182,7 @@ impl<B: Backend> Queue<B> {
// Without room the entries are released here, as they always could be.
let mut finished = if self
.finished
.reserve(self.frontiers[index].len(), GFP_KERNEL)
.reserve(self.frontiers[index].len(), GFP_KERNEL_ACCOUNT)
.is_ok()
{
Some(&mut self.finished)
Expand Down Expand Up @@ -223,10 +226,7 @@ impl<B: Backend> Queue<B> {
inputs: &[file::SyncItem],
destinations: Destinations,
) -> Result {
let engine = match &command {
Validated::Render { .. } => Engine::Render,
Validated::Compute { .. } => Engine::Compute,
};
let engine = Engine::of(&command);
let index = engine.index();
let other = 1 - index;
if let Validated::Render { ray_query, .. } = &command {
Expand All @@ -239,7 +239,6 @@ impl<B: Backend> Queue<B> {
}
self.prune_frontier(index);
self.prune_frontier(other);
self.frontiers[index].reserve(1, GFP_KERNEL)?;
if engine == Engine::Compute {
self.ensure_compute(&command)?;
}
Expand Down Expand Up @@ -447,10 +446,7 @@ impl<B: Backend> Queue<B> {
&command.payload,
)
.map_err(|error| refused("the command's requirements", error))?;
let engine = match &payload {
Validated::Render { .. } => Engine::Render,
Validated::Compute { .. } => Engine::Compute,
};
let engine = Engine::of(&payload);
if !self.backend.supports_engine(engine) { return Err(ENOTSUPP); }
self.backend
.prepare_command(&mut payload)
Expand Down Expand Up @@ -569,6 +565,16 @@ impl<B: Backend> crate::queue::Queue for Queue<B> {
command.allow_long_job();
}
}
// Room for every command's frontier entry, so that running out of memory fails
// the submission before any of it is queued. Userspace sets the frontier's
// length, so its memory is charged to the caller.
let mut room = [0; 2];
for (command, _, _) in pending.iter() {
room[Engine::of(command).index()] += 1;
}
for (frontier, room) in self.frontiers.iter_mut().zip(room) {
frontier.reserve(room, GFP_KERNEL_ACCOUNT)?;
}
let mut guards = guards.into_iter();
// Where a firmware wait reports completion before a weak stream tail's writes are
// visible, only a command that declares a visible completion is waited for there.
Expand Down
Loading