Skip to contentSkip to conversation

drm/ttm: use an operation ctx for ttm_tt_bind

PATCH In review Roger He 4 participants 9 messages Dec 25, 2017

Subsystems (5)
lore
Share & tools
lore

Roger He

author
#0 lore raw

PATCH 1/3 drm/ttm: use an operation ctx for ttm_tt_bind

forward the operation context to ttm_tt_bind as well, and the ultimate goal is swapout enablement for reserved BOs.

v2: use common term rather than amd specific

Change-Id I42a7df8c50e1ce3b527ee9cb78809f8e58136f07
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
 drivers/gpu/drm/nouveau/nouveau_bo.c    | 2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c     | 2 +-
 drivers/gpu/drm/ttm/ttm_bo.c            | 2 +-
 drivers/gpu/drm/ttm/ttm_bo_util.c       | 2 +-
 drivers/gpu/drm/ttm/ttm_tt.c            | 9 +++------
 include/drm/ttm/ttm_bo_driver.h         | 3 ++-
 7 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 044f5b5..e4bb435 100644
@@ -497,7 +497,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
 		goto out_cleanup;
 	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, ctx);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
index b141c27..a83ba6a 100644
@@ -1218,7 +1218,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
 	if (ret)
 		return ret;
 
-	ret = ttm_tt_bind(bo->ttm, &tmp_reg);
+	ret = ttm_tt_bind(bo->ttm, &tmp_reg, &ctx);
 	if (ret)
 		goto out;
 
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
index 9424b81..2b74ba1b 100644
@@ -339,7 +339,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
 		goto out_cleanup;
 	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, &ctx);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index c59f572..e7595b4 100644
@@ -300,7 +300,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 			goto out_err;
 
 		if (mem->mem_type != TTM_PL_SYSTEM) {
-			ret = ttm_tt_bind(bo->ttm, mem);
+			ret = ttm_tt_bind(bo->ttm, mem, ctx);
 			if (ret)
 				goto out_err;
 		}
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index b7eb507..153de1b 100644
@@ -73,7 +73,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		return ret;
 
 	if (new_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_tt_bind(ttm, new_mem);
+		ret = ttm_tt_bind(ttm, new_mem, ctx);
 		if (unlikely(ret != 0))
 			return ret;
 	}
drivers/gpu/drm/ttm/ttm_tt.c +3 -6
index b48d7a0..5a046a3 100644
@@ -261,12 +261,9 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
 	}
 }
 
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx)
 {
-	struct ttm_operation_ctx ctx = {
-		.interruptible = false,
-		.no_wait_gpu = false
-	};
 	int ret = 0;
 
 	if (!ttm)
@@ -275,7 +272,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
 	if (ttm->state == tt_bound)
 		return 0;
 
-	ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
+	ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
 	if (ret)
 		return ret;
 
include/drm/ttm/ttm_bo_driver.h +2 -1
index 84860ec..94064b1 100644
@@ -650,7 +650,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
  *
  * Bind the pages of @ttm to an aperture location identified by @bo_mem
  */
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx);
 
 /**
  * ttm_ttm_destroy:
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#1 lore raw

PATCH 2/3 drm/ttm: add new function to check if bo is allowable to evict or swapout

extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic.

v2: modify commit message and add description in the code

Change-Id I80a475a93fceed8d66d74a1832c815a0756341ac
---
 drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +30 -10
index e7595b4..5e64091 100644
@@ -706,6 +706,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
 }
 EXPORT_SYMBOL(ttm_bo_eviction_valuable);
 
+/**
+ * Check the target bo is allowable to be evicted or swapout, including cases:
+ *
+ * a. if share same reservation object with ctx->resv, have assumption
+ * reservation objects should already be locked, so not lock again and
+ * return true directly when either the opreation allow_reserved_eviction
+ * or the target bo already is in delayed free list;
+ *
+ * b. Otherwise, trylock it.
+ */
+static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
+			struct ttm_operation_ctx *ctx, bool *locked)
+{
+	bool ret = false;
+
+	*locked = false;
+	if (bo->resv == ctx->resv) {
+		reservation_object_assert_held(bo->resv);
+		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+			ret = true;
+	} else {
+		*locked = reservation_object_trylock(bo->resv);
+		ret = *locked;
+	}
+
+	return ret;
+}
+
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 			       uint32_t mem_type,
 			       const struct ttm_place *place,
