]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm/vgem: Convert fence_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Thu, 14 Feb 2019 17:59:43 +0000 (12:59 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:35 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/vgem/vgem_drv.h
drivers/gpu/drm/vgem/vgem_fence.c

index 5c8f6d619ff382a096d585e82b5ddf4f282366a9..56c8872b09676f2aa02fb1edefc1fa0987c35c50 100644 (file)
@@ -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)
index eb17c0cd3727a46498bc6dc0d0c77ec70cde0cfb..7abc755a7aa68b5d90049a8ed369f32164799d37 100644 (file)
@@ -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);
 }