intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH] drm/i915/gem: Avoid gem_context->mutex for simple vma lookup
@ 2020-03-16 22:51 Chris Wilson
  2020-03-17  1:30 ` [Intel-gfx] ✗ Fi.CI.DOCS: warning for " Patchwork
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Chris Wilson @ 2020-03-16 22:51 UTC (permalink / raw)
  To: intel-gfx

As we store the handle lookup inside a radix tree, we do not need the
gem_context->mutex except until we need to insert our lookup into the
common radix tree. This takes a small bit of rearranging to ensure that
the lut we insert into the tree is ready prior to actually inserting it
(as soon as it is exposed via the radixtree, it is visible to any other
submission).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 33 +++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index d3f4f28e9468..d2f15833c417 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -481,7 +481,7 @@ eb_add_vma(struct i915_execbuffer *eb,
 
 	GEM_BUG_ON(i915_vma_is_closed(vma));
 
-	ev->vma = i915_vma_get(vma);
+	ev->vma = vma;
 	ev->exec = entry;
 	ev->flags = entry->flags;
 
@@ -748,7 +748,12 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
 		struct i915_lut_handle *lut;
 		struct i915_vma *vma;
 
+lookup:
+		rcu_read_lock();
 		vma = radix_tree_lookup(handles_vma, handle);
+		if (likely(vma))
+			vma = i915_vma_tryget(vma);
+		rcu_read_unlock();
 		if (likely(vma))
 			goto add_vma;
 
@@ -770,18 +775,28 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
 			goto err_obj;
 		}
 
-		err = radix_tree_insert(handles_vma, handle, vma);
-		if (unlikely(err)) {
-			i915_lut_handle_free(lut);
-			goto err_obj;
-		}
-
 		/* transfer ref to lut */
+		i915_gem_object_get(obj);
 		if (!atomic_fetch_inc(&vma->open_count))
 			i915_vma_reopen(vma);
 		lut->handle = handle;
 		lut->ctx = eb->gem_context;
 
+		mutex_lock(&eb->gem_context->mutex);
+		err = -ENOENT;
+		if (unlikely(!i915_gem_context_is_closed(eb->gem_context)))
+			err = radix_tree_insert(handles_vma, handle, vma);
+		mutex_unlock(&eb->gem_context->mutex);
+		if (unlikely(err)) {
+			atomic_dec(&vma->open_count);
+			i915_gem_object_put(obj);
+			i915_lut_handle_free(lut);
+			i915_gem_object_put(obj);
+			if (err == -EEXIST)
+				goto lookup;
+			goto err_vma;
+		}
+
 		i915_gem_object_lock(obj);
 		list_add(&lut->obj_link, &obj->lut_list);
 		i915_gem_object_unlock(obj);
@@ -789,7 +804,7 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
 add_vma:
 		err = eb_validate_vma(eb, &eb->exec[i], vma);
 		if (unlikely(err))
-			goto err_vma;
+			goto err_obj;
 
 		eb_add_vma(eb, i, batch, vma);
 	}
@@ -1494,9 +1509,7 @@ static int eb_relocate(struct i915_execbuffer *eb)
 {
 	int err;
 
-	mutex_lock(&eb->gem_context->mutex);
 	err = eb_lookup_vmas(eb);
-	mutex_unlock(&eb->gem_context->mutex);
 	if (err)
 		return err;
 
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-03-18  4:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 22:51 [Intel-gfx] [PATCH] drm/i915/gem: Avoid gem_context->mutex for simple vma lookup Chris Wilson
2020-03-17  1:30 ` [Intel-gfx] ✗ Fi.CI.DOCS: warning for " Patchwork
2020-03-17  1:38 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-03-17 10:59 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2020-03-17 12:17 ` [Intel-gfx] [PATCH] " Chris Wilson
2020-03-17 12:58 ` [Intel-gfx] ✗ Fi.CI.DOCS: warning for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev2) Patchwork
2020-03-17 13:10 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-03-17 13:55 ` [Intel-gfx] [PATCH] drm/i915/gem: Avoid gem_context->mutex for simple vma lookup Dan Carpenter
2020-03-17 14:09 ` [Intel-gfx] [PATCH v2] " Chris Wilson
2020-03-17 19:11   ` [Intel-gfx] [PATCH v3] " Chris Wilson
2020-03-17 20:25     ` [Intel-gfx] [PATCH] " Chris Wilson
2020-03-17 15:49 ` [Intel-gfx] ✗ Fi.CI.DOCS: warning for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev3) Patchwork
2020-03-17 16:00 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-03-17 18:05 ` [Intel-gfx] ✓ Fi.CI.IGT: success for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev2) Patchwork
2020-03-17 19:53 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev4) Patchwork
2020-03-17 21:31 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev5) Patchwork
2020-03-17 22:09 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev3) Patchwork
2020-03-18  4:33 ` [Intel-gfx] ✓ Fi.CI.IGT: success for drm/i915/gem: Avoid gem_context->mutex for simple vma lookup (rev5) Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).