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 13/20] drm/i915/gt: Guard timeline pinning with its own mutex
Date: Tue, 25 Jun 2019 14:01:21 +0100	[thread overview]
Message-ID: <20190625130128.11009-13-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190625130128.11009-1-chris@chris-wilson.co.uk>

In preparation for removing struct_mutex from around context retirement,
we need to make timeline pinning safe. Since multiple engines/contexts
can share a single timeline, it needs to be protected by a mutex.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/gt/intel_timeline.c      | 29 +++++++++----------
 .../gpu/drm/i915/gt/intel_timeline_types.h    |  2 +-
 drivers/gpu/drm/i915/gt/mock_engine.c         |  6 ++--
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.c b/drivers/gpu/drm/i915/gt/intel_timeline.c
index 672bccbfd797..d7dcf54b18c5 100644
--- a/drivers/gpu/drm/i915/gt/intel_timeline.c
+++ b/drivers/gpu/drm/i915/gt/intel_timeline.c
@@ -221,7 +221,9 @@ int intel_timeline_init(struct intel_timeline *timeline,
 	BUILD_BUG_ON(KSYNCMAP < I915_NUM_ENGINES);
 
 	timeline->gt = gt;
-	timeline->pin_count = 0;
+
+	atomic_set(&timeline->pin_count, 0);
+
 	timeline->has_initial_breadcrumb = !hwsp;
 	timeline->hwsp_cacheline = NULL;
 
@@ -287,7 +289,7 @@ void intel_timelines_init(struct drm_i915_private *i915)
 
 void intel_timeline_fini(struct intel_timeline *timeline)
 {
-	GEM_BUG_ON(timeline->pin_count);
+	GEM_BUG_ON(atomic_read(&timeline->pin_count));
 	GEM_BUG_ON(!list_empty(&timeline->requests));
 
 	if (timeline->hwsp_cacheline)
@@ -323,33 +325,31 @@ int intel_timeline_pin(struct intel_timeline *tl)
 {
 	int err;
 
-	if (tl->pin_count++)
+	if (atomic_add_unless(&tl->pin_count, 1, 0))
 		return 0;
-	GEM_BUG_ON(!tl->pin_count);
-	GEM_BUG_ON(tl->active_count);
 
 	err = i915_vma_pin(tl->hwsp_ggtt, 0, 0, PIN_GLOBAL | PIN_HIGH);
 	if (err)
-		goto unpin;
+		return err;
 
 	tl->hwsp_offset =
 		i915_ggtt_offset(tl->hwsp_ggtt) +
 		offset_in_page(tl->hwsp_offset);
 
 	cacheline_acquire(tl->hwsp_cacheline);
+	if (atomic_fetch_inc(&tl->pin_count)) {
+		cacheline_release(tl->hwsp_cacheline);
+		__i915_vma_unpin(tl->hwsp_ggtt);
+	}
 
 	return 0;
-
-unpin:
-	tl->pin_count = 0;
-	return err;
 }
 
 void intel_timeline_enter(struct intel_timeline *tl)
 {
 	struct intel_gt_timelines *timelines = &tl->gt->timelines;
 
-	GEM_BUG_ON(!tl->pin_count);
+	GEM_BUG_ON(!atomic_read(&tl->pin_count));
 	if (tl->active_count++)
 		return;
 	GEM_BUG_ON(!tl->active_count); /* overflow? */
@@ -381,7 +381,7 @@ void intel_timeline_exit(struct intel_timeline *tl)
 
 static u32 timeline_advance(struct intel_timeline *tl)
 {
-	GEM_BUG_ON(!tl->pin_count);
+	GEM_BUG_ON(!atomic_read(&tl->pin_count));
 	GEM_BUG_ON(tl->seqno & tl->has_initial_breadcrumb);
 
 	return tl->seqno += 1 + tl->has_initial_breadcrumb;
@@ -532,11 +532,10 @@ int intel_timeline_read_hwsp(struct i915_request *from,
 
 void intel_timeline_unpin(struct intel_timeline *tl)
 {
-	GEM_BUG_ON(!tl->pin_count);
-	if (--tl->pin_count)
+	GEM_BUG_ON(!atomic_read(&tl->pin_count));
+	if (!atomic_dec_and_test(&tl->pin_count))
 		return;
 
-	GEM_BUG_ON(tl->active_count);
 	cacheline_release(tl->hwsp_cacheline);
 
 	__i915_vma_unpin(tl->hwsp_ggtt);
diff --git a/drivers/gpu/drm/i915/gt/intel_timeline_types.h b/drivers/gpu/drm/i915/gt/intel_timeline_types.h
index b820ee76b7f5..8dd14a2b8781 100644
--- a/drivers/gpu/drm/i915/gt/intel_timeline_types.h
+++ b/drivers/gpu/drm/i915/gt/intel_timeline_types.h
@@ -25,7 +25,7 @@ struct intel_timeline {
 
 	struct mutex mutex; /* protects the flow of requests */
 
-	unsigned int pin_count;
+	atomic_t pin_count;
 	const u32 *hwsp_seqno;
 	struct i915_vma *hwsp_ggtt;
 	u32 hwsp_offset;
diff --git a/drivers/gpu/drm/i915/gt/mock_engine.c b/drivers/gpu/drm/i915/gt/mock_engine.c
index 490ebd121f4c..a48b36d31e65 100644
--- a/drivers/gpu/drm/i915/gt/mock_engine.c
+++ b/drivers/gpu/drm/i915/gt/mock_engine.c
@@ -38,13 +38,13 @@ struct mock_ring {
 
 static void mock_timeline_pin(struct intel_timeline *tl)
 {
-	tl->pin_count++;
+	atomic_inc(&tl->pin_count);
 }
 
 static void mock_timeline_unpin(struct intel_timeline *tl)
 {
-	GEM_BUG_ON(!tl->pin_count);
-	tl->pin_count--;
+	GEM_BUG_ON(!atomic_read(&tl->pin_count));
+	atomic_dec(&tl->pin_count);
 }
 
 static struct intel_ring *mock_ring(struct intel_engine_cs *engine)
-- 
2.20.1

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

  parent reply	other threads:[~2019-06-25 13:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 13:01 [PATCH 01/20] drm/i915/execlists: Convert recursive defer_request() into iterative Chris Wilson
2019-06-25 13:01 ` [PATCH 02/20] drm/i915/gt: Pass intel_gt to pm routines Chris Wilson
2019-06-25 18:07   ` Matthew Auld
2019-06-25 13:01 ` [PATCH 03/20] drm/i915/selftests: Serialise nop reset with retirement Chris Wilson
2019-06-25 13:01 ` [PATCH 04/20] drm/i915/selftests: Drop manual request wakerefs around hangcheck Chris Wilson
2019-06-25 13:01 ` [PATCH 05/20] drm/i915/selftests: Fixup atomic reset checking Chris Wilson
2019-06-25 13:01 ` [PATCH 06/20] drm/i915: Rename intel_wakeref_[is]_active Chris Wilson
2019-06-25 13:01 ` [PATCH 07/20] drm/i915: Add a wakeref getter for iff the wakeref is already active Chris Wilson
2019-06-25 13:01 ` [PATCH 08/20] drm/i915: Only recover active engines Chris Wilson
2019-06-25 13:01 ` [PATCH 09/20] drm/i915: Lift intel_engines_resume() to callers Chris Wilson
2019-06-25 13:01 ` [PATCH 10/20] drm/i915: Teach execbuffer to take the engine wakeref not GT Chris Wilson
2019-06-25 13:01 ` [PATCH 11/20] drm/i915/gt: Track timeline activeness in enter/exit Chris Wilson
2019-06-25 13:01 ` [PATCH 12/20] drm/i915/gt: Convert timeline tracking to spinlock Chris Wilson
2019-06-25 13:01 ` Chris Wilson [this message]
2019-06-25 13:01 ` [PATCH 14/20] drm/i915/selftests: Hold ref on request across waits Chris Wilson
2019-06-25 18:39   ` Matthew Auld
2019-06-25 13:01 ` [PATCH 15/20] drm/i915/gt: Always call kref_init for the timeline Chris Wilson
2019-06-25 18:42   ` Matthew Auld
2019-06-25 13:01 ` [PATCH 16/20] drm/i915/gt: Drop stale commentary for timeline density Chris Wilson
2019-06-25 23:28   ` Daniele Ceraolo Spurio
2019-06-25 13:01 ` [PATCH 17/20] drm/i915/gt: Add some debug tracing for context pinning Chris Wilson
2019-06-25 18:47   ` Matthew Auld
2019-06-25 13:01 ` [PATCH 18/20] drm/i915: Include the breadcrumb when asserting request completion Chris Wilson
2019-06-25 14:42   ` [PATCH] " Chris Wilson
2019-06-25 13:01 ` [PATCH 19/20] drm/i915: Protect request retirement with timeline->mutex Chris Wilson
2019-06-25 13:01 ` [PATCH 20/20] drm/i915: Replace struct_mutex for batch pool serialisation Chris Wilson
2019-06-25 14:09 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/20] drm/i915/execlists: Convert recursive defer_request() into iterative Patchwork
2019-06-25 14:38 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-06-25 15:10 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/20] drm/i915/execlists: Convert recursive defer_request() into iterative (rev2) Patchwork
2019-06-25 15:18 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-06-25 15:45 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-06-25 18:01 ` [PATCH 01/20] drm/i915/execlists: Convert recursive defer_request() into iterative Matthew Auld
2019-06-25 18:19 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/20] drm/i915/execlists: Convert recursive defer_request() into iterative (rev3) Patchwork
2019-06-25 18:28 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-06-25 19:35 ` ✓ Fi.CI.BAT: success " Patchwork
2019-06-25 22:10 ` ✓ Fi.CI.IGT: " 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=20190625130128.11009-13-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.