From: Maarten Lankhorst <dev@lankhorst.se>
To: intel-xe@lists.freedesktop.org
Cc: Maarten Lankhorst <dev@lankhorst.se>
Subject: [CI 12/13] drm/xe: Allow for optimization of xe_ggtt_map_bo
Date: Fri, 4 Apr 2025 22:51:37 +0200 [thread overview]
Message-ID: <20250404205138.620455-13-dev@lankhorst.se> (raw)
In-Reply-To: <20250404205138.620455-1-dev@lankhorst.se>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/tests/xe_migrate.c | 1 +
drivers/gpu/drm/xe/xe_ggtt.c | 74 ++++++++++++++++++---------
2 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
index d6770ed4126c1..772b6db3784d9 100644
--- a/drivers/gpu/drm/xe/tests/xe_migrate.c
+++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
@@ -9,6 +9,7 @@
#include "tests/xe_kunit_helpers.h"
#include "tests/xe_pci_test.h"
+#include "xe_ggtt.h"
#include "xe_pci.h"
#include "xe_pm.h"
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 2d4fe207ff62b..4c6a92f9f9f38 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -25,6 +25,7 @@
#include "xe_gt_sriov_vf.h"
#include "xe_gt_tlb_invalidation.h"
#include "xe_map.h"
+#include "xe_migrate.h"
#include "xe_mmio.h"
#include "xe_pm.h"
#include "xe_res_cursor.h"
@@ -594,6 +595,25 @@ bool xe_ggtt_node_allocated(const struct xe_ggtt_node *node)
return drm_mm_node_allocated(&node->base);
}
+struct xe_ggtt_cb_data {
+ struct xe_res_cursor cur;
+ u64 pte_flags;
+ bool sysmem;
+};
+
+static void xe_ggtt_map_bo_cb(void *args, u32 ggtt_offset, u32 local_offset, u64 *ptes, u32 num_ptes)
+{
+ struct xe_ggtt_cb_data *data = args;
+
+ while (num_ptes--) {
+ u64 addr = data->sysmem ? xe_res_dma(&data->cur) : data->cur.start;
+
+ *ptes++ = data->pte_flags + addr;
+
+ xe_res_next(&data->cur, XE_PAGE_SIZE);
+ }
+}
+
/**
* xe_ggtt_map_bo - Map the BO into GGTT
* @ggtt: the &xe_ggtt where node will be mapped
@@ -602,39 +622,43 @@ bool xe_ggtt_node_allocated(const struct xe_ggtt_node *node)
* @pat_index: Which pat_index to use.
*/
static void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
- struct xe_bo *bo, u16 pat_index)
+ struct xe_bo *bo, u16 pat_index, bool allow_accel)
{
- u64 start, pte;
- struct xe_res_cursor cur;
+ struct xe_ggtt_cb_data data;
+ struct dma_fence *fence = NULL;
if (XE_WARN_ON(!node))
return;
- start = node->base.start;
-
- pte = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
- if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
+ data.pte_flags = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
+ data.sysmem = !xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo);
+ if (data.sysmem) {
xe_assert(xe_bo_device(bo), bo->ttm.ttm);
- for (xe_res_first_sg(xe_bo_sg(bo), 0, bo->size, &cur);
- cur.remaining;
- xe_res_next(&cur, XE_PAGE_SIZE)) {
- u64 addr = xe_res_dma(&cur);
-
- ggtt->pt_ops->ggtt_set_pte(ggtt, start + cur.start, addr | pte);
- }
+ xe_res_first_sg(xe_bo_sg(bo), 0, bo->size, &data.cur);
} else {
- u64 end = start + bo->size;
-
/* Prepend GPU offset */
- pte |= vram_region_gpu_offset(bo->ttm.resource);
+ data.pte_flags |= vram_region_gpu_offset(bo->ttm.resource);
+
+ xe_res_first(bo->ttm.resource, 0, bo->size, &data.cur);
+ }
+
+ if (allow_accel && node->base.size >= SZ_4K && ggtt->tile->migrate)
+ fence = xe_migrate_update_gtt(ggtt->tile->migrate, xe_ggtt_map_bo_cb, &data,
+ node->base.start,
+ node->base.size / XE_PAGE_SIZE);
+
+ if (!IS_ERR_OR_NULL(fence)) {
+ dma_fence_wait(fence, false);
+ dma_fence_put(fence);
+ } else {
+ /* Eat error, force map */
- for (xe_res_first(bo->ttm.resource, 0, bo->size, &cur);
- cur.remaining;
- xe_res_next(&cur, XE_PAGE_SIZE)) {
+ for (u32 local_offset = 0; local_offset < node->base.size; local_offset += XE_PAGE_SIZE) {
+ u64 pte;
+ xe_ggtt_map_bo_cb(&data, node->base.start, local_offset, &pte, 1);
- ggtt->pt_ops->ggtt_set_pte(ggtt, end - cur.remaining,
- pte + cur.start);
+ ggtt->pt_ops->ggtt_set_pte(ggtt, node->base.start + local_offset, pte);
}
}
}
@@ -652,7 +676,7 @@ void xe_ggtt_map_bo_unlocked(struct xe_ggtt *ggtt, struct xe_bo *bo)
u16 pat_index = tile_to_xe(ggtt->tile)->pat.idx[cache_mode];
mutex_lock(&ggtt->lock);
- xe_ggtt_map_bo(ggtt, bo->ggtt_node[ggtt->tile->id], bo, pat_index);
+ xe_ggtt_map_bo(ggtt, bo->ggtt_node[ggtt->tile->id], bo, pat_index, false);
mutex_unlock(&ggtt->lock);
}
@@ -696,7 +720,7 @@ struct xe_ggtt_node *xe_ggtt_node_insert_transform(struct xe_ggtt *ggtt,
u64 pte_flags = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
transform(ggtt, node, pte_flags, ggtt->pt_ops->ggtt_set_pte, arg);
} else {
- xe_ggtt_map_bo(ggtt, node, bo, pat_index);
+ xe_ggtt_map_bo(ggtt, node, bo, pat_index, true);
}
@@ -749,7 +773,7 @@ static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
u16 cache_mode = bo->flags & XE_BO_FLAG_NEEDS_UC ? XE_CACHE_NONE : XE_CACHE_WB;
u16 pat_index = tile_to_xe(ggtt->tile)->pat.idx[cache_mode];
- xe_ggtt_map_bo(ggtt, bo->ggtt_node[tile_id], bo, pat_index);
+ xe_ggtt_map_bo(ggtt, bo->ggtt_node[tile_id], bo, pat_index, false);
}
mutex_unlock(&ggtt->lock);
--
2.45.2
next prev parent reply other threads:[~2025-04-04 20:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 20:51 [CI 00/13] Offload GGTT binding to migration engine Maarten Lankhorst
2025-04-04 20:51 ` [CI 01/13] drm/xe: Use xe_ggtt_map_bo_unlocked for resume Maarten Lankhorst
2025-04-04 20:51 ` [CI 02/13] drm/xe: Add xe_ggtt_might_lock Maarten Lankhorst
2025-04-04 20:51 ` [CI 03/13] drm/xe: Add xe_ggtt_alloc Maarten Lankhorst
2025-04-04 20:51 ` [CI 04/13] drm/xe/display: Remove dereferences of ggtt for tile id Maarten Lankhorst
2025-04-04 20:51 ` [CI 05/13] drm/xe/ggtt: Seperate flags and address in PTE encoding Maarten Lankhorst
2025-04-04 20:51 ` [CI 06/13] drm/xe/display: Dont poke into GGTT internals to fill a DPT Maarten Lankhorst
2025-04-04 20:51 ` [CI 07/13] drm/xe/display: Convert GGTT mapping to use pte_encode_flags Maarten Lankhorst
2025-04-04 20:51 ` [CI 08/13] drm/xe: Remove pte_encode_bo callback Maarten Lankhorst
2025-04-04 20:51 ` [CI 09/13] drm/xe: Implement a helper for reading out a GGTT PTE at a specified offset Maarten Lankhorst
2025-04-04 20:51 ` [CI 10/13] drm/xe: Add GGTT updates to migration engine Maarten Lankhorst
2025-04-04 20:51 ` [CI 11/13] drm/xe: Convert xe_fb_pin to use a callback for insertion into GGTT Maarten Lankhorst
2025-04-04 20:51 ` Maarten Lankhorst [this message]
2025-04-04 20:51 ` [CI 13/13] drm/xe: Move struct xe_ggtt to xe_ggtt.c Maarten Lankhorst
2025-04-04 22:20 ` ✓ CI.Patch_applied: success for Offload GGTT binding to migration engine Patchwork
2025-04-04 22:20 ` ✗ CI.checkpatch: warning " Patchwork
2025-04-04 22:21 ` ✗ CI.KUnit: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250404205138.620455-13-dev@lankhorst.se \
--to=dev@lankhorst.se \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox