Skip to content

Commit

Permalink
drm/asahi: queue: Split into Queue and QueueInner
Browse files Browse the repository at this point in the history
Work around mutability issues when entity.new_job() takes a mutable
reference to the entity by moving all the fields used by the
submit_render() and submit_compute() functions to an inner struct,
eliminating the double-mutable-borrow.

Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina committed Jul 11, 2024
1 parent 55bb501 commit 38f6258
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use kernel::user_ptr::UserSlicePtr;
const DEBUG_CLASS: DebugFlags = DebugFlags::Compute;

#[versions(AGX)]
impl super::Queue::ver {
impl super::QueueInner::ver {
/// Submit work to a compute queue.
pub(super) fn submit_compute(
&self,
Expand Down
62 changes: 38 additions & 24 deletions drivers/gpu/drm/asahi/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,22 @@ pub(crate) struct Queue {
_sched: sched::Scheduler<QueueJob::ver>,
entity: sched::Entity<QueueJob::ver>,
vm: mmu::Vm,
ualloc: Arc<Mutex<alloc::DefaultAllocator>>,
q_vtx: Option<SubQueue::ver>,
q_frag: Option<SubQueue::ver>,
q_comp: Option<SubQueue::ver>,
fence_ctx: FenceContexts,
inner: QueueInner::ver,
}

#[versions(AGX)]
pub(crate) struct QueueInner {
dev: AsahiDevRef,
ualloc: Arc<Mutex<alloc::DefaultAllocator>>,
buffer: Option<buffer::Buffer::ver>,
gpu_context: Arc<workqueue::GpuContext>,
notifier_list: Arc<GpuObject<fw::event::NotifierList>>,
notifier: Arc<GpuObject<fw::event::Notifier::ver>>,
id: u64,
fence_ctx: FenceContexts,
#[ver(V >= V13_0B4)]
counter: AtomicU64,
}
Expand Down Expand Up @@ -427,22 +433,26 @@ impl Queue::ver {
_sched: sched,
entity,
vm,
ualloc,
q_vtx: None,
q_frag: None,
q_comp: None,
gpu_context: Arc::try_new(workqueue::GpuContext::new(
dev,
alloc,
buffer.as_ref().map(|b| b.any_ref()),
)?)?,
buffer,
notifier_list: Arc::try_new(notifier_list)?,
notifier,
id,
fence_ctx: FenceContexts::new(1, QUEUE_NAME, QUEUE_CLASS_KEY)?,
#[ver(V >= V13_0B4)]
counter: AtomicU64::new(0),
inner: QueueInner::ver {
dev: dev.into(),
ualloc,
gpu_context: Arc::try_new(workqueue::GpuContext::new(
dev,
alloc,
buffer.as_ref().map(|b| b.any_ref()),
)?)?,

buffer,
notifier_list: Arc::try_new(notifier_list)?,
notifier,
id,
#[ver(V >= V13_0B4)]
counter: AtomicU64::new(0),
},
};

// Rendering structures
Expand All @@ -452,15 +462,19 @@ impl Queue::ver {
*crate::initial_tvb_size.read(&lock)
};

ret.buffer.as_ref().unwrap().ensure_blocks(tvb_blocks)?;
ret.inner
.buffer
.as_ref()
.unwrap()
.ensure_blocks(tvb_blocks)?;

ret.q_vtx = Some(SubQueue::ver {
wq: workqueue::WorkQueue::ver::new(
dev,
alloc,
event_manager.clone(),
ret.gpu_context.clone(),
ret.notifier_list.clone(),
ret.inner.gpu_context.clone(),
ret.inner.notifier_list.clone(),
channel::PipeType::Vertex,
id,
priority,
Expand All @@ -480,8 +494,8 @@ impl Queue::ver {
dev,
alloc,
event_manager.clone(),
ret.gpu_context.clone(),
ret.notifier_list.clone(),
ret.inner.gpu_context.clone(),
ret.inner.notifier_list.clone(),
channel::PipeType::Fragment,
id,
priority,
Expand All @@ -497,8 +511,8 @@ impl Queue::ver {
dev,
alloc,
event_manager,
ret.gpu_context.clone(),
ret.notifier_list.clone(),
ret.inner.gpu_context.clone(),
ret.inner.notifier_list.clone(),
channel::PipeType::Compute,
id,
priority,
Expand Down Expand Up @@ -727,7 +741,7 @@ impl Queue for Queue::ver {

match cmd.cmd_type {
uapi::drm_asahi_cmd_type_DRM_ASAHI_CMD_RENDER => {
self.submit_render(
self.inner.submit_render(
&mut job,
&cmd,
result_writer,
Expand All @@ -745,7 +759,7 @@ impl Queue for Queue::ver {
))?;
}
uapi::drm_asahi_cmd_type_DRM_ASAHI_CMD_COMPUTE => {
self.submit_compute(
self.inner.submit_compute(
&mut job,
&cmd,
result_writer,
Expand Down Expand Up @@ -792,6 +806,6 @@ impl Queue for Queue::ver {
#[versions(AGX)]
impl Drop for Queue::ver {
fn drop(&mut self) {
mod_dev_dbg!(self.dev, "[Queue {}] Dropping queue\n", self.id);
mod_dev_dbg!(self.dev, "[Queue {}] Dropping queue\n", self.inner.id);
}
}
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/queue/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl RenderResult {
}

#[versions(AGX)]
impl super::Queue::ver {
impl super::QueueInner::ver {
/// Get the appropriate tiling parameters for a given userspace command buffer.
fn get_tiling_params(
cmdbuf: &uapi::drm_asahi_cmd_render,
Expand Down

0 comments on commit 38f6258

Please sign in to comment.