Skip to content

Commit 0d92cd8

Browse files
ifdumbrost05
authored andcommitted
drm/xe/exec_queue: Prepare last fence for hw engine group resume context
Ensure we can safely take a ref of the exec queue's last fence from the context of resuming jobs from the hw engine group. The locking requirements differ from the general case, hence the introduction of this new function. v2: Add kernel doc, rework the code to prevent code duplication v3: Fix kernel doc, remove now unnecessary lockdep variants (Matt Brost) v4: Remove new put function (Matt Brost) Signed-off-by: Francois Dugast <francois.dugast@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240809155156.1955925-7-francois.dugast@intel.com
1 parent 7f0d7be commit 0d92cd8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

drivers/gpu/drm/xe/xe_exec_queue.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,12 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
837837
static void xe_exec_queue_last_fence_lockdep_assert(struct xe_exec_queue *q,
838838
struct xe_vm *vm)
839839
{
840-
if (q->flags & EXEC_QUEUE_FLAG_VM)
840+
if (q->flags & EXEC_QUEUE_FLAG_VM) {
841841
lockdep_assert_held(&vm->lock);
842-
else
842+
} else {
843843
xe_vm_assert_held(vm);
844+
lockdep_assert_held(&q->hwe->hw_engine_group->mode_sem);
845+
}
844846
}
845847

846848
/**
@@ -894,6 +896,33 @@ struct dma_fence *xe_exec_queue_last_fence_get(struct xe_exec_queue *q,
894896
return fence;
895897
}
896898

899+
/**
900+
* xe_exec_queue_last_fence_get_for_resume() - Get last fence
901+
* @q: The exec queue
902+
* @vm: The VM the engine does a bind or exec for
903+
*
904+
* Get last fence, takes a ref. Only safe to be called in the context of
905+
* resuming the hw engine group's long-running exec queue, when the group
906+
* semaphore is held.
907+
*
908+
* Returns: last fence if not signaled, dma fence stub if signaled
909+
*/
910+
struct dma_fence *xe_exec_queue_last_fence_get_for_resume(struct xe_exec_queue *q,
911+
struct xe_vm *vm)
912+
{
913+
struct dma_fence *fence;
914+
915+
lockdep_assert_held_write(&q->hwe->hw_engine_group->mode_sem);
916+
917+
if (q->last_fence &&
918+
test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &q->last_fence->flags))
919+
xe_exec_queue_last_fence_put_unlocked(q);
920+
921+
fence = q->last_fence ? q->last_fence : dma_fence_get_stub();
922+
dma_fence_get(fence);
923+
return fence;
924+
}
925+
897926
/**
898927
* xe_exec_queue_last_fence_set() - Set last fence
899928
* @q: The exec queue

drivers/gpu/drm/xe/xe_exec_queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ void xe_exec_queue_last_fence_put(struct xe_exec_queue *e, struct xe_vm *vm);
7777
void xe_exec_queue_last_fence_put_unlocked(struct xe_exec_queue *e);
7878
struct dma_fence *xe_exec_queue_last_fence_get(struct xe_exec_queue *e,
7979
struct xe_vm *vm);
80+
struct dma_fence *xe_exec_queue_last_fence_get_for_resume(struct xe_exec_queue *e,
81+
struct xe_vm *vm);
8082
void xe_exec_queue_last_fence_set(struct xe_exec_queue *e, struct xe_vm *vm,
8183
struct dma_fence *fence);
8284
int xe_exec_queue_last_fence_test_dep(struct xe_exec_queue *q,

0 commit comments

Comments
 (0)