From patchwork Fri Jun 17 07:09:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: arun.siluvery@linux.intel.com X-Patchwork-Id: 9182715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AC4A56075F for ; Fri, 17 Jun 2016 07:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A3891FF21 for ; Fri, 17 Jun 2016 07:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F20028399; Fri, 17 Jun 2016 07:10:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02C621FF21 for ; Fri, 17 Jun 2016 07:10:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 176296EAE2; Fri, 17 Jun 2016 07:09:51 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F29A6EADD for ; Fri, 17 Jun 2016 07:09:33 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 17 Jun 2016 00:09:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.26,482,1459839600"; d="scan'208"; a="1003894781" Received: from asiluver-linux.isw.intel.com ([10.102.226.117]) by fmsmga002.fm.intel.com with ESMTP; 17 Jun 2016 00:09:31 -0700 From: Arun Siluvery To: intel-gfx@lists.freedesktop.org Date: Fri, 17 Jun 2016 08:09:08 +0100 Message-Id: <1466147355-4635-9-git-send-email-arun.siluvery@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466147355-4635-1-git-send-email-arun.siluvery@linux.intel.com> References: <1466147355-4635-1-git-send-email-arun.siluvery@linux.intel.com> Cc: Tomas Elf Subject: [Intel-gfx] [PATCH v2 08/15] drm/i915/tdr: Add support for per engine reset recovery X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This change implements support for per-engine reset as an initial, less intrusive hang recovery option to be attempted before falling back to the legacy full GPU reset recovery mode if necessary. This is only supported from Gen8 onwards. Hangchecker determines which engines are hung and invokes error handler to recover from it. Error handler schedules recovery for each of those engines that are hung. The recovery procedure is as follows, - force engine to idle: this is done by issuing a reset request - save current state which includes head and current request - reset engine - restore saved state and resubmit context If engine reset fails then we fall back to heavy weight full gpu reset which resets all engines and reinitiazes complete state of HW and SW. Possible reasons for failure, - engine not ready for reset - if the HW and SW doesn't agree on the context that caused the hang - reset itself failed for some reason Cc: Chris Wilson Cc: Mika Kuoppala Signed-off-by: Tomas Elf Signed-off-by: Arun Siluvery --- drivers/gpu/drm/i915/i915_drv.c | 54 +++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_gem.c | 4 +-- drivers/gpu/drm/i915/intel_uncore.c | 33 +++++++++++++++++++++++ 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index dfac8b3..cb76da1 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1027,10 +1027,60 @@ error: */ int i915_reset_engine(struct intel_engine_cs *engine) { + struct drm_device *dev = engine->i915->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_engine_cs_state state; int ret; - /* FIXME: replace me with engine reset sequence */ - ret = -ENODEV; + WARN_ON(!mutex_is_locked(&dev->struct_mutex)); + + i915_gem_reset_engine_status(dev_priv, engine); + + /*Take wake lock to prevent power saving mode */ + intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); + + ret = intel_request_for_reset(engine); + if (ret) { + DRM_ERROR("Failed to disable %s\n", engine->name); + goto out; + } + + ret = engine->save(engine, &state); + if (ret) + goto enable_engine; + + ret = intel_gpu_reset(dev_priv, intel_engine_flag(engine)); + if (ret) { + DRM_ERROR("Failed to reset %s, ret=%d\n", engine->name, ret); + goto enable_engine; + } + + ret = engine->init_hw(engine); + if (ret) + goto out; + + /* + * Restart the engine after reset. + * Engine state is first restored and the context is resubmitted. + */ + engine->start(engine, &state); + +enable_engine: + /* + * we only need to enable engine if we cannot either save engine state + * or reset fails. If the reset is successful, engine gets enabled + * automatically so we can skip this step. + */ + if (ret) + intel_clear_reset_request(engine); + +out: + if (state.req) + i915_gem_request_unreference(state.req); + + /* Wake up anything waiting on this engine's queue */ + wake_up_all(&engine->irq_queue); + intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); return ret; } diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index b35ca02..b2105bb 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2910,6 +2910,8 @@ extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask); extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv); extern int i915_reset(struct drm_i915_private *dev_priv); extern bool intel_has_engine_reset(struct drm_i915_private *dev_priv); +extern int intel_request_for_reset(struct intel_engine_cs *engine); +extern int intel_clear_reset_request(struct intel_engine_cs *engine); extern int i915_reset_engine(struct intel_engine_cs *engine); extern int intel_guc_reset(struct drm_i915_private *dev_priv); extern void intel_engine_init_hangcheck(struct intel_engine_cs *engine); @@ -3331,6 +3333,8 @@ static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv) } void i915_gem_reset(struct drm_device *dev); +void i915_gem_reset_engine_status(struct drm_i915_private *dev_priv, + struct intel_engine_cs *ring); bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force); int __must_check i915_gem_init(struct drm_device *dev); int i915_gem_init_engines(struct drm_device *dev); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 21d0dea..6160564 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3082,8 +3082,8 @@ i915_gem_find_active_request(struct intel_engine_cs *engine) return NULL; } -static void i915_gem_reset_engine_status(struct drm_i915_private *dev_priv, - struct intel_engine_cs *engine) +void i915_gem_reset_engine_status(struct drm_i915_private *dev_priv, + struct intel_engine_cs *engine) { struct drm_i915_gem_request *request; bool ring_hung; diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index d973c2a..63acaeb 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -1734,6 +1734,39 @@ int intel_guc_reset(struct drm_i915_private *dev_priv) return ret; } +/* + * On gen8+ a reset request has to be issued via the reset control register + * before a GPU engine can be reset in order to stop the command streamer + * and idle the engine. This replaces the legacy way of stopping an engine + * by writing to the stop ring bit in the MI_MODE register. + */ +int intel_request_for_reset(struct intel_engine_cs *engine) +{ + if (!intel_has_engine_reset(engine->i915)) { + DRM_ERROR("Engine Reset not supported on Gen%d\n", + INTEL_INFO(engine->i915)->gen); + return -EINVAL; + } + + return gen8_request_engine_reset(engine); +} + +/* + * It is possible to back off from a previously issued reset request by simply + * clearing the reset request bit in the reset control register. + */ +int intel_clear_reset_request(struct intel_engine_cs *engine) +{ + if (!intel_has_engine_reset(engine->i915)) { + DRM_ERROR("Request to clear reset not supported on Gen%d\n", + INTEL_INFO(engine->i915)->gen); + return -EINVAL; + } + + gen8_unrequest_engine_reset(engine); + return 0; +} + bool intel_uncore_unclaimed_mmio(struct drm_i915_private *dev_priv) { return check_for_unclaimed_mmio(dev_priv);