diff mbox series

[31/34] drm/vgem: Convert fence_idr to XArray

Message ID 20190221184226.2149-60-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:42 p.m. UTC
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/vgem/vgem_drv.h   |  3 +--
 drivers/gpu/drm/vgem/vgem_fence.c | 43 +++++++++++++------------------
 2 files changed, 19 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vgem/vgem_drv.h b/drivers/gpu/drm/vgem/vgem_drv.h
index 5c8f6d619ff3..56c8872b0967 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.h
+++ b/drivers/gpu/drm/vgem/vgem_drv.h
@@ -36,8 +36,7 @@ 
 #include <uapi/drm/vgem_drm.h>
 
 struct vgem_file {
-	struct idr fence_idr;
-	struct mutex fence_mutex;
+	struct xarray fences;
 };
 
 #define to_vgem_bo(x) container_of(x, struct drm_vgem_gem_object, base)
diff --git a/drivers/gpu/drm/vgem/vgem_fence.c b/drivers/gpu/drm/vgem/vgem_fence.c
index c1c420afe2dd..aa410ebcddf2 100644
--- a/drivers/gpu/drm/vgem/vgem_fence.c
+++ b/drivers/gpu/drm/vgem/vgem_fence.c
@@ -184,15 +184,10 @@  int vgem_fence_attach_ioctl(struct drm_device *dev,
 		reservation_object_add_shared_fence(resv, fence);
 	reservation_object_unlock(resv);
 
-	/* Record the fence in our idr for later signaling */
+	/* Record the fence in our array for later signaling */
 	if (ret == 0) {
-		mutex_lock(&vfile->fence_mutex);
-		ret = idr_alloc(&vfile->fence_idr, fence, 1, 0, GFP_KERNEL);
-		mutex_unlock(&vfile->fence_mutex);
-		if (ret > 0) {
-			arg->out_fence = ret;
-			ret = 0;
-		}
+		ret = xa_alloc(&vfile->fences, &arg->out_fence, fence,
+				xa_limit_31b, GFP_KERNEL);
 	}
 err_fence:
 	if (ret) {
@@ -232,13 +227,13 @@  int vgem_fence_signal_ioctl(struct drm_device *dev,
 	if (arg->flags)
 		return -EINVAL;
 
-	mutex_lock(&vfile->fence_mutex);
-	fence = idr_replace(&vfile->fence_idr, NULL, arg->fence);
-	mutex_unlock(&vfile->fence_mutex);
-	if (!fence)
+	fence = xa_store(&vfile->fences, arg->fence, NULL, 0);
+	if (!fence) {
+		xa_erase(&vfile->fences, arg->fence);
+		return -ENOENT;
+	}
+	if (xa_is_err(fence))
 		return -ENOENT;
-	if (IS_ERR(fence))
-		return PTR_ERR(fence);
 
 	if (dma_fence_is_signaled(fence))
 		ret = -ETIMEDOUT;
@@ -250,21 +245,19 @@  int vgem_fence_signal_ioctl(struct drm_device *dev,
 
 int vgem_fence_open(struct vgem_file *vfile)
 {
-	mutex_init(&vfile->fence_mutex);
-	idr_init(&vfile->fence_idr);
+	xa_init_flags(&vfile->fences, XA_FLAGS_ALLOC1);
 
 	return 0;
 }
 
-static int __vgem_fence_idr_fini(int id, void *p, void *data)
-{
-	dma_fence_signal(p);
-	dma_fence_put(p);
-	return 0;
-}
-
 void vgem_fence_close(struct vgem_file *vfile)
 {
-	idr_for_each(&vfile->fence_idr, __vgem_fence_idr_fini, vfile);
-	idr_destroy(&vfile->fence_idr);
+	struct dma_fence *fence;
+	unsigned long index;
+
+	xa_for_each(&vfile->fences, index, fence) {
+		dma_fence_signal(fence);
+		dma_fence_put(fence);
+	}
+	xa_destroy(&vfile->fences);
 }