All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 24/31] drm/i915: Track the last-active inside the i915_vma
Date: Mon, 25 Jun 2018 10:48:35 +0100	[thread overview]
Message-ID: <20180625094842.8499-24-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20180625094842.8499-1-chris@chris-wilson.co.uk>

Using a VMA on more than one timeline concurrently is the exception
rather than the rule (using it concurrently on multiple engines). As we
expect to only use one active tracker, store the most recently used
tracker inside the i915_vma itself and only fallback to the radixtree if
we need a second or more concurrent active trackers.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_vma.c | 46 ++++++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_vma.h |  1 +
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 6bed7a2924cd..0158d46e38ed 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -88,6 +88,12 @@ i915_vma_retire(struct i915_gem_active *base, struct i915_request *rq)
 	__i915_vma_retire(vma, rq);
 }
 
+static void
+i915_vma_last_retire(struct i915_gem_active *base, struct i915_request *rq)
+{
+	__i915_vma_retire(container_of(base, struct i915_vma, last_active), rq);
+}
+
 static struct i915_vma *
 vma_create(struct drm_i915_gem_object *obj,
 	   struct i915_address_space *vm,
@@ -105,6 +111,7 @@ vma_create(struct drm_i915_gem_object *obj,
 
 	INIT_RADIX_TREE(&vma->active_rt, GFP_KERNEL);
 
+	init_request_active(&vma->last_active, i915_vma_last_retire);
 	init_request_active(&vma->last_fence, NULL);
 	vma->vm = vm;
 	vma->ops = &vm->vma_ops;
@@ -870,8 +877,14 @@ static void export_fence(struct i915_vma *vma,
 static struct i915_gem_active *lookup_active(struct i915_vma *vma, u64 idx)
 {
 	struct i915_vma_active *active;
+	struct i915_request *old;
 	int err;
 
+	old = i915_gem_active_raw(&vma->last_active,
+				  &vma->vm->i915->drm.struct_mutex);
+	if (!old || old->fence.context == idx)
+		goto out;
+
 	/*
 	 * XXX Note that the radix_tree uses unsigned longs for it indices,
 	 * a problem for us on i386 with 32bit longs. However, the likelihood
@@ -879,13 +892,9 @@ static struct i915_gem_active *lookup_active(struct i915_vma *vma, u64 idx)
 	 * and further reduced by that both timelines must be active
 	 * simultaneously to confuse us.
 	 */
-	active = radix_tree_lookup(&vma->active_rt, idx);
-	if (likely(active)) {
-		GEM_BUG_ON(i915_gem_active_isset(&active->base) &&
-			   idx != i915_gem_active_peek(&active->base,
-						       &vma->vm->i915->drm.struct_mutex)->fence.context);
-		return &active->base;
-	}
+	active = radix_tree_lookup(&vma->active_rt, old->fence.context);
+	if (likely(active))
+		goto replace;
 
 	active = kmalloc(sizeof(*active), GFP_KERNEL);
 	if (unlikely(!active))
@@ -894,13 +903,27 @@ static struct i915_gem_active *lookup_active(struct i915_vma *vma, u64 idx)
 	init_request_active(&active->base, i915_vma_retire);
 	active->vma = vma;
 
-	err = radix_tree_insert(&vma->active_rt, idx, active);
+	err = radix_tree_insert(&vma->active_rt, old->fence.context, active);
 	if (unlikely(err)) {
 		kfree(active);
 		return ERR_PTR(err);
 	}
 
-	return &active->base;
+replace:
+	if (i915_gem_active_isset(&active->base)) {
+		GEM_BUG_ON(old->fence.context !=
+			   i915_gem_active_raw(&active->base,
+					       &vma->vm->i915->drm.struct_mutex)->fence.context);
+		__list_del_entry(&active->base.link);
+		vma->active_count--;
+		GEM_BUG_ON(!vma->active_count);
+	}
+	GEM_BUG_ON(list_empty(&vma->last_active.link));
+	list_replace_init(&vma->last_active.link, &active->base.link);
+	active->base.request = fetch_and_zero(&vma->last_active.request);
+
+out:
+	return &vma->last_active;
 }
 
 int i915_vma_move_to_active(struct i915_vma *vma,
@@ -981,6 +1004,11 @@ int i915_vma_unbind(struct i915_vma *vma)
 		 */
 		__i915_vma_pin(vma);
 
+		ret = i915_gem_active_retire(&vma->last_active,
+					     &vma->vm->i915->drm.struct_mutex);
+		if (ret)
+			goto unpin;
+
 		rcu_read_lock();
 		radix_tree_for_each_slot(slot, &vma->active_rt, &iter, 0) {
 			struct i915_vma_active *active =
diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
index 94fdf4917e95..1d3080603a18 100644
--- a/drivers/gpu/drm/i915/i915_vma.h
+++ b/drivers/gpu/drm/i915/i915_vma.h
@@ -97,6 +97,7 @@ struct i915_vma {
 
 	unsigned int active_count;
 	struct radix_tree_root active_rt;
+	struct i915_gem_active last_active;
 	struct i915_gem_active last_fence;
 
 	/**
-- 
2.18.0

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

  parent reply	other threads:[~2018-06-25  9:49 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-25  9:48 [PATCH 01/31] drm/i915: Defer modeset cleanup to a secondary task Chris Wilson
2018-06-25  9:48 ` [PATCH 02/31] drm/i915/execlists: Check for ce->state before destroy Chris Wilson
2018-06-25  9:48 ` [PATCH 03/31] drm/i915/execlists: Pull submit after dequeue under timeline lock Chris Wilson
2018-06-25 10:51   ` Tvrtko Ursulin
2018-06-25 10:55     ` Chris Wilson
2018-06-25  9:48 ` [PATCH 04/31] drm/i915/execlists: Pull CSB reset under the timeline.lock Chris Wilson
2018-06-26 10:59   ` Tvrtko Ursulin
2018-06-26 11:04     ` Chris Wilson
2018-06-26 11:50   ` [PATCH v4] " Chris Wilson
2018-06-27  9:33     ` Tvrtko Ursulin
2018-06-25  9:48 ` [PATCH 05/31] drm/i915/execlists: Process one CSB update at a time Chris Wilson
2018-06-27  9:46   ` Tvrtko Ursulin
2018-06-27 10:26     ` Chris Wilson
2018-06-27 10:43   ` [PATCH v2] " Chris Wilson
2018-06-25  9:48 ` [PATCH 06/31] drm/i915/execlists: Unify CSB access pointers Chris Wilson
2018-06-27  9:52   ` Tvrtko Ursulin
2018-06-27 10:35     ` Chris Wilson
2018-06-27 13:03       ` Tvrtko Ursulin
2018-06-27 13:09         ` Chris Wilson
2018-06-27 13:24           ` Tvrtko Ursulin
2018-06-27 13:32             ` Chris Wilson
2018-06-27 11:21     ` [PATCH] drm/i915/execlists: Reset CSB write pointer after reset Chris Wilson
2018-06-25  9:48 ` [PATCH 07/31] drm/i915/execlists: Direct submission of new requests (avoid tasklet/ksoftirqd) Chris Wilson
2018-06-27 10:40   ` Tvrtko Ursulin
2018-06-27 10:58     ` Chris Wilson
2018-06-27 13:15       ` Tvrtko Ursulin
2018-06-27 13:29         ` Chris Wilson
2018-06-27 15:21           ` Tvrtko Ursulin
2018-06-27 15:28             ` Chris Wilson
2018-06-28 11:56               ` Tvrtko Ursulin
2018-06-28 12:07                 ` Chris Wilson
2018-06-28 12:11                   ` Chris Wilson
2018-06-28 12:29                     ` Tvrtko Ursulin
2018-06-28 12:35                       ` Chris Wilson
2018-06-28 13:03                         ` Tvrtko Ursulin
2018-06-25  9:48 ` [PATCH 08/31] drm/i915: Move rate-limiting request retire to after submission Chris Wilson
2018-06-27 10:57   ` Tvrtko Ursulin
2018-06-27 11:16     ` Chris Wilson
2018-06-27 13:28       ` Tvrtko Ursulin
2018-06-27 13:37         ` Chris Wilson
2018-06-25  9:48 ` [PATCH 09/31] drm/i915: Wait for engines to idle before retiring Chris Wilson
2018-06-27 11:32   ` Tvrtko Ursulin
2018-06-27 11:41     ` Chris Wilson
2018-06-25  9:48 ` [PATCH 10/31] drm/i915: Move engine request retirement to intel_engine_cs Chris Wilson
2018-06-25  9:48 ` [PATCH 11/31] drm/i915: Hold request reference for submission until retirement Chris Wilson
2018-06-25  9:48 ` [PATCH 12/31] drm/i915: Reduce spinlock hold time during notify_ring() interrupt Chris Wilson
2018-06-27 13:08   ` Mika Kuoppala
2018-06-27 13:14     ` Chris Wilson
2018-06-27 14:01       ` Mika Kuoppala
2018-06-25  9:48 ` [PATCH 13/31] drm/i915: Move the irq_counter inside the spinlock Chris Wilson
2018-06-27 14:23   ` Mika Kuoppala
2018-06-25  9:48 ` [PATCH 14/31] drm/i915: Only signal from interrupt when requested Chris Wilson
2018-06-27 14:52   ` Mika Kuoppala
2018-06-25  9:48 ` [PATCH 15/31] drm/i915/execlists: Switch to rb_root_cached Chris Wilson
2018-06-25  9:48 ` [PATCH 16/31] drm/i915: Reserve some priority bits for internal use Chris Wilson
2018-06-25  9:48 ` [PATCH 17/31] drm/i915: Combine multiple internal plists into the same i915_priolist bucket Chris Wilson
2018-06-25  9:48 ` [PATCH 18/31] drm/i915: Priority boost for new clients Chris Wilson
2018-06-25  9:48 ` [PATCH 19/31] drm/i915: Priority boost switching to an idle ring Chris Wilson
2018-06-25  9:48 ` [PATCH 20/31] drm/i915: Refactor export_fence() after i915_vma_move_to_active() Chris Wilson
2018-06-25  9:48 ` [PATCH 21/31] drm/i915: Export i915_request_skip() Chris Wilson
2018-06-25  9:48 ` [PATCH 22/31] drm/i915: Start returning an error from i915_vma_move_to_active() Chris Wilson
2018-06-25  9:48 ` [PATCH 23/31] drm/i915: Track vma activity per fence.context, not per engine Chris Wilson
2018-06-25  9:48 ` Chris Wilson [this message]
2018-06-25  9:48 ` [PATCH 25/31] drm/i915: Stop tracking MRU activity on VMA Chris Wilson
2018-06-25  9:48 ` [PATCH 26/31] drm/i915: Introduce i915_address_space.mutex Chris Wilson
2018-06-25  9:48 ` [PATCH 27/31] drm/i915: Move fence register tracking to GGTT Chris Wilson
2018-06-25  9:48 ` [PATCH 28/31] drm/i915: Convert fences to use a GGTT lock rather than struct_mutex Chris Wilson
2018-06-25  9:48 ` [PATCH 29/31] drm/i915: Tidy i915_gem_suspend() Chris Wilson
2018-06-25  9:48 ` [PATCH 30/31] drm/i915: Pull all the reset functionality together into i915_reset.c Chris Wilson
2018-06-25  9:48 ` [PATCH 31/31] drm/i915: Remove GPU reset dependence on struct_mutex Chris Wilson
2018-06-25 10:32 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/31] drm/i915: Defer modeset cleanup to a secondary task Patchwork
2018-06-25 10:44 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-06-25 10:57 ` ✓ Fi.CI.BAT: success " Patchwork
2018-06-25 14:44 ` ✗ Fi.CI.IGT: failure " Patchwork
2018-06-26  9:28   ` Chris Wilson
2018-06-26 11:51 ` ✗ Fi.CI.BAT: failure for series starting with [01/31] drm/i915: Defer modeset cleanup to a secondary task (rev2) Patchwork
2018-06-27 11:00 ` ✗ Fi.CI.BAT: failure for series starting with [01/31] drm/i915: Defer modeset cleanup to a secondary task (rev3) Patchwork
2018-06-27 12:27 ` ✗ Fi.CI.BAT: failure for series starting with [01/31] drm/i915: Defer modeset cleanup to a secondary task (rev4) 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=20180625094842.8499-24-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.