diff mbox series

[12/34] drm/agp: Convert bo_list_handles to XArray

Message ID 20190221184226.2149-25-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert DRM to XArray | expand

Commit Message

Matthew Wilcox Feb. 21, 2019, 6:41 p.m. UTC
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h         |  3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 22 ++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 10 ++++------
 3 files changed, 13 insertions(+), 22 deletions(-)

Comments

Christian König Feb. 25, 2019, 4:06 p.m. UTC | #1
In this one there is a typo in the subject line.

Christian.

Am 21.02.19 um 19:41 schrieb Matthew Wilcox:
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h         |  3 +--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 22 ++++++++-------------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     | 10 ++++------
>   3 files changed, 13 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index bcef6ea4bcf9..6a704aaa7dbe 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -406,8 +406,7 @@ struct amdgpu_fpriv {
>   	struct amdgpu_vm	vm;
>   	struct amdgpu_bo_va	*prt_va;
>   	struct amdgpu_bo_va	*csa_va;
> -	struct mutex		bo_list_lock;
> -	struct idr		bo_list_handles;
> +	struct xarray		bo_list_handles;
>   	struct amdgpu_ctx_mgr	ctx_mgr;
>   };
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 5c79da8e1150..76439a52a6b0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -153,9 +153,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
>   {
>   	struct amdgpu_bo_list *list;
>   
> -	mutex_lock(&fpriv->bo_list_lock);
> -	list = idr_remove(&fpriv->bo_list_handles, id);
> -	mutex_unlock(&fpriv->bo_list_lock);
> +	list = xa_erase(&fpriv->bo_list_handles, id);
>   	if (list)
>   		kref_put(&list->refcount, amdgpu_bo_list_free);
>   }
> @@ -164,7 +162,7 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
>   		       struct amdgpu_bo_list **result)
>   {
>   	rcu_read_lock();
> -	*result = idr_find(&fpriv->bo_list_handles, id);
> +	*result = xa_load(&fpriv->bo_list_handles, id);
>   
>   	if (*result && kref_get_unless_zero(&(*result)->refcount)) {
>   		rcu_read_unlock();
> @@ -278,15 +276,13 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
>   		if (r)
>   			goto error_free;
>   
> -		mutex_lock(&fpriv->bo_list_lock);
> -		r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
> -		mutex_unlock(&fpriv->bo_list_lock);
> +		r = xa_alloc(&fpriv->bo_list_handles, &handle, list,
> +				xa_limit_31b, GFP_KERNEL);
>   		if (r < 0) {
>   			amdgpu_bo_list_put(list);
>   			return r;
>   		}
>   
> -		handle = r;
>   		break;
>   
>   	case AMDGPU_BO_LIST_OP_DESTROY:
> @@ -300,13 +296,11 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
>   		if (r)
>   			goto error_free;
>   
> -		mutex_lock(&fpriv->bo_list_lock);
> -		old = idr_replace(&fpriv->bo_list_handles, list, handle);
> -		mutex_unlock(&fpriv->bo_list_lock);
> -
> -		if (IS_ERR(old)) {
> +		old = xa_store(&fpriv->bo_list_handles, handle, list,
> +				GFP_KERNEL);
> +		if (xa_is_err(old)) {
>   			amdgpu_bo_list_put(list);
> -			r = PTR_ERR(old);
> +			r = xa_err(old);
>   			goto error_free;
>   		}
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index bc62bf41b7e9..1a5bf3a4f5d9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -986,8 +986,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
>   			goto error_vm;
>   	}
>   
> -	mutex_init(&fpriv->bo_list_lock);
> -	idr_init(&fpriv->bo_list_handles);
> +	xa_init_flags(&fpriv->bo_list_handles, XA_FLAGS_ALLOC1);
>   
>   	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
>   
> @@ -1026,7 +1025,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
>   	struct amdgpu_bo_list *list;
>   	struct amdgpu_bo *pd;
>   	unsigned int pasid;
> -	int handle;
> +	unsigned long handle;
>   
>   	if (!fpriv)
>   		return;
> @@ -1058,11 +1057,10 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
>   		amdgpu_pasid_free_delayed(pd->tbo.resv, pasid);
>   	amdgpu_bo_unref(&pd);
>   
> -	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
> +	xa_for_each(&fpriv->bo_list_handles, handle, list)
>   		amdgpu_bo_list_put(list);
>   
> -	idr_destroy(&fpriv->bo_list_handles);
> -	mutex_destroy(&fpriv->bo_list_lock);
> +	xa_destroy(&fpriv->bo_list_handles);
>   
>   	kfree(fpriv);
>   	file_priv->driver_priv = NULL;
Matthew Wilcox Feb. 25, 2019, 4:39 p.m. UTC | #2
On Mon, Feb 25, 2019 at 05:06:18PM +0100, Christian König wrote:
> In this one there is a typo in the subject line.

Thanks, I'll fix it.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index bcef6ea4bcf9..6a704aaa7dbe 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -406,8 +406,7 @@  struct amdgpu_fpriv {
 	struct amdgpu_vm	vm;
 	struct amdgpu_bo_va	*prt_va;
 	struct amdgpu_bo_va	*csa_va;
-	struct mutex		bo_list_lock;
-	struct idr		bo_list_handles;
+	struct xarray		bo_list_handles;
 	struct amdgpu_ctx_mgr	ctx_mgr;
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 5c79da8e1150..76439a52a6b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -153,9 +153,7 @@  static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
 {
 	struct amdgpu_bo_list *list;
 
-	mutex_lock(&fpriv->bo_list_lock);
-	list = idr_remove(&fpriv->bo_list_handles, id);
-	mutex_unlock(&fpriv->bo_list_lock);
+	list = xa_erase(&fpriv->bo_list_handles, id);
 	if (list)
 		kref_put(&list->refcount, amdgpu_bo_list_free);
 }
@@ -164,7 +162,7 @@  int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
 		       struct amdgpu_bo_list **result)
 {
 	rcu_read_lock();
-	*result = idr_find(&fpriv->bo_list_handles, id);
+	*result = xa_load(&fpriv->bo_list_handles, id);
 
 	if (*result && kref_get_unless_zero(&(*result)->refcount)) {
 		rcu_read_unlock();
@@ -278,15 +276,13 @@  int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 		if (r)
 			goto error_free;
 
-		mutex_lock(&fpriv->bo_list_lock);
-		r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
-		mutex_unlock(&fpriv->bo_list_lock);
+		r = xa_alloc(&fpriv->bo_list_handles, &handle, list,
+				xa_limit_31b, GFP_KERNEL);
 		if (r < 0) {
 			amdgpu_bo_list_put(list);
 			return r;
 		}
 
-		handle = r;
 		break;
 
 	case AMDGPU_BO_LIST_OP_DESTROY:
@@ -300,13 +296,11 @@  int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 		if (r)
 			goto error_free;
 
-		mutex_lock(&fpriv->bo_list_lock);
-		old = idr_replace(&fpriv->bo_list_handles, list, handle);
-		mutex_unlock(&fpriv->bo_list_lock);
-
-		if (IS_ERR(old)) {
+		old = xa_store(&fpriv->bo_list_handles, handle, list,
+				GFP_KERNEL);
+		if (xa_is_err(old)) {
 			amdgpu_bo_list_put(list);
-			r = PTR_ERR(old);
+			r = xa_err(old);
 			goto error_free;
 		}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index bc62bf41b7e9..1a5bf3a4f5d9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -986,8 +986,7 @@  int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 			goto error_vm;
 	}
 
-	mutex_init(&fpriv->bo_list_lock);
-	idr_init(&fpriv->bo_list_handles);
+	xa_init_flags(&fpriv->bo_list_handles, XA_FLAGS_ALLOC1);
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
 
@@ -1026,7 +1025,7 @@  void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	struct amdgpu_bo_list *list;
 	struct amdgpu_bo *pd;
 	unsigned int pasid;
-	int handle;
+	unsigned long handle;
 
 	if (!fpriv)
 		return;
@@ -1058,11 +1057,10 @@  void amdgpu_driver_postclose_kms(struct drm_device *dev,
 		amdgpu_pasid_free_delayed(pd->tbo.resv, pasid);
 	amdgpu_bo_unref(&pd);
 
-	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
+	xa_for_each(&fpriv->bo_list_handles, handle, list)
 		amdgpu_bo_list_put(list);
 
-	idr_destroy(&fpriv->bo_list_handles);
-	mutex_destroy(&fpriv->bo_list_lock);
+	xa_destroy(&fpriv->bo_list_handles);
 
 	kfree(fpriv);
 	file_priv->driver_priv = NULL;