Skip to content

Commit dddcb19

Browse files
committed
drm/xe/oa: Separate batch submission from waiting for completion
When we introduce xe_syncs, we don't wait for internal OA programming batches to complete. That is, xe_syncs are signaled asynchronously. In anticipation for this, separate out batch submission from waiting for completion of those batches. v2: Change return type of xe_oa_submit_bb to "struct dma_fence *" (Matt B) v3: Retain init "int err = 0;" in xe_oa_submit_bb (Jose) Reviewed-by: Jonathan Cavitt <[email protected]> Signed-off-by: Ashutosh Dixit <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e2d84e5 commit dddcb19

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

drivers/gpu/drm/xe/xe_oa.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,10 @@ static __poll_t xe_oa_poll(struct file *file, poll_table *wait)
570570
return ret;
571571
}
572572

573-
static int xe_oa_submit_bb(struct xe_oa_stream *stream, struct xe_bb *bb)
573+
static struct dma_fence *xe_oa_submit_bb(struct xe_oa_stream *stream, struct xe_bb *bb)
574574
{
575575
struct xe_sched_job *job;
576576
struct dma_fence *fence;
577-
long timeout;
578577
int err = 0;
579578

580579
/* Kernel configuration is issued on stream->k_exec_q, not stream->exec_q */
@@ -588,14 +587,9 @@ static int xe_oa_submit_bb(struct xe_oa_stream *stream, struct xe_bb *bb)
588587
fence = dma_fence_get(&job->drm.s_fence->finished);
589588
xe_sched_job_push(job);
590589

591-
timeout = dma_fence_wait_timeout(fence, false, HZ);
592-
dma_fence_put(fence);
593-
if (timeout < 0)
594-
err = timeout;
595-
else if (!timeout)
596-
err = -ETIME;
590+
return fence;
597591
exit:
598-
return err;
592+
return ERR_PTR(err);
599593
}
600594

601595
static void write_cs_mi_lri(struct xe_bb *bb, const struct xe_oa_reg *reg_data, u32 n_regs)
@@ -659,6 +653,7 @@ static void xe_oa_store_flex(struct xe_oa_stream *stream, struct xe_lrc *lrc,
659653
static int xe_oa_modify_ctx_image(struct xe_oa_stream *stream, struct xe_lrc *lrc,
660654
const struct flex *flex, u32 count)
661655
{
656+
struct dma_fence *fence;
662657
struct xe_bb *bb;
663658
int err;
664659

@@ -670,14 +665,24 @@ static int xe_oa_modify_ctx_image(struct xe_oa_stream *stream, struct xe_lrc *lr
670665

671666
xe_oa_store_flex(stream, lrc, bb, flex, count);
672667

673-
err = xe_oa_submit_bb(stream, bb);
668+
fence = xe_oa_submit_bb(stream, bb);
669+
if (IS_ERR(fence)) {
670+
err = PTR_ERR(fence);
671+
goto free_bb;
672+
}
673+
xe_bb_free(bb, fence);
674+
dma_fence_put(fence);
675+
676+
return 0;
677+
free_bb:
674678
xe_bb_free(bb, NULL);
675679
exit:
676680
return err;
677681
}
678682

679683
static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *reg_lri)
680684
{
685+
struct dma_fence *fence;
681686
struct xe_bb *bb;
682687
int err;
683688

@@ -689,7 +694,16 @@ static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *re
689694

690695
write_cs_mi_lri(bb, reg_lri, 1);
691696

692-
err = xe_oa_submit_bb(stream, bb);
697+
fence = xe_oa_submit_bb(stream, bb);
698+
if (IS_ERR(fence)) {
699+
err = PTR_ERR(fence);
700+
goto free_bb;
701+
}
702+
xe_bb_free(bb, fence);
703+
dma_fence_put(fence);
704+
705+
return 0;
706+
free_bb:
693707
xe_bb_free(bb, NULL);
694708
exit:
695709
return err;
@@ -919,15 +933,32 @@ static int xe_oa_emit_oa_config(struct xe_oa_stream *stream, struct xe_oa_config
919933
{
920934
#define NOA_PROGRAM_ADDITIONAL_DELAY_US 500
921935
struct xe_oa_config_bo *oa_bo;
922-
int err, us = NOA_PROGRAM_ADDITIONAL_DELAY_US;
936+
int err = 0, us = NOA_PROGRAM_ADDITIONAL_DELAY_US;
937+
struct dma_fence *fence;
938+
long timeout;
923939

940+
/* Emit OA configuration batch */
924941
oa_bo = xe_oa_alloc_config_buffer(stream, config);
925942
if (IS_ERR(oa_bo)) {
926943
err = PTR_ERR(oa_bo);
927944
goto exit;
928945
}
929946

930-
err = xe_oa_submit_bb(stream, oa_bo->bb);
947+
fence = xe_oa_submit_bb(stream, oa_bo->bb);
948+
if (IS_ERR(fence)) {
949+
err = PTR_ERR(fence);
950+
goto exit;
951+
}
952+
953+
/* Wait till all previous batches have executed */
954+
timeout = dma_fence_wait_timeout(fence, false, 5 * HZ);
955+
dma_fence_put(fence);
956+
if (timeout < 0)
957+
err = timeout;
958+
else if (!timeout)
959+
err = -ETIME;
960+
if (err)
961+
drm_dbg(&stream->oa->xe->drm, "dma_fence_wait_timeout err %d\n", err);
931962

932963
/* Additional empirical delay needed for NOA programming after registers are written */
933964
usleep_range(us, 2 * us);

0 commit comments

Comments
 (0)