[PATCH v3 5/8] drm/xe: add XE_BO_FLAG_PINNED_LATE_RESTORE
K V P, Satyanarayana
satyanarayana.k.v.p at intel.com
Wed Mar 26 06:15:12 UTC 2025
> From: Auld, Matthew <matthew.auld at intel.com>
> Sent: Friday, March 7, 2025 11:59 PM
> To: intel-xe at lists.freedesktop.org
> Cc: K V P, Satyanarayana <satyanarayana.k.v.p at intel.com>; Thomas Hellström
> <thomas.hellstrom at linux.intel.com>; Brost, Matthew
> <matthew.brost at intel.com>
> Subject: [PATCH v3 5/8] drm/xe: add XE_BO_FLAG_PINNED_LATE_RESTORE
>
> With the idea of having more pinned objects using the blitter engine
> where possible, during suspend/resume, mark the pinned objects which
> can be done during the late phase once submission/migration has been
> setup. Start out simple with lrc and page-tables from userspace.
>
> v2:
> - s/early_restore/late_restore; early restore was way too bold with too
> many places being impacted at once.
>
> Signed-off-by: Matthew Auld <matthew.auld at intel.com>
> Cc: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
> ---
> drivers/gpu/drm/xe/xe_bo.c | 4 ++--
> drivers/gpu/drm/xe/xe_bo.h | 9 +++++----
> drivers/gpu/drm/xe/xe_bo_evict.c | 6 ++++--
> drivers/gpu/drm/xe/xe_lrc.c | 10 +++++++---
> drivers/gpu/drm/xe/xe_pt.c | 13 ++++++++-----
> 5 files changed, 26 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index f22b02700778..fe5a386d5dc8 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1103,7 +1103,7 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
> goto out_unlock_bo;
> }
>
> - if (xe_bo_is_user(bo)) {
> + if (xe_bo_is_user(bo) || (bo->flags &
> XE_BO_FLAG_PINNED_LATE_RESTORE)) {
> struct xe_migrate *migrate;
> struct dma_fence *fence;
>
> @@ -1198,7 +1198,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
> goto out_backup;
> }
>
> - if (xe_bo_is_user(bo)) {
> + if (xe_bo_is_user(bo) || (bo->flags &
> XE_BO_FLAG_PINNED_LATE_RESTORE)) {
> struct xe_migrate *migrate;
> struct dma_fence *fence;
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
> index 3937111c2adb..c1961eebd0bc 100644
> --- a/drivers/gpu/drm/xe/xe_bo.h
> +++ b/drivers/gpu/drm/xe/xe_bo.h
> @@ -40,10 +40,11 @@
> #define XE_BO_FLAG_NEEDS_2M BIT(16)
> #define XE_BO_FLAG_GGTT_INVALIDATE BIT(17)
> #define XE_BO_FLAG_PINNED_NORESTORE BIT(18)
> -#define XE_BO_FLAG_GGTT0 BIT(19)
> -#define XE_BO_FLAG_GGTT1 BIT(20)
> -#define XE_BO_FLAG_GGTT2 BIT(21)
> -#define XE_BO_FLAG_GGTT3 BIT(22)
> +#define XE_BO_FLAG_PINNED_LATE_RESTORE BIT(19)
> +#define XE_BO_FLAG_GGTT0 BIT(20)
> +#define XE_BO_FLAG_GGTT1 BIT(21)
> +#define XE_BO_FLAG_GGTT2 BIT(22)
> +#define XE_BO_FLAG_GGTT3 BIT(23)
> #define XE_BO_FLAG_GGTT_ALL (XE_BO_FLAG_GGTT0 | \
> XE_BO_FLAG_GGTT1 | \
> XE_BO_FLAG_GGTT2 | \
nit: Can't we define XE_BO_FLAG_PINNED_LATE_RESTORE as BIT(23)? Do we see any issue with this?
Other than this, LGTM.
Reviewed-by: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
> diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c
> b/drivers/gpu/drm/xe/xe_bo_evict.c
> index 41a948de3583..0c2cfa534495 100644
> --- a/drivers/gpu/drm/xe/xe_bo_evict.c
> +++ b/drivers/gpu/drm/xe/xe_bo_evict.c
> @@ -24,7 +24,8 @@ static int xe_evict_pinned(struct xe_device *xe, bool
> memcpy_only)
> if (!bo)
> break;
>
> - if (!memcpy_only && !xe_bo_is_user(bo)) {
> + if (!memcpy_only &&
> + !(xe_bo_is_user(bo) || (bo->flags &
> XE_BO_FLAG_PINNED_LATE_RESTORE))) {
> list_move_tail(&bo->pinned_link, &skipped);
> continue;
> }
> @@ -135,7 +136,8 @@ static int xe_restore_pinned(struct xe_device *xe,
> bool memcpy_only)
> if (!bo)
> break;
>
> - if (memcpy_only && xe_bo_is_user(bo)) {
> + if (memcpy_only &&
> + (xe_bo_is_user(bo) || (bo->flags &
> XE_BO_FLAG_PINNED_LATE_RESTORE))) {
> list_move_tail(&bo->pinned_link, &skipped);
> continue;
> }
> diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
> index df3ceddede07..ffa07648690e 100644
> --- a/drivers/gpu/drm/xe/xe_lrc.c
> +++ b/drivers/gpu/drm/xe/xe_lrc.c
> @@ -893,6 +893,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct
> xe_hw_engine *hwe,
> void *init_data = NULL;
> u32 arb_enable;
> u32 lrc_size;
> + u32 bo_flags;
> int err;
>
> kref_init(&lrc->refcount);
> @@ -901,15 +902,18 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct
> xe_hw_engine *hwe,
> if (xe_gt_has_indirect_ring_state(gt))
> lrc->flags |= XE_LRC_FLAG_INDIRECT_RING_STATE;
>
> + bo_flags = XE_BO_FLAG_VRAM_IF_DGFX(tile) | XE_BO_FLAG_GGTT |
> + XE_BO_FLAG_GGTT_INVALIDATE;
> + if (vm && vm->xef) /* userspace */
> + bo_flags |= XE_BO_FLAG_PINNED_LATE_RESTORE;
> +
> /*
> * FIXME: Perma-pinning LRC as we don't yet support moving GGTT
> address
> * via VM bind calls.
> */
> lrc->bo = xe_bo_create_pin_map(xe, tile, vm, lrc_size,
> ttm_bo_type_kernel,
> - XE_BO_FLAG_VRAM_IF_DGFX(tile) |
> - XE_BO_FLAG_GGTT |
> - XE_BO_FLAG_GGTT_INVALIDATE);
> + bo_flags);
> if (IS_ERR(lrc->bo))
> return PTR_ERR(lrc->bo);
>
> diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
> index ffaf0d02dc7d..05209f0ffe5c 100644
> --- a/drivers/gpu/drm/xe/xe_pt.c
> +++ b/drivers/gpu/drm/xe/xe_pt.c
> @@ -103,6 +103,7 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm, struct
> xe_tile *tile,
> {
> struct xe_pt *pt;
> struct xe_bo *bo;
> + u32 bo_flags;
> int err;
>
> if (level) {
> @@ -115,14 +116,16 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm,
> struct xe_tile *tile,
> if (!pt)
> return ERR_PTR(-ENOMEM);
>
> + bo_flags = XE_BO_FLAG_VRAM_IF_DGFX(tile) |
> + XE_BO_FLAG_IGNORE_MIN_PAGE_SIZE |
> XE_BO_FLAG_PINNED |
> + XE_BO_FLAG_NO_RESV_EVICT | XE_BO_FLAG_PAGETABLE;
> + if (vm->xef) /* userspace */
> + bo_flags |= XE_BO_FLAG_PINNED_LATE_RESTORE;
> +
> pt->level = level;
> bo = xe_bo_create_pin_map(vm->xe, tile, vm, SZ_4K,
> ttm_bo_type_kernel,
> - XE_BO_FLAG_VRAM_IF_DGFX(tile) |
> - XE_BO_FLAG_IGNORE_MIN_PAGE_SIZE |
> - XE_BO_FLAG_PINNED |
> - XE_BO_FLAG_NO_RESV_EVICT |
> - XE_BO_FLAG_PAGETABLE);
> + bo_flags);
> if (IS_ERR(bo)) {
> err = PTR_ERR(bo);
> goto err_kfree;
> --
> 2.48.1
More information about the Intel-xe
mailing list