Commit 9f8aa0bc authored by Satyanarayana K V P's avatar Satyanarayana K V P Committed by Matthew Brost
Browse files

drm/xe/vf: Refactor CCS save/restore to use default migration context



Previously, CCS save/restore operations created separate migration
contexts with new VM memory allocations, resulting in significant
overhead.

This commit eliminates redundant context creation reusing the default
migration context by registering new execution queues for CCS save and
restore on the existing migrate VM.

Signed-off-by: default avatarSatyanarayana K V P <satyanarayana.k.v.p@intel.com>
Suggested-by: default avatarMatthew Brost <matthew.brost@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Reviewed-by: default avatarStuart Summers <stuart.summers@intel.com>
Signed-off-by: default avatarMatthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250808073628.32745-2-satyanarayana.k.v.p@intel.com
parent 342d1f84
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -789,6 +789,21 @@ int xe_exec_queue_get_property_ioctl(struct drm_device *dev, void *data,
	return ret;
}

/**
 * xe_exec_queue_lrc() - Get the LRC from exec queue.
 * @q: The exec_queue.
 *
 * Retrieves the primary LRC for the exec queue. Note that this function
 * returns only the first LRC instance, even when multiple parallel LRCs
 * are configured.
 *
 * Return: Pointer to LRC on success, error on failure
 */
struct xe_lrc *xe_exec_queue_lrc(struct xe_exec_queue *q)
{
	return q->lrc[0];
}

/**
 * xe_exec_queue_is_lr() - Whether an exec_queue is long-running
 * @q: The exec_queue
+1 −0
Original line number Diff line number Diff line
@@ -94,4 +94,5 @@ int xe_exec_queue_contexts_hwsp_rebase(struct xe_exec_queue *q, void *scratch);

void xe_exec_queue_jobs_ring_restore(struct xe_exec_queue *q);

struct xe_lrc *xe_exec_queue_lrc(struct xe_exec_queue *q);
#endif
+12 −9
Original line number Diff line number Diff line
@@ -951,7 +951,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
}

/**
 * xe_get_migrate_lrc() - Get the LRC from migrate context.
 * xe_migrate_lrc() - Get the LRC from migrate context.
 * @migrate: Migrate context.
 *
 * Return: Pointer to LRC on success, error on failure
@@ -961,14 +961,15 @@ struct xe_lrc *xe_migrate_lrc(struct xe_migrate *migrate)
	return migrate->q->lrc[0];
}

static int emit_flush_invalidate(struct xe_migrate *m, u32 *dw, int i,
static int emit_flush_invalidate(struct xe_exec_queue *q, u32 *dw, int i,
				 u32 flags)
{
	struct xe_lrc *lrc = xe_exec_queue_lrc(q);
	dw[i++] = MI_FLUSH_DW | MI_INVALIDATE_TLB | MI_FLUSH_DW_OP_STOREDW |
		  MI_FLUSH_IMM_DW | flags;
	dw[i++] = lower_32_bits(xe_lrc_start_seqno_ggtt_addr(xe_migrate_lrc(m))) |
	dw[i++] = lower_32_bits(xe_lrc_start_seqno_ggtt_addr(lrc)) |
		  MI_FLUSH_DW_USE_GTT;
	dw[i++] = upper_32_bits(xe_lrc_start_seqno_ggtt_addr(xe_migrate_lrc(m)));
	dw[i++] = upper_32_bits(xe_lrc_start_seqno_ggtt_addr(lrc));
	dw[i++] = MI_NOOP;
	dw[i++] = MI_NOOP;

@@ -977,7 +978,8 @@ static int emit_flush_invalidate(struct xe_migrate *m, u32 *dw, int i,

/**
 * xe_migrate_ccs_rw_copy() - Copy content of TTM resources.
 * @m: The migration context.
 * @tile: Tile whose migration context to be used.
 * @q : Execution to be used along with migration context.
 * @src_bo: The buffer object @src is currently bound to.
 * @read_write : Creates BB commands for CCS read/write.
 *
@@ -988,7 +990,7 @@ static int emit_flush_invalidate(struct xe_migrate *m, u32 *dw, int i,
 *
 * Return: 0 if successful, negative error code on failure.
 */
int xe_migrate_ccs_rw_copy(struct xe_migrate *m,
int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
			   struct xe_bo *src_bo,
			   enum xe_sriov_vf_ccs_rw_ctxs read_write)

@@ -996,7 +998,8 @@ int xe_migrate_ccs_rw_copy(struct xe_migrate *m,
	bool src_is_pltt = read_write == XE_SRIOV_VF_CCS_READ_CTX;
	bool dst_is_pltt = read_write == XE_SRIOV_VF_CCS_WRITE_CTX;
	struct ttm_resource *src = src_bo->ttm.resource;
	struct xe_gt *gt = m->tile->primary_gt;
	struct xe_migrate *m = tile->migrate;
	struct xe_gt *gt = tile->primary_gt;
	u32 batch_size, batch_size_allocated;
	struct xe_device *xe = gt_to_xe(gt);
	struct xe_res_cursor src_it, ccs_it;
@@ -1079,11 +1082,11 @@ int xe_migrate_ccs_rw_copy(struct xe_migrate *m,

		emit_pte(m, bb, ccs_pt, false, false, &ccs_it, ccs_size, src);

		bb->len = emit_flush_invalidate(m, bb->cs, bb->len, flush_flags);
		bb->len = emit_flush_invalidate(q, bb->cs, bb->len, flush_flags);
		flush_flags = xe_migrate_ccs_copy(m, bb, src_L0_ofs, src_is_pltt,
						  src_L0_ofs, dst_is_pltt,
						  src_L0, ccs_ofs, true);
		bb->len = emit_flush_invalidate(m, bb->cs, bb->len, flush_flags);
		bb->len = emit_flush_invalidate(q, bb->cs, bb->len, flush_flags);

		size -= src_L0;
	}
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
				  struct ttm_resource *dst,
				  bool copy_only_ccs);

int xe_migrate_ccs_rw_copy(struct xe_migrate *m,
int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
			   struct xe_bo *src_bo,
			   enum xe_sriov_vf_ccs_rw_ctxs read_write);

+3 −0
Original line number Diff line number Diff line
@@ -209,6 +209,9 @@ int xe_pm_resume(struct xe_device *xe)

	xe_pxp_pm_resume(xe->pxp);

	if (IS_SRIOV_VF(xe))
		xe_sriov_vf_ccs_register_context(xe);

	drm_dbg(&xe->drm, "Device resumed\n");
	return 0;
err:
Loading