All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Subject: [Intel-gfx] [PATCH 05/11] drm/i915/gem: Utilize rcu iteration of context engines
Date: Tue, 31 Mar 2020 22:31:02 +0100	[thread overview]
Message-ID: <20200331213108.11340-5-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20200331213108.11340-1-chris@chris-wilson.co.uk>

Now that we can peek at GEM->engines[] and obtain a reference to them
using RCU, do so for instances where we can safely iterate the
potentially old copy of the engines. For setting, we can do this when we
know the engine properties are copied over before swapping, so we know
the new engines already have the global property and we update the old
before they are discarded. For reading, we only need to be safe; as we
do so on behalf of the user, their races are their own problem.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 56 ++++++++++-----------
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 50e7580f9337..a8780ddc07c0 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -757,21 +757,46 @@ __create_context(struct drm_i915_private *i915)
 	return ERR_PTR(err);
 }
 
+static inline struct i915_gem_engines *
+__context_engines_await(const struct i915_gem_context *ctx)
+{
+	struct i915_gem_engines *engines;
+
+	rcu_read_lock();
+	do {
+		engines = rcu_dereference(ctx->engines);
+		GEM_BUG_ON(!engines);
+
+		if (unlikely(!i915_sw_fence_await(&engines->fence)))
+			continue;
+
+		if (likely(engines == rcu_access_pointer(ctx->engines)))
+			break;
+
+		i915_sw_fence_complete(&engines->fence);
+	} while (1);
+	rcu_read_unlock();
+
+	return engines;
+}
+
 static int
 context_apply_all(struct i915_gem_context *ctx,
 		  int (*fn)(struct intel_context *ce, void *data),
 		  void *data)
 {
 	struct i915_gem_engines_iter it;
+	struct i915_gem_engines *e;
 	struct intel_context *ce;
 	int err = 0;
 
-	for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
+	e = __context_engines_await(ctx);
+	for_each_gem_engine(ce, e, it) {
 		err = fn(ce, data);
 		if (err)
 			break;
 	}
-	i915_gem_context_unlock_engines(ctx);
+	i915_sw_fence_complete(&e->fence);
 
 	return err;
 }
@@ -858,10 +883,7 @@ i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
 			return ERR_CAST(ppgtt);
 		}
 
-		mutex_lock(&ctx->mutex);
 		__assign_ppgtt(ctx, &ppgtt->vm);
-		mutex_unlock(&ctx->mutex);
-
 		i915_vm_put(&ppgtt->vm);
 	}
 
@@ -1069,30 +1091,6 @@ static void cb_retire(struct i915_active *base)
 	kfree(cb);
 }
 
-static inline struct i915_gem_engines *
-__context_engines_await(const struct i915_gem_context *ctx)
-{
-	struct i915_gem_engines *engines;
-
-	rcu_read_lock();
-	do {
-		engines = rcu_dereference(ctx->engines);
-		if (unlikely(!engines))
-			break;
-
-		if (unlikely(!i915_sw_fence_await(&engines->fence)))
-			continue;
-
-		if (likely(engines == rcu_access_pointer(ctx->engines)))
-			break;
-
-		i915_sw_fence_complete(&engines->fence);
-	} while (1);
-	rcu_read_unlock();
-
-	return engines;
-}
-
 I915_SELFTEST_DECLARE(static intel_engine_mask_t context_barrier_inject_fault);
 static int context_barrier_task(struct i915_gem_context *ctx,
 				intel_engine_mask_t engines,
-- 
2.20.1

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

  parent reply	other threads:[~2020-03-31 21:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 21:30 [Intel-gfx] [PATCH 01/11] drm/i915/gem: Ignore readonly failures when updating relocs Chris Wilson
2020-03-31 21:30 ` [PATCH 02/11] drm/i915/gt: Fill all the unused space in the GGTT Chris Wilson
2020-03-31 21:30   ` [Intel-gfx] " Chris Wilson
2020-03-31 21:31 ` [Intel-gfx] [PATCH 03/11] drm/i915/execlists: Peek at the next submission for error interrupts Chris Wilson
2020-03-31 21:31 ` [Intel-gfx] [PATCH 04/11] drm/i915/execlists: Record the active CCID from before reset Chris Wilson
2020-03-31 21:31 ` Chris Wilson [this message]
2020-03-31 21:31 ` [Intel-gfx] [PATCH 06/11] drm/i915/gem: Prevent switching of active GEM context VM Chris Wilson
2020-03-31 21:31 ` [Intel-gfx] [PATCH 07/11] drm/i915/gem: Try allocating va from free space Chris Wilson
2020-04-01 18:20   ` Matthew Auld
2020-04-01 18:30     ` Chris Wilson
2020-03-31 21:31 ` [Intel-gfx] [PATCH 08/11] drm/i915/gt: Only wait for GPU activity before unbinding a GGTT fence Chris Wilson
2020-04-01 18:56   ` Matthew Auld
2020-04-01 19:02     ` Chris Wilson
2020-04-01 19:25       ` Matthew Auld
2020-03-31 21:31 ` [Intel-gfx] [PATCH 09/11] drm/i915/gt: Store the fence details on the fence Chris Wilson
2020-04-01 19:07   ` Matthew Auld
2020-03-31 21:31 ` [Intel-gfx] [PATCH 10/11] drm/i915/gt: Make fence revocation unequivocal Chris Wilson
2020-04-01 19:14   ` Matthew Auld
2020-03-31 21:31 ` [Intel-gfx] [PATCH 11/11] drm/i915/gem: Drop cached obj->bind_count Chris Wilson
2020-04-01 19:22   ` Matthew Auld
2020-04-01  0:22 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for series starting with [01/11] drm/i915/gem: Ignore readonly failures when updating relocs Patchwork

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=20200331213108.11340-5-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@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.