From patchwork Thu Feb 4 10:39:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 12066943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98B8AC433DB for ; Thu, 4 Feb 2021 10:39:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CAD064E0A for ; Thu, 4 Feb 2021 10:39:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CAD064E0A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC8B46E042; Thu, 4 Feb 2021 10:39:47 +0000 (UTC) Received: from fireflyinternet.com (unknown [77.68.26.236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 912A96E042 for ; Thu, 4 Feb 2021 10:39:46 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.69.177; Received: from build.alporthouse.com (unverified [78.156.69.177]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 23784811-1500050 for multiple; Thu, 04 Feb 2021 10:39:40 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 4 Feb 2021 10:39:37 +0000 Message-Id: <20210204103938.2068-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v2 1/2] drm/i915/selftests: Restore previous heartbeat interval X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Wilson Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Use the defaults we store on the engine when resetting the heartbeat as we may have had to adjust it from the config value during initialisation. Signed-off-by: Chris Wilson --- .../gpu/drm/i915/gt/selftest_engine_heartbeat.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c index b0bae6676140..b2c369317bf1 100644 --- a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c +++ b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c @@ -11,6 +11,12 @@ #include "i915_selftest.h" #include "selftest_engine_heartbeat.h" +static void reset_heartbeat(struct intel_engine_cs *engine) +{ + intel_engine_set_heartbeat(engine, + engine->defaults.heartbeat_interval_ms); +} + static int timeline_sync(struct intel_timeline *tl) { struct dma_fence *fence; @@ -269,7 +275,7 @@ static int __live_heartbeat_fast(struct intel_engine_cs *engine) err = -EINVAL; } - intel_engine_set_heartbeat(engine, CONFIG_DRM_I915_HEARTBEAT_INTERVAL); + reset_heartbeat(engine); err_pm: intel_engine_pm_put(engine); intel_context_put(ce); @@ -284,7 +290,7 @@ static int live_heartbeat_fast(void *arg) int err = 0; /* Check that the heartbeat ticks at the desired rate. */ - if (!CONFIG_DRM_I915_HEARTBEAT_INTERVAL) + if (!IS_ACTIVE(CONFIG_DRM_I915_HEARTBEAT_INTERVAL)) return 0; for_each_engine(engine, gt, id) { @@ -332,7 +338,7 @@ static int __live_heartbeat_off(struct intel_engine_cs *engine) } err_beat: - intel_engine_set_heartbeat(engine, CONFIG_DRM_I915_HEARTBEAT_INTERVAL); + reset_heartbeat(engine); err_pm: intel_engine_pm_put(engine); return err; @@ -346,7 +352,7 @@ static int live_heartbeat_off(void *arg) int err = 0; /* Check that we can turn off heartbeat and not interrupt VIP */ - if (!CONFIG_DRM_I915_HEARTBEAT_INTERVAL) + if (!IS_ACTIVE(CONFIG_DRM_I915_HEARTBEAT_INTERVAL)) return 0; for_each_engine(engine, gt, id) { From patchwork Thu Feb 4 10:39:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 12066945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40884C433E0 for ; Thu, 4 Feb 2021 10:39:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85F0664E0A for ; Thu, 4 Feb 2021 10:39:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85F0664E0A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E4056E043; Thu, 4 Feb 2021 10:39:51 +0000 (UTC) Received: from fireflyinternet.com (unknown [77.68.26.236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 619096E043 for ; Thu, 4 Feb 2021 10:39:49 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.69.177; Received: from build.alporthouse.com (unverified [78.156.69.177]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 23784812-1500050 for multiple; Thu, 04 Feb 2021 10:39:40 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 4 Feb 2021 10:39:38 +0000 Message-Id: <20210204103938.2068-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210204103938.2068-1-chris@chris-wilson.co.uk> References: <20210204103938.2068-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v2 2/2] drm/i915/gt: Ratelimit heartbeat completion probing X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Wilson Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The heartbeat runs through a few phases that we expect to complete within a certain number of heartbeat intervals. First we must submit the heartbeat to the queue, and if the queue is occupied it may take a couple of intervals before the heartbeat preempts the workload and is submitted to HW. Once running on HW, completion is not instantaneous as it may have to first reset the current workload before it itself runs through the empty request and signals completion. As such, we know that the heartbeat must take at least the preempt reset timeout and before we have had a chance to reset the engine, we do not want to issue a global reset ourselves (simply so that we only try to do one reset at a time and not confuse ourselves by resetting twice and hitting an innocent.) So by taking into consideration that once running the request must take a finite amount of time, we can delay the final completion check to accommodate that and avoid checking too early (before we've had a chance to handle any engine resets required). v2: Attach a callback to flush the work immediately upon the heartbeat completion and insert the delay before the next. Suggested-by: CQ Tang Signed-off-by: Chris Wilson --- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 83 +++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + .../drm/i915/gt/selftest_engine_heartbeat.c | 20 +++-- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c index 48a91c0dbad6..91bbda0487b9 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c @@ -20,6 +20,18 @@ * issue a reset -- in the hope that restores progress. */ +#define HEARTBEAT_COMPLETION 50u /* milliseconds */ + +static long completion_timeout(const struct intel_engine_cs *engine) +{ + long timeout = HEARTBEAT_COMPLETION; + + if (intel_engine_has_preempt_reset(engine)) + timeout += READ_ONCE(engine->props.heartbeat_interval_ms); + + return msecs_to_jiffies(timeout); +} + static bool next_heartbeat(struct intel_engine_cs *engine) { long delay; @@ -29,6 +41,28 @@ static bool next_heartbeat(struct intel_engine_cs *engine) return false; delay = msecs_to_jiffies_timeout(delay); + + /* + * Once we submit a heartbeat to the HW, we know that it will take + * at least a certain amount of time to complete. On a hanging system + * it will first have to wait for the preempt reset timeout, and + * then it will take some time for the reset to resume with the + * heartbeat and for it to complete. So once we have submitted the + * heartbeat to HW, we can wait a while longer before declaring the + * engine stuck and forcing a reset ourselves. If we do a reset + * and the engine is also doing a reset, it is possible that we + * reset the engine twice, harming an innocent. + * + * Before we have sumitted the heartbeat, we do not want to change + * the interval as we to promote the heartbeat and trigger preemption + * in a deterministic time frame. + */ + if (engine->heartbeat.systole) { + intel_engine_flush_submission(engine); + if (i915_request_is_active(engine->heartbeat.systole)) + delay = max(delay, completion_timeout(engine)); + } + if (delay >= HZ) delay = round_jiffies_up_relative(delay); mod_delayed_work(system_highpri_wq, &engine->heartbeat.work, delay); @@ -48,12 +82,44 @@ heartbeat_create(struct intel_context *ce, gfp_t gfp) return rq; } +static void defibrillator(struct dma_fence *f, struct dma_fence_cb *cb) +{ + struct intel_engine_cs *engine = + container_of(cb, typeof(*engine), heartbeat.cb); + + if (READ_ONCE(engine->heartbeat.systole)) + mod_delayed_work(system_highpri_wq, &engine->heartbeat.work, 0); +} + +static void +track_heartbeat(struct intel_engine_cs *engine, struct i915_request *rq) +{ + engine->heartbeat.systole = i915_request_get(rq); + if (dma_fence_add_callback(&rq->fence, + &engine->heartbeat.cb, + defibrillator)) + mod_delayed_work(system_highpri_wq, &engine->heartbeat.work, 0); +} + +static void +untrack_heartbeat(struct intel_engine_cs *engine) +{ + struct i915_request *rq; + + rq = fetch_and_zero(&engine->heartbeat.systole); + if (!rq) + return; + + dma_fence_remove_callback(&rq->fence, &engine->heartbeat.cb); + i915_request_put(rq); +} + static void idle_pulse(struct intel_engine_cs *engine, struct i915_request *rq) { engine->wakeref_serial = READ_ONCE(engine->serial) + 1; i915_request_add_active_barriers(rq); if (!engine->heartbeat.systole && intel_engine_has_heartbeat(engine)) - engine->heartbeat.systole = i915_request_get(rq); + track_heartbeat(engine, rq); } static void heartbeat_commit(struct i915_request *rq, @@ -91,10 +157,8 @@ static void heartbeat(struct work_struct *wrk) intel_engine_flush_submission(engine); rq = engine->heartbeat.systole; - if (rq && i915_request_completed(rq)) { - i915_request_put(rq); - engine->heartbeat.systole = NULL; - } + if (rq && i915_request_completed(rq)) + untrack_heartbeat(engine); if (!intel_engine_pm_get_if_awake(engine)) return; @@ -142,6 +206,11 @@ static void heartbeat(struct work_struct *wrk) goto out; } + /* Just completed one heartbeat, wait a tick before the next */ + if (rq) + goto out; + + /* The engine is parking. We can rest until the next user */ serial = READ_ONCE(engine->serial); if (engine->wakeref_serial == serial) goto out; @@ -166,7 +235,7 @@ static void heartbeat(struct work_struct *wrk) mutex_unlock(&ce->timeline->mutex); out: if (!engine->i915->params.enable_hangcheck || !next_heartbeat(engine)) - i915_request_put(fetch_and_zero(&engine->heartbeat.systole)); + untrack_heartbeat(engine); intel_engine_pm_put(engine); } @@ -181,7 +250,7 @@ void intel_engine_unpark_heartbeat(struct intel_engine_cs *engine) void intel_engine_park_heartbeat(struct intel_engine_cs *engine) { if (cancel_delayed_work(&engine->heartbeat.work)) - i915_request_put(fetch_and_zero(&engine->heartbeat.systole)); + untrack_heartbeat(engine); } void intel_engine_init_heartbeat(struct intel_engine_cs *engine) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_types.h b/drivers/gpu/drm/i915/gt/intel_engine_types.h index 7159f9575e65..4956594c8b93 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_types.h +++ b/drivers/gpu/drm/i915/gt/intel_engine_types.h @@ -347,6 +347,7 @@ struct intel_engine_cs { struct { struct delayed_work work; struct i915_request *systole; + struct dma_fence_cb cb; unsigned long blocked; } heartbeat; diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c index b2c369317bf1..d690de522a11 100644 --- a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c +++ b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c @@ -202,7 +202,8 @@ static int cmp_u32(const void *_a, const void *_b) static int __live_heartbeat_fast(struct intel_engine_cs *engine) { - const unsigned int error_threshold = max(20000u, jiffies_to_usecs(6)); + const unsigned int error_threshold = + max(3 * HEARTBEAT_COMPLETION * 1000, jiffies_to_usecs(6)); struct intel_context *ce; struct i915_request *rq; ktime_t t0, t1; @@ -221,6 +222,9 @@ static int __live_heartbeat_fast(struct intel_engine_cs *engine) goto err_pm; for (i = 0; i < ARRAY_SIZE(times); i++) { + unsigned long timeout; + + timeout = jiffies + 2; do { /* Manufacture a tick */ intel_engine_park_heartbeat(engine); @@ -229,19 +233,19 @@ static int __live_heartbeat_fast(struct intel_engine_cs *engine) intel_engine_unpark_heartbeat(engine); flush_delayed_work(&engine->heartbeat.work); - if (!delayed_work_pending(&engine->heartbeat.work)) { - pr_err("%s: heartbeat %d did not start\n", - engine->name, i); - err = -EINVAL; - goto err_pm; - } rcu_read_lock(); rq = READ_ONCE(engine->heartbeat.systole); if (rq) rq = i915_request_get_rcu(rq); rcu_read_unlock(); - } while (!rq); + } while (!rq && !time_after(jiffies, timeout)); + if (!rq) { + pr_err("%s: heartbeat %d did not start\n", + engine->name, i); + err = -EINVAL; + goto err_pm; + } t0 = ktime_get(); while (rq == READ_ONCE(engine->heartbeat.systole))