]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/gt: Extract emit_job_sync()
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 10 Jul 2025 20:33:48 +0000 (13:33 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 14 Jul 2025 20:20:03 +0000 (13:20 -0700)
Both the nop and wa jobs are going through the same boiler plate calls
to emit the job with a timeout and handling error for both bb and job.
Extract emit_job_sync() so those functions create the bb, handling
possible errors and delegate the part about really emitting the job
and waiting for its completion.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://lore.kernel.org/r/20250710-lrc-refactors-v2-3-a5e2ca03f6bd@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_gt.c

index 134d430cce73f997a51b993a8b87e4f4c6253dd8..08be659b9334cf745f2a480f3bb2b7e7780062b5 100644 (file)
@@ -146,30 +146,23 @@ static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
 
 static void gt_reset_worker(struct work_struct *w);
 
-static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
+static int emit_job_sync(struct xe_exec_queue *q, struct xe_bb *bb,
+                        long timeout_jiffies)
 {
        struct xe_sched_job *job;
-       struct xe_bb *bb;
        struct dma_fence *fence;
        long timeout;
 
-       bb = xe_bb_new(gt, 4, false);
-       if (IS_ERR(bb))
-               return PTR_ERR(bb);
-
        job = xe_bb_create_job(q, bb);
-       if (IS_ERR(job)) {
-               xe_bb_free(bb, NULL);
+       if (IS_ERR(job))
                return PTR_ERR(job);
-       }
 
        xe_sched_job_arm(job);
        fence = dma_fence_get(&job->drm.s_fence->finished);
        xe_sched_job_push(job);
 
-       timeout = dma_fence_wait_timeout(fence, false, HZ);
+       timeout = dma_fence_wait_timeout(fence, false, timeout_jiffies);
        dma_fence_put(fence);
-       xe_bb_free(bb, NULL);
        if (timeout < 0)
                return timeout;
        else if (!timeout)
@@ -178,17 +171,28 @@ static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
        return 0;
 }
 
+static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
+{
+       struct xe_bb *bb;
+       int ret;
+
+       bb = xe_bb_new(gt, 4, false);
+       if (IS_ERR(bb))
+               return PTR_ERR(bb);
+
+       ret = emit_job_sync(q, bb, HZ);
+       xe_bb_free(bb, NULL);
+
+       return ret;
+}
+
 static int emit_wa_job(struct xe_gt *gt, struct xe_exec_queue *q)
 {
        struct xe_reg_sr *sr = &q->hwe->reg_lrc;
        struct xe_reg_sr_entry *entry;
+       int count_rmw = 0, count = 0, ret;
        unsigned long idx;
-       struct xe_sched_job *job;
        struct xe_bb *bb;
-       struct dma_fence *fence;
-       long timeout;
-       int count_rmw = 0;
-       int count = 0;
        size_t bb_len = 0;
 
        /* count RMW registers as those will be handled separately */
@@ -293,25 +297,11 @@ static int emit_wa_job(struct xe_gt *gt, struct xe_exec_queue *q)
 
        xe_lrc_emit_hwe_state_instructions(q, bb);
 
-       job = xe_bb_create_job(q, bb);
-       if (IS_ERR(job)) {
-               xe_bb_free(bb, NULL);
-               return PTR_ERR(job);
-       }
+       ret = emit_job_sync(q, bb, HZ);
 
-       xe_sched_job_arm(job);
-       fence = dma_fence_get(&job->drm.s_fence->finished);
-       xe_sched_job_push(job);
-
-       timeout = dma_fence_wait_timeout(fence, false, HZ);
-       dma_fence_put(fence);
        xe_bb_free(bb, NULL);
-       if (timeout < 0)
-               return timeout;
-       else if (!timeout)
-               return -ETIME;
 
-       return 0;
+       return ret;
 }
 
 int xe_gt_record_default_lrcs(struct xe_gt *gt)