Skip to content

Commit 1460eae

Browse files
ksatya-devrodrigovivi
authored andcommitted
drm/xe/vf: Use drm mm instead of drm sa for CCS read/write
The suballocator algorithm tracks a hole cursor at the last allocation and tries to allocate after it. This is optimized for fence-ordered progress, where older allocations are expected to become reusable first. In fence-enabled mode, that ordering assumption holds. In fence-disabled mode, allocations may be freed in arbitrary order, so limiting allocation to the current hole window can miss valid free space and fail allocations despite sufficient total space. Use DRM memory manager instead of sub-allocator to get rid of this issue as CCS read/write operations do not use fences. Fixes: 864690c ("drm/xe/vf: Attach and detach CCS copy commands with BO") Signed-off-by: Satyanarayana K V P <satyanarayana.k.v.p@intel.com> Cc: Matthew Brost <matthew.brost@intel.com> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> Cc: Maarten Lankhorst <dev@lankhorst.se> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260408110145.1639937-6-satyanarayana.k.v.p@intel.com (cherry picked from commit 6c84b49) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent 36c6bac commit 1460eae

4 files changed

Lines changed: 63 additions & 55 deletions

File tree

drivers/gpu/drm/xe/xe_bo_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "xe_ggtt_types.h"
1919

2020
struct xe_device;
21+
struct xe_mem_pool_node;
2122
struct xe_vm;
2223