@@ -721,21 +749,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 	spin_lock(&glob->lru_lock);
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
 		list_for_each_entry(bo, &man->lru[i], lru) {
-			if (bo->resv == ctx->resv) {
-				if (!ctx->allow_reserved_eviction &&
-				    list_empty(&bo->ddestroy))
-					continue;
-			} else {
-				locked = reservation_object_trylock(bo->resv);
-				if (!locked)
-					continue;
-			}
+			if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked))
+				continue;
 
 			if (place && !bdev->driver->eviction_valuable(bo,
 								      place)) {
 				if (locked)
 					reservation_object_unlock(bo->resv);
-				locked = false;
 				continue;
 			}
 			break;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#2 lore raw

RE: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout

+ Thomas

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Roger He
Sent: Monday, December 25, 2017 2:08 PM
To: [email protected]
Cc: He, Roger <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout

extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic.

v2: modify commit message and add description in the code

Change-Id I80a475a93fceed8d66d74a1832c815a0756341ac
---
 drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +28 -0
@@ -706,6 +706,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,  }  EXPORT_SYMBOL(ttm_bo_eviction_valuable);
 
+/**
+ * Check the target bo is allowable to be evicted or swapout, including cases:
+ *
+ * a. if share same reservation object with ctx->resv, have assumption
+ * reservation objects should already be locked, so not lock again and
+ * return true directly when either the opreation 
+allow_reserved_eviction
+ * or the target bo already is in delayed free list;
+ *
+ * b. Otherwise, trylock it.
+ */
+static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
+			struct ttm_operation_ctx *ctx, bool *locked) {
+	bool ret = false;
+
+	*locked = false;
+	if (bo->resv == ctx->resv) {
+		reservation_object_assert_held(bo->resv);
+		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+			ret = true;
+	} else {
+		*locked = reservation_object_trylock(bo->resv);
+		ret = *locked;
+	}
+
+	return ret;
+}
+
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 			       uint32_t mem_type,
 			       const struct ttm_place *place, @@ -721,21 +749,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 	spin_lock(&glob->lru_lock);
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {

list_for_each_entry(bo, &man->lru[i], lru) {
- if (bo->resv == ctx->resv) {
- if (!ctx->allow_reserved_eviction &&
- list_empty(&bo->ddestroy))
- continue;
- } else {
- locked = reservation_object_trylock(bo->resv);
- if (!locked)
- continue;
- }
+ if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked))
+ continue;

if (place && !bdev->driver->eviction_valuable(bo,
place)) {
if (locked)
reservation_object_unlock(bo->resv);
- locked = false;
continue;
}
break;
--
2.7.4

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

#3 lore raw

Re: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout

The series is Reviewed-by: Chuming Zhou <[email protected]>

Quoted 81 lines · Roger

+ Thomas

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Roger He
Sent: Monday, December 25, 2017 2:08 PM
To: [email protected]
Cc: He, Roger <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout

extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic.

v2: modify commit message and add description in the code

Change-Id I80a475a93fceed8d66d74a1832c815a0756341ac
---
  drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++----------
  1 file changed, 30 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +28 -0
@@ -706,6 +706,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,  }  EXPORT_SYMBOL(ttm_bo_eviction_valuable);
 
