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
8 changes: 8 additions & 0 deletions drivers/gpu/drm/asahi/g17/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ impl Completion {
pub(super) fn is_input_source(&self, source: &Arc<super::fence::Submission>) -> bool {
self.output.output().member.is_source(source)
}
pub(crate) fn note_source_published(&self, published: super::fence::PublishedSource) {
self.output.output().member.note_published(published);
}
pub(crate) fn clear_source_published(&self) {
self.output.output().member.clear_published();
}
pub(super) fn set_source_ready(&self, ready: Fence) {
self.output.output().member.set_source_ready(ready);
}
Expand Down Expand Up @@ -682,6 +688,7 @@ impl Completion {
})
.is_ok();
if accepted {
self.clear_source_published();
self.replay_timeout.store(true, Ordering::Release);
// Callers replay only work proven not to have started; the new
// publication runs from the beginning and reports its own result.
Expand All @@ -700,6 +707,7 @@ impl Completion {

pub(crate) fn has_firmware_consumer(&self) -> bool {
self.firmware_consumer.load(Ordering::Acquire)
|| self.output.output().member.has_firmware_consumer()
}

pub(crate) fn take_replay_timeout(&self) -> bool {
Expand Down
93 changes: 87 additions & 6 deletions drivers/gpu/drm/asahi/g17/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,20 @@ pub(super) unsafe fn exported_source_raw(raw: *mut bindings::dma_fence) -> Optio
.cloned()
}

/// Immutable cross-QID kick metadata published once a compute source is committed in firmware.
/// Consumers on the same VM read this without acquiring the global device mutex.
#[derive(Clone)]
pub(crate) struct PublishedSource {
pub(crate) epoch: u64,
pub(crate) published: u64,
pub(crate) dependency: super::fw::kick::KickDependency,
pub(crate) readers: Arc<core::sync::atomic::AtomicU32>,
}

struct State {
work: Option<Arc<WorkStateLease>>,
ready: Option<Fence>,
published: Option<PublishedSource>,
}

// One Member per parsed command, plus the enqueue guard. Exported references
Expand All @@ -236,6 +247,8 @@ kernel::static_assert!(crate::file::MAX_COMMANDS_PER_SUBMISSION < u8::MAX as u32
pub(crate) struct Submission {
#[pin]
state: Mutex<State>,
/// Immutable VM status of this submission, stored outside `state` so `same_vm()` is lock-free.
vm_status: Option<Arc<super::status::VmStatus>>,
remaining: AtomicU8,
error: AtomicI32,
/// Live Member objects, plus the enqueue guard, independently of signalling.
Expand All @@ -245,22 +258,38 @@ pub(crate) struct Submission {
/// is queued, before its fence is signalled off-lock: a consumer published
/// in between needs no wait on it.
retired: AtomicBool,
/// Non-zero encoded recovery epoch (`epoch.wrapping_add(1)`) while `state.published` holds a
/// live `PublishedSource` snapshot, or `0` when unpublished.
published_epoch: AtomicU64,
/// Set atomically when a firmware kick depends on this source so replay/retirement
/// observes consumers without scanning producer queues under the device mutex.
firmware_consumer: AtomicBool,
}

impl Submission {
fn encode_epoch(epoch: u64) -> u64 {
epoch.wrapping_add(1)
}
fn new(context: Arc<Context>, firmware_source: bool) -> Result<Arc<Self>> {
let work = Arc::new(WorkStateLease::deferred(context)?, GFP_KERNEL)?;
Self::with_work(Some(work), firmware_source)
}
fn with_work(work: Option<Arc<WorkStateLease>>, firmware_source: bool) -> Result<Arc<Self>> {
let vm_status = work.as_ref().map(|work| work.status().clone());
Arc::pin_init(
pin_init!(Self {
state <- new_mutex!(State { work, ready: None }, "G17 submission work state"),
state <- new_mutex!(
State { work, ready: None, published: None },
"G17 submission work state"
),
vm_status,
remaining: AtomicU8::new(1),
error: AtomicI32::new(0),
owners: AtomicU8::new(1),
firmware_source,
retired: AtomicBool::new(false),
published_epoch: AtomicU64::new(0),
firmware_consumer: AtomicBool::new(false),
}),
GFP_KERNEL,
)
Expand All @@ -275,15 +304,55 @@ impl Submission {
Ok(complete)
}
pub(super) fn same_vm(&self, status: &Arc<super::status::VmStatus>) -> bool {
self.state
.lock()
.work
self.vm_status
.as_ref()
.is_some_and(|work| Arc::ptr_eq(work.status(), status))
.is_some_and(|vm| Arc::ptr_eq(vm, status))
}
pub(super) fn ready(&self) -> Option<Fence> {
self.state.lock().ready.clone()
}
pub(super) fn set_published(&self, source: PublishedSource) {
if !self.firmware_source {
return;
}
let tag = Self::encode_epoch(source.epoch);
let mut state = self.state.lock();
if state.work.is_some()
&& self.error.load(Ordering::Acquire) == 0
&& !self.retired.load(Ordering::Acquire)
{
state.published = Some(source);
self.published_epoch.store(tag, Ordering::Release);
}
}
pub(super) fn clear_published(&self) {
if self.published_epoch.swap(0, Ordering::AcqRel) == 0 {
return;
}
let old = self.state.lock().published.take();
drop(old);
}
pub(super) fn published_source(&self, epoch: u64) -> Option<PublishedSource> {
if !self.has_published_epoch(epoch) {
return None;
}
let state = self.state.lock();
state
.published
.as_ref()
.filter(|source| source.epoch == epoch)
.cloned()
}
pub(super) fn has_published_epoch(&self, epoch: u64) -> bool {
let tag = Self::encode_epoch(epoch);
self.firmware_source && tag != 0 && self.published_epoch.load(Ordering::Acquire) == tag
}
pub(super) fn note_firmware_consumer(&self) {
self.firmware_consumer.store(true, Ordering::Release);
}
pub(super) fn has_firmware_consumer(&self) -> bool {
self.firmware_consumer.load(Ordering::Acquire)
}
fn set_ready(&self, ready: Fence) {
if !self.firmware_source {
return;
Expand All @@ -294,14 +363,16 @@ impl Submission {
}
}
fn note_error(&self, error: Error) -> bool {
self.clear_published();
self.error
.compare_exchange(0, error.to_errno(), Ordering::AcqRel, Ordering::Acquire)
.is_ok()
}
fn release_state(&self) {
self.published_epoch.store(0, Ordering::Release);
let old = {
let mut state = self.state.lock();
(state.work.take(), state.ready.take())
(state.work.take(), state.ready.take(), state.published.take())
};
drop(old);
}
Expand Down Expand Up @@ -406,8 +477,18 @@ impl Member {
let source = self.aggregate.source();
if source.firmware_source {
source.retired.store(true, Ordering::Release);
source.clear_published();
}
}
pub(super) fn note_published(&self, published: PublishedSource) {
self.aggregate.source().set_published(published);
}
pub(super) fn clear_published(&self) {
self.aggregate.source().clear_published();
}
pub(super) fn has_firmware_consumer(&self) -> bool {
self.aggregate.source().has_firmware_consumer()
}
pub(crate) fn complete(&self, result: Result) {
if !self.complete.swap(true, Ordering::AcqRel) {
self.aggregate
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl Packet {
}
pub(crate) fn request_cancel(&self) -> bool {
self.cancelled.store(true, Ordering::Release);
self.completion.clear_source_published();
self.publication
.compare_exchange(0, 3, Ordering::AcqRel, Ordering::Acquire)
.is_ok()
Expand Down
17 changes: 17 additions & 0 deletions drivers/gpu/drm/asahi/g17/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,23 @@ impl Queue {
first || notify_activation)?)?;
}
host.notify((0x83 << 48) | 0x02 | u64::from(policy.priority()) << 2)?;
if !packet.cancel_requested() {
if let Some(dependency) =
crate::g17::fw::kick::KickDependency::new(qid, kick_timestamp)
{
packet.completion.note_source_published(
crate::g17::fence::PublishedSource {
epoch,
published,
dependency,
readers: self.source_readers.clone(),
},
);
if packet.cancel_requested() {
packet.completion.clear_source_published();
}
}
}
crate::g17::trace::publish(crate::g17::trace::COMPUTE, qid, ordinal, &packet);
host.note_submission()
})();
Expand Down
Loading
Loading