All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first
@ 2019-09-25 10:55 Christian König
  2019-09-25 10:55 ` [PATCH 2/3] drm/ttm: always keep BOs on the LRU Christian König
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Christian König @ 2019-09-25 10:55 UTC (permalink / raw)
  To: kraxel, daniel, thomas_os, dri-devel

The busy BO might actually be already deleted,
so grab only a list reference.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 881cf26d698e..02f301e1ff29 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -875,11 +875,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 
 	if (!bo) {
 		if (busy_bo)
-			ttm_bo_get(busy_bo);
+			kref_get(&busy_bo->list_kref);
 		spin_unlock(&glob->lru_lock);
 		ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket);
 		if (busy_bo)
-			ttm_bo_put(busy_bo);
+			kref_put(&busy_bo->list_kref, ttm_bo_release_list);
 		return ret;
 	}
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-09-25 10:55 [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Christian König
@ 2019-09-25 10:55 ` Christian König
  2019-09-25 12:06   ` Thomas Hellström (VMware)
  2019-09-25 10:55 ` [PATCH 3/3] drm/ttm: remove pointers to globals Christian König
  2019-09-25 11:55 ` [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Thomas Hellström (VMware)
  2 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2019-09-25 10:55 UTC (permalink / raw)
  To: kraxel, daniel, thomas_os, dri-devel

This allows blocking for BOs to become available
in the memory management.

Amdgpu is doing this for quite a while now during CS. Now
apply the new behavior to all drivers using TTM.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  9 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  4 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +-
 drivers/gpu/drm/qxl/qxl_release.c             |  4 +-
 drivers/gpu/drm/radeon/radeon_gem.c           |  2 +-
 drivers/gpu/drm/radeon/radeon_object.c        |  2 +-
 drivers/gpu/drm/ttm/ttm_bo.c                  | 48 +++++--------------
 drivers/gpu/drm/ttm/ttm_execbuf_util.c        | 25 ++--------
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |  3 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    |  2 +-
 include/drm/ttm/ttm_bo_api.h                  | 24 ----------
 include/drm/ttm/ttm_bo_driver.h               | 20 ++------
 include/drm/ttm/ttm_execbuf_util.h            |  2 +-
 15 files changed, 33 insertions(+), 118 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index b9bb35d1699e..ad01c741caaf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -586,7 +586,7 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 	amdgpu_vm_get_pd_bo(vm, &ctx->list, &ctx->vm_pd[0]);
 
 	ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
-				     false, &ctx->duplicates, true);
+				     false, &ctx->duplicates);
 	if (!ret)
 		ctx->reserved = true;
 	else {
@@ -659,7 +659,7 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 	}
 
 	ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
-				     false, &ctx->duplicates, true);
+				     false, &ctx->duplicates);
 	if (!ret)
 		ctx->reserved = true;
 	else
@@ -1796,8 +1796,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
 	}
 
 	/* Reserve all BOs and page tables for validation */
-	ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates,
-				     true);
+	ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates);
 	WARN(!list_empty(&duplicates), "Duplicates should be empty");
 	if (ret)
 		goto out_free;
@@ -1995,7 +1994,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
 	}
 
 	ret = ttm_eu_reserve_buffers(&ctx.ticket, &ctx.list,
-				     false, &duplicate_save, true);
+				     false, &duplicate_save);
 	if (ret) {
 		pr_debug("Memory eviction: TTM Reserve Failed. Try again\n");
 		goto ttm_reserve_fail;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 95ec965fcc2d..82f239ac4050 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -650,7 +650,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	}
 
 	r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
-				   &duplicates, false);
+				   &duplicates);
 	if (unlikely(r != 0)) {
 		if (r != -ERESTARTSYS)
 			DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
index 605f83046039..b1608d47508f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
@@ -80,7 +80,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	list_add(&csa_tv.head, &list);
 	amdgpu_vm_get_pd_bo(vm, &list, &pd);
 
-	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, false);
+	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
 	if (r) {
 		DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
 		return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index b25a59c4bec6..cbfb3e84f352 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -175,7 +175,7 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,
 
 	amdgpu_vm_get_pd_bo(vm, &list, &vm_pd);
 
-	r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates, false);
+	r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);
 	if (r) {
 		dev_err(adev->dev, "leaking bo va because "
 			"we fail to reserve bo (%d)\n", r);
@@ -611,7 +611,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 
 	amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd);
 
-	r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates, false);
+	r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
 	if (r)
 		goto error_unref;
 
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 5df2ee1e10d8..760078b9925b 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -4439,7 +4439,7 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
 	tv.num_shared = 1;
 	list_add(&tv.head, &list);
 
-	r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL, true);
+	r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL);
 	if (r) {
 		dev_err(adev->dev, "fail to reserve bo (%d)\n", r);
 		return r;
diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c
index aa7a28795645..71f1b51a1350 100644
--- a/drivers/gpu/drm/qxl/qxl_release.c
+++ b/drivers/gpu/drm/qxl/qxl_release.c
@@ -260,7 +260,7 @@ int qxl_release_reserve_list(struct qxl_release *release, bool no_intr)
 		return 0;
 
 	ret = ttm_eu_reserve_buffers(&release->ticket, &release->bos,
-				     !no_intr, NULL, true);
+				     !no_intr, NULL);
 	if (ret)
 		return ret;
 
@@ -459,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
 		bo = entry->bo;
 
 		dma_resv_add_shared_fence(bo->base.resv, &release->base);
-		ttm_bo_add_to_lru(bo);
+		ttm_bo_move_to_lru_tail(bo, NULL);
 		dma_resv_unlock(bo->base.resv);
 	}
 	spin_unlock(&glob->lru_lock);
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index c48c2fb35456..879eac67cdd7 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -564,7 +564,7 @@ static void radeon_gem_va_update_vm(struct radeon_device *rdev,
 	if (!vm_bos)
 		return;
 
-	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, true);
+	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
 	if (r)
 		goto error_free;
 
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 653fd7937b39..a94d827ba976 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -542,7 +542,7 @@ int radeon_bo_list_validate(struct radeon_device *rdev,
 	u64 bytes_moved_threshold = radeon_bo_get_threshold_for_moves(rdev);
 
 	INIT_LIST_HEAD(&duplicates);
-	r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates, true);
+	r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates);
 	if (unlikely(r != 0)) {
 		return r;
 	}
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 02f301e1ff29..ab9967b84e0b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -192,18 +192,12 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
 	}
 }
 
-void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
-{
-	ttm_bo_add_mem_to_lru(bo, &bo->mem);
-}
-EXPORT_SYMBOL(ttm_bo_add_to_lru);
-
 static void ttm_bo_ref_bug(struct kref *list_kref)
 {
 	BUG();
 }
 
-void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
+static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
 	bool notify = false;
@@ -223,16 +217,6 @@ void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
 		bdev->driver->del_from_lru_notify(bo);
 }
 
-void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
-{
-	struct ttm_bo_global *glob = bo->bdev->glob;
-
-	spin_lock(&glob->lru_lock);
-	ttm_bo_del_from_lru(bo);
-	spin_unlock(&glob->lru_lock);
-}
-EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
-
 static void ttm_bo_bulk_move_set_pos(struct ttm_lru_bulk_move_pos *pos,
 				     struct ttm_buffer_object *bo)
 {
@@ -247,7 +231,7 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
 	dma_resv_assert_held(bo->base.resv);
 
 	ttm_bo_del_from_lru(bo);
-	ttm_bo_add_to_lru(bo);
+	ttm_bo_add_mem_to_lru(bo, &bo->mem);
 
 	if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
 		switch (bo->mem.mem_type) {
@@ -511,7 +495,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
 		 */
 		if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
 			bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
-			ttm_bo_add_to_lru(bo);
+			ttm_bo_move_to_lru_tail(bo, NULL);
 		}
 
 		dma_resv_unlock(bo->base.resv);
@@ -892,17 +876,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 		return ret;
 	}
 
-	ttm_bo_del_from_lru(bo);
 	spin_unlock(&glob->lru_lock);
 
 	ret = ttm_bo_evict(bo, ctx);
-	if (locked) {
+	if (locked)
 		ttm_bo_unreserve(bo);
-	} else {
-		spin_lock(&glob->lru_lock);
-		ttm_bo_add_to_lru(bo);
-		spin_unlock(&glob->lru_lock);
-	}
 
 	kref_put(&bo->list_kref, ttm_bo_release_list);
 	return ret;
@@ -1064,12 +1042,10 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
 	mem->mem_type = mem_type;
 	mem->placement = cur_flags;
 
-	if (bo->mem.mem_type < mem_type && !list_empty(&bo->lru)) {
-		spin_lock(&bo->bdev->glob->lru_lock);
-		ttm_bo_del_from_lru(bo);
-		ttm_bo_add_mem_to_lru(bo, mem);
-		spin_unlock(&bo->bdev->glob->lru_lock);
-	}
+	spin_lock(&bo->bdev->glob->lru_lock);
+	ttm_bo_del_from_lru(bo);
+	ttm_bo_add_mem_to_lru(bo, mem);
+	spin_unlock(&bo->bdev->glob->lru_lock);
 
 	return 0;
 }
@@ -1375,11 +1351,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		return ret;
 	}
 
-	if (resv && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
-		spin_lock(&bdev->glob->lru_lock);
-		ttm_bo_add_to_lru(bo);
-		spin_unlock(&bdev->glob->lru_lock);
-	}
+	spin_lock(&bdev->glob->lru_lock);
+	ttm_bo_move_to_lru_tail(bo, NULL);
+	spin_unlock(&bdev->glob->lru_lock);
 
 	return ret;
 }
diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
index 71148c83cc4f..b09c2c8caf13 100644
--- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
+++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
@@ -33,16 +33,6 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 
-static void ttm_eu_del_from_lru_locked(struct list_head *list)
-{
-	struct ttm_validate_buffer *entry;
-
-	list_for_each_entry(entry, list, head) {
-		struct ttm_buffer_object *bo = entry->bo;
-		ttm_bo_del_from_lru(bo);
-	}
-}
-
 void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
 				struct list_head *list)
 {
@@ -59,8 +49,7 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
 	list_for_each_entry(entry, list, head) {
 		struct ttm_buffer_object *bo = entry->bo;
 
-		if (list_empty(&bo->lru))
-			ttm_bo_add_to_lru(bo);
+		ttm_bo_move_to_lru_tail(bo, NULL);
 		if (!ticket)
 			dma_resv_unlock(bo->base.resv);
 	}
@@ -87,7 +76,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);
 
 int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
 			   struct list_head *list, bool intr,
-			   struct list_head *dups, bool del_lru)
+			   struct list_head *dups)
 {
 	struct ttm_validate_buffer *entry;
 	struct ttm_bo_global *glob;
@@ -142,11 +131,6 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
 		}
 	}
 
-	if (del_lru) {
-		spin_lock(&glob->lru_lock);
-		ttm_eu_del_from_lru_locked(list);
-		spin_unlock(&glob->lru_lock);
-	}
 	return 0;
 
 error:
@@ -186,10 +170,7 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
 			dma_resv_add_shared_fence(bo->base.resv, fence);
 		else
 			dma_resv_add_excl_fence(bo->base.resv, fence);
-		if (list_empty(&bo->lru))
-			ttm_bo_add_to_lru(bo);
-		else
-			ttm_bo_move_to_lru_tail(bo, NULL);
+		ttm_bo_move_to_lru_tail(bo, NULL);
 		if (!ticket)
 			dma_resv_unlock(bo->base.resv);
 	}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 2d7c5ad25359..1d53a69819e5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -464,8 +464,7 @@ vmw_resource_check_buffer(struct dma_resv_ctx *ticket,
 	val_buf->bo = &res->backup->base;
 	val_buf->num_shared = 0;
 	list_add_tail(&val_buf->head, &val_list);
-	ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL,
-				     true);
+	ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL);
 	if (unlikely(ret != 0))
 		goto out_no_reserve;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
index 43f48df3844f..ebb5b68b5c1f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
@@ -169,7 +169,7 @@ vmw_validation_bo_reserve(struct vmw_validation_context *ctx,
 			  bool intr)
 {
 	return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
-				      NULL, true);
+				      NULL);
 }
 
 /**
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 43c4929a2171..288fd64b7219 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -367,30 +367,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  */
 void ttm_bo_put(struct ttm_buffer_object *bo);
 
-/**
- * ttm_bo_add_to_lru
- *
- * @bo: The buffer object.
- *
- * Add this bo to the relevant mem type lru and, if it's backed by
- * system pages (ttms) to the swap list.
- * This function must be called with struct ttm_bo_global::lru_lock held, and
- * is typically called immediately prior to unreserving a bo.
- */
-void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
-
-/**
- * ttm_bo_del_from_lru
- *
- * @bo: The buffer object.
- *
- * Remove this bo from all lru lists used to lookup and reserve an object.
- * This function must be called with struct ttm_bo_global::lru_lock held,
- * and is usually called just immediately after the bo has been reserved to
- * avoid recursive reservation from lru lists.
- */
-void ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
-
 /**
  * ttm_bo_move_to_lru_tail
  *
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 4e307f65f497..4332cc036483 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -621,9 +621,6 @@ void ttm_mem_io_free_vm(struct ttm_buffer_object *bo);
 int ttm_mem_io_lock(struct ttm_mem_type_manager *man, bool interruptible);
 void ttm_mem_io_unlock(struct ttm_mem_type_manager *man);
 
-void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo);
-void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
-
 /**
  * __ttm_bo_reserve:
  *
@@ -717,15 +714,9 @@ static inline int ttm_bo_reserve(struct ttm_buffer_object *bo,
 				 bool interruptible, bool no_wait,
 				 struct ww_acquire_ctx *ticket)
 {
-	int ret;
-
 	WARN_ON(!kref_read(&bo->kref));
 
-	ret = __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
-	if (likely(ret == 0))
-		ttm_bo_del_sub_from_lru(bo);
-
-	return ret;
+	return __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
 }
 
 /**
@@ -752,9 +743,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
 	else
 		dma_resv_lock_slow(bo->base.resv, ticket);
 
-	if (likely(ret == 0))
-		ttm_bo_del_sub_from_lru(bo);
-	else if (ret == -EINTR)
+	if (ret == -EINTR)
 		ret = -ERESTARTSYS;
 
 	return ret;
@@ -770,10 +759,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
 static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 {
 	spin_lock(&bo->bdev->glob->lru_lock);
-	if (list_empty(&bo->lru))
-		ttm_bo_add_to_lru(bo);
-	else
-		ttm_bo_move_to_lru_tail(bo, NULL);
+	ttm_bo_move_to_lru_tail(bo, NULL);
 	spin_unlock(&bo->bdev->glob->lru_lock);
 	dma_resv_unlock(bo->base.resv);
 }
diff --git a/include/drm/ttm/ttm_execbuf_util.h b/include/drm/ttm/ttm_execbuf_util.h
index 4e86b6fd6c57..1a3553ac53b1 100644
--- a/include/drm/ttm/ttm_execbuf_util.h
+++ b/include/drm/ttm/ttm_execbuf_util.h
@@ -100,7 +100,7 @@ extern void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
 
 extern int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
 				  struct list_head *list, bool intr,
-				  struct list_head *dups, bool del_lru);
+				  struct list_head *dups);
 
 /**
  * function ttm_eu_fence_buffer_objects.
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] drm/ttm: remove pointers to globals
  2019-09-25 10:55 [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Christian König
  2019-09-25 10:55 ` [PATCH 2/3] drm/ttm: always keep BOs on the LRU Christian König
