From patchwork Tue Aug 14 05:41:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 1318281 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 09B28DF266 for ; Tue, 14 Aug 2012 06:06:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D2CEA02E8 for ; Mon, 13 Aug 2012 23:06:53 -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 814D8A02E8 for ; Mon, 13 Aug 2012 22:41:29 -0700 (PDT) Received: by shiva.chad-versace.us (Postfix, from userid 1005) id 02D57885C6; Tue, 14 Aug 2012 05:41:38 +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.kumite (static-50-53-63-81.bvtn.or.frontiernet.net [50.53.63.81]) by shiva.chad-versace.us (Postfix) with ESMTPSA id 7DDA8885AE; Tue, 14 Aug 2012 05:41:27 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Mon, 13 Aug 2012 22:41:09 -0700 Message-Id: <1344922871-2248-2-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1344922871-2248-1-git-send-email-ben@bwidawsk.net> References: <1344922871-2248-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 2/4] 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 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 Signed-off-by: Ben Widawsky --- 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,