drm/xe: Take ref to job's fence in arm
authorMatthew Brost <matthew.brost@intel.com>
Mon, 21 Oct 2024 17:35:12 +0000 (10:35 -0700)
committerMatthew Brost <matthew.brost@intel.com>
Wed, 23 Oct 2024 18:06:31 +0000 (11:06 -0700)
Take ref to job's fence in arm rather than run job. This ref is owned by
the drm scheduler so it makes sense to take the ref before handing over
the job to the scheduler. Also removes an atomic from the run job path.

Suggested-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241021173512.1584248-1-matthew.brost@intel.com
drivers/gpu/drm/xe/xe_execlist.c
drivers/gpu/drm/xe/xe_guc_submit.c
drivers/gpu/drm/xe/xe_sched_job.c
drivers/gpu/drm/xe/xe_sched_job_types.h

index f3b71fe..a8c416a 100644 (file)
@@ -313,7 +313,7 @@ execlist_run_job(struct drm_sched_job *drm_job)
        q->ring_ops->emit_job(job);
        xe_execlist_make_active(exl);
 
-       return dma_fence_get(job->fence);
+       return job->fence;
 }
 
 static void execlist_job_free(struct drm_sched_job *drm_job)
index 2b6ac1d..d2dcc9a 100644 (file)
@@ -790,6 +790,7 @@ guc_exec_queue_run_job(struct drm_sched_job *drm_job)
        struct xe_exec_queue *q = job->q;
        struct xe_guc *guc = exec_queue_to_guc(q);
        struct xe_device *xe = guc_to_xe(guc);
+       struct dma_fence *fence = NULL;
        bool lr = xe_exec_queue_is_lr(q);
 
        xe_assert(xe, !(exec_queue_destroyed(q) || exec_queue_pending_disable(q)) ||
@@ -807,12 +808,12 @@ guc_exec_queue_run_job(struct drm_sched_job *drm_job)
 
        if (lr) {
                xe_sched_job_set_error(job, -EOPNOTSUPP);
-               return NULL;
-       } else if (test_and_set_bit(JOB_FLAG_SUBMIT, &job->fence->flags)) {
-               return job->fence;
+               dma_fence_put(job->fence);      /* Drop ref from xe_sched_job_arm */
        } else {
-               return dma_fence_get(job->fence);
+               fence = job->fence;
        }
+
+       return fence;
 }
 
 static void guc_exec_queue_free_job(struct drm_sched_job *drm_job)
index eeccc1c..1905ca5 100644 (file)
@@ -280,7 +280,7 @@ void xe_sched_job_arm(struct xe_sched_job *job)
                fence = &chain->base;
        }
 
-       job->fence = fence;
+       job->fence = dma_fence_get(fence);      /* Pairs with put in scheduler */
        drm_sched_job_arm(&job->drm);
 }
 
index 426d261..f13f333 100644 (file)
@@ -40,7 +40,6 @@ struct xe_sched_job {
         * @fence: dma fence to indicate completion. 1 way relationship - job
         * can safely reference fence, fence cannot safely reference job.
         */
-#define JOB_FLAG_SUBMIT                DMA_FENCE_FLAG_USER_BITS
        struct dma_fence *fence;
        /** @user_fence: write back value when BB is complete */
        struct {