All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [CI 1/2] drm/xe: only evict CCS buffers from TT on iGPU
Date: Thu,  5 Nov 2026 14:35:48 +0000	[thread overview]
Message-ID: <20261105143547.1089207-3-matthew.auld@intel.com> (raw)

On iGPU platforms with Flat CCS, xe_bo_evict_all_user() currently calls
ttm_resource_manager_evict_all() on XE_PL_TT, evicting every buffer in
TT even if it does not use Flat CCS compression.

Walk the XE_PL_TT LRU using ttm_bo_lru_for_each_reserved_guarded() and
only evict buffers with initialised CCS state (or purge them if marked
DONTNEED), leaving non-CCS buffers in place.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/xe/xe_bo_evict.c | 64 +++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index 7661fca7f278..1f95769c4a56 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -5,6 +5,8 @@
 
 #include "xe_bo_evict.h"
 
+#include <drm/ttm/ttm_bo.h>
+
 #include "xe_bo.h"
 #include "xe_device.h"
 #include "xe_ggtt.h"
@@ -104,8 +106,46 @@ void xe_bo_notifier_unprepare_all_pinned(struct xe_device *xe)
 				    xe_bo_notifier_unprepare_pinned);
 }
 
+static int xe_bo_evict_all_ccs(struct ttm_resource_manager *man)
+{
+	struct ttm_operation_ctx ctx = {
+		.interruptible = false,
+		.no_wait_gpu = false,
+	};
+	struct ttm_lru_walk_arg arg = {
+		.ctx = &ctx,
+		.sleeping_lock = true,
+	};
+	struct ttm_bo_lru_cursor cursor;
+	struct ttm_buffer_object *ttm_bo;
+	int ret = 0;
+
+	ttm_bo_lru_for_each_reserved_guarded(&cursor, man, &arg, ttm_bo) {
+		struct xe_bo *bo;
+
+		if (!xe_bo_is_xe_bo(ttm_bo) || ttm_bo->deleted)
+			continue;
+
+		bo = ttm_to_xe_bo(ttm_bo);
+		if (xe_bo_is_pinned(bo) || !xe_bo_needs_ccs_pages(bo) ||
+		    !bo->ccs_cleared)
+			continue;
+
+		if (xe_bo_madv_is_dontneed(bo))
+			ret = xe_ttm_bo_purge(ttm_bo, &ctx);
+		else
+			ret = xe_bo_evict(bo, NULL);
+		if (ret)
+			break;
+	}
+	if (IS_ERR(ttm_bo))
+		return PTR_ERR(ttm_bo);
+
+	return ret;
+}
+
 /**
- * xe_bo_evict_all_user - evict all non-pinned user BOs from VRAM
+ * xe_bo_evict_all_user - evict all non-pinned user BOs from VRAM (and CCS in TT)
  * @xe: xe device
  *
  * Evict non-pinned user BOs (via GPU).
@@ -123,22 +163,26 @@ int xe_bo_evict_all_user(struct xe_device *xe)
 		struct ttm_resource_manager *man =
 			ttm_manager_type(bdev, mem_type);
 
+		if (!man)
+			continue;
+
 		/*
 		 * On igpu platforms with flat CCS we need to ensure we save and restore any CCS
 		 * state since this state lives inside graphics stolen memory which doesn't survive
 		 * hibernation.
-		 *
-		 * This can be further improved by only evicting objects that we know have actually
-		 * used a compression enabled PAT index.
 		 */
-		if (mem_type == XE_PL_TT && (IS_DGFX(xe) || !xe_device_has_flat_ccs(xe)))
+		if (mem_type == XE_PL_TT) {
+			if (!IS_DGFX(xe) && xe_device_has_flat_ccs(xe)) {
+				ret = xe_bo_evict_all_ccs(man);
+				if (ret)
+					return ret;
+			}
 			continue;
-
-		if (man) {
-			ret = ttm_resource_manager_evict_all(bdev, man);
-			if (ret)
-				return ret;
 		}
+
+		ret = ttm_resource_manager_evict_all(bdev, man);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.56.0


             reply	other threads:[~2026-11-05 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 14:35 Matthew Auld [this message]
2026-11-05 14:35 ` [CI 2/2] drm/xe/pm: skip BO eviction on iGPU for non-hibernation sleep Matthew Auld
2026-11-05 15:06   ` sashiko-bot
2026-11-05 16:39     ` Matthew Auld
2026-11-05 14:53 ` ✓ CI.KUnit: success for series starting with [CI,1/2] drm/xe: only evict CCS buffers from TT on iGPU Patchwork
2026-11-05 15:38 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-06 13:59 ` ✓ Xe.CI.FULL: " 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=20261105143547.1089207-3-matthew.auld@intel.com \
    --to=matthew.auld@intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.