+/**
+ * Check the target bo is allowable to be evicted or swapout, including cases:
+ *
+ * a. if share same reservation object with ctx->resv, have assumption
+ * reservation objects should already be locked, so not lock again and
+ * return true directly when either the opreation
+allow_reserved_eviction
+ * or the target bo already is in delayed free list;
+ *
+ * b. Otherwise, trylock it.
+ */
+static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
+			struct ttm_operation_ctx *ctx, bool *locked) {
+	bool ret = false;
+
+	*locked = false;
+	if (bo->resv == ctx->resv) {
+		reservation_object_assert_held(bo->resv);
+		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+			ret = true;
+	} else {
+		*locked = reservation_object_trylock(bo->resv);
+		ret = *locked;
+	}
+
+	return ret;
+}
+
  static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
  			       uint32_t mem_type,
  			       const struct ttm_place *place, @@ -721,21 +749,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
  	spin_lock(&glob->lru_lock);
  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
  		list_for_each_entry(bo, &man->lru[i], lru) {
drivers/gpu/drm/ttm/ttm_bo.c +2 -11
-			if (bo->resv == ctx->resv) {
-				if (!ctx->allow_reserved_eviction &&
-				    list_empty(&bo->ddestroy))
-					continue;
-			} else {
-				locked = reservation_object_trylock(bo->resv);
-				if (!locked)
-					continue;
-			}
+			if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked))
+				continue;
 
  			if (place && !bdev->driver->eviction_valuable(bo,
  								      place)) {
  				if (locked)
  					reservation_object_unlock(bo->resv);
-				locked = false;
  				continue;
  			}
  			break;
--

2.7.4

Quoted 8 lines

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

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

maintainer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout

In reply to Roger He

Am 25.12.2017 um 07:07 schrieb Roger He:

Quoted 7 lines

extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic.

v2: modify commit message and add description in the code

Change-Id I80a475a93fceed8d66d74a1832c815a0756341ac

We might want a better name for the function, but I want to rework the locking around eviction/swapout anyway so that can wait.

Christian.

Quoted 57 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++----------
  1 file changed, 30 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +29 -9
index e7595b4..5e64091 100644
@@ -706,6 +706,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
  }
  EXPORT_SYMBOL(ttm_bo_eviction_valuable);
 
+/**
+ * Check the target bo is allowable to be evicted or swapout, including cases:
+ *
+ * a. if share same reservation object with ctx->resv, have assumption
+ * reservation objects should already be locked, so not lock again and
+ * return true directly when either the opreation allow_reserved_eviction
+ * or the target bo already is in delayed free list;
+ *
+ * b. Otherwise, trylock it.
+ */
+static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
+			struct ttm_operation_ctx *ctx, bool *locked)
+{
+	bool ret = false;
+
+	*locked = false;
+	if (bo->resv == ctx->resv) {
+		reservation_object_assert_held(bo->resv);
+		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+			ret = true;
+	} else {
+		*locked = reservation_object_trylock(bo->resv);
+		ret = *locked;
+	}
+
+	return ret;
+}
+
  static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
  			       uint32_t mem_type,
  			       const struct ttm_place *place,
@@ -721,21 +749,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
  	spin_lock(&glob->lru_lock);
  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
  		list_for_each_entry(bo, &man->lru[i], lru) {
-			if (bo->resv == ctx->resv) {
-				if (!ctx->allow_reserved_eviction &&
-				    list_empty(&bo->ddestroy))
-					continue;
-			} else {
-				locked = reservation_object_trylock(bo->resv);
-				if (!locked)
-					continue;
-			}
+			if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked))

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_mem_evict_first(struct ttm_bo_device *bdev, · line 761

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
+				continue;
 
  			if (place && !bdev->driver->eviction_valuable(bo,
  								      place)) {
  				if (locked)
  					reservation_object_unlock(bo->resv);
-				locked = false;
  				continue;
  			}
  			break;

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

author
#5 lore raw

PATCH 3/3 drm/ttm: enable swapout for reserved BOs during allocation

In reply to Roger He

if the bo shares same reservation object then not lock it again at swapout time to make it possible to swap out.

v2: refine the commmit message

Change-Id I1e87954564f38ad298bf6e4ff88c9f26f291a62d
---
 drivers/gpu/drm/ttm/ttm_bo.c     | 15 +++++++++++----
 drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++----
 include/drm/ttm/ttm_bo_api.h     |  3 ++-
 3 files changed, 21 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +11 -4
index 5e64091..ec42bb3 100644
@@ -1697,18 +1697,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
  * A buffer object shrink method that tries to swap out the first
  * buffer object on the bo_global::swap_lru list.
  */
-int ttm_bo_swapout(struct ttm_bo_global *glob)
+int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
 {
 	struct ttm_buffer_object *bo;
 	int ret = -EBUSY;
+	bool locked;
 	unsigned i;
 
 	spin_lock(&glob->lru_lock);
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
 		list_for_each_entry(bo, &glob->swap_lru[i], swap) {
-			ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY;
-			if (!ret)
+			if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) {
+				ret = 0;
 				break;
+			}
 		}
 		if (!ret)
 			break;
@@ -1784,7 +1786,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);
 
 void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
 {
-	while (ttm_bo_swapout(bdev->glob) == 0)
+	struct ttm_operation_ctx ctx = {
+		.interruptible = false,
+		.no_wait_gpu = false
+	};
+
+	while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
 		;
 }
 EXPORT_SYMBOL(ttm_bo_swapout_all);
drivers/gpu/drm/ttm/ttm_memory.c +8 -4
index 102b326..aa0c381 100644
@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,
  */
 
 static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
-		       uint64_t extra)
+			uint64_t extra, struct ttm_operation_ctx *ctx)
 {
 	int ret;
 
@@ -219,7 +219,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);
+		ret = ttm_bo_swapout(glob->bo_glob, ctx);
 		spin_lock(&glob->lock);
 		if (unlikely(ret != 0))
 			break;
@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
 
 static void ttm_shrink_work(struct work_struct *work)
 {
+	struct ttm_operation_ctx ctx = {
+		.interruptible = false,
+		.no_wait_gpu = false
+	};
 	struct ttm_mem_global *glob =
 	    container_of(work, struct ttm_mem_global, work);
 
-	ttm_shrink(glob, true, 0ULL);
+	ttm_shrink(glob, true, 0ULL, &ctx);
 }
 
 static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
 			return -ENOMEM;
 		if (unlikely(count-- == 0))
 			return -ENOMEM;
-		ttm_shrink(glob, false, memory + (memory >> 2) + 16);
+		ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx);
 	}
 
 	return 0;
include/drm/ttm/ttm_bo_api.h +2 -1
index 24a8db7..f1c74c2 100644
@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
 		  const char __user *wbuf, char __user *rbuf,
 		  size_t count, loff_t *f_pos, bool write);
 
-int ttm_bo_swapout(struct ttm_bo_global *glob);
+int ttm_bo_swapout(struct ttm_bo_global *glob,
+			struct ttm_operation_ctx *ctx);
 void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
 int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] drm/ttm: enable swapout for reserved BOs during allocation

Am 25.12.2017 um 07:07 schrieb Roger He:

Quoted 7 lines

if the bo shares same reservation object then not lock it again at swapout time to make it possible to swap out.

v2: refine the commmit message

Change-Id I1e87954564f38ad298bf6e4ff88c9f26f291a62d
Quoted 100 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c     | 15 +++++++++++----
  drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++----
  include/drm/ttm/ttm_bo_api.h     |  3 ++-
  3 files changed, 21 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +11 -4
index 5e64091..ec42bb3 100644
@@ -1697,18 +1697,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
   * A buffer object shrink method that tries to swap out the first
   * buffer object on the bo_global::swap_lru list.
   */
-int ttm_bo_swapout(struct ttm_bo_global *glob)
+int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
  {
  	struct ttm_buffer_object *bo;
  	int ret = -EBUSY;
+	bool locked;
  	unsigned i;
 
  	spin_lock(&glob->lru_lock);
  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
  		list_for_each_entry(bo, &glob->swap_lru[i], swap) {
-			ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY;
-			if (!ret)
+			if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) {
+				ret = 0;
  				break;
+			}
  		}
  		if (!ret)
  			break;
@@ -1784,7 +1786,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);
 
  void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
  {
-	while (ttm_bo_swapout(bdev->glob) == 0)
+	struct ttm_operation_ctx ctx = {
+		.interruptible = false,
+		.no_wait_gpu = false
+	};
+
+	while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
  		;
  }
  EXPORT_SYMBOL(ttm_bo_swapout_all);
drivers/gpu/drm/ttm/ttm_memory.c +8 -4
index 102b326..aa0c381 100644
@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,
   */
 
  static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
-		       uint64_t extra)
+			uint64_t extra, struct ttm_operation_ctx *ctx)
  {
  	int ret;
 
@@ -219,7 +219,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);
+		ret = ttm_bo_swapout(glob->bo_glob, ctx);
  		spin_lock(&glob->lock);
  		if (unlikely(ret != 0))
  			break;
@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
 
  static void ttm_shrink_work(struct work_struct *work)
  {
+	struct ttm_operation_ctx ctx = {
+		.interruptible = false,
+		.no_wait_gpu = false
+	};
  	struct ttm_mem_global *glob =
  	    container_of(work, struct ttm_mem_global, work);
 
-	ttm_shrink(glob, true, 0ULL);
+	ttm_shrink(glob, true, 0ULL, &ctx);
  }
 
  static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
  			return -ENOMEM;
  		if (unlikely(count-- == 0))
  			return -ENOMEM;
-		ttm_shrink(glob, false, memory + (memory >> 2) + 16);
+		ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx);
  	}
 
  	return 0;
include/drm/ttm/ttm_bo_api.h +0 -0
index 24a8db7..f1c74c2 100644

include/drm/ttm/ttm_bo_api.h ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, · line 759

Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +2 -1
@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
  		  const char __user *wbuf, char __user *rbuf,
  		  size_t count, loff_t *f_pos, bool write);
 
-int ttm_bo_swapout(struct ttm_bo_global *glob);
+int ttm_bo_swapout(struct ttm_bo_global *glob,
+			struct ttm_operation_ctx *ctx);
  void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
  int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
  #endif

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

maintainer Reviewed-by on v1 1/3
#7 lore raw
In reply to Roger He

Am 25.12.2017 um 07:07 schrieb Roger He:

Quoted 7 lines

forward the operation context to ttm_tt_bind as well, and the ultimate goal is swapout enablement for reserved BOs.

v2: use common term rather than amd specific

Change-Id I42a7df8c50e1ce3b527ee9cb78809f8e58136f07
Quoted 108 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c    | 2 +-
  drivers/gpu/drm/radeon/radeon_ttm.c     | 2 +-
  drivers/gpu/drm/ttm/ttm_bo.c            | 2 +-
  drivers/gpu/drm/ttm/ttm_bo_util.c       | 2 +-
  drivers/gpu/drm/ttm/ttm_tt.c            | 9 +++------
  include/drm/ttm/ttm_bo_driver.h         | 3 ++-
  7 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 044f5b5..e4bb435 100644
@@ -497,7 +497,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
  		goto out_cleanup;
  	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, ctx);
  	if (unlikely(r)) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
index b141c27..a83ba6a 100644
@@ -1218,7 +1218,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
  	if (ret)
  		return ret;
 
-	ret = ttm_tt_bind(bo->ttm, &tmp_reg);
+	ret = ttm_tt_bind(bo->ttm, &tmp_reg, &ctx);
  	if (ret)
  		goto out;
 
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
index 9424b81..2b74ba1b 100644
@@ -339,7 +339,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
  		goto out_cleanup;
  	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, &ctx);
  	if (unlikely(r)) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index c59f572..e7595b4 100644
@@ -300,7 +300,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
  			goto out_err;
 
  		if (mem->mem_type != TTM_PL_SYSTEM) {
-			ret = ttm_tt_bind(bo->ttm, mem);
+			ret = ttm_tt_bind(bo->ttm, mem, ctx);
  			if (ret)
  				goto out_err;
  		}
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index b7eb507..153de1b 100644
@@ -73,7 +73,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
  		return ret;
 
  	if (new_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_tt_bind(ttm, new_mem);
+		ret = ttm_tt_bind(ttm, new_mem, ctx);
  		if (unlikely(ret != 0))
  			return ret;
  	}
drivers/gpu/drm/ttm/ttm_tt.c +3 -6
index b48d7a0..5a046a3 100644
@@ -261,12 +261,9 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
  	}
  }
 
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx)
  {
-	struct ttm_operation_ctx ctx = {
-		.interruptible = false,
-		.no_wait_gpu = false
-	};
  	int ret = 0;
 
  	if (!ttm)
@@ -275,7 +272,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
  	if (ttm->state == tt_bound)
  		return 0;
 
-	ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
+	ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
  	if (ret)
  		return ret;
 
include/drm/ttm/ttm_bo_driver.h +0 -0
index 84860ec..94064b1 100644

include/drm/ttm/ttm_bo_driver.h void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma); · line 657

Quoted 9 lines
include/drm/ttm/ttm_bo_driver.h +2 -1
@@ -650,7 +650,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
   *
   * Bind the pages of @ttm to an aperture location identified by @bo_mem
   */
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx);
 
  /**
   * ttm_ttm_destroy:

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

#8 lore raw
In reply to Roger He

This series,

Thanks!

/Thomas

Quoted 115 lines · Roger He

forward the operation context to ttm_tt_bind as well, and the ultimate goal is swapout enablement for reserved BOs.

v2: use common term rather than amd specific

Change-Id I42a7df8c50e1ce3b527ee9cb78809f8e58136f07
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c    | 2 +-
  drivers/gpu/drm/radeon/radeon_ttm.c     | 2 +-
  drivers/gpu/drm/ttm/ttm_bo.c            | 2 +-
  drivers/gpu/drm/ttm/ttm_bo_util.c       | 2 +-
  drivers/gpu/drm/ttm/ttm_tt.c            | 9 +++------
  include/drm/ttm/ttm_bo_driver.h         | 3 ++-
  7 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 044f5b5..e4bb435 100644
@@ -497,7 +497,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
  		goto out_cleanup;
  	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, ctx);
  	if (unlikely(r)) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
index b141c27..a83ba6a 100644
@@ -1218,7 +1218,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
  	if (ret)
  		return ret;
 
-	ret = ttm_tt_bind(bo->ttm, &tmp_reg);
+	ret = ttm_tt_bind(bo->ttm, &tmp_reg, &ctx);
  	if (ret)
  		goto out;
 
drivers/gpu/drm/radeon/radeon_ttm.c +1 -1
index 9424b81..2b74ba1b 100644
@@ -339,7 +339,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
  		goto out_cleanup;
  	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem);
+	r = ttm_tt_bind(bo->ttm, &tmp_mem, &ctx);
  	if (unlikely(r)) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
index c59f572..e7595b4 100644
@@ -300,7 +300,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
  			goto out_err;
 
  		if (mem->mem_type != TTM_PL_SYSTEM) {
-			ret = ttm_tt_bind(bo->ttm, mem);
+			ret = ttm_tt_bind(bo->ttm, mem, ctx);
  			if (ret)
  				goto out_err;
  		}
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index b7eb507..153de1b 100644
@@ -73,7 +73,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
  		return ret;
 
  	if (new_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_tt_bind(ttm, new_mem);
+		ret = ttm_tt_bind(ttm, new_mem, ctx);
  		if (unlikely(ret != 0))
  			return ret;
  	}
drivers/gpu/drm/ttm/ttm_tt.c +3 -6
index b48d7a0..5a046a3 100644
@@ -261,12 +261,9 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
  	}
  }
 
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx)
  {
-	struct ttm_operation_ctx ctx = {
-		.interruptible = false,
-		.no_wait_gpu = false
-	};
  	int ret = 0;
 
  	if (!ttm)
@@ -275,7 +272,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
  	if (ttm->state == tt_bound)
  		return 0;
 
-	ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
+	ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
  	if (ret)
  		return ret;
 
include/drm/ttm/ttm_bo_driver.h +0 -0
index 84860ec..94064b1 100644

include/drm/ttm/ttm_bo_driver.h void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma); · line 657

Quoted 9 lines
include/drm/ttm/ttm_bo_driver.h +2 -1
@@ -650,7 +650,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
   *
   * Bind the pages of @ttm to an aperture location identified by @bo_mem
   */
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+		struct ttm_operation_ctx *ctx);
 
  /**
   * ttm_ttm_destroy:

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