2324
#define XE_BO_MAX_PLACEMENTS 3
@@ -88,7 +89,7 @@ struct xe_bo {
8889
bool ccs_cleared;
8990

9091
/** @bb_ccs: BB instructions of CCS read/write. Valid only for VF */
91-
struct xe_bb *bb_ccs[XE_SRIOV_VF_CCS_CTX_COUNT];
92+
struct xe_mem_pool_node *bb_ccs[XE_SRIOV_VF_CCS_CTX_COUNT];
9293

9394
/**
9495
* @cpu_caching: CPU caching mode. Currently only used for userspace

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "xe_hw_engine.h"
3030
#include "xe_lrc.h"
3131
#include "xe_map.h"
32+
#include "xe_mem_pool.h"
3233
#include "xe_mocs.h"
3334
#include "xe_printk.h"
3435
#include "xe_pt.h"
@@ -1166,11 +1167,12 @@ int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
11661167
u32 batch_size, batch_size_allocated;
11671168
struct xe_device *xe = gt_to_xe(gt);
11681169
struct xe_res_cursor src_it, ccs_it;
1170+
struct xe_mem_pool *bb_pool;
11691171
struct xe_sriov_vf_ccs_ctx *ctx;
1170-
struct xe_sa_manager *bb_pool;
11711172
u64 size = xe_bo_size(src_bo);
1172-
struct xe_bb *bb = NULL;
1173+
struct xe_mem_pool_node *bb;
11731174
u64 src_L0, src_L0_ofs;
1175+
struct xe_bb xe_bb_tmp;
11741176
u32 src_L0_pt;
11751177
int err;
11761178

@@ -1208,25 +1210,26 @@ int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
12081210
size -= src_L0;
12091211
}
12101212

1211-
bb = xe_bb_alloc(gt);
1213+
bb = xe_mem_pool_alloc_node();
12121214
if (IS_ERR(bb))
12131215
return PTR_ERR(bb);
12141216

12151217
bb_pool = ctx->mem.ccs_bb_pool;
1216-
scoped_guard(mutex, xe_sa_bo_swap_guard(bb_pool)) {
1217-
xe_sa_bo_swap_shadow(bb_pool);
1218+
scoped_guard(mutex, xe_mem_pool_bo_swap_guard(bb_pool)) {
1219+
xe_mem_pool_swap_shadow_locked(bb_pool);
12181220

1219-
err = xe_bb_init(bb, bb_pool, batch_size);
1221+
err = xe_mem_pool_insert_node(bb_pool, bb, batch_size * sizeof(u32));
12201222
if (err) {
12211223
xe_gt_err(gt, "BB allocation failed.\n");
1222-
xe_bb_free(bb, NULL);
1224+
kfree(bb);
12231225
return err;
12241226
}
12251227

12261228
batch_size_allocated = batch_size;
12271229
size = xe_bo_size(src_bo);
12281230
batch_size = 0;
12291231

1232+
xe_bb_tmp = (struct xe_bb){ .cs = xe_mem_pool_node_cpu_addr(bb), .len = 0 };
12301233
/*
12311234
* Emit PTE and copy commands here.
12321235
* The CCS copy command can only support limited size. If the size to be
@@ -1255,24 +1258,27 @@ int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
12551258
xe_assert(xe, IS_ALIGNED(ccs_it.start, PAGE_SIZE));
12561259
batch_size += EMIT_COPY_CCS_DW;
12571260

1258-
emit_pte(m, bb, src_L0_pt, false, true, &src_it, src_L0, src);
1261+
emit_pte(m, &xe_bb_tmp, src_L0_pt, false, true, &src_it, src_L0, src);
12591262

1260-
emit_pte(m, bb, ccs_pt, false, false, &ccs_it, ccs_size, src);
1263+
emit_pte(m, &xe_bb_tmp, ccs_pt, false, false, &ccs_it, ccs_size, src);
12611264

1262-
bb->len = emit_flush_invalidate(bb->cs, bb->len, flush_flags);
1263-
flush_flags = xe_migrate_ccs_copy(m, bb, src_L0_ofs, src_is_pltt,
1265+
xe_bb_tmp.len = emit_flush_invalidate(xe_bb_tmp.cs, xe_bb_tmp.len,
1266+
flush_flags);
1267+
flush_flags = xe_migrate_ccs_copy(m, &xe_bb_tmp, src_L0_ofs, src_is_pltt,
12641268
src_L0_ofs, dst_is_pltt,
12651269
src_L0, ccs_ofs, true);
1266-
bb->len = emit_flush_invalidate(bb->cs, bb->len, flush_flags);
1270+
xe_bb_tmp.len = emit_flush_invalidate(xe_bb_tmp.cs, xe_bb_tmp.len,
1271+
flush_flags);
12671272

12681273
size -= src_L0;
12691274
}
12701275

1271-
xe_assert(xe, (batch_size_allocated == bb->len));
1276+
xe_assert(xe, (batch_size_allocated == xe_bb_tmp.len));
1277+
xe_assert(xe, bb->sa_node.size == xe_bb_tmp.len * sizeof(u32));
12721278
src_bo->bb_ccs[read_write] = bb;
12731279

12741280
xe_sriov_vf_ccs_rw_update_bb_addr(ctx);
1275-
xe_sa_bo_sync_shadow(bb->bo);
1281+
xe_mem_pool_sync_shadow_locked(bb);
12761282
}
12771283

12781284
return 0;
@@ -1297,28 +1303,28 @@ int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
12971303
void xe_migrate_ccs_rw_copy_clear(struct xe_bo *src_bo,
12981304
enum xe_sriov_vf_ccs_rw_ctxs read_write)
12991305
{
1300-
struct xe_bb *bb = src_bo->bb_ccs[read_write];
1306+
struct xe_mem_pool_node *bb = src_bo->bb_ccs[read_write];
13011307
struct xe_device *xe = xe_bo_device(src_bo);
1308+
struct xe_mem_pool *bb_pool;
13021309
struct xe_sriov_vf_ccs_ctx *ctx;
1303-
struct xe_sa_manager *bb_pool;
13041310
u32 *cs;
13051311

13061312
xe_assert(xe, IS_SRIOV_VF(xe));
13071313

13081314
ctx = &xe->sriov.vf.ccs.contexts[read_write];
13091315
bb_pool = ctx->mem.ccs_bb_pool;
13101316

1311-
guard(mutex) (xe_sa_bo_swap_guard(bb_pool));
1312-
xe_sa_bo_swap_shadow(bb_pool);
1313-
1314-
cs = xe_sa_bo_cpu_addr(bb->bo);
1315-
memset(cs, MI_NOOP, bb->len * sizeof(u32));
1316-
xe_sriov_vf_ccs_rw_update_bb_addr(ctx);
1317+
scoped_guard(mutex, xe_mem_pool_bo_swap_guard(bb_pool)) {
1318+
xe_mem_pool_swap_shadow_locked(bb_pool);
13171319

1318-
xe_sa_bo_sync_shadow(bb->bo);
1320+
cs = xe_mem_pool_node_cpu_addr(bb);
1321+
memset(cs, MI_NOOP, bb->sa_node.size);
1322+
xe_sriov_vf_ccs_rw_update_bb_addr(ctx);
13191323

1320-
xe_bb_free(bb, NULL);
1321-
src_bo->bb_ccs[read_write] = NULL;
1324+
xe_mem_pool_sync_shadow_locked(bb);
1325+
xe_mem_pool_free_node(bb);
1326+
src_bo->bb_ccs[read_write] = NULL;
1327+
}
13221328
}
13231329

13241330
/**

drivers/gpu/drm/xe/xe_sriov_vf_ccs.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include "xe_guc.h"
1515
#include "xe_guc_submit.h"
1616
#include "xe_lrc.h"
17+
#include "xe_mem_pool.h"
1718
#include "xe_migrate.h"
1819
#include "xe_pm.h"
19-
#include "xe_sa.h"
2020
#include "xe_sriov_printk.h"
2121
#include "xe_sriov_vf.h"
2222
#include "xe_sriov_vf_ccs.h"
@@ -141,43 +141,47 @@ static u64 get_ccs_bb_pool_size(struct xe_device *xe)
141141

142142
static int alloc_bb_pool(struct xe_tile *tile, struct xe_sriov_vf_ccs_ctx *ctx)
143143
{
144+
struct xe_mem_pool *pool;
144145
struct xe_device *xe = tile_to_xe(tile);
145-
struct xe_sa_manager *sa_manager;
146+
u32 *pool_cpu_addr, *last_dw_addr;
146147
u64 bb_pool_size;
147-
int offset, err;
148+
int err;
148149

149150
bb_pool_size = get_ccs_bb_pool_size(xe);
150151
xe_sriov_info(xe, "Allocating %s CCS BB pool size = %lldMB\n",
151152
ctx->ctx_id ? "Restore" : "Save", bb_pool_size / SZ_1M);
152153

153-
sa_manager = __xe_sa_bo_manager_init(tile, bb_pool_size, SZ_4K, SZ_16,
154-
XE_SA_BO_MANAGER_FLAG_SHADOW);
155-
156-
if (IS_ERR(sa_manager)) {
157-
xe_sriov_err(xe, "Suballocator init failed with error: %pe\n",
158-
sa_manager);
159-
err = PTR_ERR(sa_manager);
154+
pool = xe_mem_pool_init(tile, bb_pool_size, sizeof(u32),
155+
XE_MEM_POOL_BO_FLAG_INIT_SHADOW_COPY);
156+
if (IS_ERR(pool)) {
157+
xe_sriov_err(xe, "xe_mem_pool_init failed with error: %pe\n",
158+
pool);
159+
err = PTR_ERR(pool);
160160
return err;
161161
}
162162

163-
offset = 0;
164-
xe_map_memset(xe, &sa_manager->bo->vmap, offset, MI_NOOP,
165-
bb_pool_size);
166-
xe_map_memset(xe, &sa_manager->shadow->vmap, offset, MI_NOOP,
167-
bb_pool_size);
163+
pool_cpu_addr = xe_mem_pool_cpu_addr(pool);
164+
memset(pool_cpu_addr, 0, bb_pool_size);
168165

169-
offset = bb_pool_size - sizeof(u32);
170-
xe_map_wr(xe, &sa_manager->bo->vmap, offset, u32, MI_BATCH_BUFFER_END);
171-
xe_map_wr(xe, &sa_manager->shadow->vmap, offset, u32, MI_BATCH_BUFFER_END);
166+
last_dw_addr = pool_cpu_addr + (bb_pool_size / sizeof(u32)) - 1;
167+
*last_dw_addr = MI_BATCH_BUFFER_END;
172168

173-
ctx->mem.ccs_bb_pool = sa_manager;
169+
/**
170+
* Sync the main copy and shadow copy so that the shadow copy is
171+
* replica of main copy. We sync only BBs after init part. So, we
172+
* need to make sure the main pool and shadow copy are in sync after
173+
* this point. This is needed as GuC may read the BB commands from
174+
* shadow copy.
175+
*/
176+
xe_mem_pool_sync(pool);
174177

178+
ctx->mem.ccs_bb_pool = pool;
175179
return 0;
176180
}
177181

