[PATCH 2/6] dma-buf: add reservation object shared fence accessor

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

 



On Thu, Aug 09, 2018 at 01:37:09PM +0200, Christian König wrote:
> Add a helper to access the shared fences in an reservation object.
> 
> Signed-off-by: Christian König <christian.koenig at amd.com>

Reviewed-by: Huang Rui <ray.huang at amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c |  7 ++-----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c         |  3 +--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c          |  4 ++--
>  drivers/gpu/drm/msm/msm_gem.c                    |  4 ++--
>  drivers/gpu/drm/nouveau/nouveau_fence.c          |  3 +--
>  drivers/gpu/drm/radeon/radeon_sync.c             |  3 +--
>  drivers/gpu/drm/ttm/ttm_bo.c                     |  4 +---
>  include/linux/reservation.h                      | 19 +++++++++++++++++++
>  8 files changed, 29 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index fa38a960ce00..989932234160 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -238,9 +238,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
>  	for (i = 0; i < shared_count; ++i) {
>  		struct dma_fence *f;
>  
> -		f = rcu_dereference_protected(fobj->shared[i],
> -					      reservation_object_held(resv));
> -
> +		f = reservation_object_get_shared_fence(resv, fobj, i);
>  		if (ef) {
>  			if (f->context == ef->base.context) {
>  				dma_fence_put(f);
> @@ -273,8 +271,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
>  		struct dma_fence *f;
>  		struct amdgpu_amdkfd_fence *efence;
>  
> -		f = rcu_dereference_protected(fobj->shared[i],
> -			reservation_object_held(resv));
> +		f = reservation_object_get_shared_fence(resv, fobj, i);
>  
>  		efence = to_amdgpu_amdkfd_fence(f);
>  		if (efence) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
> index 2d6f5ec77a68..dbfd62ab67e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
> @@ -212,8 +212,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
>  		return r;
>  
>  	for (i = 0; i < flist->shared_count; ++i) {
> -		f = rcu_dereference_protected(flist->shared[i],
> -					      reservation_object_held(resv));
> +		f = reservation_object_get_shared_fence(resv, flist, i);
>  		/* We only want to trigger KFD eviction fences on
>  		 * evict or move jobs. Skip KFD fences otherwise.
>  		 */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index c6611cff64c8..22896a398eab 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1482,8 +1482,8 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
>  	flist = reservation_object_get_list(bo->resv);
>  	if (flist) {
>  		for (i = 0; i < flist->shared_count; ++i) {
> -			f = rcu_dereference_protected(flist->shared[i],
> -				reservation_object_held(bo->resv));
> +			f = reservation_object_get_shared_fence(bo->resv,
> +								flist, i);
>  			if (amdkfd_fence_check_mm(f, current->mm))
>  				return false;
>  		}
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index f583bb4222f9..95d25dbfde2b 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -651,8 +651,8 @@ int msm_gem_sync_object(struct drm_gem_object *obj,
>  		return 0;
>  
>  	for (i = 0; i < fobj->shared_count; i++) {
> -		fence = rcu_dereference_protected(fobj->shared[i],
> -						reservation_object_held(msm_obj->resv));
> +		fence = reservation_object_get_shared_fence(msm_obj->resv,
> +							    fobj, i);
>  		if (fence->context != fctx->context) {
>  			ret = dma_fence_wait(fence, true);
>  			if (ret)
> diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
> index 412d49bc6e56..3ce921c276c1 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> @@ -376,8 +376,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
>  		struct nouveau_channel *prev = NULL;
>  		bool must_wait = true;
>  
> -		fence = rcu_dereference_protected(fobj->shared[i],
> -						reservation_object_held(resv));
> +		fence = reservation_object_get_shared_fence(resv, fobj, i);
>  
>  		f = nouveau_local_fence(fence, chan->drm);
>  		if (f) {
> diff --git a/drivers/gpu/drm/radeon/radeon_sync.c b/drivers/gpu/drm/radeon/radeon_sync.c
> index be5d7a38d3aa..bf7f9a648838 100644
> --- a/drivers/gpu/drm/radeon/radeon_sync.c
> +++ b/drivers/gpu/drm/radeon/radeon_sync.c
> @@ -110,8 +110,7 @@ int radeon_sync_resv(struct radeon_device *rdev,
>  		return r;
>  
>  	for (i = 0; i < flist->shared_count; ++i) {
> -		f = rcu_dereference_protected(flist->shared[i],
> -					      reservation_object_held(resv));
> +		f = reservation_object_get_shared_fence(resv, flist, i);
>  		fence = to_radeon_fence(f);
>  		if (fence && fence->rdev == rdev)
>  			radeon_sync_fence(sync, fence);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 7c484729f9b2..820d97d3e8b9 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -370,9 +370,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)
>  		dma_fence_enable_sw_signaling(fence);
>  
>  	for (i = 0; fobj && i < fobj->shared_count; ++i) {
> -		fence = rcu_dereference_protected(fobj->shared[i],
> -					reservation_object_held(bo->resv));
> -
> +		fence = reservation_object_get_shared_fence(bo->resv, fobj, i);
>  		if (!fence->ops->signaled)
>  			dma_fence_enable_sw_signaling(fence);
>  	}
> diff --git a/include/linux/reservation.h b/include/linux/reservation.h
> index 54cf6773a14c..8a3298574bf5 100644
> --- a/include/linux/reservation.h
> +++ b/include/linux/reservation.h
> @@ -140,6 +140,25 @@ reservation_object_get_list(struct reservation_object *obj)
>  					 reservation_object_held(obj));
>  }
>  
> +/**
> + * reservation_object_get_shared_fence - get a fence from a reservation object's
> + * shared fence list.
> + * @obj: the reservation object
> + * @list: the list to get the fence from
> + * @idx: the index in the list to get
> + *
> + * Returns the fence from the shared fence list.  Does NOT take references to
> + * the fence.  Needs to be in RCU context or the obj->lock must be held.
> + */
> +static inline struct dma_fence *
> +reservation_object_get_shared_fence(struct reservation_object *obj,
> +				    struct reservation_object_list *list,
> +				    unsigned int idx)
> +{
> +	return rcu_dereference_protected(list->shared[idx],
> +					 reservation_object_held(obj));
> +}
> +
>  /**
>   * reservation_object_lock - lock the reservation object
>   * @obj: the reservation object
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


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

  Powered by Linux