[PATCH 3/3] drm/amdgpu: Warn and update pin_size values when destroying a pinned BO

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

 



Am 11.07.2018 um 18:23 schrieb Michel Dänzer:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> This shouldn't happen, but if it does, we'll get a backtrace of the
> caller, and update the pin_size values as needed.
>
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 37 +++++++++++++++++-----
>   1 file changed, 29 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 24d6fb87f3b6..9945f080ea7a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -63,10 +63,38 @@ static bool amdgpu_need_backup(struct amdgpu_device *adev)
>   	return true;
>   }
>   
> +/**
> + * amdgpu_bo_subtract_pin_size - Remove BO from pin size accounting
> + *
> + * @bo: &amdgpu_bo buffer object
> + *
> + * This function is called when a BO stops being pinned, and updates the
> + * &amdgpu_device pin_size values accordingly.
> + */
> +static void amdgpu_bo_subtract_pin_size(struct amdgpu_bo *bo)
> +{
> +	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
> +
> +	if (bo->tbo.mem.mem_type == TTM_PL_VRAM) {
> +		atomic64_sub(amdgpu_bo_size(bo), &adev->vram_pin_size);
> +		atomic64_sub(amdgpu_bo_size(bo) -
> +			     amdgpu_vram_mgr_bo_invisible_size(bo),
> +			     &adev->visible_pin_size);
> +	} else if (bo->tbo.mem.mem_type == TTM_PL_TT) {
> +		atomic64_sub(amdgpu_bo_size(bo), &adev->gart_pin_size);
> +	}
> +}
> +
>   static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
>   {
>   	struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
>   	struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
> +	int i;
> +
> +	for (i = 0; i < bo->placement.num_placement; i++) {
> +		if (WARN_ON_ONCE(bo->placements[i].flags & TTM_PL_FLAG_NO_EVICT))
> +			amdgpu_bo_subtract_pin_size(bo);
> +	}

That would subtract the values once for each placement which is not 
something we want. I would rather take a look at bo->pin_count.

Regards,
Christian.

>   
>   	if (bo->kfd_bo)
>   		amdgpu_amdkfd_unreserve_system_memory_limit(bo);
> @@ -969,14 +997,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
>   	if (bo->pin_count)
>   		return 0;
>   
> -	if (bo->tbo.mem.mem_type == TTM_PL_VRAM) {
> -		atomic64_sub(amdgpu_bo_size(bo), &adev->vram_pin_size);
> -		atomic64_sub(amdgpu_bo_size(bo) -
> -			     amdgpu_vram_mgr_bo_invisible_size(bo),
> -			     &adev->visible_pin_size);
> -	} else if (bo->tbo.mem.mem_type == TTM_PL_TT) {
> -		atomic64_sub(amdgpu_bo_size(bo), &adev->gart_pin_size);
> -	}
> +	amdgpu_bo_subtract_pin_size(bo);
>   
>   	for (i = 0; i < bo->placement.num_placement; i++) {
>   		bo->placements[i].lpfn = 0;



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux