[PATCH 37/45] drm/ttm: add a helper to allocate a temp tt for copies.

Christian König christian.koenig at amd.com
Thu Sep 24 12:42:36 UTC 2020


Am 24.09.20 um 07:18 schrieb Dave Airlie:
> From: Dave Airlie <airlied at redhat.com>
>
> All the accel moves do the same pattern here, provide a helper

And exactly that pattern I want to get away from.

See what happens if we (for example) have a VRAM -> SYSTEM move is the 
following:

1. TTM allocates a new ttm_resource object in the SYSTEM domain.
2. We call the driver to move from VRAM to SYSTEM.
3. Driver finds that it can't do this and calls TTM  to allocate GTT.
4. Since we are maybe out of GTT TTM evicts a different BO from GTT to 
SYSTEM and call driver again.

This is a horrible ping/pong between driver/TTM/driver/TTM/driver and we 
should stop that immediately.

My suggestion is that we rewrite how drivers call the ttm_bo_validate() 
function so that we can guarantee that this never happens.

What do you think?

Thanks,
Christian.

>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 28 ++++++++++++++++++++++++++++
>   include/drm/ttm/ttm_bo_driver.h |  5 +++++
>   2 files changed, 33 insertions(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index eb76002aa53d..358d1580dc16 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1541,3 +1541,31 @@ void ttm_bo_tt_destroy(struct ttm_buffer_object *bo)
>   	ttm_tt_destroy(bo->bdev, bo->ttm);
>   	bo->ttm = NULL;
>   }
> +
> +int ttm_bo_create_tt_tmp(struct ttm_buffer_object *bo,
> +			 struct ttm_operation_ctx *ctx,
> +			 struct ttm_resource *new_mem,
> +			 struct ttm_resource *new_temp)
> +{
> +	struct ttm_place placement_memtype = {
> +		.fpfn = 0,
> +		.lpfn = 0,
> +		.mem_type = TTM_PL_TT,
> +		.flags = TTM_PL_MASK_CACHING
> +	};
> +	struct ttm_placement placement;
> +	int ret;
> +
> +	placement.num_placement = placement.num_busy_placement = 1;
> +	placement.placement = placement.busy_placement = &placement_memtype;
> +
> +	*new_temp = *new_mem;
> +	new_temp->mm_node = NULL;
> +
> +	ret = ttm_bo_mem_space(bo, &placement, new_temp, ctx);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(ttm_bo_create_tt_tmp);
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 4a63fec24e90..a7507dfaa89d 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -558,6 +558,11 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
>   int ttm_bo_move_to_new_tt_mem(struct ttm_buffer_object *bo,
>   			      struct ttm_operation_ctx *ctx,
>   			      struct ttm_resource *new_mem);
> +
> +int ttm_bo_create_tt_tmp(struct ttm_buffer_object *bo,
> +			 struct ttm_operation_ctx *ctx,
> +			 struct ttm_resource *new_mem,
> +			 struct ttm_resource *new_temp);
>   /**
>    * ttm_bo_move_memcpy
>    *



More information about the dri-devel mailing list