diff mbox

[2/3] drm/i915: Move fiddling with engine->last_retired_context

Message ID 20180419071746.15996-2-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson April 19, 2018, 7:17 a.m. UTC
Move the knowledge about resetting the current context tracking on the
engine from inside i915_gem_context.c into intel_engine_cs.c

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 12 ++----------
 drivers/gpu/drm/i915/intel_engine_cs.c  | 24 ++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_ringbuffer.h |  2 ++
 3 files changed, 28 insertions(+), 10 deletions(-)

Comments

Tvrtko Ursulin April 19, 2018, 10:45 a.m. UTC | #1
On 19/04/2018 08:17, Chris Wilson wrote:
> Move the knowledge about resetting the current context tracking on the
> engine from inside i915_gem_context.c into intel_engine_cs.c
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>   drivers/gpu/drm/i915/i915_gem_context.c | 12 ++----------
>   drivers/gpu/drm/i915/intel_engine_cs.c  | 24 ++++++++++++++++++++++++
>   drivers/gpu/drm/i915/intel_ringbuffer.h |  2 ++
>   3 files changed, 28 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> index 74435affe23f..2fe779cab298 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -514,16 +514,8 @@ void i915_gem_contexts_lost(struct drm_i915_private *dev_priv)
>   
>   	lockdep_assert_held(&dev_priv->drm.struct_mutex);
>   
> -	for_each_engine(engine, dev_priv, id) {
> -		engine->legacy_active_context = NULL;
> -		engine->legacy_active_ppgtt = NULL;
> -
> -		if (!engine->last_retired_context)
> -			continue;
> -
> -		engine->context_unpin(engine, engine->last_retired_context);
> -		engine->last_retired_context = NULL;
> -	}
> +	for_each_engine(engine, dev_priv, id)
> +		intel_engine_lost_context(engine);
>   }
>   
>   void i915_gem_contexts_fini(struct drm_i915_private *i915)
> diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c
> index 0248d64c2a72..4749426f9cad 100644
> --- a/drivers/gpu/drm/i915/intel_engine_cs.c
> +++ b/drivers/gpu/drm/i915/intel_engine_cs.c
> @@ -1084,6 +1084,30 @@ void intel_engines_unpark(struct drm_i915_private *i915)
>   	}
>   }
>   
> +
> +/**
> + * intel_engine_lost_context: called when the GPU is reset into unknown state
> + * @engine: the engine
> + *
> + * We have either reset the GPU or otherwise about to lose state tracking of
> + * the current GPU logical state (e.g. suspend). On next use, it is therefore
> + * imperative that we make no presumptions about the current state and load
> + * from scratch.
> + */
> +void intel_engine_lost_context(struct intel_engine_cs *engine)
> +{
> +	struct i915_gem_context *ctx;
> +
> +	lockdep_assert_held(&engine->i915->drm.struct_mutex);
> +
> +	engine->legacy_active_context = NULL;
> +	engine->legacy_active_ppgtt = NULL;
> +
> +	ctx = fetch_and_zero(&engine->last_retired_context);
> +	if (ctx)
> +		engine->context_unpin(engine, ctx);
> +}
> +
>   bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
>   {
>   	switch (INTEL_GEN(engine->i915)) {
> diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
> index c5e27905b0e1..1231695fb4da 100644
> --- a/drivers/gpu/drm/i915/intel_ringbuffer.h
> +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
> @@ -1044,6 +1044,8 @@ bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine);
>   void intel_engines_park(struct drm_i915_private *i915);
>   void intel_engines_unpark(struct drm_i915_private *i915);
>   
> +void intel_engine_lost_context(struct intel_engine_cs *engine);
> +
>   void intel_engines_reset_default_submission(struct drm_i915_private *i915);
>   unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915);
>   
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 74435affe23f..2fe779cab298 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -514,16 +514,8 @@  void i915_gem_contexts_lost(struct drm_i915_private *dev_priv)
 
 	lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
-	for_each_engine(engine, dev_priv, id) {
-		engine->legacy_active_context = NULL;
-		engine->legacy_active_ppgtt = NULL;
-
-		if (!engine->last_retired_context)
-			continue;
-
-		engine->context_unpin(engine, engine->last_retired_context);
-		engine->last_retired_context = NULL;
-	}
+	for_each_engine(engine, dev_priv, id)
+		intel_engine_lost_context(engine);
 }
 
 void i915_gem_contexts_fini(struct drm_i915_private *i915)
diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c
index 0248d64c2a72..4749426f9cad 100644
--- a/drivers/gpu/drm/i915/intel_engine_cs.c
+++ b/drivers/gpu/drm/i915/intel_engine_cs.c
@@ -1084,6 +1084,30 @@  void intel_engines_unpark(struct drm_i915_private *i915)
 	}
 }
 
+
+/**
+ * intel_engine_lost_context: called when the GPU is reset into unknown state
+ * @engine: the engine
+ *
+ * We have either reset the GPU or otherwise about to lose state tracking of
+ * the current GPU logical state (e.g. suspend). On next use, it is therefore
+ * imperative that we make no presumptions about the current state and load
+ * from scratch.
+ */
+void intel_engine_lost_context(struct intel_engine_cs *engine)
+{
+	struct i915_gem_context *ctx;
+
+	lockdep_assert_held(&engine->i915->drm.struct_mutex);
+
+	engine->legacy_active_context = NULL;
+	engine->legacy_active_ppgtt = NULL;
+
+	ctx = fetch_and_zero(&engine->last_retired_context);
+	if (ctx)
+		engine->context_unpin(engine, ctx);
+}
+
 bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
 {
 	switch (INTEL_GEN(engine->i915)) {
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index c5e27905b0e1..1231695fb4da 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -1044,6 +1044,8 @@  bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine);
 void intel_engines_park(struct drm_i915_private *i915);
 void intel_engines_unpark(struct drm_i915_private *i915);
 
+void intel_engine_lost_context(struct intel_engine_cs *engine);
+
 void intel_engines_reset_default_submission(struct drm_i915_private *i915);
 unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915);