diff mbox series

[29/34] drm/vc4: Convert perfmon IDR to XArray

Message ID 20190221184226.2149-57-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/vc4/vc4_drv.h     |  2 +-
 drivers/gpu/drm/vc4/vc4_perfmon.c | 33 +++++++++++--------------------
 2 files changed, 13 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index 4f87b03f837d..845b84d27f82 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -561,7 +561,7 @@  struct vc4_exec_info {
  */
 struct vc4_file {
 	struct {
-		struct idr idr;
+		struct xarray array;
 		struct mutex lock;
 	} perfmon;
 };
diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
index 437e7a27f21d..d5485821f996 100644
--- a/drivers/gpu/drm/vc4/vc4_perfmon.c
+++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
@@ -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);
 }
 
@@ -130,8 +122,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) {
@@ -139,7 +131,6 @@  int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
 		return ret;
 	}
 
-	req->id = ret;
 	return 0;
 }
 
@@ -151,7 +142,7 @@  int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
 	struct vc4_perfmon *perfmon;
 
 	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)
@@ -170,7 +161,7 @@  int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
 	int ret;
 
 	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);