Skip to content

Commit afcad92

Browse files
mbrost05lucasdemarchi
authored andcommitted
drm/xe: Make WA BB part of LRC BO
No idea why, but without this GuC context switches randomly fail when running IGTs in a loop. Need to follow up why this fixes the aforementioned issue but can live with a stable driver for now. Fixes: 617d824 ("drm/xe: Add WA BB to capture active context utilization") Cc: [email protected] Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Tested-by: Shuicheng Lin <[email protected]> Link: https://lore.kernel.org/r/[email protected] (cherry picked from commit 3a1edef) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 2d5cff2 commit afcad92

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#define LRC_PPHWSP_SIZE SZ_4K
4242
#define LRC_INDIRECT_RING_STATE_SIZE SZ_4K
43+
#define LRC_WA_BB_SIZE SZ_4K
4344

4445
static struct xe_device *
4546
lrc_to_xe(struct xe_lrc *lrc)
@@ -910,7 +911,11 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
910911
{
911912
xe_hw_fence_ctx_finish(&lrc->fence_ctx);
912913
xe_bo_unpin_map_no_vm(lrc->bo);
913-
xe_bo_unpin_map_no_vm(lrc->bb_per_ctx_bo);
914+
}
915+
916+
static size_t wa_bb_offset(struct xe_lrc *lrc)
917+
{
918+
return lrc->bo->size - LRC_WA_BB_SIZE;
914919
}
915920

916921
/*
@@ -943,15 +948,16 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
943948
#define CONTEXT_ACTIVE 1ULL
944949
static int xe_lrc_setup_utilization(struct xe_lrc *lrc)
945950
{
951+
const size_t max_size = LRC_WA_BB_SIZE;
946952
u32 *cmd, *buf = NULL;
947953

948-
if (lrc->bb_per_ctx_bo->vmap.is_iomem) {
949-
buf = kmalloc(lrc->bb_per_ctx_bo->size, GFP_KERNEL);
954+
if (lrc->bo->vmap.is_iomem) {
955+
buf = kmalloc(max_size, GFP_KERNEL);
950956
if (!buf)
951957
return -ENOMEM;
952958
cmd = buf;
953959
} else {
954-
cmd = lrc->bb_per_ctx_bo->vmap.vaddr;
960+
cmd = lrc->bo->vmap.vaddr + wa_bb_offset(lrc);
955961
}
956962

957963
*cmd++ = MI_STORE_REGISTER_MEM | MI_SRM_USE_GGTT | MI_SRM_ADD_CS_OFFSET;
@@ -974,13 +980,14 @@ static int xe_lrc_setup_utilization(struct xe_lrc *lrc)
974980
*cmd++ = MI_BATCH_BUFFER_END;
975981

976982
if (buf) {
977-
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bb_per_ctx_bo->vmap, 0,
978-
buf, (cmd - buf) * sizeof(*cmd));
983+
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap,
984+
wa_bb_offset(lrc), buf,
985+
(cmd - buf) * sizeof(*cmd));
979986
kfree(buf);
980987
}
981988

982-
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
983-
xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
989+
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR, xe_bo_ggtt_addr(lrc->bo) +
990+
wa_bb_offset(lrc) + 1);
984991

985992
return 0;
986993
}
@@ -1018,20 +1025,13 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10181025
* FIXME: Perma-pinning LRC as we don't yet support moving GGTT address
10191026
* via VM bind calls.
10201027
*/
1021-
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, lrc_size,
1028+
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL,
1029+
lrc_size + LRC_WA_BB_SIZE,
10221030
ttm_bo_type_kernel,
10231031
bo_flags);
10241032
if (IS_ERR(lrc->bo))
10251033
return PTR_ERR(lrc->bo);
10261034

1027-
lrc->bb_per_ctx_bo = xe_bo_create_pin_map(xe, tile, NULL, SZ_4K,
1028-
ttm_bo_type_kernel,
1029-
bo_flags);
1030-
if (IS_ERR(lrc->bb_per_ctx_bo)) {
1031-
err = PTR_ERR(lrc->bb_per_ctx_bo);
1032-
goto err_lrc_finish;
1033-
}
1034-
10351035
lrc->size = lrc_size;
10361036
lrc->ring.size = ring_size;
10371037
lrc->ring.tail = 0;
@@ -1819,7 +1819,8 @@ struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc)
18191819
snapshot->seqno = xe_lrc_seqno(lrc);
18201820
snapshot->lrc_bo = xe_bo_get(lrc->bo);
18211821
snapshot->lrc_offset = xe_lrc_pphwsp_offset(lrc);
1822-
snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset;
1822+
snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset -
1823+
LRC_WA_BB_SIZE;
18231824
snapshot->lrc_snapshot = NULL;
18241825
snapshot->ctx_timestamp = lower_32_bits(xe_lrc_ctx_timestamp(lrc));
18251826
snapshot->ctx_job_timestamp = xe_lrc_ctx_job_timestamp(lrc);

drivers/gpu/drm/xe/xe_lrc_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ struct xe_lrc {
5353

5454
/** @ctx_timestamp: readout value of CTX_TIMESTAMP on last update */
5555
u64 ctx_timestamp;
56-
57-
/** @bb_per_ctx_bo: buffer object for per context batch wa buffer */
58-
struct xe_bo *bb_per_ctx_bo;
5956
};
6057

6158
struct xe_lrc_snapshot;

0 commit comments

Comments
 (0)