diff mbox

[2/4] drm/i915/contexts: Add forced switches

Message ID 1344922871-2248-2-git-send-email-ben@bwidawsk.net (mailing list archive)
State Superseded
Headers show

Commit Message

Ben Widawsky Aug. 14, 2012, 5:41 a.m. UTC
A force parameter for switch currently only has one use, the first time
we load the default context.

Slightly hand-wavy explanation: We want to get the default context
actually loaded so that the GPU has some real state to load (instead of
garbage) after a reset or resume

Therefore, the benefit to adding a parameter instead of trying to
determine when to force is that we can strictly limit when such switches
occur.

As a +1 to me:
This existed in earlier versions of the patch series, but got removed as
part of the review process. The reason before was the same, and the same
person who convinced me to remove it before has convinced me to re-add
it. :-)

References: https://bugs.freedesktop.org/show_bug.cgi?id=52429
Tested-by: Guang A Yang <guang.a.yang@intel.com>
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 5c2d354..3945e79 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -97,7 +97,7 @@ 
 
 static struct i915_hw_context *
 i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
-static int do_switch(struct i915_hw_context *to);
+static int do_switch(struct i915_hw_context *to, bool force);
 
 static int get_context_size(struct drm_device *dev)
 {
@@ -225,7 +225,7 @@  static int create_default_context(struct drm_i915_private *dev_priv)
 	if (ret)
 		goto err_destroy;
 
-	ret = do_switch(ctx);
+	ret = do_switch(ctx, false);
 	if (ret)
 		goto err_unpin;
 
@@ -362,7 +362,7 @@  mi_set_context(struct intel_ring_buffer *ring,
 	return ret;
 }
 
-static int do_switch(struct i915_hw_context *to)
+static int do_switch(struct i915_hw_context *to, bool force)
 {
 	struct intel_ring_buffer *ring = to->ring;
 	struct drm_i915_gem_object *from_obj = ring->last_context_obj;
@@ -371,7 +371,7 @@  static int do_switch(struct i915_hw_context *to)
 
 	BUG_ON(from_obj != NULL && from_obj->pin_count == 0);
 
-	if (from_obj == to->obj)
+	if (!force && (from_obj == to->obj))
 		return 0;
 
 	ret = i915_gem_object_pin(to->obj, CONTEXT_ALIGN, false);
@@ -392,10 +392,10 @@  static int do_switch(struct i915_hw_context *to)
 	if (!to->obj->has_global_gtt_mapping)
 		i915_gem_gtt_bind_object(to->obj, to->obj->cache_level);
 
-	if (!to->is_initialized || is_default_context(to))
-		hw_flags |= MI_RESTORE_INHIBIT;
-	else if (WARN_ON_ONCE(from_obj == to->obj)) /* not yet expected */
+	if (force) {
 		hw_flags |= MI_FORCE_RESTORE;
+	} else if (!to->is_initialized || is_default_context(to))
+		hw_flags |= MI_RESTORE_INHIBIT;
 
 	ret = mi_set_context(ring, to, hw_flags);
 	if (ret) {
@@ -471,7 +471,7 @@  int i915_switch_context(struct intel_ring_buffer *ring,
 			return -ENOENT;
 	}
 
-	return do_switch(to);
+	return do_switch(to, false);
 }
 
 int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,