A future patch performs the destination DMA mapping of a defrag move in two stages when the BO is IOVA mapped: a temporary contiguous mapping of just tht changed pages used for the GPU copy, followed by a post-copy finalize stet that tears that mapping down and links the new backing into the (transferred) IOVA reservation. The finalize step must run only after the GPU copy it depends on has completed, so it is dispatched as an xe_dep_job,
Add a per-device xe_dep_scheduler dedicated to these finalize jobs, created in xe_bo_defrag_init() (after the migrate contexts are up) and torn down in xe_bo_defrag_fini(). No users yet; the job itself is added in a later patch. Cc: Carlos Santa <[email protected]> Cc: Ryan Neph <[email protected]> Cc: Christian Koenig <[email protected]> Cc: Huang Rui <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Maarten Lankhorst <[email protected]> Cc: Maxime Ripard <[email protected]> Cc: Thomas Zimmermann <[email protected]> Cc: David Airlie <[email protected]> Cc: Simona Vetter <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Thomas Hellström <[email protected]> Assisted-by: GitHub_Copilot:claude-opus-4.8 Signed-off-by: Matthew Brost <[email protected]> --- drivers/gpu/drm/xe/xe_bo.c | 15 +++++++++++++++ drivers/gpu/drm/xe/xe_device_types.h | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index f3d76ad9a105..ec034518e2ea 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -25,6 +25,7 @@ #include <trace/events/gpu_mem.h> #include "xe_device.h" +#include "xe_dep_scheduler.h" #include "xe_dma_buf.h" #include "xe_drm_client.h" #include "xe_ggtt.h" @@ -1300,6 +1301,10 @@ static void xe_bo_defrag_fini(void *arg) struct xe_device *xe = arg; disable_delayed_work_sync(&xe->mem.defrag.worker); + if (xe->mem.defrag.iova_sched) { + xe_dep_scheduler_fini(xe->mem.defrag.iova_sched); + xe->mem.defrag.iova_sched = NULL; + } } /** @@ -1336,6 +1341,16 @@ void xe_bo_defrag_init_early(struct xe_device *xe) */ int xe_bo_defrag_init(struct xe_device *xe) { +#define XE_BO_MAX_IOVA_DEFRAG_JOBS 16 /* Picking a reasonable value */ + struct xe_dep_scheduler *iova_sched; + + iova_sched = xe_dep_scheduler_create(xe, NULL, "xe_iova_defrag", + XE_BO_MAX_IOVA_DEFRAG_JOBS); + if (IS_ERR(iova_sched)) + return PTR_ERR(iova_sched); + xe->mem.defrag.iova_sched = iova_sched; +#undef XE_BO_MAX_IOVA_DEFRAG_JOBS + return devm_add_action_or_reset(xe->drm.dev, xe_bo_defrag_fini, xe); } diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 6e68add4d652..b55d549d5e30 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -38,6 +38,7 @@ struct drm_pagemap_shrinker; struct intel_display; +struct xe_dep_scheduler; struct intel_dg_nvm_dev; struct xe_ggtt; struct xe_i2c; @@ -325,6 +326,15 @@ struct xe_device { * @mem.defrag.worker, in milliseconds. */ unsigned int interval_ms; + /** + * @mem.defrag.iova_sched: Dependency scheduler used to + * run the post-copy IOVA finalize job for defrag moves + * of IOVA-mapped BOs. The job tears down the temporary + * copy-step IOVA mapping and links the new backing into + * the (transferred) reservation once the GPU copy that + * its dependencies gate has completed. + */ + struct xe_dep_scheduler *iova_sched; } defrag; } mem; -- 2.34.1