@ 2019-09-25 10:55 ` Christian König
  2019-09-25 11:56   ` Thomas Hellström (VMware)
  2019-09-25 11:55 ` [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Thomas Hellström (VMware)
  2 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2019-09-25 10:55 UTC (permalink / raw)
  To: kraxel, daniel, thomas_os, dri-devel

As the name says global memory and bo accounting is global. So it doesn't
make to much sense having pointers to global structures all around the code.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   |  9 ++--
 drivers/gpu/drm/drm_gem_vram_helper.c    |  5 +-
 drivers/gpu/drm/qxl/qxl_release.c        |  7 +--
 drivers/gpu/drm/qxl/qxl_ttm.c            |  7 +--
 drivers/gpu/drm/ttm/ttm_agp_backend.c    |  2 +-
 drivers/gpu/drm/ttm/ttm_bo.c             | 65 +++++++++++-------------
 drivers/gpu/drm/ttm/ttm_bo_util.c        |  2 +-
 drivers/gpu/drm/ttm/ttm_bo_vm.c          |  4 +-
 drivers/gpu/drm/ttm/ttm_execbuf_util.c   | 25 +++------
 drivers/gpu/drm/ttm/ttm_memory.c         |  2 +-
 drivers/gpu/drm/ttm/ttm_page_alloc.c     |  4 +-
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c |  4 +-
 include/drm/ttm/ttm_bo_driver.h          |  6 +--
 include/drm/ttm/ttm_memory.h             |  1 -
 15 files changed, 57 insertions(+), 88 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index d79ab1da9e07..c392f7672e06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -71,7 +71,7 @@
  */
 static int amdgpu_gart_dummy_page_init(struct amdgpu_device *adev)
 {
-	struct page *dummy_page = adev->mman.bdev.glob->dummy_read_page;
+	struct page *dummy_page = ttm_bo_glob.dummy_read_page;
 
 	if (adev->dummy_page_addr)
 		return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index f555843daef0..cca1887465a4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -600,21 +600,20 @@ void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo)
 void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
 				struct amdgpu_vm *vm)
 {
-	struct ttm_bo_global *glob = adev->mman.bdev.glob;
 	struct amdgpu_vm_bo_base *bo_base;
 
 #if 0
 	if (vm->bulk_moveable) {
-		spin_lock(&glob->lru_lock);
+		spin_lock(&ttm_bo_glob.lru_lock);
 		ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move);
-		spin_unlock(&glob->lru_lock);
+		spin_unlock(&ttm_bo_glob.lru_lock);
 		return;
 	}
 #endif
 
 	memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move));
 
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	list_for_each_entry(bo_base, &vm->idle, vm_status) {
 		struct amdgpu_bo *bo = bo_base->bo;
 
@@ -626,7 +625,7 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
 			ttm_bo_move_to_lru_tail(&bo->shadow->tbo,
 						&vm->lru_bulk_move);
 	}
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	vm->bulk_moveable = true;
 }
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 49588de88959..3695168206b5 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -896,12 +896,11 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
 	struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv;
-	struct ttm_bo_global *glob = vmm->bdev.glob;
 	struct drm_printer p = drm_seq_file_printer(m);
 
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	drm_mm_print(mm, &p);
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c
index 71f1b51a1350..a0d388b7b53b 100644
--- a/drivers/gpu/drm/qxl/qxl_release.c
+++ b/drivers/gpu/drm/qxl/qxl_release.c
@@ -429,7 +429,6 @@ void qxl_release_unmap(struct qxl_device *qdev,
 void qxl_release_fence_buffer_objects(struct qxl_release *release)
 {
 	struct ttm_buffer_object *bo;
-	struct ttm_bo_global *glob;
 	struct ttm_bo_device *bdev;
 	struct ttm_validate_buffer *entry;
 	struct qxl_device *qdev;
@@ -451,9 +450,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
 		       release->id | 0xf0000000, release->base.seqno);
 	trace_dma_fence_emit(&release->base);
 
-	glob = bdev->glob;
-
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 
 	list_for_each_entry(entry, &release->bos, head) {
 		bo = entry->bo;
@@ -462,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
 		ttm_bo_move_to_lru_tail(bo, NULL);
 		dma_resv_unlock(bo->base.resv);
 	}
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	dma_resv_ctx_fini(&release->ticket);
 }
 
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index cbc6c2ba8630..8d779ca2682a 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -369,14 +369,11 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
 	struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
-	struct drm_device *dev = node->minor->dev;
-	struct qxl_device *rdev = dev->dev_private;
-	struct ttm_bo_global *glob = rdev->mman.bdev.glob;
 	struct drm_printer p = drm_seq_file_printer(m);
 
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	drm_mm_print(mm, &p);
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	return 0;
 }
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index ea4d59eb8966..6050dc846894 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -51,7 +51,7 @@ struct ttm_agp_backend {
 static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
-	struct page *dummy_read_page = ttm->bdev->glob->dummy_read_page;
+	struct page *dummy_read_page = ttm_bo_glob.dummy_read_page;
 	struct drm_mm_node *node = bo_mem->mm_node;
 	struct agp_memory *mem;
 	int ret, cached = (bo_mem->placement & TTM_PL_FLAG_CACHED);
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index ab9967b84e0b..57cb77811dd5 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -51,6 +51,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj);
 DEFINE_MUTEX(ttm_global_mutex);
 unsigned ttm_bo_glob_use_count;
 struct ttm_bo_global ttm_bo_glob;
+EXPORT_SYMBOL(ttm_bo_glob);
 
 static struct attribute ttm_bo_count = {
 	.name = "bo_count",
@@ -148,7 +149,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
 {
 	struct ttm_buffer_object *bo =
 	    container_of(list_kref, struct ttm_buffer_object, list_kref);
-	struct ttm_bo_device *bdev = bo->bdev;
 	size_t acc_size = bo->acc_size;
 
 	BUG_ON(kref_read(&bo->list_kref));
@@ -158,13 +158,13 @@ static void ttm_bo_release_list(struct kref *list_kref)
 	BUG_ON(!list_empty(&bo->lru));
 	BUG_ON(!list_empty(&bo->ddestroy));
 	ttm_tt_destroy(bo->ttm);
-	atomic_dec(&bo->bdev->glob->bo_count);
+	atomic_dec(&ttm_bo_glob.bo_count);
 	dma_fence_put(bo->moving);
 	if (!ttm_bo_uses_embedded_gem_object(bo))
 		dma_resv_fini(&bo->base._resv);
 	mutex_destroy(&bo->wu_mutex);
 	bo->destroy(bo);
-	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
+	ttm_mem_global_free(&ttm_mem_glob, acc_size);
 }
 
 static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
@@ -187,7 +187,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
 
 	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]);
+		list_add_tail(&bo->swap, &ttm_bo_glob.swap_lru[bo->priority]);
 		kref_get(&bo->list_kref);
 	}
 }
@@ -294,7 +294,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
 		dma_resv_assert_held(pos->first->base.resv);
 		dma_resv_assert_held(pos->last->base.resv);
 
-		lru = &pos->first->bdev->glob->swap_lru[i];
+		lru = &ttm_bo_glob.swap_lru[i];
 		list_bulk_move_tail(lru, &pos->first->swap, &pos->last->swap);
 	}
 }
@@ -458,7 +458,6 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)
 static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_bo_global *glob = bdev->glob;
 	int ret;
 
 	ret = ttm_bo_individualize_resv(bo);
@@ -468,16 +467,16 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
 		 */
 		dma_resv_wait_timeout_rcu(bo->base.resv, true, false,
 						    30 * HZ);
-		spin_lock(&glob->lru_lock);
+		spin_lock(&ttm_bo_glob.lru_lock);
 		goto error;
 	}
 
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	ret = dma_resv_trylock(bo->base.resv) ? 0 : -EBUSY;
 	if (!ret) {
 		if (dma_resv_test_signaled_rcu(&bo->base._resv, true)) {
 			ttm_bo_del_from_lru(bo);
-			spin_unlock(&glob->lru_lock);
+			spin_unlock(&ttm_bo_glob.lru_lock);
 			if (bo->base.resv != &bo->base._resv)
 				dma_resv_unlock(&bo->base._resv);
 
@@ -506,7 +505,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
 error:
 	kref_get(&bo->list_kref);
 	list_add_tail(&bo->ddestroy, &bdev->ddestroy);
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	schedule_delayed_work(&bdev->wq,
 			      ((HZ / 100) < 1) ? 1 : HZ / 100);
@@ -529,7 +528,6 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 			       bool interruptible, bool no_wait_gpu,
 			       bool unlock_resv)
 {
-	struct ttm_bo_global *glob = bo->bdev->glob;
 	struct dma_resv *resv;
 	int ret;
 
@@ -548,7 +546,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 
 		if (unlock_resv)
 			dma_resv_unlock(bo->base.resv);
-		spin_unlock(&glob->lru_lock);
+		spin_unlock(&ttm_bo_glob.lru_lock);
 
 		lret = dma_resv_wait_timeout_rcu(resv, true,
 							   interruptible,
@@ -559,7 +557,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 		else if (lret == 0)
 			return -EBUSY;
 
-		spin_lock(&glob->lru_lock);
+		spin_lock(&ttm_bo_glob.lru_lock);
 		if (unlock_resv && !dma_resv_trylock(bo->base.resv)) {
 			/*
 			 * We raced, and lost, someone else holds the reservation now,
@@ -569,7 +567,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 			 * delayed destruction would succeed, so just return success
 			 * here.
 			 */
-			spin_unlock(&glob->lru_lock);
+			spin_unlock(&ttm_bo_glob.lru_lock);
 			return 0;
 		}
 		ret = 0;
@@ -578,7 +576,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 	if (ret || unlikely(list_empty(&bo->ddestroy))) {
 		if (unlock_resv)
 			dma_resv_unlock(bo->base.resv);
-		spin_unlock(&glob->lru_lock);
+		spin_unlock(&ttm_bo_glob.lru_lock);
 		return ret;
 	}
 
@@ -586,7 +584,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 	list_del_init(&bo->ddestroy);
 	kref_put(&bo->list_kref, ttm_bo_ref_bug);
 
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	ttm_bo_cleanup_memtype_use(bo);
 
 	if (unlock_resv)
@@ -601,7 +599,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
  */
 static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)
 {
-	struct ttm_bo_global *glob = bdev->glob;
+	struct ttm_bo_global *glob = &ttm_bo_glob;
 	struct list_head removed;
 	bool empty;
 
@@ -822,13 +820,12 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 			       struct ww_acquire_ctx *ticket)
 {
 	struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
-	struct ttm_bo_global *glob = bdev->glob;
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 	bool locked = false;
 	unsigned i;
 	int ret;
 
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
 		list_for_each_entry(bo, &man->lru[i], lru) {
 			bool busy;
@@ -860,7 +857,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 	if (!bo) {
 		if (busy_bo)
 			kref_get(&busy_bo->list_kref);
-		spin_unlock(&glob->lru_lock);
+		spin_unlock(&ttm_bo_glob.lru_lock);
 		ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket);
 		if (busy_bo)
 			kref_put(&busy_bo->list_kref, ttm_bo_release_list);
@@ -876,7 +873,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 		return ret;
 	}
 
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	ret = ttm_bo_evict(bo, ctx);
 	if (locked)
@@ -1042,10 +1039,10 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
 	mem->mem_type = mem_type;
 	mem->placement = cur_flags;
 
-	spin_lock(&bo->bdev->glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	ttm_bo_del_from_lru(bo);
 	ttm_bo_add_mem_to_lru(bo, mem);
-	spin_unlock(&bo->bdev->glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	return 0;
 }
@@ -1132,9 +1129,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 
 error:
 	if (bo->mem.mem_type == TTM_PL_SYSTEM && !list_empty(&bo->lru)) {
-		spin_lock(&bo->bdev->glob->lru_lock);
+		spin_lock(&ttm_bo_glob.lru_lock);
 		ttm_bo_move_to_lru_tail(bo, NULL);
-		spin_unlock(&bo->bdev->glob->lru_lock);
+		spin_unlock(&ttm_bo_glob.lru_lock);
 	}
 
 	return ret;
@@ -1258,9 +1255,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 			 struct dma_resv *resv,
 			 void (*destroy) (struct ttm_buffer_object *))
 {
+	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
 	int ret = 0;
 	unsigned long num_pages;
-	struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
 	bool locked;
 
 	ret = ttm_mem_global_alloc(mem_glob, acc_size, ctx);
@@ -1321,7 +1318,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		dma_resv_init(&bo->base._resv);
 		drm_vma_node_reset(&bo->base.vma_node);
 	}
-	atomic_inc(&bo->bdev->glob->bo_count);
+	atomic_inc(&ttm_bo_glob.bo_count);
 
 	/*
 	 * For ttm_bo_type_device buffers, allocate
@@ -1351,9 +1348,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		return ret;
 	}
 
-	spin_lock(&bdev->glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	ttm_bo_move_to_lru_tail(bo, NULL);
-	spin_unlock(&bdev->glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	return ret;
 }
@@ -1451,7 +1448,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 		.flags = TTM_OPT_FLAG_FORCE_ALLOC
 	};
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
-	struct ttm_bo_global *glob = bdev->glob;
+	struct ttm_bo_global *glob = &ttm_bo_glob;
 	struct dma_fence *fence;
 	int ret;
 	unsigned i;
@@ -1620,8 +1617,6 @@ static int ttm_bo_global_init(void)
 		goto out;
 
 	spin_lock_init(&glob->lru_lock);
-	glob->mem_glob = &ttm_mem_glob;
-	glob->mem_glob->bo_glob = glob;
 	glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
 
 	if (unlikely(glob->dummy_read_page == NULL)) {
@@ -1645,10 +1640,10 @@ static int ttm_bo_global_init(void)
 
 int ttm_bo_device_release(struct ttm_bo_device *bdev)
 {
+	struct ttm_bo_global *glob = &ttm_bo_glob;
 	int ret = 0;
 	unsigned i = TTM_NUM_MEM_TYPES;
 	struct ttm_mem_type_manager *man;
-	struct ttm_bo_global *glob = bdev->glob;
 
 	while (i--) {
 		man = &bdev->man[i];
@@ -1717,7 +1712,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 	INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue);
 	INIT_LIST_HEAD(&bdev->ddestroy);
 	bdev->dev_mapping = mapping;
-	bdev->glob = glob;
 	bdev->need_dma32 = need_dma32;
 	mutex_lock(&ttm_global_mutex);
 	list_add_tail(&bdev->device_list, &glob->device_list);
@@ -1921,8 +1915,7 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
 		.no_wait_gpu = false
 	};
 
-	while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
-		;
+	while (ttm_bo_swapout(&ttm_bo_glob, &ctx) == 0);
 }
 EXPORT_SYMBOL(ttm_bo_swapout_all);
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index fe81c565e7ef..3940afa6f3ad 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -503,7 +503,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
 	 * TODO: Explicit member copy would probably be better here.
 	 */
 
-	atomic_inc(&bo->bdev->glob->bo_count);
+	atomic_inc(&ttm_bo_glob.bo_count);
 	INIT_LIST_HEAD(&fbo->base.ddestroy);
 	INIT_LIST_HEAD(&fbo->base.lru);
 	INIT_LIST_HEAD(&fbo->base.swap);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 4aa007edffb0..263f4c33079a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -177,9 +177,9 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 		}
 
 		if (bo->moving != moving) {
-			spin_lock(&bdev->glob->lru_lock);
+			spin_lock(&ttm_bo_glob.lru_lock);
 			ttm_bo_move_to_lru_tail(bo, NULL);
-			spin_unlock(&bdev->glob->lru_lock);
+			spin_unlock(&ttm_bo_glob.lru_lock);
 		}
 		dma_fence_put(moving);
 	}
diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
index b09c2c8caf13..8f1dcdd0c3f5 100644
--- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
+++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
@@ -37,15 +37,11 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
 				struct list_head *list)
 {
 	struct ttm_validate_buffer *entry;
-	struct ttm_bo_global *glob;
 
 	if (list_empty(list))
 		return;
 
-	entry = list_first_entry(list, struct ttm_validate_buffer, head);
-	glob = entry->bo->bdev->glob;
-
-	spin_lock(&glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	list_for_each_entry(entry, list, head) {
 		struct ttm_buffer_object *bo = entry->bo;
 
@@ -53,7 +49,7 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
 		if (!ticket)
 			dma_resv_unlock(bo->base.resv);
 	}
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 
 	if (ticket) {
 		dma_resv_ctx_unlock_all(ticket);
@@ -79,15 +75,11 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
 			   struct list_head *dups)
 {
 	struct ttm_validate_buffer *entry;
-	struct ttm_bo_global *glob;
 	int ret;
 
 	if (list_empty(list))
 		return 0;
 
-	entry = list_first_entry(list, struct ttm_validate_buffer, head);
-	glob = entry->bo->bdev->glob;
-
 	if (ticket)
 		dma_resv_ctx_init(ticket);
 
@@ -153,19 +145,14 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
 				 struct dma_fence *fence)
 {
 	struct ttm_validate_buffer *entry;
-	struct ttm_buffer_object *bo;
-	struct ttm_bo_global *glob;
 
 	if (list_empty(list))
 		return;
 
-	bo = list_first_entry(list, struct ttm_validate_buffer, head)->bo;
-	glob = bo->bdev->glob;
-
-	spin_lock(&glob->lru_lock);
-
+	spin_lock(&ttm_bo_glob.lru_lock);
 	list_for_each_entry(entry, list, head) {
-		bo = entry->bo;
+		struct ttm_buffer_object *bo = entry->bo;
+
 		if (entry->num_shared)
 			dma_resv_add_shared_fence(bo->base.resv, fence);
 		else
@@ -174,7 +161,7 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
 		if (!ticket)
 			dma_resv_unlock(bo->base.resv);
 	}
-	spin_unlock(&glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	if (ticket) {
 		dma_resv_ctx_unlock_all(ticket);
 		dma_resv_ctx_fini(ticket);
diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index 8617958b7ae6..acd63b70d814 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -275,7 +275,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
 
 	while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
 		spin_unlock(&glob->lock);
-		ret = ttm_bo_swapout(glob->bo_glob, ctx);
+		ret = ttm_bo_swapout(&ttm_bo_glob, ctx);
 		spin_lock(&glob->lock);
 		if (unlikely(ret != 0))
 			break;
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index 627f8dc91d0e..b40a4678c296 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1028,7 +1028,7 @@ void ttm_page_alloc_fini(void)
 static void
 ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
 {
-	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
+	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
 	unsigned i;
 
 	if (mem_count_update == 0)
@@ -1049,7 +1049,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
 
 int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
-	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
+	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
 	unsigned i;
 	int ret;
 
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index d594f7520b7b..9cb588a93d43 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -882,8 +882,8 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)
 int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 			struct ttm_operation_ctx *ctx)
 {
+	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
 	struct ttm_tt *ttm = &ttm_dma->ttm;
-	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
 	unsigned long num_pages = ttm->num_pages;
 	struct dma_pool *pool;
 	struct dma_page *d_page;
@@ -987,8 +987,8 @@ EXPORT_SYMBOL_GPL(ttm_dma_populate);
 /* Put all pages in pages list to correct pool to wait for reuse */
 void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
 {
+	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
 	struct ttm_tt *ttm = &ttm_dma->ttm;
-	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
 	struct dma_pool *pool;
 	struct dma_page *d_page, *next;
 	enum pool_type type;
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 4332cc036483..381961979302 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -413,7 +413,6 @@ extern struct ttm_bo_global {
 	 */
 
 	struct kobject kobj;
-	struct ttm_mem_global *mem_glob;
 	struct page *dummy_read_page;
 	spinlock_t lru_lock;
 
@@ -457,7 +456,6 @@ struct ttm_bo_device {
 	 * Constant after bo device init / atomic.
 	 */
 	struct list_head device_list;
-	struct ttm_bo_global *glob;
 	struct ttm_bo_driver *driver;
 	struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES];
 
@@ -758,9 +756,9 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
  */
 static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 {
-	spin_lock(&bo->bdev->glob->lru_lock);
+	spin_lock(&ttm_bo_glob.lru_lock);
 	ttm_bo_move_to_lru_tail(bo, NULL);
-	spin_unlock(&bo->bdev->glob->lru_lock);
+	spin_unlock(&ttm_bo_glob.lru_lock);
 	dma_resv_unlock(bo->base.resv);
 }
 
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
index 3ff48a0a2d7b..c78ea99c42cf 100644
--- a/include/drm/ttm/ttm_memory.h
+++ b/include/drm/ttm/ttm_memory.h
@@ -65,7 +65,6 @@
 struct ttm_mem_zone;
 extern struct ttm_mem_global {
 	struct kobject kobj;
-	struct ttm_bo_global *bo_glob;
 	struct workqueue_struct *swap_queue;
 	struct work_struct work;
 	spinlock_t lock;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first
  2019-09-25 10:55 [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Christian König
  2019-09-25 10:55 ` [PATCH 2/3] drm/ttm: always keep BOs on the LRU Christian König
  2019-09-25 10:55 ` [PATCH 3/3] drm/ttm: remove pointers to globals Christian König
@ 2019-09-25 11:55 ` Thomas Hellström (VMware)
  2 siblings, 0 replies; 10+ messages in thread
