[PATCH] drm/amdgpu: Place new CPU-accessbile BOs in GTT if visible VRAM is full

John Brooks john at fastquake.com
Fri May 19 03:04:46 UTC 2017


Set GTT as the busy placement for newly created BOs that have the
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED flag, so that they don't cause
established BOs to be evicted from visible VRAM.

Signed-off-by: John Brooks <john at fastquake.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 365883d..655718a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -392,6 +392,17 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 #endif
 
 	amdgpu_fill_placement_to_bo(bo, placement);
+
+	/* This is a new BO that wants to be CPU-visible; set GTT as the busy
+	 * placement so that it does not evict established BOs from visible VRAM.
+	 */
+	if (domain & (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT) &&
+	    flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+		bo->placement.num_placement = 1;
+		bo->placement.num_busy_placement = 1;
+		bo->placement.busy_placement = &bo->placement.placement[1];
+	}
+
 	/* Kernel allocation are uninterruptible */
 
 	initial_bytes_moved = atomic64_read(&adev->num_bytes_moved);
@@ -484,6 +495,13 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	memset(&placements, 0,
 	       (AMDGPU_GEM_DOMAIN_MAX + 1) * sizeof(struct ttm_place));
 
+
+	/* New CPU-visible BOs will have GTT set as their busy placement */
+	if (domain & AMDGPU_GEM_DOMAIN_VRAM &&
+	    flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+		domain |= AMDGPU_GEM_DOMAIN_GTT;
+	}
+
 	amdgpu_ttm_placement_init(adev, &placement,
 				  placements, domain, flags);
 
-- 
2.7.4



More information about the amd-gfx mailing list