From patchwork Thu May 3 06:37:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10377159 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 652EF603B4 for ; Thu, 3 May 2018 06:38:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54972251F9 for ; Thu, 3 May 2018 06:38:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46B9628E2B; Thu, 3 May 2018 06:38:58 +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=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 CA4BD251F9 for ; Thu, 3 May 2018 06:38:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 400F06E6A0; Thu, 3 May 2018 06:38:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 36E8A6E696 for ; Thu, 3 May 2018 06:38:51 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 11578250-1500050 for multiple; Thu, 03 May 2018 07:38:46 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Thu, 03 May 2018 07:38:44 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 3 May 2018 07:37:07 +0100 Message-Id: <20180503063757.22238-21-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180503063757.22238-1-chris@chris-wilson.co.uk> References: <20180503063757.22238-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH 21/71] drm/i915/execlists: Try preempt-reset from hardirq timer context X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP When circumstances allow, trying resetting the engine directly from the preemption timeout handler. As this is softirq context, we have to be careful both not to sleep and not to spin on anything we may be interrupting (e.g. the submission tasklet). Signed-off-by: Chris Wilson Cc: Mika Kuoppala Cc: MichaƂ Winiarski CC: Michel Thierry Cc: Jeff McGee Cc: Tvrtko Ursulin --- drivers/gpu/drm/i915/intel_lrc.c | 35 +++++- drivers/gpu/drm/i915/selftests/intel_lrc.c | 122 +++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index 0c962ed0150d..e9b8121cc1c7 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -555,6 +555,38 @@ static void inject_preempt_context(struct intel_engine_cs *engine) execlists_set_active(execlists, EXECLISTS_ACTIVE_PREEMPT); } +static int try_preempt_reset(struct intel_engine_execlists *execlists) +{ + int err = -EBUSY; + + if (tasklet_trylock(&execlists->tasklet)) { + struct intel_engine_cs *engine = + container_of(execlists, typeof(*engine), execlists); + const unsigned int bit = I915_RESET_ENGINE + engine->id; + unsigned long *lock = &engine->i915->gpu_error.flags; + + execlists->tasklet.func(execlists->tasklet.data); + + if (!execlists_is_active(execlists, + EXECLISTS_ACTIVE_PREEMPT_TIMEOUT)) { + /* Nothing to do; the tasklet was just delayed. */ + err = 0; + } else if (!test_and_set_bit(bit, lock)) { + tasklet_disable_nosync(&execlists->tasklet); + err = i915_reset_engine(engine, + "preemption time out"); + tasklet_enable(&execlists->tasklet); + + clear_bit(bit, lock); + wake_up_bit(lock, bit); + } + + tasklet_unlock(&execlists->tasklet); + } + + return err; +} + static enum hrtimer_restart preempt_timeout(struct hrtimer *hrtimer) { struct intel_engine_execlists *execlists = @@ -577,7 +609,8 @@ static enum hrtimer_restart preempt_timeout(struct hrtimer *hrtimer) intel_engine_dump(engine, &p, "%s\n", engine->name); } - queue_work(system_highpri_wq, &execlists->preempt_reset); + if (try_preempt_reset(execlists)) + queue_work(system_highpri_wq, &execlists->preempt_reset); return HRTIMER_NORESTART; } diff --git a/drivers/gpu/drm/i915/selftests/intel_lrc.c b/drivers/gpu/drm/i915/selftests/intel_lrc.c index 2aaab6072512..5ac4bf36aa84 100644 --- a/drivers/gpu/drm/i915/selftests/intel_lrc.c +++ b/drivers/gpu/drm/i915/selftests/intel_lrc.c @@ -562,6 +562,127 @@ static int live_preempt_timeout(void *arg) return err; } +static void __softirq_begin(void) +{ + local_bh_disable(); +} + +static void __softirq_end(void) +{ + local_bh_enable(); +} + +static void __hardirq_begin(void) +{ + local_irq_disable(); +} + +static void __hardirq_end(void) +{ + local_irq_enable(); +} + +static int live_preempt_reset(void *arg) +{ + struct drm_i915_private *i915 = arg; + struct intel_engine_cs *engine; + struct i915_gem_context *ctx; + enum intel_engine_id id; + struct spinner spin; + int err = -ENOMEM; + + if (!HAS_LOGICAL_RING_PREEMPTION(i915)) + return 0; + + mutex_lock(&i915->drm.struct_mutex); + + if (spinner_init(&spin, i915)) + goto err_unlock; + + ctx = kernel_context(i915); + if (!ctx) + goto err_spin; + + for_each_engine(engine, i915, id) { + static const struct { + const char *name; + void (*critical_section_begin)(void); + void (*critical_section_end)(void); + } phases[] = { + { "softirq", __softirq_begin, __softirq_end }, + { "hardirq", __hardirq_begin, __hardirq_end }, + { } + }; + const typeof(*phases) *p; + + for (p = phases; p->name; p++) { + struct i915_request *rq; + + rq = spinner_create_request(&spin, ctx, engine, + MI_NOOP); + if (IS_ERR(rq)) { + err = PTR_ERR(rq); + goto err_ctx; + } + + i915_request_add(rq); + if (!wait_for_spinner(&spin, rq)) { + i915_gem_set_wedged(i915); + err = -EIO; + goto err_ctx; + } + + /* Flush to give try_preempt_reset a chance */ + do { + tasklet_schedule(&engine->execlists.tasklet); + usleep_range(100, 1000); + tasklet_kill(&engine->execlists.tasklet); + } while (test_bit(ENGINE_IRQ_EXECLIST, + &engine->irq_posted)); + GEM_BUG_ON(i915_request_completed(rq)); + + GEM_TRACE("%s triggering %s reset\n", + engine->name, p->name); + p->critical_section_begin(); + + /* Trick execution of the tasklet from within reset */ + set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); + + mark_preemption_hang(&engine->execlists); + err = try_preempt_reset(&engine->execlists); + + p->critical_section_end(); + if (err) { + pr_err("Preempt softirq reset failed on %s, irq_posted? %d, tasklet state %lx\n", + engine->name, + test_bit(ENGINE_IRQ_EXECLIST, + &engine->irq_posted), + engine->execlists.tasklet.state); + spinner_end(&spin); + i915_gem_set_wedged(i915); + goto err_ctx; + } + GEM_BUG_ON(test_bit(ENGINE_IRQ_EXECLIST, + &engine->irq_posted)); + + if (flush_test(i915, I915_WAIT_LOCKED)) { + err = -EIO; + goto err_ctx; + } + } + } + + err = 0; +err_ctx: + kernel_context_close(ctx); +err_spin: + spinner_fini(&spin); +err_unlock: + flush_test(i915, I915_WAIT_LOCKED); + mutex_unlock(&i915->drm.struct_mutex); + return err; +} + int intel_execlists_live_selftests(struct drm_i915_private *i915) { static const struct i915_subtest tests[] = { @@ -569,6 +690,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915) SUBTEST(live_preempt), SUBTEST(live_late_preempt), SUBTEST(live_preempt_timeout), + SUBTEST(live_preempt_reset), }; return i915_subtests(tests, i915); }