From: Thomas Hellström (VMware) @ 2019-09-25 11:55 UTC (permalink / raw)
  To: Christian König, kraxel, daniel, dri-devel

On 9/25/19 12:55 PM, Christian König wrote:
> The busy BO might actually be already deleted,
> so grab only a list reference.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 881cf26d698e..02f301e1ff29 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -875,11 +875,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
>   
>   	if (!bo) {
>   		if (busy_bo)
> -			ttm_bo_get(busy_bo);
> +			kref_get(&busy_bo->list_kref);
>   		spin_unlock(&glob->lru_lock);
>   		ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket);
>   		if (busy_bo)
> -			ttm_bo_put(busy_bo);
> +			kref_put(&busy_bo->list_kref, ttm_bo_release_list);
>   		return ret;
>   	}
>   

lgtm.

Reviewed-by: Thomas Hellström <thellstrom@vmware.com>


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] drm/ttm: remove pointers to globals
  2019-09-25 10:55 ` [PATCH 3/3] drm/ttm: remove pointers to globals Christian König
@ 2019-09-25 11:56   ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Hellström (VMware) @ 2019-09-25 11:56 UTC (permalink / raw)
  To: Christian König, kraxel, daniel, dri-devel

On 9/25/19 12:55 PM, Christian König wrote:
> As the name says global memory and bo accounting is global. So it doesn't
> make to much sense having pointers to global structures all around the code.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   |  9 ++--
>   drivers/gpu/drm/drm_gem_vram_helper.c    |  5 +-
>   drivers/gpu/drm/qxl/qxl_release.c        |  7 +--
>   drivers/gpu/drm/qxl/qxl_ttm.c            |  7 +--
>   drivers/gpu/drm/ttm/ttm_agp_backend.c    |  2 +-
>   drivers/gpu/drm/ttm/ttm_bo.c             | 65 +++++++++++-------------
>   drivers/gpu/drm/ttm/ttm_bo_util.c        |  2 +-
>   drivers/gpu/drm/ttm/ttm_bo_vm.c          |  4 +-
>   drivers/gpu/drm/ttm/ttm_execbuf_util.c   | 25 +++------
>   drivers/gpu/drm/ttm/ttm_memory.c         |  2 +-
>   drivers/gpu/drm/ttm/ttm_page_alloc.c     |  4 +-
>   drivers/gpu/drm/ttm/ttm_page_alloc_dma.c |  4 +-
>   include/drm/ttm/ttm_bo_driver.h          |  6 +--
>   include/drm/ttm/ttm_memory.h             |  1 -
>   15 files changed, 57 insertions(+), 88 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> index d79ab1da9e07..c392f7672e06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> @@ -71,7 +71,7 @@
>    */
>   static int amdgpu_gart_dummy_page_init(struct amdgpu_device *adev)
>   {
> -	struct page *dummy_page = adev->mman.bdev.glob->dummy_read_page;
> +	struct page *dummy_page = ttm_bo_glob.dummy_read_page;
>   
>   	if (adev->dummy_page_addr)
>   		return 0;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index f555843daef0..cca1887465a4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -600,21 +600,20 @@ void amdgpu_vm_del_from_lru_notify(struct ttm_buffer_object *bo)
>   void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
>   				struct amdgpu_vm *vm)
>   {
> -	struct ttm_bo_global *glob = adev->mman.bdev.glob;
>   	struct amdgpu_vm_bo_base *bo_base;
>   
>   #if 0
>   	if (vm->bulk_moveable) {
> -		spin_lock(&glob->lru_lock);
> +		spin_lock(&ttm_bo_glob.lru_lock);
>   		ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move);
> -		spin_unlock(&glob->lru_lock);
> +		spin_unlock(&ttm_bo_glob.lru_lock);
>   		return;
>   	}
>   #endif
>   
>   	memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move));
>   
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	list_for_each_entry(bo_base, &vm->idle, vm_status) {
>   		struct amdgpu_bo *bo = bo_base->bo;
>   
> @@ -626,7 +625,7 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
>   			ttm_bo_move_to_lru_tail(&bo->shadow->tbo,
>   						&vm->lru_bulk_move);
>   	}
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	vm->bulk_moveable = true;
>   }
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index 49588de88959..3695168206b5 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -896,12 +896,11 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
>   	struct drm_info_node *node = (struct drm_info_node *) m->private;
>   	struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
>   	struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv;
> -	struct ttm_bo_global *glob = vmm->bdev.glob;
>   	struct drm_printer p = drm_seq_file_printer(m);
>   
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	drm_mm_print(mm, &p);
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	return 0;
>   }
>   
> diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c
> index 71f1b51a1350..a0d388b7b53b 100644
> --- a/drivers/gpu/drm/qxl/qxl_release.c
> +++ b/drivers/gpu/drm/qxl/qxl_release.c
> @@ -429,7 +429,6 @@ void qxl_release_unmap(struct qxl_device *qdev,
>   void qxl_release_fence_buffer_objects(struct qxl_release *release)
>   {
>   	struct ttm_buffer_object *bo;
> -	struct ttm_bo_global *glob;
>   	struct ttm_bo_device *bdev;
>   	struct ttm_validate_buffer *entry;
>   	struct qxl_device *qdev;
> @@ -451,9 +450,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
>   		       release->id | 0xf0000000, release->base.seqno);
>   	trace_dma_fence_emit(&release->base);
>   
> -	glob = bdev->glob;
> -
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   
>   	list_for_each_entry(entry, &release->bos, head) {
>   		bo = entry->bo;
> @@ -462,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
>   		ttm_bo_move_to_lru_tail(bo, NULL);
>   		dma_resv_unlock(bo->base.resv);
>   	}
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	dma_resv_ctx_fini(&release->ticket);
>   }
>   
> diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
> index cbc6c2ba8630..8d779ca2682a 100644
> --- a/drivers/gpu/drm/qxl/qxl_ttm.c
> +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
> @@ -369,14 +369,11 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
>   {
>   	struct drm_info_node *node = (struct drm_info_node *)m->private;
>   	struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
> -	struct drm_device *dev = node->minor->dev;
> -	struct qxl_device *rdev = dev->dev_private;
> -	struct ttm_bo_global *glob = rdev->mman.bdev.glob;
>   	struct drm_printer p = drm_seq_file_printer(m);
>   
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	drm_mm_print(mm, &p);
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	return 0;
>   }
>   #endif
> diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
> index ea4d59eb8966..6050dc846894 100644
> --- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
> +++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
> @@ -51,7 +51,7 @@ struct ttm_agp_backend {
>   static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
>   {
>   	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
> -	struct page *dummy_read_page = ttm->bdev->glob->dummy_read_page;
> +	struct page *dummy_read_page = ttm_bo_glob.dummy_read_page;
>   	struct drm_mm_node *node = bo_mem->mm_node;
>   	struct agp_memory *mem;
>   	int ret, cached = (bo_mem->placement & TTM_PL_FLAG_CACHED);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index ab9967b84e0b..57cb77811dd5 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -51,6 +51,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj);
>   DEFINE_MUTEX(ttm_global_mutex);
>   unsigned ttm_bo_glob_use_count;
>   struct ttm_bo_global ttm_bo_glob;
> +EXPORT_SYMBOL(ttm_bo_glob);
>   
>   static struct attribute ttm_bo_count = {
>   	.name = "bo_count",
> @@ -148,7 +149,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
>   {
>   	struct ttm_buffer_object *bo =
>   	    container_of(list_kref, struct ttm_buffer_object, list_kref);
> -	struct ttm_bo_device *bdev = bo->bdev;
>   	size_t acc_size = bo->acc_size;
>   
>   	BUG_ON(kref_read(&bo->list_kref));
> @@ -158,13 +158,13 @@ static void ttm_bo_release_list(struct kref *list_kref)
>   	BUG_ON(!list_empty(&bo->lru));
>   	BUG_ON(!list_empty(&bo->ddestroy));
>   	ttm_tt_destroy(bo->ttm);
> -	atomic_dec(&bo->bdev->glob->bo_count);
> +	atomic_dec(&ttm_bo_glob.bo_count);
>   	dma_fence_put(bo->moving);
>   	if (!ttm_bo_uses_embedded_gem_object(bo))
>   		dma_resv_fini(&bo->base._resv);
>   	mutex_destroy(&bo->wu_mutex);
>   	bo->destroy(bo);
> -	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
> +	ttm_mem_global_free(&ttm_mem_glob, acc_size);
>   }
>   
>   static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
> @@ -187,7 +187,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
>   
>   	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]);
> +		list_add_tail(&bo->swap, &ttm_bo_glob.swap_lru[bo->priority]);
>   		kref_get(&bo->list_kref);
>   	}
>   }
> @@ -294,7 +294,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>   		dma_resv_assert_held(pos->first->base.resv);
>   		dma_resv_assert_held(pos->last->base.resv);
>   
> -		lru = &pos->first->bdev->glob->swap_lru[i];
> +		lru = &ttm_bo_glob.swap_lru[i];
>   		list_bulk_move_tail(lru, &pos->first->swap, &pos->last->swap);
>   	}
>   }
> @@ -458,7 +458,6 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)
>   static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_bo_global *glob = bdev->glob;
>   	int ret;
>   
>   	ret = ttm_bo_individualize_resv(bo);
> @@ -468,16 +467,16 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
>   		 */
>   		dma_resv_wait_timeout_rcu(bo->base.resv, true, false,
>   						    30 * HZ);
> -		spin_lock(&glob->lru_lock);
> +		spin_lock(&ttm_bo_glob.lru_lock);
>   		goto error;
>   	}
>   
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	ret = dma_resv_trylock(bo->base.resv) ? 0 : -EBUSY;
>   	if (!ret) {
>   		if (dma_resv_test_signaled_rcu(&bo->base._resv, true)) {
>   			ttm_bo_del_from_lru(bo);
> -			spin_unlock(&glob->lru_lock);
> +			spin_unlock(&ttm_bo_glob.lru_lock);
>   			if (bo->base.resv != &bo->base._resv)
>   				dma_resv_unlock(&bo->base._resv);
>   
> @@ -506,7 +505,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
>   error:
>   	kref_get(&bo->list_kref);
>   	list_add_tail(&bo->ddestroy, &bdev->ddestroy);
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	schedule_delayed_work(&bdev->wq,
>   			      ((HZ / 100) < 1) ? 1 : HZ / 100);
> @@ -529,7 +528,6 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   			       bool interruptible, bool no_wait_gpu,
>   			       bool unlock_resv)
>   {
> -	struct ttm_bo_global *glob = bo->bdev->glob;
>   	struct dma_resv *resv;
>   	int ret;
>   
> @@ -548,7 +546,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   
>   		if (unlock_resv)
>   			dma_resv_unlock(bo->base.resv);
> -		spin_unlock(&glob->lru_lock);
> +		spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   		lret = dma_resv_wait_timeout_rcu(resv, true,
>   							   interruptible,
> @@ -559,7 +557,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   		else if (lret == 0)
>   			return -EBUSY;
>   
> -		spin_lock(&glob->lru_lock);
> +		spin_lock(&ttm_bo_glob.lru_lock);
>   		if (unlock_resv && !dma_resv_trylock(bo->base.resv)) {
>   			/*
>   			 * We raced, and lost, someone else holds the reservation now,
> @@ -569,7 +567,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   			 * delayed destruction would succeed, so just return success
>   			 * here.
>   			 */
> -			spin_unlock(&glob->lru_lock);
> +			spin_unlock(&ttm_bo_glob.lru_lock);
>   			return 0;
>   		}
>   		ret = 0;
> @@ -578,7 +576,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   	if (ret || unlikely(list_empty(&bo->ddestroy))) {
>   		if (unlock_resv)
>   			dma_resv_unlock(bo->base.resv);
> -		spin_unlock(&glob->lru_lock);
> +		spin_unlock(&ttm_bo_glob.lru_lock);
>   		return ret;
>   	}
>   
> @@ -586,7 +584,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>   	list_del_init(&bo->ddestroy);
>   	kref_put(&bo->list_kref, ttm_bo_ref_bug);
>   
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	ttm_bo_cleanup_memtype_use(bo);
>   
>   	if (unlock_resv)
> @@ -601,7 +599,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
>    */
>   static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)
>   {
> -	struct ttm_bo_global *glob = bdev->glob;
> +	struct ttm_bo_global *glob = &ttm_bo_glob;
>   	struct list_head removed;
>   	bool empty;
>   
> @@ -822,13 +820,12 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
>   			       struct ww_acquire_ctx *ticket)
>   {
>   	struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
> -	struct ttm_bo_global *glob = bdev->glob;
>   	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
>   	bool locked = false;
>   	unsigned i;
>   	int ret;
>   
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
>   		list_for_each_entry(bo, &man->lru[i], lru) {
>   			bool busy;
> @@ -860,7 +857,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
>   	if (!bo) {
>   		if (busy_bo)
>   			kref_get(&busy_bo->list_kref);
> -		spin_unlock(&glob->lru_lock);
> +		spin_unlock(&ttm_bo_glob.lru_lock);
>   		ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket);
>   		if (busy_bo)
>   			kref_put(&busy_bo->list_kref, ttm_bo_release_list);
> @@ -876,7 +873,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
>   		return ret;
>   	}
>   
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	ret = ttm_bo_evict(bo, ctx);
>   	if (locked)
> @@ -1042,10 +1039,10 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>   	mem->mem_type = mem_type;
>   	mem->placement = cur_flags;
>   
> -	spin_lock(&bo->bdev->glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	ttm_bo_del_from_lru(bo);
>   	ttm_bo_add_mem_to_lru(bo, mem);
> -	spin_unlock(&bo->bdev->glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	return 0;
>   }
> @@ -1132,9 +1129,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>   
>   error:
>   	if (bo->mem.mem_type == TTM_PL_SYSTEM && !list_empty(&bo->lru)) {
> -		spin_lock(&bo->bdev->glob->lru_lock);
> +		spin_lock(&ttm_bo_glob.lru_lock);
>   		ttm_bo_move_to_lru_tail(bo, NULL);
> -		spin_unlock(&bo->bdev->glob->lru_lock);
> +		spin_unlock(&ttm_bo_glob.lru_lock);
>   	}
>   
>   	return ret;
> @@ -1258,9 +1255,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   			 struct dma_resv *resv,
>   			 void (*destroy) (struct ttm_buffer_object *))
>   {
> +	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
>   	int ret = 0;
>   	unsigned long num_pages;
> -	struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
>   	bool locked;
>   
>   	ret = ttm_mem_global_alloc(mem_glob, acc_size, ctx);
> @@ -1321,7 +1318,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   		dma_resv_init(&bo->base._resv);
>   		drm_vma_node_reset(&bo->base.vma_node);
>   	}
> -	atomic_inc(&bo->bdev->glob->bo_count);
> +	atomic_inc(&ttm_bo_glob.bo_count);
>   
>   	/*
>   	 * For ttm_bo_type_device buffers, allocate
> @@ -1351,9 +1348,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   		return ret;
>   	}
>   
> -	spin_lock(&bdev->glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	ttm_bo_move_to_lru_tail(bo, NULL);
> -	spin_unlock(&bdev->glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	return ret;
>   }
> @@ -1451,7 +1448,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
>   		.flags = TTM_OPT_FLAG_FORCE_ALLOC
>   	};
>   	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> -	struct ttm_bo_global *glob = bdev->glob;
> +	struct ttm_bo_global *glob = &ttm_bo_glob;
>   	struct dma_fence *fence;
>   	int ret;
>   	unsigned i;
> @@ -1620,8 +1617,6 @@ static int ttm_bo_global_init(void)
>   		goto out;
>   
>   	spin_lock_init(&glob->lru_lock);
> -	glob->mem_glob = &ttm_mem_glob;
> -	glob->mem_glob->bo_glob = glob;
>   	glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
>   
>   	if (unlikely(glob->dummy_read_page == NULL)) {
> @@ -1645,10 +1640,10 @@ static int ttm_bo_global_init(void)
>   
>   int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   {
> +	struct ttm_bo_global *glob = &ttm_bo_glob;
>   	int ret = 0;
>   	unsigned i = TTM_NUM_MEM_TYPES;
>   	struct ttm_mem_type_manager *man;
> -	struct ttm_bo_global *glob = bdev->glob;
>   
>   	while (i--) {
>   		man = &bdev->man[i];
> @@ -1717,7 +1712,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
>   	INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue);
>   	INIT_LIST_HEAD(&bdev->ddestroy);
>   	bdev->dev_mapping = mapping;
> -	bdev->glob = glob;
>   	bdev->need_dma32 = need_dma32;
>   	mutex_lock(&ttm_global_mutex);
>   	list_add_tail(&bdev->device_list, &glob->device_list);
> @@ -1921,8 +1915,7 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>   		.no_wait_gpu = false
>   	};
>   
> -	while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
> -		;
> +	while (ttm_bo_swapout(&ttm_bo_glob, &ctx) == 0);
>   }
>   EXPORT_SYMBOL(ttm_bo_swapout_all);
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fe81c565e7ef..3940afa6f3ad 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -503,7 +503,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
>   	 * TODO: Explicit member copy would probably be better here.
>   	 */
>   
> -	atomic_inc(&bo->bdev->glob->bo_count);
> +	atomic_inc(&ttm_bo_glob.bo_count);
>   	INIT_LIST_HEAD(&fbo->base.ddestroy);
>   	INIT_LIST_HEAD(&fbo->base.lru);
>   	INIT_LIST_HEAD(&fbo->base.swap);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 4aa007edffb0..263f4c33079a 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -177,9 +177,9 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   		}
>   
>   		if (bo->moving != moving) {
> -			spin_lock(&bdev->glob->lru_lock);
> +			spin_lock(&ttm_bo_glob.lru_lock);
>   			ttm_bo_move_to_lru_tail(bo, NULL);
> -			spin_unlock(&bdev->glob->lru_lock);
> +			spin_unlock(&ttm_bo_glob.lru_lock);
>   		}
>   		dma_fence_put(moving);
>   	}
> diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> index b09c2c8caf13..8f1dcdd0c3f5 100644
> --- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> @@ -37,15 +37,11 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>   				struct list_head *list)
>   {
>   	struct ttm_validate_buffer *entry;
> -	struct ttm_bo_global *glob;
>   
>   	if (list_empty(list))
>   		return;
>   
> -	entry = list_first_entry(list, struct ttm_validate_buffer, head);
> -	glob = entry->bo->bdev->glob;
> -
> -	spin_lock(&glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	list_for_each_entry(entry, list, head) {
>   		struct ttm_buffer_object *bo = entry->bo;
>   
> @@ -53,7 +49,7 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>   		if (!ticket)
>   			dma_resv_unlock(bo->base.resv);
>   	}
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   
>   	if (ticket) {
>   		dma_resv_ctx_unlock_all(ticket);
> @@ -79,15 +75,11 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>   			   struct list_head *dups)
>   {
>   	struct ttm_validate_buffer *entry;
> -	struct ttm_bo_global *glob;
>   	int ret;
>   
>   	if (list_empty(list))
>   		return 0;
>   
> -	entry = list_first_entry(list, struct ttm_validate_buffer, head);
> -	glob = entry->bo->bdev->glob;
> -
>   	if (ticket)
>   		dma_resv_ctx_init(ticket);
>   
> @@ -153,19 +145,14 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
>   				 struct dma_fence *fence)
>   {
>   	struct ttm_validate_buffer *entry;
> -	struct ttm_buffer_object *bo;
> -	struct ttm_bo_global *glob;
>   
>   	if (list_empty(list))
>   		return;
>   
> -	bo = list_first_entry(list, struct ttm_validate_buffer, head)->bo;
> -	glob = bo->bdev->glob;
> -
> -	spin_lock(&glob->lru_lock);
> -
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	list_for_each_entry(entry, list, head) {
> -		bo = entry->bo;
> +		struct ttm_buffer_object *bo = entry->bo;
> +
>   		if (entry->num_shared)
>   			dma_resv_add_shared_fence(bo->base.resv, fence);
>   		else
> @@ -174,7 +161,7 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
>   		if (!ticket)
>   			dma_resv_unlock(bo->base.resv);
>   	}
> -	spin_unlock(&glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	if (ticket) {
>   		dma_resv_ctx_unlock_all(ticket);
>   		dma_resv_ctx_fini(ticket);
> diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
> index 8617958b7ae6..acd63b70d814 100644
> --- a/drivers/gpu/drm/ttm/ttm_memory.c
> +++ b/drivers/gpu/drm/ttm/ttm_memory.c
> @@ -275,7 +275,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
>   
>   	while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
>   		spin_unlock(&glob->lock);
> -		ret = ttm_bo_swapout(glob->bo_glob, ctx);
> +		ret = ttm_bo_swapout(&ttm_bo_glob, ctx);
>   		spin_lock(&glob->lock);
>   		if (unlikely(ret != 0))
>   			break;
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> index 627f8dc91d0e..b40a4678c296 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> @@ -1028,7 +1028,7 @@ void ttm_page_alloc_fini(void)
>   static void
>   ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
>   {
> -	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
> +	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
>   	unsigned i;
>   
>   	if (mem_count_update == 0)
> @@ -1049,7 +1049,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
>   
>   int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>   {
> -	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
> +	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
>   	unsigned i;
>   	int ret;
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> index d594f7520b7b..9cb588a93d43 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> @@ -882,8 +882,8 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)
>   int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
>   			struct ttm_operation_ctx *ctx)
>   {
> +	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
>   	struct ttm_tt *ttm = &ttm_dma->ttm;
> -	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
>   	unsigned long num_pages = ttm->num_pages;
>   	struct dma_pool *pool;
>   	struct dma_page *d_page;
> @@ -987,8 +987,8 @@ EXPORT_SYMBOL_GPL(ttm_dma_populate);
>   /* Put all pages in pages list to correct pool to wait for reuse */
>   void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
>   {
> +	struct ttm_mem_global *mem_glob = &ttm_mem_glob;
>   	struct ttm_tt *ttm = &ttm_dma->ttm;
> -	struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
>   	struct dma_pool *pool;
>   	struct dma_page *d_page, *next;
>   	enum pool_type type;
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 4332cc036483..381961979302 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -413,7 +413,6 @@ extern struct ttm_bo_global {
>   	 */
>   
>   	struct kobject kobj;
> -	struct ttm_mem_global *mem_glob;
>   	struct page *dummy_read_page;
>   	spinlock_t lru_lock;
>   
> @@ -457,7 +456,6 @@ struct ttm_bo_device {
>   	 * Constant after bo device init / atomic.
>   	 */
>   	struct list_head device_list;
> -	struct ttm_bo_global *glob;
>   	struct ttm_bo_driver *driver;
>   	struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES];
>   
> @@ -758,9 +756,9 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>    */
>   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   {
> -	spin_lock(&bo->bdev->glob->lru_lock);
> +	spin_lock(&ttm_bo_glob.lru_lock);
>   	ttm_bo_move_to_lru_tail(bo, NULL);
> -	spin_unlock(&bo->bdev->glob->lru_lock);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
>   	dma_resv_unlock(bo->base.resv);
>   }
>   
> diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
> index 3ff48a0a2d7b..c78ea99c42cf 100644
> --- a/include/drm/ttm/ttm_memory.h
> +++ b/include/drm/ttm/ttm_memory.h
> @@ -65,7 +65,6 @@
>   struct ttm_mem_zone;
>   extern struct ttm_mem_global {
>   	struct kobject kobj;
> -	struct ttm_bo_global *bo_glob;
>   	struct workqueue_struct *swap_queue;
>   	struct work_struct work;
>   	spinlock_t lock;

lgtm.

Reviewed-by: Thomas Hellström <thellstrom@vmware.com>


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-09-25 10:55 ` [PATCH 2/3] drm/ttm: always keep BOs on the LRU Christian König
@ 2019-09-25 12:06   ` Thomas Hellström (VMware)
  2019-09-25 12:10     ` Christian König
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Hellström (VMware) @ 2019-09-25 12:06 UTC (permalink / raw)
  To: Christian König, kraxel, daniel, dri-devel

