public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: intel-gfx@lists.freedesktop.org
Cc: Ben Widawsky <ben@bwidawsk.net>
Subject: [PATCH 2/4] drm/i915/contexts: Add forced switches
Date: Mon, 13 Aug 2012 22:41:09 -0700	[thread overview]
Message-ID: <1344922871-2248-2-git-send-email-ben@bwidawsk.net> (raw)
In-Reply-To: <1344922871-2248-1-git-send-email-ben@bwidawsk.net>

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 --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,
-- 
1.7.11.4

  reply	other threads:[~2012-08-14  5:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14  5:41 [PATCH 1/4] drm/i915/contexts: fix list corruption Ben Widawsky
2012-08-14  5:41 ` Ben Widawsky [this message]
2012-08-14  5:41 ` [PATCH 3/4] drm/i915/contexts: Serialize default context init Ben Widawsky
2012-08-14  7:41   ` Chris Wilson
2012-08-14 16:41     ` Ben Widawsky
2012-08-14  5:41 ` [PATCH 4/4] drm/i915: Cleanup instdone state when idle Ben Widawsky
2012-08-14  7:39   ` Chris Wilson
2012-08-14 16:42     ` Ben Widawsky
2012-08-14 16:48       ` Chris Wilson
2012-08-14  7:36 ` [PATCH 1/4] drm/i915/contexts: fix list corruption Chris Wilson

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=1344922871-2248-2-git-send-email-ben@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox