]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm/vc4: Convert perfmon IDR to XArray
authorMatthew Wilcox <willy@infradead.org>
Fri, 15 Feb 2019 19:13:49 +0000 (14:13 -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/vc4/vc4_drv.h
drivers/gpu/drm/vc4/vc4_perfmon.c

index 616c011bcb82aef4cea8037ae3805812d124605e..9d51b19de2d4f21385b9e8d74e3d91052b81e580 100644 (file)
@@ -598,7 +598,7 @@ struct vc4_exec_info {
  */
 struct vc4_file {
        struct {
-               struct idr idr;
+               struct xarray array;
                struct mutex lock;
        } perfmon;
 
index f4aa75efd16b0d41df379a3d73efca20593e5296..b006660534920785dbc8dec4a3ee9fb878cf932c 100644 (file)
@@ -12,9 +12,6 @@
 #include "vc4_drv.h"
 #include "vc4_regs.h"
 
-#define VC4_PERFMONID_MIN      1
-#define VC4_PERFMONID_MAX      U32_MAX
-
 void vc4_perfmon_get(struct vc4_perfmon *perfmon)
 {
        if (perfmon)
@@ -67,7 +64,7 @@ struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id)
        struct vc4_perfmon *perfmon;
 
        mutex_lock(&vc4file->perfmon.lock);
-       perfmon = idr_find(&vc4file->perfmon.idr, id);
+       perfmon = xa_load(&vc4file->perfmon.array, id);
        vc4_perfmon_get(perfmon);
        mutex_unlock(&vc4file->perfmon.lock);
 
@@ -77,23 +74,18 @@ struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id)
 void vc4_perfmon_open_file(struct vc4_file *vc4file)
 {
        mutex_init(&vc4file->perfmon.lock);
-       idr_init(&vc4file->perfmon.idr);
-}
-
-static int vc4_perfmon_idr_del(int id, void *elem, void *data)
-{
-       struct vc4_perfmon *perfmon = elem;
-
-       vc4_perfmon_put(perfmon);
-
-       return 0;
+       xa_init_flags(&vc4file->perfmon.array, XA_FLAGS_ALLOC1);
 }
 
 void vc4_perfmon_close_file(struct vc4_file *vc4file)
 {
+       struct vc4_perfmon *perfmon;
+       unsigned long index;
+
        mutex_lock(&vc4file->perfmon.lock);
-       idr_for_each(&vc4file->perfmon.idr, vc4_perfmon_idr_del, NULL);
-       idr_destroy(&vc4file->perfmon.idr);
+       xa_for_each(&vc4file->perfmon.array, index, perfmon)
+               vc4_perfmon_put(perfmon);
+       xa_destroy(&vc4file->perfmon.array);
        mutex_unlock(&vc4file->perfmon.lock);
 }
 
@@ -136,8 +128,8 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
        refcount_set(&perfmon->refcnt, 1);
 
        mutex_lock(&vc4file->perfmon.lock);
-       ret = idr_alloc(&vc4file->perfmon.idr, perfmon, VC4_PERFMONID_MIN,
-                       VC4_PERFMONID_MAX, GFP_KERNEL);
+       ret = xa_alloc(&vc4file->perfmon.array, &req->id, perfmon,
+                       xa_limit_32b, GFP_KERNEL);
        mutex_unlock(&vc4file->perfmon.lock);
 
        if (ret < 0) {
@@ -145,7 +137,6 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
                return ret;
        }
 
-       req->id = ret;
        return 0;
 }
 
@@ -163,7 +154,7 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
        }
 
        mutex_lock(&vc4file->perfmon.lock);
-       perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
+       perfmon = xa_erase(&vc4file->perfmon.array, req->id);
        mutex_unlock(&vc4file->perfmon.lock);
 
        if (!perfmon)
@@ -188,7 +179,7 @@ int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
        }
 
        mutex_lock(&vc4file->perfmon.lock);
-       perfmon = idr_find(&vc4file->perfmon.idr, req->id);
+       perfmon = xa_load(&vc4file->perfmon.array, req->id);
        vc4_perfmon_get(perfmon);
        mutex_unlock(&vc4file->perfmon.lock);