[PATCH 3/4] drm/amdgpu: Make amdgpu_vram_mgr_bo_invisible_size always accurate

Christian König ckoenig.leichtzumerken at gmail.com
Fri Jun 15 15:11:00 UTC 2018


Am 15.06.2018 um 16:42 schrieb Michel Dänzer:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> Even BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS may end up at least
> partially in CPU visible VRAM, in particular when all VRAM is visible.
>
> Cc: stable at vger.kernel.org
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 26 ++++++++++++++++++--
>   1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 491fd0a789f7..9b34df7017f0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -106,10 +106,32 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev,
>    */
>   u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo)
>   {
> -	if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
> +	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
> +	struct amdgpu_vram_mgr *mgr = adev->mman.bdev.man[TTM_PL_VRAM].priv;
> +	struct ttm_mem_reg *mem = &bo->tbo.mem;
> +	struct drm_mm_node *nodes = mem->mm_node;
> +	unsigned pages = mem->num_pages;
> +	u64 usage = 0;
> +
> +	if (adev->gmc.visible_vram_size == adev->gmc.real_vram_size)
> +		return 0;

Andrey just added a helper for that into amdgpu_gmc.h.

> +
> +	if (mem->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT)
>   		return amdgpu_bo_size(bo);
>   
> -	return 0;
> +	if (!nodes)
> +		return 0;
> +
> +	spin_lock(&mgr->lock);

I actually don't see any need to grab the lock here.

Apart from that looks like a good cleanup to me,
Christian.

> +	while (pages) {
> +		pages -= nodes->size;
> +		usage += nodes->size << PAGE_SHIFT;
> +		usage -= amdgpu_vram_mgr_vis_size(adev, nodes);
> +		++nodes;
> +	}
> +	spin_unlock(&mgr->lock);
> +
> +	return usage;
>   }
>   
>   /**



More information about the amd-gfx mailing list