[RFC PATCH 07/18] drm/amdgpu: Add TTM uneviction control functions

Friedrich Vock friedrich.vock at gmx.de
Wed Apr 24 16:56:57 UTC 2024


Try unevicting only VRAM/GTT BOs.

Signed-off-by: Friedrich Vock <friedrich.vock at gmx.de>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 64f5001a7dc5d..98e8a40408804 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -166,6 +166,31 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 	*placement = abo->placement;
 }

+/**
+ * amdgpu_unevict_flags - Compute placement flags
+ *
+ * @bo: The buffer object to unevict
+ * @dest: Destination for unevicted BO
+ *
+ * Fill in placement data when for restoring evicted BOs
+ */
+static void amdgpu_unevict_flags(struct ttm_buffer_object *bo,
+				 struct ttm_placement *dest)
+{
+	struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
+
+	WARN_ON(bo->evicted_type == AMDGPU_PL_GDS ||
+		bo->evicted_type == AMDGPU_PL_GWS ||
+		bo->evicted_type == AMDGPU_PL_OA ||
+		bo->evicted_type == AMDGPU_PL_DOORBELL);
+	WARN_ON(bo->evicted_type == TTM_NUM_MEM_TYPES);
+
+	amdgpu_bo_placement_from_domain(abo, abo->preferred_domains);
+	*dest = abo->placement;
+	dest->num_placement = 1;
+	dest->num_busy_placement = 1;
+}
+
 /**
  * amdgpu_ttm_map_buffer - Map memory into the GART windows
  * @bo: buffer object to map
@@ -1424,6 +1449,29 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
 	return ttm_bo_eviction_valuable(bo, place);
 }

+/*
+ * amdgpu_ttm_bo_uneviction_valuable - Check to see if we can unevict a
+ * buffer object.
+ *
+ * Return true if uneviction is sensible. Called by ttm_bo_evict to
+ * decide whether to consider the buffer object for uneviction later.
+ */
+static bool amdgpu_ttm_bo_uneviction_valuable(struct ttm_buffer_object *bo)
+{
+	struct amdgpu_bo *abo;
+
+	if (!amdgpu_bo_is_amdgpu_bo(bo))
+		return false;
+
+	abo = ttm_to_amdgpu_bo(bo);
+
+	if (bo->type != ttm_bo_type_device)
+		return false;
+
+	return (abo->preferred_domains &
+		(AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) != 0;
+}
+
 static void amdgpu_ttm_vram_mm_access(struct amdgpu_device *adev, loff_t pos,
 				      void *buf, size_t size, bool write)
 {
@@ -1581,6 +1629,8 @@ static struct ttm_device_funcs amdgpu_bo_driver = {
 	.ttm_tt_destroy = &amdgpu_ttm_backend_destroy,
 	.eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
+	.uneviction_valuable = &amdgpu_ttm_bo_uneviction_valuable,
+	.unevict_flags = &amdgpu_unevict_flags,
 	.move = &amdgpu_bo_move,
 	.delete_mem_notify = &amdgpu_bo_delete_mem_notify,
 	.release_notify = &amdgpu_bo_release_notify,
--
2.44.0



More information about the amd-gfx mailing list