From patchwork Tue Aug 14 21:35:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 1324441 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 0C0243FD8C for ; Wed, 15 Aug 2012 00:21:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F3EA8A0A1D for ; Tue, 14 Aug 2012 17:21:37 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.chad-versace.us (209-20-75-48.static.cloud-ips.com [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id A1D269EB0F for ; Tue, 14 Aug 2012 14:35:53 -0700 (PDT) Received: by shiva.chad-versace.us (Postfix, from userid 1005) id 3E727885B9; Tue, 14 Aug 2012 21:36:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on shiva.chad-versace.us X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.2 Received: from stallone.nims.intel.com (unknown [192.102.209.254]) by shiva.chad-versace.us (Postfix) with ESMTPSA id AE6CC885C8; Tue, 14 Aug 2012 21:35:36 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Tue, 14 Aug 2012 14:35:16 -0700 Message-Id: <1344980117-1993-5-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1344980117-1993-1-git-send-email-ben@bwidawsk.net> References: <1344980117-1993-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 4/5] drm/i915/contexts: Add forced switches X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org 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. The reason it's hand-wavy is because the context we load is still somewhat random. Certain things may be initialized, and certain other things may not. However it should definitely be better than he random state that HW comes up in (and better than all 0's). 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. References: https://bugs.freedesktop.org/show_bug.cgi?id=52429 Tested-by: Guang A Yang Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/i915_gem_context.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 3e884dc..3db84e2 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; @@ -256,7 +256,7 @@ void i915_gem_context_init(struct drm_device *dev) * context so our HW CCID matches what we think it should be in software. */ if (dev_priv->ring[RCS].default_context) { - int ret = do_switch(dev_priv->ring[RCS].default_context); + int ret = do_switch(dev_priv->ring[RCS].default_context, false); if (ret) { DRM_ERROR("HW contexts were broken after resume\n"); i915_gem_context_fini(dev); @@ -373,7 +373,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; @@ -382,7 +382,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); @@ -403,10 +403,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) { @@ -482,7 +482,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,