From patchwork Wed Apr 17 10:11:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 2452951 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 37DC9DF23A for ; Wed, 17 Apr 2013 10:12:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15C02E6628 for ; Wed, 17 Apr 2013 03:12:07 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id F0DB4E5C33 for ; Wed, 17 Apr 2013 03:11:54 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 17 Apr 2013 03:11:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,492,1363158000"; d="scan'208";a="320355975" Received: from gaia.fi.intel.com (HELO gaia) ([10.237.72.66]) by fmsmga001.fm.intel.com with ESMTP; 17 Apr 2013 03:11:53 -0700 Received: by gaia (Postfix, from userid 1000) id 4EA7B40E2E; Wed, 17 Apr 2013 13:11:49 +0300 (EEST) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Wed, 17 Apr 2013 13:11:43 +0300 Message-Id: <1366193503-28135-1-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20130416135941.GD13387@cantiga.alporthouse.com> References: <20130416135941.GD13387@cantiga.alporthouse.com> Subject: [Intel-gfx] [PATCH v3 14/16] drm/i915: refuse to submit more batchbuffers from guilty context 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 If context has recently submitted a faulty batchbuffers guilty of gpu hang and decides to keep submitting more crap, ban it permanently. v2: Store guilty ban status bool in gpu_error instead of pointers that might become danling before hang is declared. v3: Use return value for banned status instead of stashing state into gpu_error (Chris Wilson) Signed-off-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_drv.c | 5 ++-- drivers/gpu/drm/i915/i915_drv.h | 8 ++++++- drivers/gpu/drm/i915/i915_gem.c | 35 +++++++++++++++++++++------- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 13 +++++++++++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 9ebe895..fe6f8d2 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -883,16 +883,17 @@ int i915_reset(struct drm_device *dev) { drm_i915_private_t *dev_priv = dev->dev_private; int ret; + bool ctx_banned; if (!i915_try_reset) return 0; mutex_lock(&dev->struct_mutex); - i915_gem_reset(dev); + ctx_banned = i915_gem_reset(dev); ret = -ENODEV; - if (get_seconds() - dev_priv->gpu_error.last_reset < 5) + if (!ctx_banned && get_seconds() - dev_priv->gpu_error.last_reset < 5) DRM_ERROR("GPU hanging too fast, declaring wedged!\n"); else ret = intel_gpu_reset(dev); diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index d7fd16b..ecd979e 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -459,6 +459,12 @@ struct i915_ctx_hang_stats { /* This context had batch active when hang was declared */ unsigned batch_active; + + /* Time when this context was last blamed for a GPU reset */ + unsigned long batch_active_reset_ts; + + /* This context is banned to submit more work */ + bool banned; }; /* This must match up with the value previously used for execbuf2.rsvd1. */ @@ -1662,7 +1668,7 @@ static inline bool i915_terminally_wedged(struct i915_gpu_error *error) return atomic_read(&error->reset_counter) == I915_WEDGED; } -void i915_gem_reset(struct drm_device *dev); +bool i915_gem_reset(struct drm_device *dev); void i915_gem_clflush_object(struct drm_i915_gem_object *obj); int __must_check i915_gem_object_set_domain(struct drm_i915_gem_object *obj, uint32_t read_domains, diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 0e87765..646bb7e 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2143,15 +2143,15 @@ static bool i915_request_guilty(struct drm_i915_gem_request *request, return false; } -static void i915_set_reset_status(struct intel_ring_buffer *ring, +static bool i915_set_reset_status(struct intel_ring_buffer *ring, struct drm_i915_gem_request *request, u32 acthd) { struct i915_ctx_hang_stats *hs = NULL; - bool inside, guilty; + bool inside, guilty, banned; /* Innocent until proven guilty */ - guilty = false; + guilty = banned = false; if (!ring->hangcheck.was_waiting && i915_request_guilty(request, acthd, &inside)) { @@ -2175,11 +2175,21 @@ static void i915_set_reset_status(struct intel_ring_buffer *ring, hs = &request->file_priv->hang_stats; if (hs) { - if (guilty) + if (guilty) { + if (!hs->banned && + get_seconds() - hs->batch_active_reset_ts < 5) { + hs->banned = banned = true; + DRM_ERROR("context hanging too fast, " + "declaring banned\n"); + } hs->batch_active++; - else + hs->batch_active_reset_ts = get_seconds(); + } else { hs->batch_pending++; + } } + + return banned; } static void i915_gem_free_request(struct drm_i915_gem_request *request) @@ -2193,11 +2203,12 @@ static void i915_gem_free_request(struct drm_i915_gem_request *request) kfree(request); } -static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv, +static bool i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv, struct intel_ring_buffer *ring) { u32 completed_seqno; u32 acthd; + bool ctx_banned = false; acthd = intel_ring_get_active_head(ring); completed_seqno = ring->get_seqno(ring, false); @@ -2210,7 +2221,8 @@ static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv, list); if (request->seqno > completed_seqno) - i915_set_reset_status(ring, request, acthd); + ctx_banned |= i915_set_reset_status(ring, + request, acthd); i915_gem_free_request(request); } @@ -2224,6 +2236,8 @@ static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv, i915_gem_object_move_to_inactive(obj); } + + return ctx_banned; } static void i915_gem_reset_fences(struct drm_device *dev) @@ -2247,15 +2261,16 @@ static void i915_gem_reset_fences(struct drm_device *dev) INIT_LIST_HEAD(&dev_priv->mm.fence_list); } -void i915_gem_reset(struct drm_device *dev) +bool i915_gem_reset(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_gem_object *obj; struct intel_ring_buffer *ring; int i; + bool ctx_banned = false; for_each_ring(ring, dev_priv, i) - i915_gem_reset_ring_lists(dev_priv, ring); + ctx_banned |= i915_gem_reset_ring_lists(dev_priv, ring); /* Move everything out of the GPU domains to ensure we do any * necessary invalidation upon reuse. @@ -2269,6 +2284,8 @@ void i915_gem_reset(struct drm_device *dev) /* The fence registers are invalidated so clear them out */ i915_gem_reset_fences(dev); + + return ctx_banned; } /** diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index bd1750a..f1b1ea9 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -844,6 +844,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, struct drm_clip_rect *cliprects = NULL; struct intel_ring_buffer *ring; struct i915_hw_context *ctx; + struct i915_ctx_hang_stats *hs; u32 ctx_id = i915_execbuffer2_get_context_id(*args); u32 exec_start, exec_len; u32 mask, flags; @@ -1026,6 +1027,18 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, if (ret) goto err; + hs = i915_gem_context_get_hang_stats(&dev_priv->ring[RCS], + file, ctx_id); + if (IS_ERR(hs)) { + ret = PTR_ERR(hs); + goto err; + } + + if (hs->banned) { + ret = -EIO; + goto err; + } + ctx = i915_switch_context(ring, file, ctx_id); if (IS_ERR(ctx)) { ret = PTR_ERR(ctx);