Commit 08dea767 authored by Matt Roper's avatar Matt Roper Committed by Rodrigo Vivi
Browse files

drm/xe: Move migration from GT to tile



Migration primarily focuses on the memory associated with a tile, so it
makes more sense to track this at the tile level (especially since the
driver was already skipping migration operations on media GTs).

Note that the blitter engine used to perform the migration always lives
in the tile's primary GT today.  In theory that could change if media
GTs ever start including blitter engines in the future, but we can
extend the design if/when that happens in the future.

v2:
 - Fix kunit test build
 - Kerneldoc parameter name update
v3:
 - Removed leftover prototype for removed function.  (Gustavo)
 - Remove unrelated / unwanted error handling change.  (Gustavo)

Cc: Gustavo Sousa <gustavo.sousa@intel.com>
Reviewed-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Acked-by: default avatarGustavo Sousa <gustavo.sousa@intel.com>
Link: https://lore.kernel.org/r/20230601215244.678611-15-matthew.d.roper@intel.com


Signed-off-by: default avatarMatt Roper <matthew.d.roper@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent 876611c2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ static int ccs_test_migrate(struct xe_gt *gt, struct xe_bo *bo,

	/* Optionally clear bo *and* CCS data in VRAM. */
	if (clear) {
		fence = xe_migrate_clear(gt->migrate, bo, bo->ttm.resource);
		fence = xe_migrate_clear(gt_to_tile(gt)->migrate, bo, bo->ttm.resource);
		if (IS_ERR(fence)) {
			KUNIT_FAIL(test, "Failed to submit bo clear.\n");
			return PTR_ERR(fence);
@@ -174,7 +174,7 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
	struct xe_bo *bo, *external;
	unsigned int bo_flags = XE_BO_CREATE_USER_BIT |
		XE_BO_CREATE_VRAM_IF_DGFX(gt_to_tile(gt));
	struct xe_vm *vm = xe_migrate_get_vm(xe_device_get_root_tile(xe)->primary_gt.migrate);
	struct xe_vm *vm = xe_migrate_get_vm(xe_device_get_root_tile(xe)->migrate);
	struct ww_acquire_ctx ww;
	int err, i;

+12 −13
Original line number Diff line number Diff line
@@ -101,14 +101,14 @@ static const struct xe_migrate_pt_update_ops sanity_ops = {
static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
		      struct kunit *test)
{
	struct xe_device *xe = gt_to_xe(m->gt);
	struct xe_device *xe = tile_to_xe(m->tile);
	u64 retval, expected = 0;
	bool big = bo->size >= SZ_2M;
	struct dma_fence *fence;
	const char *str = big ? "Copying big bo" : "Copying small bo";
	int err;

	struct xe_bo *sysmem = xe_bo_create_locked(xe, gt_to_tile(m->gt), NULL,
	struct xe_bo *sysmem = xe_bo_create_locked(xe, m->tile, NULL,
						   bo->size,
						   ttm_bo_type_kernel,
						   XE_BO_CREATE_SYSTEM_BIT);
@@ -189,7 +189,7 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
static void test_pt_update(struct xe_migrate *m, struct xe_bo *pt,
			   struct kunit *test, bool force_gpu)
{
	struct xe_device *xe = gt_to_xe(m->gt);
	struct xe_device *xe = tile_to_xe(m->tile);
	struct dma_fence *fence;
	u64 retval, expected;
	ktime_t then, now;
@@ -239,16 +239,15 @@ static void test_pt_update(struct xe_migrate *m, struct xe_bo *pt,

static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)
{
	struct xe_gt *gt = m->gt;
	struct xe_tile *tile = gt_to_tile(m->gt);
	struct xe_device *xe = gt_to_xe(gt);
	struct xe_tile *tile = m->tile;
	struct xe_device *xe = tile_to_xe(tile);
	struct xe_bo *pt, *bo = m->pt_bo, *big, *tiny;
	struct xe_res_cursor src_it;
	struct dma_fence *fence;
	u64 retval, expected;
	struct xe_bb *bb;
	int err;
	u8 id = gt->info.id;
	u8 id = tile->id;

	err = xe_bo_vmap(bo);
	if (err) {
@@ -287,7 +286,7 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)
		goto free_pt;
	}

	bb = xe_bb_new(gt, 32, xe->info.supports_usm);
	bb = xe_bb_new(&tile->primary_gt, 32, xe->info.supports_usm);
	if (IS_ERR(bb)) {
		KUNIT_FAIL(test, "Failed to create batchbuffer: %li\n",
			   PTR_ERR(bb));
@@ -324,7 +323,7 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)
	xe_map_wr(xe, &pt->vmap, 0, u32, 0xdeaddead);
	expected = 0;

	emit_clear(m->gt, bb, xe_migrate_vm_addr(NUM_KERNEL_PDE - 1, 0), 4, 4,
	emit_clear(&tile->primary_gt, bb, xe_migrate_vm_addr(NUM_KERNEL_PDE - 1, 0), 4, 4,
		   IS_DGFX(xe));
	run_sanity_job(m, xe, bb, 1, "Writing to our newly mapped pagetable",
		       test);
@@ -391,14 +390,14 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)
static int migrate_test_run_device(struct xe_device *xe)
{
	struct kunit *test = xe_cur_kunit();
	struct xe_gt *gt;
	struct xe_tile *tile;
	int id;

	for_each_gt(gt, xe, id) {
		struct xe_migrate *m = gt->migrate;
	for_each_tile(tile, xe, id) {
		struct xe_migrate *m = tile->migrate;
		struct ww_acquire_ctx ww;

		kunit_info(test, "Testing gt id %d.\n", id);
		kunit_info(test, "Testing tile id %d.\n", id);
		xe_vm_lock(m->eng->vm, &ww, 0, true);
		xe_device_mem_access_get(xe);
		xe_migrate_sanity_test(m, test);
+3 −3
Original line number Diff line number Diff line
@@ -643,7 +643,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
		tile = mem_type_to_tile(xe, old_mem->mem_type);

	XE_BUG_ON(!tile);
	XE_BUG_ON(!tile->primary_gt.migrate);
	XE_BUG_ON(!tile->migrate);

	trace_xe_bo_move(bo);
	xe_device_mem_access_get(xe);
@@ -681,9 +681,9 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
		}
	} else {
		if (move_lacks_source)
			fence = xe_migrate_clear(tile->primary_gt.migrate, bo, new_mem);
			fence = xe_migrate_clear(tile->migrate, bo, new_mem);
		else
			fence = xe_migrate_copy(tile->primary_gt.migrate,
			fence = xe_migrate_copy(tile->migrate,
						bo, bo, old_mem, new_mem);
		if (IS_ERR(fence)) {
			ret = PTR_ERR(fence);
+7 −7
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
#include "xe_bo.h"
#include "xe_device.h"
#include "xe_ggtt.h"
#include "xe_gt.h"
#include "xe_tile.h"

/**
 * xe_bo_evict_all - evict all BOs from VRAM
@@ -29,7 +29,7 @@ int xe_bo_evict_all(struct xe_device *xe)
	struct ttm_device *bdev = &xe->ttm;
	struct ww_acquire_ctx ww;
	struct xe_bo *bo;
	struct xe_gt *gt;
	struct xe_tile *tile;
	struct list_head still_in_list;
	u32 mem_type;
	u8 id;
@@ -83,8 +83,8 @@ int xe_bo_evict_all(struct xe_device *xe)
	 * Wait for all user BO to be evicted as those evictions depend on the
	 * memory moved below.
	 */
	for_each_gt(gt, xe, id)
		xe_gt_migrate_wait(gt);
	for_each_tile(tile, xe, id)
		xe_tile_migrate_wait(tile);

	spin_lock(&xe->pinned.lock);
	for (;;) {
@@ -186,7 +186,7 @@ int xe_bo_restore_user(struct xe_device *xe)
{
	struct ww_acquire_ctx ww;
	struct xe_bo *bo;
	struct xe_gt *gt;
	struct xe_tile *tile;
	struct list_head still_in_list;
	u8 id;
	int ret;
@@ -224,8 +224,8 @@ int xe_bo_restore_user(struct xe_device *xe)
	spin_unlock(&xe->pinned.lock);

	/* Wait for validate to complete */
	for_each_gt(gt, xe, id)
		xe_gt_migrate_wait(gt);
	for_each_tile(tile, xe, id)
		xe_tile_migrate_wait(tile);

	return 0;
}
+3 −0
Original line number Diff line number Diff line
@@ -136,6 +136,9 @@ struct xe_tile {
		 */
		struct xe_sa_manager *kernel_bb_pool;
	} mem;

	/** @migrate: Migration helper for vram blits and clearing */
	struct xe_migrate *migrate;
};

/**
Loading