All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 12/15] drm/i915/execlists: Try preempt-reset from softirq context
Date: Wed, 28 Mar 2018 22:18:54 +0100	[thread overview]
Message-ID: <20180328211857.32457-13-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20180328211857.32457-1-chris@chris-wilson.co.uk>

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 <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
CC: Michel Thierry <michel.thierry@intel.com>
Cc: Jeff McGee <jeff.mcgee@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/intel_lrc.c           | 31 +++++++++++-
 drivers/gpu/drm/i915/selftests/intel_lrc.c | 81 ++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 7989881545f1..e6a71d4a6261 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -535,6 +535,33 @@ 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)
+{
+	struct intel_engine_cs *engine =
+		container_of(execlists, typeof(*engine), execlists);
+	int err = -EBUSY;
+
+	if (!test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted) &&
+	    tasklet_trylock(&execlists->tasklet)) {
+		unsigned long *lock = &engine->i915->gpu_error.flags;
+		unsigned int bit = I915_RESET_ENGINE + engine->id;
+
+		if (!test_and_set_bit(bit, lock)) {
+			tasklet_disable_nosync(&engine->execlists.tasklet);
+			err = i915_reset_engine(engine,
+						"preemption time out");
+			tasklet_enable(&engine->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 =
@@ -548,7 +575,9 @@ static enum hrtimer_restart preempt_timeout(struct hrtimer *hrtimer)
 	if (!execlists_is_active(execlists, EXECLISTS_ACTIVE_PREEMPT_TIMEOUT))
 		return HRTIMER_NORESTART;
 
-	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 af16b0a40653..fe12df163cbd 100644
--- a/drivers/gpu/drm/i915/selftests/intel_lrc.c
+++ b/drivers/gpu/drm/i915/selftests/intel_lrc.c
@@ -546,6 +546,86 @@ static int live_preempt_timeout(void *arg)
 	return err;
 }
 
+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) {
+		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 improve our odds of enabling try_preempt_reset. */
+		do {
+			tasklet_schedule(&engine->execlists.tasklet);
+			tasklet_kill(&engine->execlists.tasklet);
+		} while (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted));
+		GEM_BUG_ON(i915_request_completed(rq));
+
+		local_bh_disable(); /* emulate the timer/softirq context */
+		err = try_preempt_reset(&engine->execlists);
+		local_bh_enable();
+		if (err) {
+			pr_err("Preempt 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);
+			i915_gem_set_wedged(i915);
+			goto err_ctx;
+		}
+
+		/*
+		 * In such a simple case as above; triggering a reset allows
+		 * us to save and restore the hog perfectly...
+		 */
+		spinner_end(&spin);
+
+		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[] = {
@@ -553,6 +633,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);
 }
-- 
2.16.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2018-03-28 21:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 21:18 Sleepless per-engine resests Chris Wilson
2018-03-28 21:18 ` [PATCH 01/15] drm/i915/execlists: Refactor out complete_preempt_context() Chris Wilson
2018-03-28 21:18 ` [PATCH 02/15] drm/i915: Move engine reset prepare/finish to backends Chris Wilson
2018-03-28 21:18 ` [PATCH 03/15] drm/i915: Split execlists/guc reset prepartions Chris Wilson
2018-03-28 21:18 ` [PATCH 04/15] drm/i915/execlists: Flush pending preemption events during reset Chris Wilson
2018-03-28 21:18 ` [PATCH 05/15] drm/i915/selftests: Add basic sanitychecks for execlists Chris Wilson
2018-03-28 21:18 ` [PATCH 06/15] drm/i915: Only warn for might_sleep() before a slow wait_for_register Chris Wilson
2018-03-29  9:19   ` Mika Kuoppala
2018-03-28 21:18 ` [PATCH 07/15] drm/i915/breadcrumbs: Keep the fake irq armed across reset Chris Wilson
2018-03-28 21:18 ` [PATCH 08/15] drm/i915: Combine tasklet_kill and tasklet_disable Chris Wilson
2018-03-28 21:18 ` [PATCH 09/15] drm/i915: Stop parking the signaler around reset Chris Wilson
2018-03-28 21:18 ` [PATCH 10/15] drm/i915: Avoid sleeping inside per-engine reset Chris Wilson
2018-03-28 21:47   ` Michel Thierry
2018-03-28 21:52     ` Chris Wilson
2018-03-28 21:56       ` Michel Thierry
2018-03-28 21:18 ` [PATCH 11/15] drm/i915/execlists: Force preemption via reset on timeout Chris Wilson
2018-03-28 21:26   ` Chris Wilson
2018-03-28 21:18 ` Chris Wilson [this message]
2018-03-28 21:18 ` [PATCH 13/15] drm/i915/preemption: Select timeout when scheduling Chris Wilson
2018-03-28 21:18 ` [PATCH 14/15] drm/i915: Use a preemption timeout to enforce interactivity Chris Wilson
2018-03-28 21:18 ` [PATCH 15/15] drm/i915: Allow user control over preempt timeout on the important context Chris Wilson
2018-03-28 22:43 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/15] drm/i915/execlists: Refactor out complete_preempt_context() Patchwork
2018-03-28 23:01 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-03-28 23:38   ` Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180328211857.32457-13-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.