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 19/23] drm/i915/gt: Mark context->active_count as protected by timeline->mutex
Date: Tue, 23 Jul 2019 19:38:38 +0100	[thread overview]
Message-ID: <20190723183842.20372-19-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190723183842.20372-1-chris@chris-wilson.co.uk>

We use timeline->mutex to protect modifications to
context->active_count, and the associated enable/disable callbacks.
Due to complications with engine-pm barrier there is a path where we used
a "superlock" to provide serialised protect and so could not
unconditionally assert with lockdep that it was always held. However,
we can mark the mutex as taken (noting that we may be nested underneath
ourselves) which means we can be reassured the right timeline->mutex is
always treated as held and let lockdep roam free.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/gt/intel_context.h       |  3 +++
 drivers/gpu/drm/i915/gt/intel_context_types.h |  2 +-
 drivers/gpu/drm/i915/gt/intel_engine_pm.c     | 12 ++++++++++++
 drivers/gpu/drm/i915/gt/intel_timeline.c      |  4 ++++
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h
index 0772f77394c5..08e512fc4ed0 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.h
+++ b/drivers/gpu/drm/i915/gt/intel_context.h
@@ -89,17 +89,20 @@ void intel_context_exit_engine(struct intel_context *ce);
 
 static inline void intel_context_enter(struct intel_context *ce)
 {
+	lockdep_assert_held(&ce->ring->timeline->mutex);
 	if (!ce->active_count++)
 		ce->ops->enter(ce);
 }
 
 static inline void intel_context_mark_active(struct intel_context *ce)
 {
+	lockdep_assert_held(&ce->ring->timeline->mutex);
 	++ce->active_count;
 }
 
 static inline void intel_context_exit(struct intel_context *ce)
 {
+	lockdep_assert_held(&ce->ring->timeline->mutex);
 	GEM_BUG_ON(!ce->active_count);
 	if (!--ce->active_count)
 		ce->ops->exit(ce);
diff --git a/drivers/gpu/drm/i915/gt/intel_context_types.h b/drivers/gpu/drm/i915/gt/intel_context_types.h
index 68a7e979b1a9..92afc207ec80 100644
--- a/drivers/gpu/drm/i915/gt/intel_context_types.h
+++ b/drivers/gpu/drm/i915/gt/intel_context_types.h
@@ -55,7 +55,7 @@ struct intel_context {
 	u32 *lrc_reg_state;
 	u64 lrc_desc;
 
-	unsigned int active_count; /* notionally protected by timeline->mutex */
+	unsigned int active_count; /* protected by timeline->mutex */
 
 	atomic_t pin_count;
 	struct mutex pin_mutex; /* guards pinning and associated on-gpuing */
diff --git a/drivers/gpu/drm/i915/gt/intel_engine_pm.c b/drivers/gpu/drm/i915/gt/intel_engine_pm.c
index 76c828d11b05..1218b7d53b88 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine_pm.c
+++ b/drivers/gpu/drm/i915/gt/intel_engine_pm.c
@@ -59,6 +59,16 @@ void intel_engine_park(struct intel_engine_cs *engine)
 	}
 }
 
+static inline void __timeline_mark_lock(struct intel_context *ce)
+{
+	mutex_acquire(&ce->ring->timeline->mutex.dep_map, 2, 0, _THIS_IP_);
+}
+
+static inline void __timeline_mark_unlock(struct intel_context *ce)
+{
+	mutex_release(&ce->ring->timeline->mutex.dep_map, 0, _THIS_IP_);
+}
+
 static bool switch_to_kernel_context(struct intel_engine_cs *engine)
 {
 	struct i915_request *rq;
@@ -83,6 +93,7 @@ static bool switch_to_kernel_context(struct intel_engine_cs *engine)
 	 * retiring the last request, thus all rings should be empty and
 	 * all timelines idle.
 	 */
+	__timeline_mark_lock(engine->kernel_context);
 	rq = __i915_request_create(engine->kernel_context, GFP_NOWAIT);
 	if (IS_ERR(rq))
 		/* Context switch failed, hope for the best! Maybe reset? */
@@ -94,6 +105,7 @@ static bool switch_to_kernel_context(struct intel_engine_cs *engine)
 
 	i915_request_add_barriers(rq);
 	__i915_request_commit(rq);
+	__timeline_mark_unlock(engine->kernel_context);
 
 	return false;
 }
diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.c b/drivers/gpu/drm/i915/gt/intel_timeline.c
index 7b476cd55dac..eafd94d5e211 100644
--- a/drivers/gpu/drm/i915/gt/intel_timeline.c
+++ b/drivers/gpu/drm/i915/gt/intel_timeline.c
@@ -338,6 +338,8 @@ void intel_timeline_enter(struct intel_timeline *tl)
 {
 	struct intel_gt_timelines *timelines = &tl->gt->timelines;
 
+	lockdep_assert_held(&tl->mutex);
+
 	GEM_BUG_ON(!atomic_read(&tl->pin_count));
 	if (tl->active_count++)
 		return;
@@ -352,6 +354,8 @@ void intel_timeline_exit(struct intel_timeline *tl)
 {
 	struct intel_gt_timelines *timelines = &tl->gt->timelines;
 
+	lockdep_assert_held(&tl->mutex);
+
 	GEM_BUG_ON(!tl->active_count);
 	if (--tl->active_count)
 		return;
-- 
2.22.0

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

  parent reply	other threads:[~2019-07-23 18:56 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 18:38 [PATCH 01/23] drm/i915: Move aliasing_ppgtt underneath its i915_ggtt Chris Wilson
2019-07-23 18:38 ` [PATCH 02/23] drm/i915/gt: Provide a local intel_context.vm Chris Wilson
2019-07-23 18:38 ` [PATCH 03/23] drm/i915: Remove lrc default desc from GEM context Chris Wilson
2019-07-24  9:20   ` Tvrtko Ursulin
2019-08-01  8:37     ` Tvrtko Ursulin
2019-08-01  8:41       ` Chris Wilson
2019-08-01  8:53         ` Tvrtko Ursulin
2019-08-01 10:57           ` Chris Wilson
2019-08-01 11:13             ` Chris Wilson
2019-08-01 15:29               ` Tvrtko Ursulin
2019-08-01 15:48                 ` Chris Wilson
2019-08-01 16:00                   ` Chris Wilson
2019-08-01 16:22                     ` Tvrtko Ursulin
2019-08-01 16:36                       ` Chris Wilson
2019-07-23 18:38 ` [PATCH 04/23] drm/i915: Push the ring creation flags to the backend Chris Wilson
2019-07-24 11:11   ` Tvrtko Ursulin
2019-07-26  8:43     ` Chris Wilson
2019-07-29 12:59       ` Tvrtko Ursulin
2019-07-30  9:38         ` Chris Wilson
2019-08-01  8:42           ` Tvrtko Ursulin
2019-08-01  8:45             ` Chris Wilson
2019-08-01  8:46             ` Chris Wilson
2019-07-23 18:38 ` [PATCH 05/23] drm/i915: Flush extra hard after writing relocations through the GTT Chris Wilson
2019-07-23 18:38 ` [PATCH 06/23] drm/i915: Hide unshrinkable context objects from the shrinker Chris Wilson
2019-07-23 18:38 ` [PATCH 07/23] drm/i915/gt: Move the [class][inst] lookup for engines onto the GT Chris Wilson
2019-07-25 21:21   ` Daniele Ceraolo Spurio
2019-07-26  9:22   ` Tvrtko Ursulin
2019-07-26  9:33     ` Chris Wilson
2019-07-26  9:51       ` Tvrtko Ursulin
2019-07-26  9:57         ` Chris Wilson
2019-07-23 18:38 ` [PATCH 08/23] drm/i915: Introduce for_each_user_engine() Chris Wilson
2019-07-23 18:38 ` [PATCH 09/23] drm/i915: Use intel_engine_lookup_user for probing HAS_BSD etc Chris Wilson
2019-07-23 18:38 ` [PATCH 10/23] drm/i915: Isolate i915_getparam_ioctl() Chris Wilson
2019-07-23 18:38 ` [PATCH 11/23] drm/i915: Only include active engines in the capture state Chris Wilson
2019-07-23 18:38 ` [PATCH 12/23] drm/i915: Teach execbuffer to take the engine wakeref not GT Chris Wilson
2019-07-23 18:38 ` [PATCH 13/23] drm/i915/gt: Track timeline activeness in enter/exit Chris Wilson
2019-07-23 18:38 ` [PATCH 14/23] drm/i915/gt: Convert timeline tracking to spinlock Chris Wilson
2019-07-23 18:38 ` [PATCH 15/23] drm/i915/gt: Guard timeline pinning with its own mutex Chris Wilson
2019-07-23 18:38 ` [PATCH 16/23] drm/i915/gt: Add to timeline requires the timeline mutex Chris Wilson
2019-07-23 18:38 ` [PATCH 17/23] drm/i915: Protect request retirement with timeline->mutex Chris Wilson
2019-07-23 18:38 ` [PATCH 18/23] drm/i915: Replace struct_mutex for batch pool serialisation Chris Wilson
2019-07-23 18:38 ` Chris Wilson [this message]
2019-07-23 18:38 ` [PATCH 20/23] drm/i915: Forgo last_fence active request tracking Chris Wilson
2019-07-23 18:38 ` [PATCH 21/23] drm/i915/overlay: Switch to using i915_active tracking Chris Wilson
2019-07-23 18:38 ` [PATCH 22/23] drm/i915: Extract intel_frontbuffer active tracking Chris Wilson
2019-07-23 18:38 ` [PATCH 23/23] drm/i915: Markup expected timeline locks for i915_active Chris Wilson
2019-07-23 20:16 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/23] drm/i915: Move aliasing_ppgtt underneath its i915_ggtt Patchwork
2019-07-23 20:27 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-07-23 20:38 ` ✓ Fi.CI.BAT: success " Patchwork
2019-07-24  4:13 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-07-24  8:56 ` [PATCH 01/23] " Tvrtko Ursulin
2019-07-24  9:27   ` Chris Wilson
2019-07-24  9:37     ` Chris Wilson
2019-07-24  9:47       ` Chris Wilson
2019-07-24  9:54         ` Tvrtko Ursulin

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=20190723183842.20372-19-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.