Skip to content

Commit fab2cc0

Browse files
committed
drm/xe/gt: Extract emit_job_sync()
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent e4cb582 commit fab2cc0

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

drivers/gpu/drm/xe/xe_gt.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,30 +146,23 @@ static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
146146

147147
static void gt_reset_worker(struct work_struct *w);
148148

149-
static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
149+
static int emit_job_sync(struct xe_exec_queue *q, struct xe_bb *bb,
150+
long timeout_jiffies)
150151
{
151152
struct xe_sched_job *job;
152-
struct xe_bb *bb;
153153
struct dma_fence *fence;
154154
long timeout;
155155

156-
bb = xe_bb_new(gt, 4, false);
157-
if (IS_ERR(bb))
158-
return PTR_ERR(bb);
159-
160156
job = xe_bb_create_job(q, bb);
161-
if (IS_ERR(job)) {
162-
xe_bb_free(bb, NULL);
157+
if (IS_ERR(job))
163158
return PTR_ERR(job);
164-
}
165159

166160
xe_sched_job_arm(job);
167161
fence = dma_fence_get(&job->drm.s_fence->finished);
168162
xe_sched_job_push(job);
169163

170-
timeout = dma_fence_wait_timeout(fence, false, HZ);
164+
timeout = dma_fence_wait_timeout(fence, false, timeout_jiffies);
171165
dma_fence_put(fence);
172-
xe_bb_free(bb, NULL);
173166
if (timeout < 0)
174167
return timeout;
175168
else if (!timeout)
@@ -178,17 +171,28 @@ static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
178171
return 0;
179172
}
180173

174+
static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
175+
{
176+
struct xe_bb *bb;
177+
int ret;
178+
179+
bb = xe_bb_new(gt, 4, false);
180+
if (IS_ERR(bb))
181+
return PTR_ERR(bb);
182+
183+
ret = emit_job_sync(q, bb, HZ);
184+
xe_bb_free(bb, NULL);
185+
186+
return ret;
187+
}
188+
181189
static int emit_wa_job(struct xe_gt *gt, struct xe_exec_queue *q)
182190
{
183191
struct xe_reg_sr *sr = &q->hwe->reg_lrc;
184192
struct xe_reg_sr_entry *entry;
193+
int count_rmw = 0, count = 0, ret;
185194
unsigned long idx;
186-
struct xe_sched_job *job;
187195
struct xe_bb *bb;
188-
struct dma_fence *fence;
189-
long timeout;
190-
int count_rmw = 0;
191-
int count = 0;
192196
size_t bb_len = 0;
193197

194198
/* 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)
293297

294298
xe_lrc_emit_hwe_state_instructions(q, bb);
295299

296-
job = xe_bb_create_job(q, bb);
297-
if (IS_ERR(job)) {
298-
xe_bb_free(bb, NULL);
299-
return PTR_ERR(job);
300-
}
300+
ret = emit_job_sync(q, bb, HZ);
301301

302-
xe_sched_job_arm(job);
303-
fence = dma_fence_get(&job->drm.s_fence->finished);
304-
xe_sched_job_push(job);
305-
306-
timeout = dma_fence_wait_timeout(fence, false, HZ);
307-
dma_fence_put(fence);
308302
xe_bb_free(bb, NULL);
309-
if (timeout < 0)
310-
return timeout;
311-
else if (!timeout)
312-
return -ETIME;
313303

314-
return 0;
304+
return ret;
315305
}
316306

317307
int xe_gt_record_default_lrcs(struct xe_gt *gt)

0 commit comments

Comments
 (0)