[PATCH 06/13] drm/amdgpu: add amdgpu lru implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change-Id: I023d3dd314e49bc9b1649468a82ecca6043e4317
Signed-off-by: Chunming Zhou <david1.zhou@xxxxxxx>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 59 ++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 72ff2d9c8686..27b3fdb6dd46 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -163,11 +163,70 @@ struct ttm_buffer_object *amdgpu_vm_get_evictable_bo(struct ttm_bo_device *bdev,
 						     struct ttm_operation_ctx *ctx,
 						     bool *locked)
 {
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
+	struct ttm_buffer_object *bo = NULL;
+	struct amdgpu_vm_lru *vm_lru;
+	int i;
+
+	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
+		list_for_each_entry(vm_lru, &adev->vm_lru_list, vm_lru_list) {
+			list_for_each_entry(bo, &vm_lru->dynamic_lru[mem_type][i], lru) {
+				if (!ttm_bo_evict_swapout_allowable(bo, ctx, locked))
+					continue;
+				if (place && !bdev->driver->eviction_valuable(bo, place)) {
+					if (locked)
+						reservation_object_unlock(bo->resv);
+					continue;
+				}
+				break;
+			}
+			/* If the inner loop terminated early, we have our candidate */
+			if (&bo->lru != &vm_lru->dynamic_lru[mem_type][i])
+				break;
+			bo = NULL;
+			list_for_each_entry(bo, &vm_lru->fixed_lru[mem_type][i], lru) {
+				if (!ttm_bo_evict_swapout_allowable(bo, ctx, locked))
+					continue;
+				if (place && !bdev->driver->eviction_valuable(bo, place)) {
+					if (locked)
+						reservation_object_unlock(bo->resv);
+					continue;
+				}
+				break;
+			}
+			/* If the inner loop terminated early, we have our candidate */
+			if (&bo->lru != &vm_lru->fixed_lru[mem_type][i])
+				break;
+			bo = NULL;
+		}
+		if (bo)
+			break;
+	}
+
+	return bo;
 
 }
 
 void amdgpu_vm_add_to_lru(struct ttm_buffer_object *bo)
 {
+	struct ttm_bo_device *bdev = bo->bdev;
+	struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
+	struct amdgpu_vm_lru *vm_lru = abo->vm_lru;
+
+	if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
+		if (bo->resv == vm_lru->resv)
+			list_add_tail(&bo->lru, &vm_lru->fixed_lru[bo->mem.mem_type][bo->priority]);
+		else
+			list_add_tail(&bo->lru, &vm_lru->dynamic_lru[bo->mem.mem_type][bo->priority]);
+		kref_get(&bo->list_kref);
+
+		if (bo->ttm && !(bo->ttm->page_flags &
+				 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
+			list_add_tail(&bo->swap,
+				      &bdev->glob->swap_lru[bo->priority]);
+			kref_get(&bo->list_kref);
+		}
+	}
 
 }
 
-- 
2.14.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux