Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 11 additions & 11 deletions drivers/gpu/drm/asahi/g17/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ use kernel::{
pub(crate) struct CompletionFence;

unsafe extern "C" {
fn asahi_g17_signal_fence(fence: *mut bindings::dma_fence);
fn asahi_g17_finish_fence(fence: *mut bindings::dma_fence, error: i32, scoped: bool) -> bool;
}

fn signal_exported(fence: &dyn RawDmaFence) {
/// Sets `error` (if non-zero) and signals `fence` in one step under the fence's lock, unless it
/// has already signalled: its waiters saw that result, and `dma_fence_set_error()` must neither
/// follow nor race a signal. A scoped output drains the queue scopes it completes. Returns
/// whether this call signalled the fence.
fn finish_exported(fence: &dyn RawDmaFence, error: i32, scoped: bool) -> bool {
// SAFETY: The borrowed fence remains owned throughout synchronous signaling.
// Ready completion scopes are drained iteratively after its lock is released.
unsafe { asahi_g17_signal_fence(fence.raw()) };
unsafe { asahi_g17_finish_fence(fence.raw(), error, scoped) }
}

#[vtable]
Expand Down Expand Up @@ -389,17 +393,13 @@ impl Submission {
}
if self.remaining.fetch_sub(1, Ordering::AcqRel) == 1 {
let error = self.error.load(Ordering::Acquire);
if error != 0 {
fence.set_error(Error::from_errno(error));
} else {
if error == 0 {
self.release_state();
}
super::trace::output(fence, error);
if fence.scoped {
signal_exported(fence);
} else {
fence.signal();
}
// An early completion path may already have signalled the fence: its waiters keep
// the result they saw, even when this member was cancelled afterwards.
finish_exported(fence, error, fence.scoped);
unwaited(&fence.waited);
compute_unwaited(&fence.compute_waited);
}
Expand Down
45 changes: 40 additions & 5 deletions drivers/gpu/drm/asahi/g17/sync_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,47 @@ static void scope_defer_list(struct llist_node *nodes)
}
}

void asahi_g17_signal_fence(struct dma_fence *fence)
/* Set @error, if any, and signal @fence in one step under its lock, unless it
* has already signalled: its waiters have seen that result, and
* dma_fence_set_error() must neither follow nor race the signal.
* Returns whether this call signalled @fence.
*/
static bool signal_with_error(struct dma_fence *fence, int error)
{
unsigned long flags;
bool cookie, first;

cookie = dma_fence_begin_signalling();
dma_fence_lock_irqsave(fence, flags);
first = !dma_fence_test_signaled_flag(fence);
if (first && error)
dma_fence_set_error(fence, error);
dma_fence_signal_locked(fence);
dma_fence_unlock_irqrestore(fence, flags);
dma_fence_end_signalling(cookie);
return first;
}

static bool signal_draining_scopes(struct dma_fence *fence, int error)
{
struct llist_head ready = LLIST_HEAD_INIT(ready);
struct llist_node *nodes, *node, *next;
unsigned long flags;
unsigned int completed = 0;
bool first;

/* Fence callbacks are atomic. Keep the local ready list pinned while
* signaling, then finish ready scopes after the source fence is unlocked.
* New ready scopes append to this list instead of recursing or sending IPIs.
*/
preempt_disable();
if (__this_cpu_read(active_scopes)) {
dma_fence_signal(fence);
first = signal_with_error(fence, error);
preempt_enable();
return;
return first;
}
__this_cpu_write(active_scopes, &ready);
dma_fence_signal(fence);
first = signal_with_error(fence, error);
for (;;) {
/* An interrupt must not append after the final empty test. */
local_irq_save(flags);
Expand All @@ -198,13 +220,26 @@ void asahi_g17_signal_fence(struct dma_fence *fence)
preempt_enable();
scope_defer_list(node);
scope_defer_list(more);
return;
return first;
}
scope_complete(container_of(node, struct asahi_g17_scope, ready));
++completed;
}
}
preempt_enable();
return first;
}

void asahi_g17_signal_fence(struct dma_fence *fence)
{
signal_draining_scopes(fence, 0);
}

bool asahi_g17_finish_fence(struct dma_fence *fence, int error, bool scoped)
{
if (scoped)
return signal_draining_scopes(fence, error);
return signal_with_error(fence, error);
}

static void scope_arrived(struct asahi_g17_scope *scope, int error)
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/g17/sync_scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <linux/types.h>
struct dma_fence;
void asahi_g17_signal_fence(struct dma_fence *fence);
/* Sets @error (if non-zero) and signals @fence under its lock unless it has
* already signalled; @scoped drains ready queue scopes as above. Returns
* whether this call signalled @fence.
*/
bool asahi_g17_finish_fence(struct dma_fence *fence, int error, bool scoped);
/* Only for explicitly signalled driver completion fences, with no poll op. */
int asahi_g17_completion_fence_status(struct dma_fence *fence);

Expand Down
Loading
Loading