178182
static void ccs_rw_update_ring(struct xe_sriov_vf_ccs_ctx *ctx)
179183
{
180-
u64 addr = xe_sa_manager_gpu_addr(ctx->mem.ccs_bb_pool);
184+
u64 addr = xe_mem_pool_gpu_addr(ctx->mem.ccs_bb_pool);
181185
struct xe_lrc *lrc = xe_exec_queue_lrc(ctx->mig_q);
182186
u32 dw[10], i = 0;
183187

@@ -388,7 +392,7 @@ int xe_sriov_vf_ccs_init(struct xe_device *xe)
388392
#define XE_SRIOV_VF_CCS_RW_BB_ADDR_OFFSET (2 * sizeof(u32))
389393
void xe_sriov_vf_ccs_rw_update_bb_addr(struct xe_sriov_vf_ccs_ctx *ctx)
390394
{
391-
u64 addr = xe_sa_manager_gpu_addr(ctx->mem.ccs_bb_pool);
395+
u64 addr = xe_mem_pool_gpu_addr(ctx->mem.ccs_bb_pool);
392396
struct xe_lrc *lrc = xe_exec_queue_lrc(ctx->mig_q);
393397
struct xe_device *xe = gt_to_xe(ctx->mig_q->gt);
394398

@@ -412,8 +416,8 @@ int xe_sriov_vf_ccs_attach_bo(struct xe_bo *bo)
412416
struct xe_device *xe = xe_bo_device(bo);
413417
enum xe_sriov_vf_ccs_rw_ctxs ctx_id;
414418
struct xe_sriov_vf_ccs_ctx *ctx;
419+
struct xe_mem_pool_node *bb;
415420
struct xe_tile *tile;
416-
struct xe_bb *bb;
417421
int err = 0;
418422

419423
xe_assert(xe, IS_VF_CCS_READY(xe));
@@ -445,7 +449,7 @@ int xe_sriov_vf_ccs_detach_bo(struct xe_bo *bo)
445449
{
446450
struct xe_device *xe = xe_bo_device(bo);
447451
enum xe_sriov_vf_ccs_rw_ctxs ctx_id;
448-
struct xe_bb *bb;
452+
struct xe_mem_pool_node *bb;
449453

450454
xe_assert(xe, IS_VF_CCS_READY(xe));
451455

@@ -471,8 +475,8 @@ int xe_sriov_vf_ccs_detach_bo(struct xe_bo *bo)
471475
*/
472476
void xe_sriov_vf_ccs_print(struct xe_device *xe, struct drm_printer *p)
473477
{
474-
struct xe_sa_manager *bb_pool;
475478
enum xe_sriov_vf_ccs_rw_ctxs ctx_id;
479+
struct xe_mem_pool *bb_pool;
476480

477481
if (!IS_VF_CCS_READY(xe))
478482
return;
@@ -485,7 +489,7 @@ void xe_sriov_vf_ccs_print(struct xe_device *xe, struct drm_printer *p)
485489

486490
drm_printf(p, "ccs %s bb suballoc info\n", ctx_id ? "write" : "read");
487491
drm_printf(p, "-------------------------\n");
488-
drm_suballoc_dump_debug_info(&bb_pool->base, p, xe_sa_manager_gpu_addr(bb_pool));
492+
xe_mem_pool_dump(bb_pool, p);
489493
drm_puts(p, "\n");
490494
}
491495
}

drivers/gpu/drm/xe/xe_sriov_vf_ccs_types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ enum xe_sriov_vf_ccs_rw_ctxs {
1717
XE_SRIOV_VF_CCS_CTX_COUNT
1818
};
1919

20-
struct xe_migrate;
21-
struct xe_sa_manager;
22-
2320
/**
2421
* struct xe_sriov_vf_ccs_ctx - VF CCS migration context data.
2522
*/
@@ -33,7 +30,7 @@ struct xe_sriov_vf_ccs_ctx {
3330
/** @mem: memory data */
3431
struct {
3532
/** @mem.ccs_bb_pool: Pool from which batch buffers are allocated. */
36-
struct xe_sa_manager *ccs_bb_pool;
33+
struct xe_mem_pool *ccs_bb_pool;
3734
} mem;
3835
};
3936

0 commit comments

Comments
 (0)