[PATCH 1/3] drm/amdgpu: Drop useless loops for placement restrictions

Christian König deathsimple at vodafone.de
Thu May 18 09:17:16 UTC 2017


Am 18.05.2017 um 11:08 schrieb Michel Dänzer:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> We know how the placements were initialized in these cases, so we can
> set the restrictions directly without a loop.
>
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 13 +++----------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 19 ++++---------------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c    |  6 +-----
>   3 files changed, 8 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 365883d7948d..b3252bc8fe51 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -939,8 +939,8 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
>   {
>   	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
>   	struct amdgpu_bo *abo;
> -	unsigned long offset, size, lpfn;
> -	int i, r;
> +	unsigned long offset, size;
> +	int r;
>   
>   	if (!amdgpu_ttm_bo_is_amdgpu_bo(bo))
>   		return 0;
> @@ -961,14 +961,7 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
>   
>   	/* hurrah the memory is not visible ! */
>   	amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM);
> -	lpfn =	adev->mc.visible_vram_size >> PAGE_SHIFT;
> -	for (i = 0; i < abo->placement.num_placement; i++) {
> -		/* Force into visible VRAM */
> -		if ((abo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
> -		    (!abo->placements[i].lpfn ||
> -		     abo->placements[i].lpfn > lpfn))
> -			abo->placements[i].lpfn = lpfn;
> -	}
> +	abo->placements[0].lpfn = adev->mc.visible_vram_size >> PAGE_SHIFT;
>   	r = ttm_bo_validate(bo, &abo->placement, false, false);
>   	if (unlikely(r == -ENOMEM)) {
>   		amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 5db0230e45c6..57789b860768 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -191,7 +191,6 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
>   		.lpfn = 0,
>   		.flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM
>   	};
> -	unsigned i;
>   
>   	if (!amdgpu_ttm_bo_is_amdgpu_bo(bo)) {
>   		placement->placement = &placements;
> @@ -209,20 +208,10 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
>   			amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_CPU);
>   		} else {
>   			amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT);
> -			for (i = 0; i < abo->placement.num_placement; ++i) {
> -				if (!(abo->placements[i].flags &
> -				      TTM_PL_FLAG_TT))
> -					continue;
> -
> -				if (abo->placements[i].lpfn)
> -					continue;
> -
> -				/* set an upper limit to force directly
> -				 * allocating address space for the BO.
> -				 */
> -				abo->placements[i].lpfn =
> -					adev->mc.gtt_size >> PAGE_SHIFT;
> -			}
> +			/* Set an upper limit to force directly allocating
> +			 * address space for the BO.
> +			 */
> +			abo->placements[0].lpfn = adev->mc.gtt_size >> PAGE_SHIFT;
>   		}
>   		break;
>   	case TTM_PL_TT:
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> index 2ca09f111f08..60688fa5ef98 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> @@ -375,11 +375,7 @@ void amdgpu_uvd_free_handles(struct amdgpu_device *adev, struct drm_file *filp)
>   
>   static void amdgpu_uvd_force_into_uvd_segment(struct amdgpu_bo *abo)
>   {
> -	int i;
> -	for (i = 0; i < abo->placement.num_placement; ++i) {
> -		abo->placements[i].fpfn = 0 >> PAGE_SHIFT;
> -		abo->placements[i].lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
> -	}
> +	abo->placements[0].lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;

This is not correct. The restriction applies to all placements, not only 
the first one.

Christian.

>   }
>   
>   static u64 amdgpu_uvd_get_addr_from_ctx(struct amdgpu_uvd_cs_ctx *ctx)




More information about the amd-gfx mailing list