All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: dri-devel@lists.freedesktop.org
Cc: Matthew Wilcox <willy@infradead.org>
Subject: [PATCH 27/34] drm/qxl: Convert surf_id_idr to XArray
Date: Thu, 21 Feb 2019 10:42:12 -0800	[thread overview]
Message-ID: <20190221184226.2149-53-willy@infradead.org> (raw)
In-Reply-To: <20190221184226.2149-1-willy@infradead.org>

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/qxl/qxl_cmd.c | 60 ++++++++++++-----------------------
 drivers/gpu/drm/qxl/qxl_drv.h |  3 +-
 drivers/gpu/drm/qxl/qxl_kms.c |  5 +--
 3 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
index dffc5093ff16..afe8079453af 100644
--- a/drivers/gpu/drm/qxl/qxl_cmd.c
+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
@@ -420,41 +420,27 @@ void qxl_io_monitors_config(struct qxl_device *qdev)
 int qxl_surface_id_alloc(struct qxl_device *qdev,
 		      struct qxl_bo *surf)
 {
-	uint32_t handle;
-	int idr_ret;
-	int count = 0;
+	int ret;
 again:
-	idr_preload(GFP_ATOMIC);
-	spin_lock(&qdev->surf_id_idr_lock);
-	idr_ret = idr_alloc(&qdev->surf_id_idr, NULL, 1, 0, GFP_NOWAIT);
-	spin_unlock(&qdev->surf_id_idr_lock);
-	idr_preload_end();
-	if (idr_ret < 0)
-		return idr_ret;
-	handle = idr_ret;
-
-	if (handle >= qdev->rom->n_surfaces) {
-		count++;
-		spin_lock(&qdev->surf_id_idr_lock);
-		idr_remove(&qdev->surf_id_idr, handle);
-		spin_unlock(&qdev->surf_id_idr_lock);
+	ret = xa_alloc(&qdev->surfaces, &surf->surface_id, NULL,
+			XA_LIMIT(0, qdev->rom->n_surfaces - 1), GFP_ATOMIC);
+	if (ret == -EBUSY) {
 		qxl_reap_surface_id(qdev, 2);
 		goto again;
 	}
-	surf->surface_id = handle;
+	if (ret < 0)
+		return ret;
 
-	spin_lock(&qdev->surf_id_idr_lock);
-	qdev->last_alloced_surf_id = handle;
-	spin_unlock(&qdev->surf_id_idr_lock);
+	xa_lock(&qdev->surfaces);
+	qdev->last_alloced_surf_id = surf->surface_id;
+	xa_unlock(&qdev->surfaces);
 	return 0;
 }
 
 void qxl_surface_id_dealloc(struct qxl_device *qdev,
 			    uint32_t surface_id)
 {
-	spin_lock(&qdev->surf_id_idr_lock);
-	idr_remove(&qdev->surf_id_idr, surface_id);
-	spin_unlock(&qdev->surf_id_idr_lock);
+	xa_erase(&qdev->surfaces, surface_id);
 }
 
 int qxl_hw_surface_alloc(struct qxl_device *qdev,
@@ -507,9 +493,7 @@ int qxl_hw_surface_alloc(struct qxl_device *qdev,
 	qxl_release_fence_buffer_objects(release);
 
 	surf->hw_surf_alloc = true;
-	spin_lock(&qdev->surf_id_idr_lock);
-	idr_replace(&qdev->surf_id_idr, surf, surf->surface_id);
-	spin_unlock(&qdev->surf_id_idr_lock);
+	xa_store(&qdev->surfaces, surf->surface_id, surf, GFP_KERNEL);
 	return 0;
 }
 
@@ -531,10 +515,8 @@ int qxl_hw_surface_dealloc(struct qxl_device *qdev,
 		return ret;
 
 	surf->surf_create = NULL;
-	/* remove the surface from the idr, but not the surface id yet */
-	spin_lock(&qdev->surf_id_idr_lock);
-	idr_replace(&qdev->surf_id_idr, NULL, surf->surface_id);
-	spin_unlock(&qdev->surf_id_idr_lock);
+	/* remove the surface from the array, but don't free the surface id */
+	xa_store(&qdev->surfaces, surf->surface_id, NULL, 0);
 	surf->hw_surf_alloc = false;
 
 	id = surf->surface_id;
@@ -623,20 +605,20 @@ static int qxl_reap_surface_id(struct qxl_device *qdev, int max_to_reap)
 	mutex_lock(&qdev->surf_evict_mutex);
 again:
 
-	spin_lock(&qdev->surf_id_idr_lock);
+	xa_lock(&qdev->surfaces);
 	start = qdev->last_alloced_surf_id + 1;
-	spin_unlock(&qdev->surf_id_idr_lock);
+	xa_unlock(&qdev->surfaces);
 
 	for (i = start; i < start + qdev->rom->n_surfaces; i++) {
 		void *objptr;
 		int surfid = i % qdev->rom->n_surfaces;
 
-		/* this avoids the case where the objects is in the
-		   idr but has been evicted half way - its makes
-		   the idr lookup atomic with the eviction */
-		spin_lock(&qdev->surf_id_idr_lock);
-		objptr = idr_find(&qdev->surf_id_idr, surfid);
-		spin_unlock(&qdev->surf_id_idr_lock);
+		/* this avoids the case where the object is in the
+		   array but has been evicted half way - it makes
+		   the array lookup atomic with the eviction */
+		xa_lock(&qdev->surfaces);
+		objptr = xa_load(&qdev->surfaces, surfid);
+		xa_unlock(&qdev->surfaces);
 
 		if (!objptr)
 			continue;
diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
index 3abd432a4b85..8d0254a133dc 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.h
+++ b/drivers/gpu/drm/qxl/qxl_drv.h
@@ -260,8 +260,7 @@ struct qxl_device {
 
 	struct mutex		update_area_mutex;
 
-	struct idr	surf_id_idr;
-	spinlock_t surf_id_idr_lock;
+	struct xarray	surfaces;
 	int last_alloced_surf_id;
 
 	struct mutex surf_evict_mutex;
diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c
index b2cc71c95142..dafdb61f7a32 100644
--- a/drivers/gpu/drm/qxl/qxl_kms.c
+++ b/drivers/gpu/drm/qxl/qxl_kms.c
@@ -249,10 +249,7 @@ int qxl_device_init(struct qxl_device *qdev,
 
 	xa_init_flags(&qdev->releases, XA_FLAGS_ALLOC1);
 	spin_lock_init(&qdev->release_lock);
-
-	idr_init(&qdev->surf_id_idr);
-	spin_lock_init(&qdev->surf_id_idr_lock);
-
+	xa_init_flags(&qdev->surfaces, XA_FLAGS_ALLOC1);
 	mutex_init(&qdev->async_io_mutex);
 
 	/* reset the device into a known state - no memslots, no primary
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-02-21 18:42 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 18:41 [PATCH 00/34] Convert DRM to XArray Matthew Wilcox
2019-02-21 18:41 ` [PATCH 01/34] drm: Convert drm_minors_idr " Matthew Wilcox
2019-02-22  9:11   ` Daniel Vetter
2019-02-22  9:55     ` Daniel Vetter
2019-02-22 15:13     ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 02/34] drm: Convert aux_idr " Matthew Wilcox
2019-02-25 17:57   ` Ville Syrjälä
2019-02-25 18:42     ` Matthew Wilcox
2019-02-25 18:50       ` Ville Syrjälä
2019-02-21 18:41 ` [PATCH 03/34] drm: Convert object_name_idr " Matthew Wilcox
2019-02-22  9:17   ` Daniel Vetter
2019-02-21 18:41 ` [PATCH 04/34] drm: Convert object_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 05/34] drm: Convert syncobj_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 06/34] drm: Convert magic_map " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 07/34] drm: Convert lessee_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 08/34] drm: Remove linked lists for lessees Matthew Wilcox
2019-02-21 18:41 ` [PATCH 09/34] drm: Convert ctx_idr to XArray Matthew Wilcox
2019-02-21 18:41 ` [PATCH 10/34] drm: Convert tile_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 11/34] drm: Convert crtc_idr " Matthew Wilcox
2019-02-22  9:40   ` Daniel Vetter
2019-02-22 15:32     ` Matthew Wilcox
2019-02-22 17:12       ` Daniel Vetter
2019-02-21 18:41 ` [PATCH 12/34] drm/agp: Convert bo_list_handles " Matthew Wilcox
2019-02-25 16:06   ` Christian König
2019-02-25 16:39     ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 13/34] drm/amdgpu: Convert ctx_handles " Matthew Wilcox
2019-02-25 16:07   ` Christian König
2019-02-25 16:39     ` Matthew Wilcox
2019-02-25 16:59       ` Koenig, Christian
2019-02-25 18:47         ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 14/34] drm/amdgpu: Convert pasid_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 15/34] drm/amdkfd: Convert event_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 16/34] drm/amdkfd: Convert alloc_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 17/34] drm/etnaviv: Convert fence_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 18/34] drm/i915: Convert handles_vma " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 19/34] drm/i915: Convert spt_tree " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 20/34] drm/i915: Convert page_track_tree " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 21/34] drm/i915: Convert get_page " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 22/34] drm/i915: Convert object_idr to IDA Matthew Wilcox
2019-02-21 18:42 ` [PATCH 23/34] drm/i915: Convert context_idr to XArray Matthew Wilcox
2019-02-21 18:42 ` [PATCH 24/34] drm/i915: Convert metrics_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 25/34] drm/i915: Convert vgpus_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 26/34] drm/qxl: Convert release_idr " Matthew Wilcox
2019-02-21 18:42 ` Matthew Wilcox [this message]
2019-02-21 18:42 ` [PATCH 28/34] drm/tegra: Convert contexts IDR " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 29/34] drm/vc4: Convert perfmon " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 30/34] drm/sis: Convert object_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 31/34] drm/vgem: Convert fence_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 32/34] drm/via: Convert object_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 33/34] drm/vmwgfx: Convert base IDR " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 34/34] drm/vmwgfx: Convert res_idr " Matthew Wilcox
2019-02-22  9:54 ` [PATCH 00/34] Convert DRM " Daniel Vetter
2019-02-24  4:21   ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190221184226.2149-53-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.