Skip to contentSkip to conversation

drm/amdgpu: use moving fence instead of exclusive for VM updates

PATCH In review Christian König 3 participants 5 messages Sep 3, 2019 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: use moving fence instead of exclusive for VM updates

Make VM updates depend on the moving fence instead of the exclusive one.

Makes it less likely to actually have a dependency.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index 189ad5699946..501e13420786 100644
@@ -1706,7 +1706,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,
 			ttm = container_of(bo->tbo.ttm, struct ttm_dma_tt, ttm);
 			pages_addr = ttm->dma_address;
 		}
-		exclusive = reservation_object_get_excl(bo->tbo.resv);
+		exclusive = bo->tbo.moving;
 	}
 
 	if (bo) {
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20190903090904.30747-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/3 drm/amdgpu: reserve at least 4MB of VRAM for page tables v2

This hopefully helps reduce the contention for page tables.

v2: adjust maximum reported VRAM size as well

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c      | 18 ++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h       |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c |  9 +++++++--
 3 files changed, 22 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +12 -6
index 6cf61e01041f..5bc20d84351d 100644
@@ -616,9 +616,12 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 		struct drm_amdgpu_info_vram_gtt vram_gtt;
 
 		vram_gtt.vram_size = adev->gmc.real_vram_size -
-			atomic64_read(&adev->vram_pin_size);
-		vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size -
-			atomic64_read(&adev->visible_pin_size);
+			atomic64_read(&adev->vram_pin_size) -
+			AMDGPU_VM_RESERVED_VRAM;
+		vram_gtt.vram_cpu_accessible_size =
+			min(adev->gmc.visible_vram_size -
+			    atomic64_read(&adev->visible_pin_size),
+			    vram_gtt.vram_size);
 		vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT].size;
 		vram_gtt.gtt_size *= PAGE_SIZE;
 		vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size);
@@ -631,15 +634,18 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 		memset(&mem, 0, sizeof(mem));
 		mem.vram.total_heap_size = adev->gmc.real_vram_size;
 		mem.vram.usable_heap_size = adev->gmc.real_vram_size -
-			atomic64_read(&adev->vram_pin_size);
+			atomic64_read(&adev->vram_pin_size) -
+			AMDGPU_VM_RESERVED_VRAM;
 		mem.vram.heap_usage =
 			amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
 		mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
 
 		mem.cpu_accessible_vram.total_heap_size =
 			adev->gmc.visible_vram_size;
-		mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size -
-			atomic64_read(&adev->visible_pin_size);
+		mem.cpu_accessible_vram.usable_heap_size =
+			min(adev->gmc.visible_vram_size -
+			    atomic64_read(&adev->visible_pin_size),
+			    mem.vram.usable_heap_size);
 		mem.cpu_accessible_vram.heap_usage =
 			amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
 		mem.cpu_accessible_vram.max_allocation =
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
index 2eda3a8c330d..3352a87b822e 100644
@@ -99,6 +99,9 @@ struct amdgpu_bo_list_entry;
 #define AMDGPU_VM_FAULT_STOP_FIRST	1
 #define AMDGPU_VM_FAULT_STOP_ALWAYS	2
 
+/* Reserve 4MB VRAM for page tables */
+#define AMDGPU_VM_RESERVED_VRAM		(4ULL << 20)
+
 /* max number of VMHUB */
 #define AMDGPU_MAX_VMHUBS			3
 #define AMDGPU_GFXHUB_0				0
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7 -2
index 1150e34bc28f..59440f71d304 100644
@@ -24,6 +24,7 @@
 
 #include <drm/drmP.h>
 #include "amdgpu.h"
