From: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: matthew.auld@intel.com
Subject: [PATCH v6] drm/xe/migrate: Revamp PAT index selection for migrate PTEs
Date: Fri, 10 Jul 2026 14:00:05 +0530 [thread overview]
Message-ID: <20260710083004.1546599-2-sanjay.kumar.yadav@intel.com> (raw)
Improve PAT index selection logic in xe_migrate.c to avoid unnecessary
coherency overhead when host-side memory is uncached. Previously,
we defaulted to XE_CACHE_WB, which enforces 2-way coherency and may
trigger cacheline pulls from CPU even when host-side memory is never
dirty.
This change introduces xe_migrate_pat_index() to choose the appropriate
PAT index based on the actual TTM caching mode of the buffer object
being mapped. For iGPUs with WC host mappings, we now prefer
XE_CACHE_NONE to skip coherency snoops. For compressed PTEs on newer
platforms, we select XE_CACHE_NONE_COMPRESSION.
This avoids unnecessary cache traffic for uncached host mappings.
v6: (sashiko)
- Only apply the BO's host-side caching for system-memory PTEs.
v5: (Matt A)
- Simplify emit_pte() to derive caching from res->bo directly, removing
the separate bo parameter
- Leave changes in __xe_migrate_update_pgtables() and
build_pt_update_batch_sram()
- Fix comment about page-walker coherency in xe_migrate_pat_index()
v4:
- Keep xe_migrate_prepare_vm() on XE_CACHE_WB since page tables require
page-walker coherency.
- Pass BO into emit_pte() and select PAT attributes from the BO's TTM
caching mode.
Assisted-by: GitHub Copilot:claude-opus-4.8
Signed-off-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
Suggested-by: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/xe/xe_migrate.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 9428dd5e7760..cad8f0e443af 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -117,6 +117,27 @@ static void xe_migrate_fini(void *arg)
xe_exec_queue_put(m->q);
}
+static inline u16 xe_migrate_pat_index(struct xe_device *xe,
+ enum ttm_caching caching,
+ bool is_comp_pte)
+{
+ enum xe_cache_level cache_level;
+
+ /*
+ * Select the appropriate PAT index for buffer object PTEs programmed
+ * by emit_pte(). We choose not to mess with xe_migrate_prepare_vm()
+ * yet, for simplicity.
+ */
+ if (is_comp_pte && GRAPHICS_VERx100(xe) >= 2000)
+ cache_level = XE_CACHE_NONE_COMPRESSION;
+ else if (caching == ttm_cached)
+ cache_level = XE_CACHE_WB;
+ else
+ cache_level = XE_CACHE_NONE;
+
+ return xe_cache_pat_idx(xe, cache_level);
+}
+
static u64 xe_migrate_vm_addr(u64 slot, u32 level)
{
XE_WARN_ON(slot >= NUM_PT_SLOTS);
@@ -631,17 +652,17 @@ static void emit_pte(struct xe_migrate *m,
{
struct xe_device *xe = tile_to_xe(m->tile);
struct xe_vm *vm = m->q->vm;
+ struct xe_bo *bo = ttm_to_xe_bo(res->bo);
+ enum ttm_caching caching = ttm_cached;
u16 pat_index;
u32 ptes;
u64 ofs = (u64)at_pt * XE_PAGE_SIZE;
u64 cur_ofs;
- /* Indirect access needs compression enabled uncached PAT index */
- if (GRAPHICS_VERx100(xe) >= 2000)
- pat_index = is_comp_pte ? xe_cache_pat_idx(xe, XE_CACHE_NONE_COMPRESSION) :
- xe_cache_pat_idx(xe, XE_CACHE_WB);
- else
- pat_index = xe_cache_pat_idx(xe, XE_CACHE_WB);
+ if (!is_vram && bo->ttm.ttm)
+ caching = bo->ttm.ttm->caching;
+
+ pat_index = xe_migrate_pat_index(xe, caching, is_comp_pte);
ptes = DIV_ROUND_UP(size, XE_PAGE_SIZE);
--
2.52.0
next reply other threads:[~2026-07-10 8:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 8:30 Sanjay Yadav [this message]
2026-07-10 8:38 ` ✗ CI.checkpatch: warning for drm/xe/migrate: Revamp PAT index selection for migrate PTEs (rev6) Patchwork
2026-07-10 8:40 ` ✓ CI.KUnit: success " Patchwork
2026-07-10 9:21 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-10 17:30 ` ✗ Xe.CI.FULL: 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=20260710083004.1546599-2-sanjay.kumar.yadav@intel.com \
--to=sanjay.kumar.yadav@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
/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