From patchwork Fri Aug 5 16:30:03 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: 9265555 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 C10476048B for ; Fri, 5 Aug 2016 16:30:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B02D128449 for ; Fri, 5 Aug 2016 16:30:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4FA928457; Fri, 5 Aug 2016 16:30:30 +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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0DEA728449 for ; Fri, 5 Aug 2016 16:30:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B3DB6EBE2; Fri, 5 Aug 2016 16:30:29 +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 779DF6EBE7 for ; Fri, 5 Aug 2016 16:30:28 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 05 Aug 2016 09:30:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,474,1464678000"; d="scan'208"; a="1020351316" Received: from asiluver-linux.isw.intel.com ([10.102.226.117]) by fmsmga001.fm.intel.com with ESMTP; 05 Aug 2016 09:30:23 -0700 From: Arun Siluvery To: intel-gfx@lists.freedesktop.org Date: Fri, 5 Aug 2016 17:30:03 +0100 Message-Id: <1470414607-32453-8-git-send-email-arun.siluvery@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470414607-32453-1-git-send-email-arun.siluvery@linux.intel.com> References: <1470414607-32453-1-git-send-email-arun.siluvery@linux.intel.com> Cc: Mika Kuoppala , Tomas Elf Subject: [Intel-gfx] [PATCH v2 07/11] 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, - identifies the request that caused the hang and it is dropped - force engine to idle: this is done by issuing a reset request - reset and re-init engine - restart submissions to the engine 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. Cc: Chris Wilson Cc: Mika Kuoppala Signed-off-by: Tomas Elf Signed-off-by: Arun Siluvery --- drivers/gpu/drm/i915/i915_drv.c | 59 +++++++++++++++++++++++++++++++++---- drivers/gpu/drm/i915/i915_drv.h | 3 ++ drivers/gpu/drm/i915/i915_gem.c | 2 +- drivers/gpu/drm/i915/intel_lrc.c | 10 +++++++ drivers/gpu/drm/i915/intel_lrc.h | 1 + drivers/gpu/drm/i915/intel_uncore.c | 41 +++++++++++++++++++++++--- 6 files changed, 105 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index a92183b..04d15f3 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1809,21 +1809,68 @@ error: * Returns zero on successful reset or otherwise an error code. * * Procedure is fairly simple: - * - force engine to idle - * - save current state which includes head and current request - * - reset engine - * - restore saved state and resubmit context + * - identifies the request that caused the hang and it is dropped + * - force engine to idle: this is done by issuing a reset request + * - reset engine + * - restart submissions to the engine */ int i915_reset_engine(struct intel_engine_cs *engine) { int ret; struct drm_i915_private *dev_priv = engine->i915; - /* FIXME: replace me with engine reset sequence */ - ret = -ENODEV; + /* + * We need to first idle the engine by issuing a reset request, + * then perform soft reset and re-initialize hw state, for all of + * this GT power need to be awake so ensure it does throughout the + * process + */ + intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); + + /* + * the request that caused the hang is stuck on elsp, identify the + * active request and drop it, adjust head to skip the offending + * request to resume executing remaining requests in the queue. + */ + i915_gem_reset_engine(engine); + + ret = intel_engine_reset_begin(engine); + if (ret) { + DRM_ERROR("Failed to disable %s\n", engine->name); + goto error; + } + + ret = intel_gpu_reset(dev_priv, intel_engine_flag(engine)); + if (ret) { + DRM_ERROR("Failed to reset %s, ret=%d\n", engine->name, ret); + intel_engine_reset_cancel(engine); + goto error; + } + + ret = engine->init_hw(engine); + if (ret) + goto error; + + intel_engine_reset_cancel(engine); + intel_execlists_restart_submission(engine); + intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); + return 0; + +error: + /* use full gpu reset to recover on error */ set_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags); + /* Engine reset is performed without taking struct_mutex, since it + * failed we now fallback to full gpu reset. Wakeup any waiters + * which should now see the reset_in_progress and release + * struct_mutex for us to continue recovery. + */ + rcu_read_lock(); + intel_engine_wakeup(engine); + rcu_read_unlock(); + + 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 fd01a29..ffbdfc1 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2869,6 +2869,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_engine_reset_begin(struct intel_engine_cs *engine); +extern int intel_engine_reset_cancel(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); @@ -3230,6 +3232,7 @@ static inline u32 i915_reset_count(struct i915_gpu_error *error) void i915_gem_reset(struct drm_device *dev); void i915_gem_set_wedged(struct drm_i915_private *dev_priv); +void i915_gem_reset_engine(struct intel_engine_cs *engine); bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force); int __must_check i915_gem_init(struct drm_device *dev); int __must_check i915_gem_init_hw(struct drm_device *dev); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 669fb35..1578851 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2402,7 +2402,7 @@ i915_gem_find_active_request(struct intel_engine_cs *engine) return NULL; } -static void i915_gem_reset_engine(struct intel_engine_cs *engine) +void i915_gem_reset_engine(struct intel_engine_cs *engine) { struct drm_i915_gem_request *request; struct i915_gem_context *incomplete_ctx; diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index efd3773..b52765a 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -543,6 +543,16 @@ static void execlists_submit_request(struct drm_i915_gem_request *request) spin_unlock_bh(&engine->execlist_lock); } +void intel_execlists_restart_submission(struct intel_engine_cs *engine) +{ + spin_lock_bh(&engine->execlist_lock); + + if (execlists_elsp_idle(engine)) + tasklet_hi_schedule(&engine->irq_tasklet); + + spin_unlock_bh(&engine->execlist_lock); +} + int intel_logical_ring_alloc_request_extras(struct drm_i915_gem_request *request) { struct intel_engine_cs *engine = request->engine; diff --git a/drivers/gpu/drm/i915/intel_lrc.h b/drivers/gpu/drm/i915/intel_lrc.h index 4d70346..853a0dc 100644 --- a/drivers/gpu/drm/i915/intel_lrc.h +++ b/drivers/gpu/drm/i915/intel_lrc.h @@ -96,5 +96,6 @@ uint64_t intel_lr_context_descriptor(struct i915_gem_context *ctx, int intel_sanitize_enable_execlists(struct drm_i915_private *dev_priv, int enable_execlists); void intel_execlists_enable_submission(struct drm_i915_private *dev_priv); +void intel_execlists_restart_submission(struct intel_engine_cs *engine); #endif /* _INTEL_LRC_H_ */ diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 418fd0d..d0f89e8 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -1683,7 +1683,7 @@ int intel_wait_for_register(struct drm_i915_private *dev_priv, return ret; } -static int gen8_request_engine_reset(struct intel_engine_cs *engine) +static int gen8_engine_reset_begin(struct intel_engine_cs *engine) { struct drm_i915_private *dev_priv = engine->i915; int ret; @@ -1702,7 +1702,7 @@ static int gen8_request_engine_reset(struct intel_engine_cs *engine) return ret; } -static void gen8_unrequest_engine_reset(struct intel_engine_cs *engine) +static void gen8_engine_reset_cancel(struct intel_engine_cs *engine) { struct drm_i915_private *dev_priv = engine->i915; @@ -1716,14 +1716,14 @@ static int gen8_reset_engines(struct drm_i915_private *dev_priv, struct intel_engine_cs *engine; for_each_engine_masked(engine, dev_priv, engine_mask) - if (gen8_request_engine_reset(engine)) + if (gen8_engine_reset_begin(engine)) goto not_ready; return gen6_reset_engines(dev_priv, engine_mask); not_ready: for_each_engine_masked(engine, dev_priv, engine_mask) - gen8_unrequest_engine_reset(engine); + gen8_engine_reset_cancel(engine); return -EIO; } @@ -1799,6 +1799,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_engine_reset_begin(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_engine_reset_begin(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_engine_reset_cancel(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_engine_reset_cancel(engine); + return 0; +} + bool intel_uncore_unclaimed_mmio(struct drm_i915_private *dev_priv) { return check_for_unclaimed_mmio(dev_priv);