On 9/25/19 12:55 PM, Christian König wrote:
> This allows blocking for BOs to become available
> in the memory management.
>
> Amdgpu is doing this for quite a while now during CS. Now
> apply the new behavior to all drivers using TTM.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>

Got to test this to see that there are no regressions.

There are some ugly cases in the vmwgfx driver (coded before we could 
create bos in the reserved state) that relies on creating a bo as 
NO_EVICT to make sure a following tryreserve will always succeed. So how 
are NO_EVICT bos handled after the below changes? Taken off the lru or 
just avoided when walking the lru?

Also, does this mean we can in theory start using the drm_mm_scan() 
interface for VRAM evictions, relying on the ww_mutexes to resolve 
contention?

/Thomas


> ---
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  9 ++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  4 +-
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +-
>   drivers/gpu/drm/qxl/qxl_release.c             |  4 +-
>   drivers/gpu/drm/radeon/radeon_gem.c           |  2 +-
>   drivers/gpu/drm/radeon/radeon_object.c        |  2 +-
>   drivers/gpu/drm/ttm/ttm_bo.c                  | 48 +++++--------------
>   drivers/gpu/drm/ttm/ttm_execbuf_util.c        | 25 ++--------
>   drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |  3 +-
>   drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    |  2 +-
>   include/drm/ttm/ttm_bo_api.h                  | 24 ----------
>   include/drm/ttm/ttm_bo_driver.h               | 20 ++------
>   include/drm/ttm/ttm_execbuf_util.h            |  2 +-
>   15 files changed, 33 insertions(+), 118 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index b9bb35d1699e..ad01c741caaf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -586,7 +586,7 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
>   	amdgpu_vm_get_pd_bo(vm, &ctx->list, &ctx->vm_pd[0]);
>   
>   	ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
> -				     false, &ctx->duplicates, true);
> +				     false, &ctx->duplicates);
>   	if (!ret)
>   		ctx->reserved = true;
>   	else {
> @@ -659,7 +659,7 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
>   	}
>   
>   	ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
> -				     false, &ctx->duplicates, true);
> +				     false, &ctx->duplicates);
>   	if (!ret)
>   		ctx->reserved = true;
>   	else
> @@ -1796,8 +1796,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
>   	}
>   
>   	/* Reserve all BOs and page tables for validation */
> -	ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates,
> -				     true);
> +	ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, &duplicates);
>   	WARN(!list_empty(&duplicates), "Duplicates should be empty");
>   	if (ret)
>   		goto out_free;
> @@ -1995,7 +1994,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
>   	}
>   
>   	ret = ttm_eu_reserve_buffers(&ctx.ticket, &ctx.list,
> -				     false, &duplicate_save, true);
> +				     false, &duplicate_save);
>   	if (ret) {
>   		pr_debug("Memory eviction: TTM Reserve Failed. Try again\n");
>   		goto ttm_reserve_fail;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 95ec965fcc2d..82f239ac4050 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -650,7 +650,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>   	}
>   
>   	r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
> -				   &duplicates, false);
> +				   &duplicates);
>   	if (unlikely(r != 0)) {
>   		if (r != -ERESTARTSYS)
>   			DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
> index 605f83046039..b1608d47508f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
> @@ -80,7 +80,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>   	list_add(&csa_tv.head, &list);
>   	amdgpu_vm_get_pd_bo(vm, &list, &pd);
>   
> -	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, false);
> +	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>   	if (r) {
>   		DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
>   		return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index b25a59c4bec6..cbfb3e84f352 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -175,7 +175,7 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,
>   
>   	amdgpu_vm_get_pd_bo(vm, &list, &vm_pd);
>   
> -	r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates, false);
> +	r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);
>   	if (r) {
>   		dev_err(adev->dev, "leaking bo va because "
>   			"we fail to reserve bo (%d)\n", r);
> @@ -611,7 +611,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
>   
>   	amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd);
>   
> -	r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates, false);
> +	r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
>   	if (r)
>   		goto error_unref;
>   
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 5df2ee1e10d8..760078b9925b 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -4439,7 +4439,7 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
>   	tv.num_shared = 1;
>   	list_add(&tv.head, &list);
>   
> -	r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL, true);
> +	r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL);
>   	if (r) {
>   		dev_err(adev->dev, "fail to reserve bo (%d)\n", r);
>   		return r;
> diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c
> index aa7a28795645..71f1b51a1350 100644
> --- a/drivers/gpu/drm/qxl/qxl_release.c
> +++ b/drivers/gpu/drm/qxl/qxl_release.c
> @@ -260,7 +260,7 @@ int qxl_release_reserve_list(struct qxl_release *release, bool no_intr)
>   		return 0;
>   
>   	ret = ttm_eu_reserve_buffers(&release->ticket, &release->bos,
> -				     !no_intr, NULL, true);
> +				     !no_intr, NULL);
>   	if (ret)
>   		return ret;
>   
> @@ -459,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)
>   		bo = entry->bo;
>   
>   		dma_resv_add_shared_fence(bo->base.resv, &release->base);
> -		ttm_bo_add_to_lru(bo);
> +		ttm_bo_move_to_lru_tail(bo, NULL);
>   		dma_resv_unlock(bo->base.resv);
>   	}
>   	spin_unlock(&glob->lru_lock);
> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
> index c48c2fb35456..879eac67cdd7 100644
> --- a/drivers/gpu/drm/radeon/radeon_gem.c
> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
> @@ -564,7 +564,7 @@ static void radeon_gem_va_update_vm(struct radeon_device *rdev,
>   	if (!vm_bos)
>   		return;
>   
> -	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, true);
> +	r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>   	if (r)
>   		goto error_free;
>   
> diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
> index 653fd7937b39..a94d827ba976 100644
> --- a/drivers/gpu/drm/radeon/radeon_object.c
> +++ b/drivers/gpu/drm/radeon/radeon_object.c
> @@ -542,7 +542,7 @@ int radeon_bo_list_validate(struct radeon_device *rdev,
>   	u64 bytes_moved_threshold = radeon_bo_get_threshold_for_moves(rdev);
>   
>   	INIT_LIST_HEAD(&duplicates);
> -	r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates, true);
> +	r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates);
>   	if (unlikely(r != 0)) {
>   		return r;
>   	}
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 02f301e1ff29..ab9967b84e0b 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -192,18 +192,12 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
>   	}
>   }
>   
> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
> -{
> -	ttm_bo_add_mem_to_lru(bo, &bo->mem);
> -}
> -EXPORT_SYMBOL(ttm_bo_add_to_lru);
> -
>   static void ttm_bo_ref_bug(struct kref *list_kref)
>   {
>   	BUG();
>   }
>   
> -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
> +static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
>   	bool notify = false;
> @@ -223,16 +217,6 @@ void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>   		bdev->driver->del_from_lru_notify(bo);
>   }
>   
> -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
> -{
> -	struct ttm_bo_global *glob = bo->bdev->glob;
> -
> -	spin_lock(&glob->lru_lock);
> -	ttm_bo_del_from_lru(bo);
> -	spin_unlock(&glob->lru_lock);
> -}
> -EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
> -
>   static void ttm_bo_bulk_move_set_pos(struct ttm_lru_bulk_move_pos *pos,
>   				     struct ttm_buffer_object *bo)
>   {
> @@ -247,7 +231,7 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
>   	dma_resv_assert_held(bo->base.resv);
>   
>   	ttm_bo_del_from_lru(bo);
> -	ttm_bo_add_to_lru(bo);
> +	ttm_bo_add_mem_to_lru(bo, &bo->mem);
>   
>   	if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>   		switch (bo->mem.mem_type) {
> @@ -511,7 +495,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
>   		 */
>   		if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
>   			bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
> -			ttm_bo_add_to_lru(bo);
> +			ttm_bo_move_to_lru_tail(bo, NULL);
>   		}
>   
>   		dma_resv_unlock(bo->base.resv);
> @@ -892,17 +876,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
>   		return ret;
>   	}
>   
> -	ttm_bo_del_from_lru(bo);
>   	spin_unlock(&glob->lru_lock);
>   
>   	ret = ttm_bo_evict(bo, ctx);
> -	if (locked) {
> +	if (locked)
>   		ttm_bo_unreserve(bo);
> -	} else {
> -		spin_lock(&glob->lru_lock);
> -		ttm_bo_add_to_lru(bo);
> -		spin_unlock(&glob->lru_lock);
> -	}
>   
>   	kref_put(&bo->list_kref, ttm_bo_release_list);
>   	return ret;
> @@ -1064,12 +1042,10 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>   	mem->mem_type = mem_type;
>   	mem->placement = cur_flags;
>   
> -	if (bo->mem.mem_type < mem_type && !list_empty(&bo->lru)) {
> -		spin_lock(&bo->bdev->glob->lru_lock);
> -		ttm_bo_del_from_lru(bo);
> -		ttm_bo_add_mem_to_lru(bo, mem);
> -		spin_unlock(&bo->bdev->glob->lru_lock);
> -	}
> +	spin_lock(&bo->bdev->glob->lru_lock);
> +	ttm_bo_del_from_lru(bo);
> +	ttm_bo_add_mem_to_lru(bo, mem);
> +	spin_unlock(&bo->bdev->glob->lru_lock);
>   
>   	return 0;
>   }
> @@ -1375,11 +1351,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   		return ret;
>   	}
>   
> -	if (resv && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
> -		spin_lock(&bdev->glob->lru_lock);
> -		ttm_bo_add_to_lru(bo);
> -		spin_unlock(&bdev->glob->lru_lock);
> -	}
> +	spin_lock(&bdev->glob->lru_lock);
> +	ttm_bo_move_to_lru_tail(bo, NULL);
> +	spin_unlock(&bdev->glob->lru_lock);
>   
>   	return ret;
>   }
> diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> index 71148c83cc4f..b09c2c8caf13 100644
> --- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> @@ -33,16 +33,6 @@
>   #include <linux/sched.h>
>   #include <linux/module.h>
>   
> -static void ttm_eu_del_from_lru_locked(struct list_head *list)
> -{
> -	struct ttm_validate_buffer *entry;
> -
> -	list_for_each_entry(entry, list, head) {
> -		struct ttm_buffer_object *bo = entry->bo;
> -		ttm_bo_del_from_lru(bo);
> -	}
> -}
> -
>   void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>   				struct list_head *list)
>   {
> @@ -59,8 +49,7 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>   	list_for_each_entry(entry, list, head) {
>   		struct ttm_buffer_object *bo = entry->bo;
>   
> -		if (list_empty(&bo->lru))
> -			ttm_bo_add_to_lru(bo);
> +		ttm_bo_move_to_lru_tail(bo, NULL);
>   		if (!ticket)
>   			dma_resv_unlock(bo->base.resv);
>   	}
> @@ -87,7 +76,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);
>   
>   int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>   			   struct list_head *list, bool intr,
> -			   struct list_head *dups, bool del_lru)
> +			   struct list_head *dups)
>   {
>   	struct ttm_validate_buffer *entry;
>   	struct ttm_bo_global *glob;
> @@ -142,11 +131,6 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>   		}
>   	}
>   
> -	if (del_lru) {
> -		spin_lock(&glob->lru_lock);
> -		ttm_eu_del_from_lru_locked(list);
> -		spin_unlock(&glob->lru_lock);
> -	}
>   	return 0;
>   
>   error:
> @@ -186,10 +170,7 @@ void ttm_eu_fence_buffer_objects(struct dma_resv_ctx *ticket,
>   			dma_resv_add_shared_fence(bo->base.resv, fence);
>   		else
>   			dma_resv_add_excl_fence(bo->base.resv, fence);
> -		if (list_empty(&bo->lru))
> -			ttm_bo_add_to_lru(bo);
> -		else
> -			ttm_bo_move_to_lru_tail(bo, NULL);
> +		ttm_bo_move_to_lru_tail(bo, NULL);
>   		if (!ticket)
>   			dma_resv_unlock(bo->base.resv);
>   	}
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> index 2d7c5ad25359..1d53a69819e5 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> @@ -464,8 +464,7 @@ vmw_resource_check_buffer(struct dma_resv_ctx *ticket,
>   	val_buf->bo = &res->backup->base;
>   	val_buf->num_shared = 0;
>   	list_add_tail(&val_buf->head, &val_list);
> -	ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL,
> -				     true);
> +	ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL);
>   	if (unlikely(ret != 0))
>   		goto out_no_reserve;
>   
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> index 43f48df3844f..ebb5b68b5c1f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> @@ -169,7 +169,7 @@ vmw_validation_bo_reserve(struct vmw_validation_context *ctx,
>   			  bool intr)
>   {
>   	return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
> -				      NULL, true);
> +				      NULL);
>   }
>   
>   /**
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 43c4929a2171..288fd64b7219 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -367,30 +367,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>    */
>   void ttm_bo_put(struct ttm_buffer_object *bo);
>   
> -/**
> - * ttm_bo_add_to_lru
> - *
> - * @bo: The buffer object.
> - *
> - * Add this bo to the relevant mem type lru and, if it's backed by
> - * system pages (ttms) to the swap list.
> - * This function must be called with struct ttm_bo_global::lru_lock held, and
> - * is typically called immediately prior to unreserving a bo.
> - */
> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
> -
> -/**
> - * ttm_bo_del_from_lru
> - *
> - * @bo: The buffer object.
> - *
> - * Remove this bo from all lru lists used to lookup and reserve an object.
> - * This function must be called with struct ttm_bo_global::lru_lock held,
> - * and is usually called just immediately after the bo has been reserved to
> - * avoid recursive reservation from lru lists.
> - */
> -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
> -
>   /**
>    * ttm_bo_move_to_lru_tail
>    *
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 4e307f65f497..4332cc036483 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -621,9 +621,6 @@ void ttm_mem_io_free_vm(struct ttm_buffer_object *bo);
>   int ttm_mem_io_lock(struct ttm_mem_type_manager *man, bool interruptible);
>   void ttm_mem_io_unlock(struct ttm_mem_type_manager *man);
>   
> -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo);
> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
> -
>   /**
>    * __ttm_bo_reserve:
>    *
> @@ -717,15 +714,9 @@ static inline int ttm_bo_reserve(struct ttm_buffer_object *bo,
>   				 bool interruptible, bool no_wait,
>   				 struct ww_acquire_ctx *ticket)
>   {
> -	int ret;
> -
>   	WARN_ON(!kref_read(&bo->kref));
>   
> -	ret = __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
> -	if (likely(ret == 0))
> -		ttm_bo_del_sub_from_lru(bo);
> -
> -	return ret;
> +	return __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
>   }
>   
>   /**
> @@ -752,9 +743,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>   	else
>   		dma_resv_lock_slow(bo->base.resv, ticket);
>   
> -	if (likely(ret == 0))
> -		ttm_bo_del_sub_from_lru(bo);
> -	else if (ret == -EINTR)
> +	if (ret == -EINTR)
>   		ret = -ERESTARTSYS;
>   
>   	return ret;
> @@ -770,10 +759,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   {
>   	spin_lock(&bo->bdev->glob->lru_lock);
> -	if (list_empty(&bo->lru))
> -		ttm_bo_add_to_lru(bo);
> -	else
> -		ttm_bo_move_to_lru_tail(bo, NULL);
> +	ttm_bo_move_to_lru_tail(bo, NULL);
>   	spin_unlock(&bo->bdev->glob->lru_lock);
>   	dma_resv_unlock(bo->base.resv);
>   }
> diff --git a/include/drm/ttm/ttm_execbuf_util.h b/include/drm/ttm/ttm_execbuf_util.h
> index 4e86b6fd6c57..1a3553ac53b1 100644
> --- a/include/drm/ttm/ttm_execbuf_util.h
> +++ b/include/drm/ttm/ttm_execbuf_util.h
> @@ -100,7 +100,7 @@ extern void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>   
>   extern int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>   				  struct list_head *list, bool intr,
> -				  struct list_head *dups, bool del_lru);
> +				  struct list_head *dups);
>   
>   /**
>    * function ttm_eu_fence_buffer_objects.


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-09-25 12:06   ` Thomas Hellström (VMware)
@ 2019-09-25 12:10     ` Christian König
  2019-10-16  9:30       ` Christian König
  0 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2019-09-25 12:10 UTC (permalink / raw)
  To: Thomas Hellström (VMware), kraxel, daniel, dri-devel

Am 25.09.19 um 14:06 schrieb Thomas Hellström (VMware):
> On 9/25/19 12:55 PM, Christian König wrote:
>> This allows blocking for BOs to become available
>> in the memory management.
>>
>> Amdgpu is doing this for quite a while now during CS. Now
>> apply the new behavior to all drivers using TTM.
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>
> Got to test this to see that there are no regressions.
>
> There are some ugly cases in the vmwgfx driver (coded before we could 
> create bos in the reserved state) that relies on creating a bo as 
> NO_EVICT to make sure a following tryreserve will always succeed. So 
> how are NO_EVICT bos handled after the below changes? Taken off the 
> lru or just avoided when walking the lru?

They are never added to the LRU in the first place, the NO_EVICT flag is 
still checked during BO init.

>
> Also, does this mean we can in theory start using the drm_mm_scan() 
> interface for VRAM evictions, relying on the ww_mutexes to resolve 
> contention?

It's the first step towards this, we still need some rather funky 
ww_mutex dance to completely get this working.

Christian.

>
> /Thomas
>
>
>> ---
>>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  9 ++--
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  4 +-
>>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +-
>>   drivers/gpu/drm/qxl/qxl_release.c             |  4 +-
>>   drivers/gpu/drm/radeon/radeon_gem.c           |  2 +-
>>   drivers/gpu/drm/radeon/radeon_object.c        |  2 +-
>>   drivers/gpu/drm/ttm/ttm_bo.c                  | 48 +++++--------------
>>   drivers/gpu/drm/ttm/ttm_execbuf_util.c        | 25 ++--------
>>   drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |  3 +-
>>   drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    |  2 +-
>>   include/drm/ttm/ttm_bo_api.h                  | 24 ----------
>>   include/drm/ttm/ttm_bo_driver.h               | 20 ++------
>>   include/drm/ttm/ttm_execbuf_util.h            |  2 +-
>>   15 files changed, 33 insertions(+), 118 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> index b9bb35d1699e..ad01c741caaf 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> @@ -586,7 +586,7 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
>>       amdgpu_vm_get_pd_bo(vm, &ctx->list, &ctx->vm_pd[0]);
>>         ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
>> -                     false, &ctx->duplicates, true);
>> +                     false, &ctx->duplicates);
>>       if (!ret)
>>           ctx->reserved = true;
>>       else {
>> @@ -659,7 +659,7 @@ static int reserve_bo_and_cond_vms(struct kgd_mem 
>> *mem,
>>       }
>>         ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
>> -                     false, &ctx->duplicates, true);
>> +                     false, &ctx->duplicates);
>>       if (!ret)
>>           ctx->reserved = true;
>>       else
>> @@ -1796,8 +1796,7 @@ static int validate_invalid_user_pages(struct 
>> amdkfd_process_info *process_info)
>>       }
>>         /* Reserve all BOs and page tables for validation */
>> -    ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, 
>> &duplicates,
>> -                     true);
>> +    ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, 
>> &duplicates);
>>       WARN(!list_empty(&duplicates), "Duplicates should be empty");
>>       if (ret)
>>           goto out_free;
>> @@ -1995,7 +1994,7 @@ int 
>> amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence 
>> **ef)
>>       }
>>         ret = ttm_eu_reserve_buffers(&ctx.ticket, &ctx.list,
>> -                     false, &duplicate_save, true);
>> +                     false, &duplicate_save);
>>       if (ret) {
>>           pr_debug("Memory eviction: TTM Reserve Failed. Try again\n");
>>           goto ttm_reserve_fail;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> index 95ec965fcc2d..82f239ac4050 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> @@ -650,7 +650,7 @@ static int amdgpu_cs_parser_bos(struct 
>> amdgpu_cs_parser *p,
>>       }
>>         r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
>> -                   &duplicates, false);
>> +                   &duplicates);
>>       if (unlikely(r != 0)) {
>>           if (r != -ERESTARTSYS)
>>               DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>> index 605f83046039..b1608d47508f 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>> @@ -80,7 +80,7 @@ int amdgpu_map_static_csa(struct amdgpu_device 
>> *adev, struct amdgpu_vm *vm,
>>       list_add(&csa_tv.head, &list);
>>       amdgpu_vm_get_pd_bo(vm, &list, &pd);
>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, false);
>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>>       if (r) {
>>           DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
>>           return r;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> index b25a59c4bec6..cbfb3e84f352 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> @@ -175,7 +175,7 @@ void amdgpu_gem_object_close(struct 
>> drm_gem_object *obj,
>>         amdgpu_vm_get_pd_bo(vm, &list, &vm_pd);
>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates, 
>> false);
>> +    r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);
>>       if (r) {
>>           dev_err(adev->dev, "leaking bo va because "
>>               "we fail to reserve bo (%d)\n", r);
>> @@ -611,7 +611,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, 
>> void *data,
>>         amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd);
>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates, 
>> false);
>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
>>       if (r)
>>           goto error_unref;
>>   diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
>> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>> index 5df2ee1e10d8..760078b9925b 100644
>> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>> @@ -4439,7 +4439,7 @@ static int dm_plane_helper_prepare_fb(struct 
>> drm_plane *plane,
>>       tv.num_shared = 1;
>>       list_add(&tv.head, &list);
>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL, true);
>> +    r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL);
>>       if (r) {
>>           dev_err(adev->dev, "fail to reserve bo (%d)\n", r);
>>           return r;
>> diff --git a/drivers/gpu/drm/qxl/qxl_release.c 
>> b/drivers/gpu/drm/qxl/qxl_release.c
>> index aa7a28795645..71f1b51a1350 100644
>> --- a/drivers/gpu/drm/qxl/qxl_release.c
>> +++ b/drivers/gpu/drm/qxl/qxl_release.c
>> @@ -260,7 +260,7 @@ int qxl_release_reserve_list(struct qxl_release 
>> *release, bool no_intr)
>>           return 0;
>>         ret = ttm_eu_reserve_buffers(&release->ticket, &release->bos,
>> -                     !no_intr, NULL, true);
>> +                     !no_intr, NULL);
>>       if (ret)
>>           return ret;
>>   @@ -459,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct 
>> qxl_release *release)
>>           bo = entry->bo;
>>             dma_resv_add_shared_fence(bo->base.resv, &release->base);
>> -        ttm_bo_add_to_lru(bo);
>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>           dma_resv_unlock(bo->base.resv);
>>       }
>>       spin_unlock(&glob->lru_lock);
>> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
>> b/drivers/gpu/drm/radeon/radeon_gem.c
>> index c48c2fb35456..879eac67cdd7 100644
>> --- a/drivers/gpu/drm/radeon/radeon_gem.c
>> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
>> @@ -564,7 +564,7 @@ static void radeon_gem_va_update_vm(struct 
>> radeon_device *rdev,
>>       if (!vm_bos)
>>           return;
>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, true);
>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>>       if (r)
>>           goto error_free;
>>   diff --git a/drivers/gpu/drm/radeon/radeon_object.c 
>> b/drivers/gpu/drm/radeon/radeon_object.c
>> index 653fd7937b39..a94d827ba976 100644
>> --- a/drivers/gpu/drm/radeon/radeon_object.c
>> +++ b/drivers/gpu/drm/radeon/radeon_object.c
>> @@ -542,7 +542,7 @@ int radeon_bo_list_validate(struct radeon_device 
>> *rdev,
>>       u64 bytes_moved_threshold = 
>> radeon_bo_get_threshold_for_moves(rdev);
>>         INIT_LIST_HEAD(&duplicates);
>> -    r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates, true);
>> +    r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates);
>>       if (unlikely(r != 0)) {
>>           return r;
>>       }
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 02f301e1ff29..ab9967b84e0b 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -192,18 +192,12 @@ static void ttm_bo_add_mem_to_lru(struct 
>> ttm_buffer_object *bo,
>>       }
>>   }
>>   -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>> -{
>> -    ttm_bo_add_mem_to_lru(bo, &bo->mem);
>> -}
>> -EXPORT_SYMBOL(ttm_bo_add_to_lru);
>> -
>>   static void ttm_bo_ref_bug(struct kref *list_kref)
>>   {
>>       BUG();
>>   }
>>   -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>> +static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>>   {
>>       struct ttm_bo_device *bdev = bo->bdev;
>>       bool notify = false;
>> @@ -223,16 +217,6 @@ void ttm_bo_del_from_lru(struct 
>> ttm_buffer_object *bo)
>>           bdev->driver->del_from_lru_notify(bo);
>>   }
>>   -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
>> -{
>> -    struct ttm_bo_global *glob = bo->bdev->glob;
>> -
>> -    spin_lock(&glob->lru_lock);
>> -    ttm_bo_del_from_lru(bo);
>> -    spin_unlock(&glob->lru_lock);
>> -}
>> -EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
>> -
>>   static void ttm_bo_bulk_move_set_pos(struct ttm_lru_bulk_move_pos 
>> *pos,
>>                        struct ttm_buffer_object *bo)
>>   {
>> @@ -247,7 +231,7 @@ void ttm_bo_move_to_lru_tail(struct 
>> ttm_buffer_object *bo,
>>       dma_resv_assert_held(bo->base.resv);
>>         ttm_bo_del_from_lru(bo);
>> -    ttm_bo_add_to_lru(bo);
>> +    ttm_bo_add_mem_to_lru(bo, &bo->mem);
>>         if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>>           switch (bo->mem.mem_type) {
>> @@ -511,7 +495,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct 
>> ttm_buffer_object *bo)
>>            */
>>           if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
>>               bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
>> -            ttm_bo_add_to_lru(bo);
>> +            ttm_bo_move_to_lru_tail(bo, NULL);
>>           }
>>             dma_resv_unlock(bo->base.resv);
>> @@ -892,17 +876,11 @@ static int ttm_mem_evict_first(struct 
>> ttm_bo_device *bdev,
>>           return ret;
>>       }
>>   -    ttm_bo_del_from_lru(bo);
>>       spin_unlock(&glob->lru_lock);
>>         ret = ttm_bo_evict(bo, ctx);
>> -    if (locked) {
>> +    if (locked)
>>           ttm_bo_unreserve(bo);
>> -    } else {
>> -        spin_lock(&glob->lru_lock);
>> -        ttm_bo_add_to_lru(bo);
>> -        spin_unlock(&glob->lru_lock);
>> -    }
>>         kref_put(&bo->list_kref, ttm_bo_release_list);
>>       return ret;
>> @@ -1064,12 +1042,10 @@ static int ttm_bo_mem_placement(struct 
>> ttm_buffer_object *bo,
>>       mem->mem_type = mem_type;
>>       mem->placement = cur_flags;
>>   -    if (bo->mem.mem_type < mem_type && !list_empty(&bo->lru)) {
>> -        spin_lock(&bo->bdev->glob->lru_lock);
>> -        ttm_bo_del_from_lru(bo);
>> -        ttm_bo_add_mem_to_lru(bo, mem);
>> -        spin_unlock(&bo->bdev->glob->lru_lock);
>> -    }
>> +    spin_lock(&bo->bdev->glob->lru_lock);
>> +    ttm_bo_del_from_lru(bo);
>> +    ttm_bo_add_mem_to_lru(bo, mem);
>> +    spin_unlock(&bo->bdev->glob->lru_lock);
>>         return 0;
>>   }
>> @@ -1375,11 +1351,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device 
>> *bdev,
>>           return ret;
>>       }
>>   -    if (resv && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>> -        spin_lock(&bdev->glob->lru_lock);
>> -        ttm_bo_add_to_lru(bo);
>> -        spin_unlock(&bdev->glob->lru_lock);
>> -    }
>> +    spin_lock(&bdev->glob->lru_lock);
>> +    ttm_bo_move_to_lru_tail(bo, NULL);
>> +    spin_unlock(&bdev->glob->lru_lock);
>>         return ret;
>>   }
>> diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c 
>> b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>> index 71148c83cc4f..b09c2c8caf13 100644
>> --- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>> +++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>> @@ -33,16 +33,6 @@
>>   #include <linux/sched.h>
>>   #include <linux/module.h>
>>   -static void ttm_eu_del_from_lru_locked(struct list_head *list)
>> -{
>> -    struct ttm_validate_buffer *entry;
>> -
>> -    list_for_each_entry(entry, list, head) {
>> -        struct ttm_buffer_object *bo = entry->bo;
>> -        ttm_bo_del_from_lru(bo);
>> -    }
>> -}
>> -
>>   void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>>                   struct list_head *list)
>>   {
>> @@ -59,8 +49,7 @@ void ttm_eu_backoff_reservation(struct dma_resv_ctx 
>> *ticket,
>>       list_for_each_entry(entry, list, head) {
>>           struct ttm_buffer_object *bo = entry->bo;
>>   -        if (list_empty(&bo->lru))
>> -            ttm_bo_add_to_lru(bo);
>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>           if (!ticket)
>>               dma_resv_unlock(bo->base.resv);
>>       }
>> @@ -87,7 +76,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);
>>     int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>>                  struct list_head *list, bool intr,
>> -               struct list_head *dups, bool del_lru)
>> +               struct list_head *dups)
>>   {
>>       struct ttm_validate_buffer *entry;
>>       struct ttm_bo_global *glob;
>> @@ -142,11 +131,6 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx 
>> *ticket,
>>           }
>>       }
>>   -    if (del_lru) {
>> -        spin_lock(&glob->lru_lock);
>> -        ttm_eu_del_from_lru_locked(list);
>> -        spin_unlock(&glob->lru_lock);
>> -    }
>>       return 0;
>>     error:
>> @@ -186,10 +170,7 @@ void ttm_eu_fence_buffer_objects(struct 
>> dma_resv_ctx *ticket,
>>               dma_resv_add_shared_fence(bo->base.resv, fence);
>>           else
>>               dma_resv_add_excl_fence(bo->base.resv, fence);
>> -        if (list_empty(&bo->lru))
>> -            ttm_bo_add_to_lru(bo);
>> -        else
>> -            ttm_bo_move_to_lru_tail(bo, NULL);
>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>           if (!ticket)
>>               dma_resv_unlock(bo->base.resv);
>>       }
>> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c 
>> b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>> index 2d7c5ad25359..1d53a69819e5 100644
>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>> @@ -464,8 +464,7 @@ vmw_resource_check_buffer(struct dma_resv_ctx 
>> *ticket,
>>       val_buf->bo = &res->backup->base;
>>       val_buf->num_shared = 0;
>>       list_add_tail(&val_buf->head, &val_list);
>> -    ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, 
>> NULL,
>> -                     true);
>> +    ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, 
>> NULL);
>>       if (unlikely(ret != 0))
>>           goto out_no_reserve;
>>   diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h 
>> b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>> index 43f48df3844f..ebb5b68b5c1f 100644
>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>> @@ -169,7 +169,7 @@ vmw_validation_bo_reserve(struct 
>> vmw_validation_context *ctx,
>>                 bool intr)
>>   {
>>       return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
>> -                      NULL, true);
>> +                      NULL);
>>   }
>>     /**
>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>> index 43c4929a2171..288fd64b7219 100644
>> --- a/include/drm/ttm/ttm_bo_api.h
>> +++ b/include/drm/ttm/ttm_bo_api.h
>> @@ -367,30 +367,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>>    */
>>   void ttm_bo_put(struct ttm_buffer_object *bo);
>>   -/**
>> - * ttm_bo_add_to_lru
>> - *
>> - * @bo: The buffer object.
>> - *
>> - * Add this bo to the relevant mem type lru and, if it's backed by
>> - * system pages (ttms) to the swap list.
>> - * This function must be called with struct ttm_bo_global::lru_lock 
>> held, and
>> - * is typically called immediately prior to unreserving a bo.
>> - */
>> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
>> -
>> -/**
>> - * ttm_bo_del_from_lru
>> - *
>> - * @bo: The buffer object.
>> - *
>> - * Remove this bo from all lru lists used to lookup and reserve an 
>> object.
>> - * This function must be called with struct ttm_bo_global::lru_lock 
>> held,
>> - * and is usually called just immediately after the bo has been 
>> reserved to
>> - * avoid recursive reservation from lru lists.
>> - */
>> -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
>> -
>>   /**
>>    * ttm_bo_move_to_lru_tail
>>    *
>> diff --git a/include/drm/ttm/ttm_bo_driver.h 
>> b/include/drm/ttm/ttm_bo_driver.h
>> index 4e307f65f497..4332cc036483 100644
>> --- a/include/drm/ttm/ttm_bo_driver.h
>> +++ b/include/drm/ttm/ttm_bo_driver.h
>> @@ -621,9 +621,6 @@ void ttm_mem_io_free_vm(struct ttm_buffer_object 
>> *bo);
>>   int ttm_mem_io_lock(struct ttm_mem_type_manager *man, bool 
>> interruptible);
>>   void ttm_mem_io_unlock(struct ttm_mem_type_manager *man);
>>   -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo);
>> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
>> -
>>   /**
>>    * __ttm_bo_reserve:
>>    *
>> @@ -717,15 +714,9 @@ static inline int ttm_bo_reserve(struct 
>> ttm_buffer_object *bo,
>>                    bool interruptible, bool no_wait,
>>                    struct ww_acquire_ctx *ticket)
>>   {
>> -    int ret;
>> -
>>       WARN_ON(!kref_read(&bo->kref));
>>   -    ret = __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
>> -    if (likely(ret == 0))
>> -        ttm_bo_del_sub_from_lru(bo);
>> -
>> -    return ret;
>> +    return __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
>>   }
>>     /**
>> @@ -752,9 +743,7 @@ static inline int ttm_bo_reserve_slowpath(struct 
>> ttm_buffer_object *bo,
>>       else
>>           dma_resv_lock_slow(bo->base.resv, ticket);
>>   -    if (likely(ret == 0))
>> -        ttm_bo_del_sub_from_lru(bo);
>> -    else if (ret == -EINTR)
>> +    if (ret == -EINTR)
>>           ret = -ERESTARTSYS;
>>         return ret;
>> @@ -770,10 +759,7 @@ static inline int ttm_bo_reserve_slowpath(struct 
>> ttm_buffer_object *bo,
>>   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>>   {
>>       spin_lock(&bo->bdev->glob->lru_lock);
>> -    if (list_empty(&bo->lru))
>> -        ttm_bo_add_to_lru(bo);
>> -    else
>> -        ttm_bo_move_to_lru_tail(bo, NULL);
>> +    ttm_bo_move_to_lru_tail(bo, NULL);
>>       spin_unlock(&bo->bdev->glob->lru_lock);
>>       dma_resv_unlock(bo->base.resv);
>>   }
>> diff --git a/include/drm/ttm/ttm_execbuf_util.h 
>> b/include/drm/ttm/ttm_execbuf_util.h
>> index 4e86b6fd6c57..1a3553ac53b1 100644
>> --- a/include/drm/ttm/ttm_execbuf_util.h
>> +++ b/include/drm/ttm/ttm_execbuf_util.h
>> @@ -100,7 +100,7 @@ extern void ttm_eu_backoff_reservation(struct 
>> dma_resv_ctx *ticket,
>>     extern int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>>                     struct list_head *list, bool intr,
>> -                  struct list_head *dups, bool del_lru);
>> +                  struct list_head *dups);
>>     /**
>>    * function ttm_eu_fence_buffer_objects.
>
>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-09-25 12:10     ` Christian König
@ 2019-10-16  9:30       ` Christian König
  2019-10-18 13:49         ` Thomas Hellström (VMware)
  0 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2019-10-16  9:30 UTC (permalink / raw)
  To: Thomas Hellström (VMware), kraxel, daniel, dri-devel

Am 25.09.19 um 14:10 schrieb Christian König:
> Am 25.09.19 um 14:06 schrieb Thomas Hellström (VMware):
>> On 9/25/19 12:55 PM, Christian König wrote:
>>> This allows blocking for BOs to become available
>>> in the memory management.
>>>
>>> Amdgpu is doing this for quite a while now during CS. Now
>>> apply the new behavior to all drivers using TTM.
>>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>
>> Got to test this to see that there are no regressions.

Did you got time to test this or did I just missed your response?

Thanks in advance,
Christian.

>>
>> There are some ugly cases in the vmwgfx driver (coded before we could 
>> create bos in the reserved state) that relies on creating a bo as 
>> NO_EVICT to make sure a following tryreserve will always succeed. So 
>> how are NO_EVICT bos handled after the below changes? Taken off the 
>> lru or just avoided when walking the lru?
>
> They are never added to the LRU in the first place, the NO_EVICT flag 
> is still checked during BO init.
>
>>
>> Also, does this mean we can in theory start using the drm_mm_scan() 
>> interface for VRAM evictions, relying on the ww_mutexes to resolve 
>> contention?
>
> It's the first step towards this, we still need some rather funky 
> ww_mutex dance to completely get this working.
>
> Christian.
>
>>
>> /Thomas
>>
>>
>>> ---
>>>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  9 ++--
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  4 +-
>>>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +-
>>>   drivers/gpu/drm/qxl/qxl_release.c             |  4 +-
>>>   drivers/gpu/drm/radeon/radeon_gem.c           |  2 +-
>>>   drivers/gpu/drm/radeon/radeon_object.c        |  2 +-
>>>   drivers/gpu/drm/ttm/ttm_bo.c                  | 48 
>>> +++++--------------
>>>   drivers/gpu/drm/ttm/ttm_execbuf_util.c        | 25 ++--------
>>>   drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |  3 +-
>>>   drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    |  2 +-
>>>   include/drm/ttm/ttm_bo_api.h                  | 24 ----------
>>>   include/drm/ttm/ttm_bo_driver.h               | 20 ++------
>>>   include/drm/ttm/ttm_execbuf_util.h            |  2 +-
>>>   15 files changed, 33 insertions(+), 118 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> index b9bb35d1699e..ad01c741caaf 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> @@ -586,7 +586,7 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
>>>       amdgpu_vm_get_pd_bo(vm, &ctx->list, &ctx->vm_pd[0]);
>>>         ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
>>> -                     false, &ctx->duplicates, true);
>>> +                     false, &ctx->duplicates);
>>>       if (!ret)
>>>           ctx->reserved = true;
>>>       else {
>>> @@ -659,7 +659,7 @@ static int reserve_bo_and_cond_vms(struct 
>>> kgd_mem *mem,
>>>       }
>>>         ret = ttm_eu_reserve_buffers(&ctx->ticket, &ctx->list,
>>> -                     false, &ctx->duplicates, true);
>>> +                     false, &ctx->duplicates);
>>>       if (!ret)
>>>           ctx->reserved = true;
>>>       else
>>> @@ -1796,8 +1796,7 @@ static int validate_invalid_user_pages(struct 
>>> amdkfd_process_info *process_info)
>>>       }
>>>         /* Reserve all BOs and page tables for validation */
>>> -    ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, 
>>> &duplicates,
>>> -                     true);
>>> +    ret = ttm_eu_reserve_buffers(&ticket, &resv_list, false, 
>>> &duplicates);
>>>       WARN(!list_empty(&duplicates), "Duplicates should be empty");
>>>       if (ret)
>>>           goto out_free;
>>> @@ -1995,7 +1994,7 @@ int 
>>> amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence 
>>> **ef)
>>>       }
>>>         ret = ttm_eu_reserve_buffers(&ctx.ticket, &ctx.list,
>>> -                     false, &duplicate_save, true);
>>> +                     false, &duplicate_save);
>>>       if (ret) {
>>>           pr_debug("Memory eviction: TTM Reserve Failed. Try again\n");
>>>           goto ttm_reserve_fail;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> index 95ec965fcc2d..82f239ac4050 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> @@ -650,7 +650,7 @@ static int amdgpu_cs_parser_bos(struct 
>>> amdgpu_cs_parser *p,
>>>       }
>>>         r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
>>> -                   &duplicates, false);
>>> +                   &duplicates);
>>>       if (unlikely(r != 0)) {
>>>           if (r != -ERESTARTSYS)
>>>               DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>>> index 605f83046039..b1608d47508f 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
>>> @@ -80,7 +80,7 @@ int amdgpu_map_static_csa(struct amdgpu_device 
>>> *adev, struct amdgpu_vm *vm,
>>>       list_add(&csa_tv.head, &list);
>>>       amdgpu_vm_get_pd_bo(vm, &list, &pd);
>>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, false);
>>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>>>       if (r) {
>>>           DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
>>>           return r;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> index b25a59c4bec6..cbfb3e84f352 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> @@ -175,7 +175,7 @@ void amdgpu_gem_object_close(struct 
>>> drm_gem_object *obj,
>>>         amdgpu_vm_get_pd_bo(vm, &list, &vm_pd);
>>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, false, 
>>> &duplicates, false);
>>> +    r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);
>>>       if (r) {
>>>           dev_err(adev->dev, "leaking bo va because "
>>>               "we fail to reserve bo (%d)\n", r);
>>> @@ -611,7 +611,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, 
>>> void *data,
>>>         amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd);
>>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates, 
>>> false);
>>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
>>>       if (r)
>>>           goto error_unref;
>>>   diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
>>> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>>> index 5df2ee1e10d8..760078b9925b 100644
>>> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>>> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
>>> @@ -4439,7 +4439,7 @@ static int dm_plane_helper_prepare_fb(struct 
>>> drm_plane *plane,
>>>       tv.num_shared = 1;
>>>       list_add(&tv.head, &list);
>>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL, true);
>>> +    r = ttm_eu_reserve_buffers(&ticket, &list, false, NULL);
>>>       if (r) {
>>>           dev_err(adev->dev, "fail to reserve bo (%d)\n", r);
>>>           return r;
>>> diff --git a/drivers/gpu/drm/qxl/qxl_release.c 
>>> b/drivers/gpu/drm/qxl/qxl_release.c
>>> index aa7a28795645..71f1b51a1350 100644
>>> --- a/drivers/gpu/drm/qxl/qxl_release.c
>>> +++ b/drivers/gpu/drm/qxl/qxl_release.c
>>> @@ -260,7 +260,7 @@ int qxl_release_reserve_list(struct qxl_release 
>>> *release, bool no_intr)
>>>           return 0;
>>>         ret = ttm_eu_reserve_buffers(&release->ticket, &release->bos,
>>> -                     !no_intr, NULL, true);
>>> +                     !no_intr, NULL);
>>>       if (ret)
>>>           return ret;
>>>   @@ -459,7 +459,7 @@ void qxl_release_fence_buffer_objects(struct 
>>> qxl_release *release)
>>>           bo = entry->bo;
>>>             dma_resv_add_shared_fence(bo->base.resv, &release->base);
>>> -        ttm_bo_add_to_lru(bo);
>>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>>           dma_resv_unlock(bo->base.resv);
>>>       }
>>>       spin_unlock(&glob->lru_lock);
>>> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
>>> b/drivers/gpu/drm/radeon/radeon_gem.c
>>> index c48c2fb35456..879eac67cdd7 100644
>>> --- a/drivers/gpu/drm/radeon/radeon_gem.c
>>> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
>>> @@ -564,7 +564,7 @@ static void radeon_gem_va_update_vm(struct 
>>> radeon_device *rdev,
>>>       if (!vm_bos)
>>>           return;
>>>   -    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL, true);
>>> +    r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
>>>       if (r)
>>>           goto error_free;
>>>   diff --git a/drivers/gpu/drm/radeon/radeon_object.c 
>>> b/drivers/gpu/drm/radeon/radeon_object.c
>>> index 653fd7937b39..a94d827ba976 100644
>>> --- a/drivers/gpu/drm/radeon/radeon_object.c
>>> +++ b/drivers/gpu/drm/radeon/radeon_object.c
>>> @@ -542,7 +542,7 @@ int radeon_bo_list_validate(struct radeon_device 
>>> *rdev,
>>>       u64 bytes_moved_threshold = 
>>> radeon_bo_get_threshold_for_moves(rdev);
>>>         INIT_LIST_HEAD(&duplicates);
>>> -    r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates, true);
>>> +    r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates);
>>>       if (unlikely(r != 0)) {
>>>           return r;
>>>       }
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c 
>>> b/drivers/gpu/drm/ttm/ttm_bo.c
>>> index 02f301e1ff29..ab9967b84e0b 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>> @@ -192,18 +192,12 @@ static void ttm_bo_add_mem_to_lru(struct 
>>> ttm_buffer_object *bo,
>>>       }
>>>   }
>>>   -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>>> -{
>>> -    ttm_bo_add_mem_to_lru(bo, &bo->mem);
>>> -}
>>> -EXPORT_SYMBOL(ttm_bo_add_to_lru);
>>> -
>>>   static void ttm_bo_ref_bug(struct kref *list_kref)
>>>   {
>>>       BUG();
>>>   }
>>>   -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>>> +static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
>>>   {
>>>       struct ttm_bo_device *bdev = bo->bdev;
>>>       bool notify = false;
>>> @@ -223,16 +217,6 @@ void ttm_bo_del_from_lru(struct 
>>> ttm_buffer_object *bo)
>>>           bdev->driver->del_from_lru_notify(bo);
>>>   }
>>>   -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
>>> -{
>>> -    struct ttm_bo_global *glob = bo->bdev->glob;
>>> -
>>> -    spin_lock(&glob->lru_lock);
>>> -    ttm_bo_del_from_lru(bo);
>>> -    spin_unlock(&glob->lru_lock);
>>> -}
>>> -EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
>>> -
>>>   static void ttm_bo_bulk_move_set_pos(struct ttm_lru_bulk_move_pos 
>>> *pos,
>>>                        struct ttm_buffer_object *bo)
>>>   {
>>> @@ -247,7 +231,7 @@ void ttm_bo_move_to_lru_tail(struct 
>>> ttm_buffer_object *bo,
>>>       dma_resv_assert_held(bo->base.resv);
>>>         ttm_bo_del_from_lru(bo);
>>> -    ttm_bo_add_to_lru(bo);
>>> +    ttm_bo_add_mem_to_lru(bo, &bo->mem);
>>>         if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>>>           switch (bo->mem.mem_type) {
>>> @@ -511,7 +495,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct 
>>> ttm_buffer_object *bo)
>>>            */
>>>           if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
>>>               bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
>>> -            ttm_bo_add_to_lru(bo);
>>> +            ttm_bo_move_to_lru_tail(bo, NULL);
>>>           }
>>>             dma_resv_unlock(bo->base.resv);
>>> @@ -892,17 +876,11 @@ static int ttm_mem_evict_first(struct 
>>> ttm_bo_device *bdev,
>>>           return ret;
>>>       }
>>>   -    ttm_bo_del_from_lru(bo);
>>>       spin_unlock(&glob->lru_lock);
>>>         ret = ttm_bo_evict(bo, ctx);
>>> -    if (locked) {
>>> +    if (locked)
>>>           ttm_bo_unreserve(bo);
>>> -    } else {
>>> -        spin_lock(&glob->lru_lock);
>>> -        ttm_bo_add_to_lru(bo);
>>> -        spin_unlock(&glob->lru_lock);
>>> -    }
>>>         kref_put(&bo->list_kref, ttm_bo_release_list);
>>>       return ret;
>>> @@ -1064,12 +1042,10 @@ static int ttm_bo_mem_placement(struct 
>>> ttm_buffer_object *bo,
>>>       mem->mem_type = mem_type;
>>>       mem->placement = cur_flags;
>>>   -    if (bo->mem.mem_type < mem_type && !list_empty(&bo->lru)) {
>>> -        spin_lock(&bo->bdev->glob->lru_lock);
>>> -        ttm_bo_del_from_lru(bo);
>>> -        ttm_bo_add_mem_to_lru(bo, mem);
>>> -        spin_unlock(&bo->bdev->glob->lru_lock);
>>> -    }
>>> +    spin_lock(&bo->bdev->glob->lru_lock);
>>> +    ttm_bo_del_from_lru(bo);
>>> +    ttm_bo_add_mem_to_lru(bo, mem);
>>> +    spin_unlock(&bo->bdev->glob->lru_lock);
>>>         return 0;
>>>   }
>>> @@ -1375,11 +1351,9 @@ int ttm_bo_init_reserved(struct ttm_bo_device 
>>> *bdev,
>>>           return ret;
>>>       }
>>>   -    if (resv && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>>> -        spin_lock(&bdev->glob->lru_lock);
>>> -        ttm_bo_add_to_lru(bo);
>>> -        spin_unlock(&bdev->glob->lru_lock);
>>> -    }
>>> +    spin_lock(&bdev->glob->lru_lock);
>>> +    ttm_bo_move_to_lru_tail(bo, NULL);
>>> +    spin_unlock(&bdev->glob->lru_lock);
>>>         return ret;
>>>   }
>>> diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c 
>>> b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>>> index 71148c83cc4f..b09c2c8caf13 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
>>> @@ -33,16 +33,6 @@
>>>   #include <linux/sched.h>
>>>   #include <linux/module.h>
>>>   -static void ttm_eu_del_from_lru_locked(struct list_head *list)
>>> -{
>>> -    struct ttm_validate_buffer *entry;
>>> -
>>> -    list_for_each_entry(entry, list, head) {
>>> -        struct ttm_buffer_object *bo = entry->bo;
>>> -        ttm_bo_del_from_lru(bo);
>>> -    }
>>> -}
>>> -
>>>   void ttm_eu_backoff_reservation(struct dma_resv_ctx *ticket,
>>>                   struct list_head *list)
>>>   {
>>> @@ -59,8 +49,7 @@ void ttm_eu_backoff_reservation(struct 
>>> dma_resv_ctx *ticket,
>>>       list_for_each_entry(entry, list, head) {
>>>           struct ttm_buffer_object *bo = entry->bo;
>>>   -        if (list_empty(&bo->lru))
>>> -            ttm_bo_add_to_lru(bo);
>>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>>           if (!ticket)
>>>               dma_resv_unlock(bo->base.resv);
>>>       }
>>> @@ -87,7 +76,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);
>>>     int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>>>                  struct list_head *list, bool intr,
>>> -               struct list_head *dups, bool del_lru)
>>> +               struct list_head *dups)
>>>   {
>>>       struct ttm_validate_buffer *entry;
>>>       struct ttm_bo_global *glob;
>>> @@ -142,11 +131,6 @@ int ttm_eu_reserve_buffers(struct dma_resv_ctx 
>>> *ticket,
>>>           }
>>>       }
>>>   -    if (del_lru) {
>>> -        spin_lock(&glob->lru_lock);
>>> -        ttm_eu_del_from_lru_locked(list);
>>> -        spin_unlock(&glob->lru_lock);
>>> -    }
>>>       return 0;
>>>     error:
>>> @@ -186,10 +170,7 @@ void ttm_eu_fence_buffer_objects(struct 
>>> dma_resv_ctx *ticket,
>>>               dma_resv_add_shared_fence(bo->base.resv, fence);
>>>           else
>>>               dma_resv_add_excl_fence(bo->base.resv, fence);
>>> -        if (list_empty(&bo->lru))
>>> -            ttm_bo_add_to_lru(bo);
>>> -        else
>>> -            ttm_bo_move_to_lru_tail(bo, NULL);
>>> +        ttm_bo_move_to_lru_tail(bo, NULL);
>>>           if (!ticket)
>>>               dma_resv_unlock(bo->base.resv);
>>>       }
>>> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c 
>>> b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>>> index 2d7c5ad25359..1d53a69819e5 100644
>>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
>>> @@ -464,8 +464,7 @@ vmw_resource_check_buffer(struct dma_resv_ctx 
>>> *ticket,
>>>       val_buf->bo = &res->backup->base;
>>>       val_buf->num_shared = 0;
>>>       list_add_tail(&val_buf->head, &val_list);
>>> -    ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, 
>>> NULL,
>>> -                     true);
>>> +    ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, 
>>> NULL);
>>>       if (unlikely(ret != 0))
>>>           goto out_no_reserve;
>>>   diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h 
>>> b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>>> index 43f48df3844f..ebb5b68b5c1f 100644
>>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
>>> @@ -169,7 +169,7 @@ vmw_validation_bo_reserve(struct 
>>> vmw_validation_context *ctx,
>>>                 bool intr)
>>>   {
>>>       return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
>>> -                      NULL, true);
>>> +                      NULL);
>>>   }
>>>     /**
>>> diff --git a/include/drm/ttm/ttm_bo_api.h 
>>> b/include/drm/ttm/ttm_bo_api.h
>>> index 43c4929a2171..288fd64b7219 100644
>>> --- a/include/drm/ttm/ttm_bo_api.h
>>> +++ b/include/drm/ttm/ttm_bo_api.h
>>> @@ -367,30 +367,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>>>    */
>>>   void ttm_bo_put(struct ttm_buffer_object *bo);
>>>   -/**
>>> - * ttm_bo_add_to_lru
>>> - *
>>> - * @bo: The buffer object.
>>> - *
>>> - * Add this bo to the relevant mem type lru and, if it's backed by
>>> - * system pages (ttms) to the swap list.
>>> - * This function must be called with struct ttm_bo_global::lru_lock 
>>> held, and
>>> - * is typically called immediately prior to unreserving a bo.
>>> - */
>>> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
>>> -
>>> -/**
>>> - * ttm_bo_del_from_lru
>>> - *
>>> - * @bo: The buffer object.
>>> - *
>>> - * Remove this bo from all lru lists used to lookup and reserve an 
>>> object.
>>> - * This function must be called with struct ttm_bo_global::lru_lock 
>>> held,
>>> - * and is usually called just immediately after the bo has been 
>>> reserved to
>>> - * avoid recursive reservation from lru lists.
>>> - */
>>> -void ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
>>> -
>>>   /**
>>>    * ttm_bo_move_to_lru_tail
>>>    *
>>> diff --git a/include/drm/ttm/ttm_bo_driver.h 
>>> b/include/drm/ttm/ttm_bo_driver.h
>>> index 4e307f65f497..4332cc036483 100644
>>> --- a/include/drm/ttm/ttm_bo_driver.h
>>> +++ b/include/drm/ttm/ttm_bo_driver.h
>>> @@ -621,9 +621,6 @@ void ttm_mem_io_free_vm(struct ttm_buffer_object 
>>> *bo);
>>>   int ttm_mem_io_lock(struct ttm_mem_type_manager *man, bool 
>>> interruptible);
>>>   void ttm_mem_io_unlock(struct ttm_mem_type_manager *man);
>>>   -void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo);
>>> -void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
>>> -
>>>   /**
>>>    * __ttm_bo_reserve:
>>>    *
>>> @@ -717,15 +714,9 @@ static inline int ttm_bo_reserve(struct 
>>> ttm_buffer_object *bo,
>>>                    bool interruptible, bool no_wait,
>>>                    struct ww_acquire_ctx *ticket)
>>>   {
>>> -    int ret;
>>> -
>>>       WARN_ON(!kref_read(&bo->kref));
>>>   -    ret = __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
>>> -    if (likely(ret == 0))
>>> -        ttm_bo_del_sub_from_lru(bo);
>>> -
>>> -    return ret;
>>> +    return __ttm_bo_reserve(bo, interruptible, no_wait, ticket);
>>>   }
>>>     /**
>>> @@ -752,9 +743,7 @@ static inline int ttm_bo_reserve_slowpath(struct 
>>> ttm_buffer_object *bo,
>>>       else
>>>           dma_resv_lock_slow(bo->base.resv, ticket);
>>>   -    if (likely(ret == 0))
>>> -        ttm_bo_del_sub_from_lru(bo);
>>> -    else if (ret == -EINTR)
>>> +    if (ret == -EINTR)
>>>           ret = -ERESTARTSYS;
>>>         return ret;
>>> @@ -770,10 +759,7 @@ static inline int 
>>> ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>>>   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>>>   {
>>>       spin_lock(&bo->bdev->glob->lru_lock);
>>> -    if (list_empty(&bo->lru))
>>> -        ttm_bo_add_to_lru(bo);
>>> -    else
>>> -        ttm_bo_move_to_lru_tail(bo, NULL);
>>> +    ttm_bo_move_to_lru_tail(bo, NULL);
>>>       spin_unlock(&bo->bdev->glob->lru_lock);
>>>       dma_resv_unlock(bo->base.resv);
>>>   }
>>> diff --git a/include/drm/ttm/ttm_execbuf_util.h 
>>> b/include/drm/ttm/ttm_execbuf_util.h
>>> index 4e86b6fd6c57..1a3553ac53b1 100644
>>> --- a/include/drm/ttm/ttm_execbuf_util.h
>>> +++ b/include/drm/ttm/ttm_execbuf_util.h
>>> @@ -100,7 +100,7 @@ extern void ttm_eu_backoff_reservation(struct 
>>> dma_resv_ctx *ticket,
>>>     extern int ttm_eu_reserve_buffers(struct dma_resv_ctx *ticket,
>>>                     struct list_head *list, bool intr,
>>> -                  struct list_head *dups, bool del_lru);
>>> +                  struct list_head *dups);
>>>     /**
>>>    * function ttm_eu_fence_buffer_objects.
>>
>>
>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-10-16  9:30       ` Christian König
@ 2019-10-18 13:49         ` Thomas Hellström (VMware)
  2019-10-21 12:27           ` Thomas Hellström (VMware)
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Hellström (VMware) @ 2019-10-18 13:49 UTC (permalink / raw)
  To: christian.koenig, kraxel, daniel, dri-devel

Hi, Christian,


On 10/16/19 11:30 AM, Christian König wrote:
> Am 25.09.19 um 14:10 schrieb Christian König:
>> Am 25.09.19 um 14:06 schrieb Thomas Hellström (VMware):
>>> On 9/25/19 12:55 PM, Christian König wrote:
>>>> This allows blocking for BOs to become available
>>>> in the memory management.
>>>>
>>>> Amdgpu is doing this for quite a while now during CS. Now
>>>> apply the new behavior to all drivers using TTM.
>>>>
>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>
>>> Got to test this to see that there are no regressions.
>
> Did you got time to test this or did I just missed your response?
>
> Thanks in advance,
> Christian.

Sorry for the delay. A  lot on my plate currently. I'll get around to 
this later today or on monday.

Thanks,

Thomas


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] drm/ttm: always keep BOs on the LRU
  2019-10-18 13:49         ` Thomas Hellström (VMware)
@ 2019-10-21 12:27           ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Hellström (VMware) @ 2019-10-21 12:27 UTC (permalink / raw)
  To: christian.koenig, kraxel, daniel, dri-devel

On 10/18/19 3:49 PM, Thomas Hellström (VMware) wrote:
> Hi, Christian,
>
>
> On 10/16/19 11:30 AM, Christian König wrote:
>> Am 25.09.19 um 14:10 schrieb Christian König:
>>> Am 25.09.19 um 14:06 schrieb Thomas Hellström (VMware):
>>>> On 9/25/19 12:55 PM, Christian König wrote:
>>>>> This allows blocking for BOs to become available
>>>>> in the memory management.
>>>>>
>>>>> Amdgpu is doing this for quite a while now during CS. Now
>>>>> apply the new behavior to all drivers using TTM.
>>>>>
>>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>>
>>>> Got to test this to see that there are no regressions.
>>
>> Did you got time to test this or did I just missed your response?
>>
>> Thanks in advance,
>> Christian.
>
> Sorry for the delay. A  lot on my plate currently. I'll get around to 
> this later today or on monday.
>
> Thanks,
>
> Thomas
>
>
Hi, Christian!

This patch is

Acked-by: Thomas Hellstrom <thellstrom@vmware.com>

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-10-21 12:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 10:55 [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Christian König
2019-09-25 10:55 ` [PATCH 2/3] drm/ttm: always keep BOs on the LRU Christian König
2019-09-25 12:06   ` Thomas Hellström (VMware)
2019-09-25 12:10     ` Christian König
2019-10-16  9:30       ` Christian König
2019-10-18 13:49         ` Thomas Hellström (VMware)
2019-10-21 12:27           ` Thomas Hellström (VMware)
2019-09-25 10:55 ` [PATCH 3/3] drm/ttm: remove pointers to globals Christian König
2019-09-25 11:56   ` Thomas Hellström (VMware)
2019-09-25 11:55 ` [PATCH 1/3] drm/ttm: fix busy reference in ttm_mem_evict_first Thomas Hellström (VMware)

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.