+#include "amdgpu_vm.h"
 
 struct amdgpu_vram_mgr {
 	struct drm_mm mm;
@@ -276,7 +277,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
 	struct drm_mm_node *nodes;
 	enum drm_mm_insert_mode mode;
 	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes;
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
 	unsigned i;
 	int r;
 
@@ -284,9 +285,13 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
 	if (!lpfn)
 		lpfn = man->size;
 
+	max_bytes = adev->gmc.mc_vram_size;
+	if (tbo->type != ttm_bo_type_kernel)
+		max_bytes -= AMDGPU_VM_RESERVED_VRAM;
+
 	/* bail out quickly if there's likely not enough VRAM for this BO */
 	mem_bytes = (u64)mem->num_pages << PAGE_SHIFT;
-	if (atomic64_add_return(mem_bytes, &mgr->usage) > adev->gmc.mc_vram_size) {
+	if (atomic64_add_return(mem_bytes, &mgr->usage) > max_bytes) {
 		atomic64_sub(mem_bytes, &mgr->usage);
 		mem->mm_node = NULL;
 		return 0;
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20190903090904.30747-2-christian.koenig-5C7GfCeVMHo@public.gmane.org

Reviewed-by Felix Kuehling
#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: reserve at least 4MB of VRAM for page tables v2

Quoted 5 lines · Christian König

This hopefully helps reduce the contention for page tables.

v2: adjust maximum reported VRAM size as well

I'll need to do something similar (and also take the vram_pin_size into account) in amdgpu_amdkfd_reserve_mem_limit. It doesn't even account for the vram_pin_size at the moment, which I should fix too. Otherwise this commit looks good to me.

Quoted 88 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c      | 18 ++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h       |  3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c |  9 +++++++--
  3 files changed, 22 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +12 -6
index 6cf61e01041f..5bc20d84351d 100644
@@ -616,9 +616,12 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
  		struct drm_amdgpu_info_vram_gtt vram_gtt;
 
  		vram_gtt.vram_size = adev->gmc.real_vram_size -
-			atomic64_read(&adev->vram_pin_size);
-		vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size -
-			atomic64_read(&adev->visible_pin_size);
+			atomic64_read(&adev->vram_pin_size) -
+			AMDGPU_VM_RESERVED_VRAM;
+		vram_gtt.vram_cpu_accessible_size =
+			min(adev->gmc.visible_vram_size -
+			    atomic64_read(&adev->visible_pin_size),
+			    vram_gtt.vram_size);
  		vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT].size;
  		vram_gtt.gtt_size *= PAGE_SIZE;
  		vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size);
@@ -631,15 +634,18 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
  		memset(&mem, 0, sizeof(mem));
  		mem.vram.total_heap_size = adev->gmc.real_vram_size;
  		mem.vram.usable_heap_size = adev->gmc.real_vram_size -
-			atomic64_read(&adev->vram_pin_size);
+			atomic64_read(&adev->vram_pin_size) -
+			AMDGPU_VM_RESERVED_VRAM;
  		mem.vram.heap_usage =
  			amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
  		mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
 
  		mem.cpu_accessible_vram.total_heap_size =
  			adev->gmc.visible_vram_size;
-		mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size -
-			atomic64_read(&adev->visible_pin_size);
+		mem.cpu_accessible_vram.usable_heap_size =
+			min(adev->gmc.visible_vram_size -
+			    atomic64_read(&adev->visible_pin_size),
+			    mem.vram.usable_heap_size);
  		mem.cpu_accessible_vram.heap_usage =
  			amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
  		mem.cpu_accessible_vram.max_allocation =
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
index 2eda3a8c330d..3352a87b822e 100644
@@ -99,6 +99,9 @@ struct amdgpu_bo_list_entry;
  #define AMDGPU_VM_FAULT_STOP_FIRST	1
  #define AMDGPU_VM_FAULT_STOP_ALWAYS	2
 
+/* Reserve 4MB VRAM for page tables */
+#define AMDGPU_VM_RESERVED_VRAM		(4ULL << 20)
+
  /* max number of VMHUB */
  #define AMDGPU_MAX_VMHUBS			3
  #define AMDGPU_GFXHUB_0				0
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3 -1
index 1150e34bc28f..59440f71d304 100644
@@ -24,6 +24,7 @@
 
  #include <drm/drmP.h>
  #include "amdgpu.h"
+#include "amdgpu_vm.h"
 
  struct amdgpu_vram_mgr {
  	struct drm_mm mm;
@@ -276,7 +277,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
  	struct drm_mm_node *nodes;
  	enum drm_mm_insert_mode mode;
  	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes;
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
  	unsigned i;
  	int r;
 
@@ -284,9 +285,13 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
  	if (!lpfn)
  		lpfn = man->size;
 
+	max_bytes = adev->gmc.mc_vram_size;

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, · line 297

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -1
+	if (tbo->type != ttm_bo_type_kernel)
+		max_bytes -= AMDGPU_VM_RESERVED_VRAM;
+
  	/* bail out quickly if there's likely not enough VRAM for this BO */
  	mem_bytes = (u64)mem->num_pages << PAGE_SHIFT;
-	if (atomic64_add_return(mem_bytes, &mgr->usage) > adev->gmc.mc_vram_size) {
+	if (atomic64_add_return(mem_bytes, &mgr->usage) > max_bytes) {
  		atomic64_sub(mem_bytes, &mgr->usage);
  		mem->mm_node = NULL;
  		return 0;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

PATCH 3/3 drm/amdgpu: remove amdgpu_cs_try_evict

In reply to a message not in the archive

Trying to evict things from the current working set doesn't work that well anymore because of per VM BOs.

Rely on reserving VRAM for page tables to avoid contention.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 71 +-------------------------
 2 files changed, 1 insertion(+), 71 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index a236213f8e8e..d1995156733e 100644
@@ -478,7 +478,6 @@ struct amdgpu_cs_parser {
 	uint64_t			bytes_moved_vis_threshold;
 	uint64_t			bytes_moved;
 	uint64_t			bytes_moved_vis;
-	struct amdgpu_bo_list_entry	*evictable;
 
 	/* user fence */
 	struct amdgpu_bo_list_entry	uf_entry;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -70

94 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20190903090904.30747-3-christian.koenig-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: remove amdgpu_cs_try_evict

-David

Quoted 115 lines · Christian König

Trying to evict things from the current working set doesn't work that well anymore because of per VM BOs.

Rely on reserving VRAM for page tables to avoid contention.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  1 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 71 +-------------------------
  2 files changed, 1 insertion(+), 71 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index a236213f8e8e..d1995156733e 100644
@@ -478,7 +478,6 @@ struct amdgpu_cs_parser {
  	uint64_t			bytes_moved_vis_threshold;
  	uint64_t			bytes_moved;
  	uint64_t			bytes_moved_vis;
-	struct amdgpu_bo_list_entry	*evictable;
 
  	/* user fence */
  	struct amdgpu_bo_list_entry	uf_entry;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -67
index fd95b586b590..03182d968d3d 100644
@@ -447,75 +447,12 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
  	return r;
  }
 
-/* Last resort, try to evict something from the current working set */
-static bool amdgpu_cs_try_evict(struct amdgpu_cs_parser *p,
-				struct amdgpu_bo *validated)
-{
-	uint32_t domain = validated->allowed_domains;
-	struct ttm_operation_ctx ctx = { true, false };
-	int r;
-
-	if (!p->evictable)
-		return false;
-
-	for (;&p->evictable->tv.head != &p->validated;
-	     p->evictable = list_prev_entry(p->evictable, tv.head)) {
-
-		struct amdgpu_bo_list_entry *candidate = p->evictable;
-		struct amdgpu_bo *bo = ttm_to_amdgpu_bo(candidate->tv.bo);
-		struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-		bool update_bytes_moved_vis;
-		uint32_t other;
-
-		/* If we reached our current BO we can forget it */
-		if (bo == validated)
-			break;
-
-		/* We can't move pinned BOs here */
-		if (bo->pin_count)
-			continue;
-
-		other = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
-
-		/* Check if this BO is in one of the domains we need space for */
-		if (!(other & domain))
-			continue;
-
-		/* Check if we can move this BO somewhere else */
-		other = bo->allowed_domains & ~domain;
-		if (!other)
-			continue;
-
-		/* Good we can try to move this BO somewhere else */
-		update_bytes_moved_vis =
-				!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
-				amdgpu_bo_in_cpu_visible_vram(bo);
-		amdgpu_bo_placement_from_domain(bo, other);
-		r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-		p->bytes_moved += ctx.bytes_moved;
-		if (update_bytes_moved_vis)
-			p->bytes_moved_vis += ctx.bytes_moved;
-
-		if (unlikely(r))
-			break;
-
-		p->evictable = list_prev_entry(p->evictable, tv.head);
-		list_move(&candidate->tv.head, &p->validated);
-
-		return true;
-	}
-
-	return false;
-}
-
  static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo)
  {
  	struct amdgpu_cs_parser *p = param;
  	int r;
 
-	do {
-		r = amdgpu_cs_bo_validate(p, bo);
-	} while (r == -ENOMEM && amdgpu_cs_try_evict(p, bo));
+	r = amdgpu_cs_bo_validate(p, bo);
  	if (r)
  		return r;
 
@@ -554,9 +491,6 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p,
  			binding_userptr = true;
  		}
 
-		if (p->evictable == lobj)
-			p->evictable = NULL;
-
  		r = amdgpu_cs_validate(p, bo);
  		if (r)
  			return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 598

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -3
@@ -659,9 +593,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
  					  &p->bytes_moved_vis_threshold);
  	p->bytes_moved = 0;
  	p->bytes_moved_vis = 0;
-	p->evictable = list_last_entry(&p->validated,
-				       struct amdgpu_bo_list_entry,
-				       tv.head);
 
  	r = amdgpu_vm_validate_pt_bos(p->adev, &fpriv->vm,
  				      amdgpu_cs_validate, p);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx