All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: Refactor ttm_bo_pipeline_move
@ 2019-08-16 18:59 Brian Welty
  2019-08-16 19:10 ` Koenig, Christian
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Welty @ 2019-08-16 18:59 UTC (permalink / raw)
  To: Christian König, Daniel Vetter, dri-devel

ttm_bo_pipeline_move needlessly duplicates code. Refactor this to
instead call ttm_bo_move_accel_cleanup.

Signed-off-by: Brian Welty <brian.welty@intel.com>

---
Builds but otherwise currently untested.
Came across this duplication and thought would see if others cared
to see it cleaned up this way or not.

 drivers/gpu/drm/ttm/ttm_bo_util.c | 64 +++----------------------------
 1 file changed, 5 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index fe81c565e7ef..086ba2c2f60b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -746,49 +746,10 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 {
 	struct ttm_bo_device *bdev = bo->bdev;
 	struct ttm_mem_reg *old_mem = &bo->mem;
-
 	struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type];
-	struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type];
-
-	int ret;
-
-	dma_resv_add_excl_fence(bo->base.resv, fence);
-
-	if (!evict) {
-		struct ttm_buffer_object *ghost_obj;
-
-		/**
-		 * This should help pipeline ordinary buffer moves.
-		 *
-		 * Hang old buffer memory on a new buffer object,
-		 * and leave it to be released when the GPU
-		 * operation has completed.
-		 */
-
-		dma_fence_put(bo->moving);
-		bo->moving = dma_fence_get(fence);
 
-		ret = ttm_buffer_object_transfer(bo, &ghost_obj);
-		if (ret)
-			return ret;
-
-		dma_resv_add_excl_fence(ghost_obj->base.resv, fence);
-
-		/**
-		 * If we're not moving to fixed memory, the TTM object
-		 * needs to stay alive. Otherwhise hang it on the ghost
-		 * bo to be unbound and destroyed.
-		 */
-
-		if (!(to->flags & TTM_MEMTYPE_FLAG_FIXED))
-			ghost_obj->ttm = NULL;
-		else
-			bo->ttm = NULL;
-
-		ttm_bo_unreserve(ghost_obj);
-		ttm_bo_put(ghost_obj);
-
-	} else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) {
+	if (evict && from->flags & TTM_MEMTYPE_FLAG_FIXED) {
+		dma_resv_add_excl_fence(bo->base.resv, fence);
 
 		/**
 		 * BO doesn't have a TTM we need to bind/unbind. Just remember
@@ -807,27 +768,12 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 		dma_fence_put(bo->moving);
 		bo->moving = dma_fence_get(fence);
 
+		*old_mem = *new_mem;
+		new_mem->mm_node = NULL;
 	} else {
-		/**
-		 * Last resort, wait for the move to be completed.
-		 *
-		 * Should never happen in pratice.
-		 */
-
-		ret = ttm_bo_wait(bo, false, false);
-		if (ret)
-			return ret;
-
-		if (to->flags & TTM_MEMTYPE_FLAG_FIXED) {
-			ttm_tt_destroy(bo->ttm);
-			bo->ttm = NULL;
-		}
-		ttm_bo_free_old_node(bo);
+		return ttm_bo_move_accel_cleanup(bo, fence, evict, new_mem);
 	}
 
-	*old_mem = *new_mem;
-	new_mem->mm_node = NULL;
-
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_pipeline_move);
-- 
2.21.0

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

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

* Re: [PATCH] drm/ttm: Refactor ttm_bo_pipeline_move
  2019-08-16 18:59 [PATCH] drm/ttm: Refactor ttm_bo_pipeline_move Brian Welty
@ 2019-08-16 19:10 ` Koenig, Christian
  0 siblings, 0 replies; 2+ messages in thread
From: Koenig, Christian @ 2019-08-16 19:10 UTC (permalink / raw)
  To: Brian Welty, Daniel Vetter, dri-devel

Am 16.08.19 um 20:59 schrieb Brian Welty:
> ttm_bo_pipeline_move needlessly duplicates code. Refactor this to
> instead call ttm_bo_move_accel_cleanup.
>
> Signed-off-by: Brian Welty <brian.welty@intel.com>

At least of hand that looks valid to me, Reviewed-by: Christian König 
<christian.koenig@amd.com> for now.

Regards,
Christian.

>
> ---
> Builds but otherwise currently untested.
> Came across this duplication and thought would see if others cared
> to see it cleaned up this way or not.
>
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 64 +++----------------------------
>   1 file changed, 5 insertions(+), 59 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fe81c565e7ef..086ba2c2f60b 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -746,49 +746,10 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
>   	struct ttm_mem_reg *old_mem = &bo->mem;
> -
>   	struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type];
> -	struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type];
> -
> -	int ret;
> -
> -	dma_resv_add_excl_fence(bo->base.resv, fence);
> -
> -	if (!evict) {
> -		struct ttm_buffer_object *ghost_obj;
> -
> -		/**
> -		 * This should help pipeline ordinary buffer moves.
> -		 *
> -		 * Hang old buffer memory on a new buffer object,
> -		 * and leave it to be released when the GPU
> -		 * operation has completed.
> -		 */
> -
> -		dma_fence_put(bo->moving);
> -		bo->moving = dma_fence_get(fence);
>   
> -		ret = ttm_buffer_object_transfer(bo, &ghost_obj);
> -		if (ret)
> -			return ret;
> -
> -		dma_resv_add_excl_fence(ghost_obj->base.resv, fence);
> -
> -		/**
> -		 * If we're not moving to fixed memory, the TTM object
> -		 * needs to stay alive. Otherwhise hang it on the ghost
> -		 * bo to be unbound and destroyed.
> -		 */
> -
> -		if (!(to->flags & TTM_MEMTYPE_FLAG_FIXED))
> -			ghost_obj->ttm = NULL;
> -		else
> -			bo->ttm = NULL;
> -
> -		ttm_bo_unreserve(ghost_obj);
> -		ttm_bo_put(ghost_obj);
> -
> -	} else if (from->flags & TTM_MEMTYPE_FLAG_FIXED) {
> +	if (evict && from->flags & TTM_MEMTYPE_FLAG_FIXED) {
> +		dma_resv_add_excl_fence(bo->base.resv, fence);
>   
>   		/**
>   		 * BO doesn't have a TTM we need to bind/unbind. Just remember
> @@ -807,27 +768,12 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
>   		dma_fence_put(bo->moving);
>   		bo->moving = dma_fence_get(fence);
>   
> +		*old_mem = *new_mem;
> +		new_mem->mm_node = NULL;
>   	} else {
> -		/**
> -		 * Last resort, wait for the move to be completed.
> -		 *
> -		 * Should never happen in pratice.
> -		 */
> -
> -		ret = ttm_bo_wait(bo, false, false);
> -		if (ret)
> -			return ret;
> -
> -		if (to->flags & TTM_MEMTYPE_FLAG_FIXED) {
> -			ttm_tt_destroy(bo->ttm);
> -			bo->ttm = NULL;
> -		}
> -		ttm_bo_free_old_node(bo);
> +		return ttm_bo_move_accel_cleanup(bo, fence, evict, new_mem);
>   	}
>   
> -	*old_mem = *new_mem;
> -	new_mem->mm_node = NULL;
> -
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_bo_pipeline_move);

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

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

end of thread, other threads:[~2019-08-16 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16 18:59 [PATCH] drm/ttm: Refactor ttm_bo_pipeline_move Brian Welty
2019-08-16 19:10 ` Koenig, Christian

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.