From a201c6ee37d63e7c0a2973fb7790e94211b7fa83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= Date: Mon, 26 Jun 2023 20:17:41 +0200 Subject: [PATCH] drm/xe/bo: Evict VRAM to TT rather than to system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main difference is that we don't bounce and sync on eviction, allowing for pipelined eviction. Moving forward we also need to be careful with dma mappings which can be released in SYSTEM but may remain in TT. v2: - Remove a stale comment (Matthew Brost) Signed-off-by: Thomas Hellström Reviewed-by: Matthew Brost Link: https://patchwork.freedesktop.org/patch/msgid/20230626181741.32820-5-thomas.hellstrom@linux.intel.com Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_dma_buf.c | 5 ++--- drivers/gpu/drm/xe/xe_bo.c | 17 ++++++++++++++++- drivers/gpu/drm/xe/xe_dma_buf.c | 11 ++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/xe/tests/xe_dma_buf.c b/drivers/gpu/drm/xe/tests/xe_dma_buf.c index 513a3b3362e9..810a035bf720 100644 --- a/drivers/gpu/drm/xe/tests/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/tests/xe_dma_buf.c @@ -72,7 +72,7 @@ static void check_residency(struct kunit *test, struct xe_bo *exported, } /* Verify that also importer has been evicted to SYSTEM */ - if (!xe_bo_is_mem_type(imported, XE_PL_SYSTEM)) { + if (exported != imported && !xe_bo_is_mem_type(imported, XE_PL_SYSTEM)) { KUNIT_FAIL(test, "Importer wasn't properly evicted.\n"); return; } @@ -91,8 +91,7 @@ static void check_residency(struct kunit *test, struct xe_bo *exported, * possible, saving a migration step as the transfer is just * likely as fast from system memory. */ - if (params->force_different_devices && - params->mem_mask & XE_BO_CREATE_SYSTEM_BIT) + if (params->mem_mask & XE_BO_CREATE_SYSTEM_BIT) KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(exported, XE_PL_TT)); else KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(exported, mem_type)); diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 1f4d1790d57c..17c0c6c2ae65 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -40,6 +40,20 @@ static struct ttm_placement sys_placement = { .busy_placement = &sys_placement_flags, }; +static const struct ttm_place tt_placement_flags = { + .fpfn = 0, + .lpfn = 0, + .mem_type = XE_PL_TT, + .flags = 0, +}; + +static struct ttm_placement tt_placement = { + .num_placement = 1, + .placement = &tt_placement_flags, + .num_busy_placement = 1, + .busy_placement = &sys_placement_flags, +}; + bool mem_type_is_vram(u32 mem_type) { return mem_type >= XE_PL_VRAM0 && mem_type != XE_PL_STOLEN; @@ -225,9 +239,10 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo, case XE_PL_VRAM0: case XE_PL_VRAM1: case XE_PL_STOLEN: + *placement = tt_placement; + break; case XE_PL_TT: default: - /* for now kick out to system */ *placement = sys_placement; break; } diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index 975dee1f770f..b9bf4b4dd8a5 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -81,13 +81,10 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach, return ERR_PTR(-EOPNOTSUPP); if (!xe_bo_is_pinned(bo)) { - if (!attach->peer2peer || - bo->ttm.resource->mem_type == XE_PL_SYSTEM) { - if (xe_bo_can_migrate(bo, XE_PL_TT)) - r = xe_bo_migrate(bo, XE_PL_TT); - else - r = xe_bo_validate(bo, NULL, false); - } + if (!attach->peer2peer) + r = xe_bo_migrate(bo, XE_PL_TT); + else + r = xe_bo_validate(bo, NULL, false); if (r) return ERR_PTR(r); }