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 21/34] drm/i915: Convert get_page to XArray
Date: Thu, 21 Feb 2019 10:42:01 -0800	[thread overview]
Message-ID: <20190221184226.2149-42-willy@infradead.org> (raw)
In-Reply-To: <20190221184226.2149-1-willy@infradead.org>

This initially seemed like an ideal use-case for the store_range
functionality, but there's no easy way to determine where we were
relative to the base of the entry.  So this is a straightforward
conversion which doesn't even touch the locking.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/i915/i915_gem.c         | 38 ++++++++++---------------
 drivers/gpu/drm/i915/i915_gem_context.h |  2 +-
 drivers/gpu/drm/i915/i915_gem_object.h  |  4 +--
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 0cdccc886587..f8c36c2d32c2 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2428,13 +2428,7 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj,
 
 static void __i915_gem_object_reset_page_iter(struct drm_i915_gem_object *obj)
 {
-	struct radix_tree_iter iter;
-	void __rcu **slot;
-
-	rcu_read_lock();
-	radix_tree_for_each_slot(slot, &obj->mm.get_page.radix, &iter, 0)
-		radix_tree_delete(&obj->mm.get_page.radix, iter.index);
-	rcu_read_unlock();
+	xa_destroy(&obj->mm.get_page.xa);
 }
 
 static struct sg_table *
@@ -4716,7 +4710,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
 	init_request_active(&obj->frontbuffer_write, frontbuffer_retire);
 
 	obj->mm.madv = I915_MADV_WILLNEED;
-	INIT_RADIX_TREE(&obj->mm.get_page.radix, GFP_KERNEL | __GFP_NOWARN);
+	xa_init(&obj->mm.get_page.xa);
 	mutex_init(&obj->mm.get_page.lock);
 
 	i915_gem_info_add_obj(to_i915(obj->base.dev), obj->base.size);
@@ -6073,8 +6067,8 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 	GEM_BUG_ON(n >= obj->base.size >> PAGE_SHIFT);
 	GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
 
-	/* As we iterate forward through the sg, we record each entry in a
-	 * radixtree for quick repeated (backwards) lookups. If we have seen
+	/* As we iterate forward through the sg, we record each entry in an
+	 * xarray for quick repeated (backwards) lookups. If we have seen
 	 * this index previously, we will have an entry for it.
 	 *
 	 * Initial lookup is O(N), but this is amortized to O(1) for
@@ -6089,7 +6083,7 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 
 	/* We prefer to reuse the last sg so that repeated lookup of this
 	 * (or the subsequent) sg are fast - comparing against the last
-	 * sg is faster than going through the radixtree.
+	 * sg is faster than going through the xarray.
 	 */
 
 	sg = iter->sg_pos;
@@ -6099,24 +6093,22 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 	while (idx + count <= n) {
 		void *entry;
 		unsigned long i;
-		int ret;
 
 		/* If we cannot allocate and insert this entry, or the
 		 * individual pages from this range, cancel updating the
 		 * sg_idx so that on this lookup we are forced to linearly
 		 * scan onwards, but on future lookups we will try the
-		 * insertion again (in which case we need to be careful of
-		 * the error return reporting that we have already inserted
-		 * this index).
+		 * insertion again.
 		 */
-		ret = radix_tree_insert(&iter->radix, idx, sg);
-		if (ret && ret != -EEXIST)
+		if (xa_store(&iter->xa, idx, sg, GFP_KERNEL | __GFP_NOWARN)
+				== XA_ERROR(-ENOMEM))
 			goto scan;
 
 		entry = xa_mk_value(idx);
 		for (i = 1; i < count; i++) {
-			ret = radix_tree_insert(&iter->radix, idx + i, entry);
-			if (ret && ret != -EEXIST)
+			if (xa_store(&iter->xa, idx + i, entry,
+					GFP_KERNEL | __GFP_NOWARN)
+						== XA_ERROR(-ENOMEM))
 				goto scan;
 		}
 
@@ -6134,7 +6126,7 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 	if (unlikely(n < idx)) /* insertion completed by another thread */
 		goto lookup;
 
-	/* In case we failed to insert the entry into the radixtree, we need
+	/* In case we failed to insert the entry into the xarray, we need
 	 * to look beyond the current sg.
 	 */
 	while (idx + count <= n) {
@@ -6149,11 +6141,11 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 lookup:
 	rcu_read_lock();
 
-	sg = radix_tree_lookup(&iter->radix, n);
+	sg = xa_load(&iter->xa, n);
 	GEM_BUG_ON(!sg);
 
 	/* If this index is in the middle of multi-page sg entry,
-	 * the radix tree will contain a value entry that points
+	 * the xarray will contain a value entry that points
 	 * to the start of that range. We will return the pointer to
 	 * the base page and the offset of this page within the
 	 * sg entry's range.
@@ -6162,7 +6154,7 @@ i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
 	if (unlikely(xa_is_value(sg))) {
 		unsigned long base = xa_to_value(sg);
 
-		sg = radix_tree_lookup(&iter->radix, base);
+		sg = xa_load(&iter->xa, base);
 		GEM_BUG_ON(!sg);
 
 		*offset = n - base;
diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
index ec22de370a22..052ad66a5bae 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.h
+++ b/drivers/gpu/drm/i915/i915_gem_context.h
@@ -27,7 +27,7 @@
 
 #include <linux/bitops.h>
 #include <linux/list.h>
-#include <linux/radix-tree.h>
+#include <linux/xarray.h>
 
 #include "i915_gem.h"
 #include "i915_scheduler.h"
diff --git a/drivers/gpu/drm/i915/i915_gem_object.h b/drivers/gpu/drm/i915/i915_gem_object.h
index 7f6493229f50..9febe70b4da9 100644
--- a/drivers/gpu/drm/i915/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/i915_gem_object.h
@@ -40,7 +40,7 @@ struct drm_i915_gem_object;
 
 /*
  * struct i915_lut_handle tracks the fast lookups from handle to vma used
- * for execbuf. Although we use a radixtree for that mapping, in order to
+ * for execbuf. Although we use an xarray for that mapping, in order to
  * remove them as the object or context is closed, we need a secondary list
  * and a translation entry (i915_lut_handle).
  */
@@ -218,7 +218,7 @@ struct drm_i915_gem_object {
 			struct scatterlist *sg_pos;
 			unsigned int sg_idx; /* in pages, but 32bit eek! */
 
-			struct radix_tree_root radix;
+			struct xarray xa;
 			struct mutex lock; /* protects this cache */
 		} get_page;
 
-- 
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 ` Matthew Wilcox [this message]
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 ` [PATCH 27/34] drm/qxl: Convert surf_id_idr " Matthew Wilcox
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-42-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.