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: [Intel-gfx] [CI 14/14] drm/i915: Fix the iterative dfs for defering requests
Date: Tue,  2 Feb 2021 15:14:45 +0000	[thread overview]
Message-ID: <20210202151445.20002-14-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20210202151445.20002-1-chris@chris-wilson.co.uk>

The current implementation of walking the children of a deferred
requests lacks the backtracking required to reduce the dfs to linear.
Having pulled it from execlists into the common layer, we can reuse the
dfs code for priority inheritance.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_scheduler.c | 56 +++++++++++++++++++--------
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_scheduler.c b/drivers/gpu/drm/i915/i915_scheduler.c
index 641141f3ce10..8dd999f09412 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -466,8 +466,10 @@ void i915_request_set_priority(struct i915_request *rq, int prio)
 void __i915_sched_defer_request(struct intel_engine_cs *engine,
 				struct i915_request *rq)
 {
-	struct list_head *pl;
-	LIST_HEAD(list);
+	struct list_head *pos = &rq->sched.waiters_list;
+	const int prio = rq_prio(rq);
+	struct i915_request *rn;
+	LIST_HEAD(dfs);
 
 	lockdep_assert_held(&engine->active.lock);
 	GEM_BUG_ON(!test_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags));
@@ -477,14 +479,11 @@ void __i915_sched_defer_request(struct intel_engine_cs *engine,
 	 * to those that are waiting upon it. So we traverse its chain of
 	 * waiters and move any that are earlier than the request to after it.
 	 */
-	pl = lookup_priolist(engine, rq_prio(rq));
+	rq->sched.dfs.prev = NULL;
 	do {
-		struct i915_dependency *p;
-
-		GEM_BUG_ON(i915_request_is_active(rq));
-		list_move_tail(&rq->sched.link, pl);
-
-		for_each_waiter(p, rq) {
+		list_for_each_continue(pos, &rq->sched.waiters_list) {
+			struct i915_dependency *p =
+				list_entry(pos, typeof(*p), wait_link);
 			struct i915_request *w =
 				container_of(p->waiter, typeof(*w), sched);
 
@@ -500,19 +499,44 @@ void __i915_sched_defer_request(struct intel_engine_cs *engine,
 				   __i915_request_has_started(w) &&
 				   !__i915_request_is_complete(rq));
 
-			if (!i915_request_is_ready(w))
+			if (!i915_request_in_priority_queue(w))
 				continue;
 
-			if (rq_prio(w) < rq_prio(rq))
+			/*
+			 * We also need to reorder within the same priority.
+			 *
+			 * This is unlike priority-inheritance, where if the
+			 * signaler already has a higher priority [earlier
+			 * deadline] than us, we can ignore as it will be
+			 * scheduled first. If a waiter already has the
+			 * same priority, we still have to push it to the end
+			 * of the list. This unfortunately means we cannot
+			 * use the rq_deadline() itself as a 'visited' bit.
+			 */
+			if (rq_prio(w) < prio)
 				continue;
 
-			GEM_BUG_ON(rq_prio(w) > rq_prio(rq));
-			GEM_BUG_ON(i915_request_is_active(w));
-			list_move_tail(&w->sched.link, &list);
+			GEM_BUG_ON(rq_prio(w) != prio);
+
+			/* Remember our position along this branch */
+			rq = stack_push(w, rq, pos);
+			pos = &rq->sched.waiters_list;
 		}
 
-		rq = list_first_entry_or_null(&list, typeof(*rq), sched.link);
-	} while (rq);
+		/* Note list is reversed for waiters wrt signal hierarchy */
+		GEM_BUG_ON(rq->engine != engine);
+		GEM_BUG_ON(!i915_request_in_priority_queue(rq));
+		list_move(&rq->sched.link, &dfs);
+
+		/* Track our visit, and prevent duplicate processing */
+		clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
+	} while ((rq = stack_pop(rq, &pos)));
+
+	pos = lookup_priolist(engine, prio);
+	list_for_each_entry_safe(rq, rn, &dfs, sched.link) {
+		set_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
+		list_add_tail(&rq->sched.link, pos);
+	}
 }
 
 static void queue_request(struct intel_engine_cs *engine,
-- 
2.20.1

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

  parent reply	other threads:[~2021-02-02 15:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 15:14 [Intel-gfx] [CI 01/14] drm/i915/gt: Move engine setup out of set_default_submission Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 02/14] drm/i915/gt: Move submission_method into intel_gt Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 03/14] drm/i915/gt: Move CS interrupt handler to the backend Chris Wilson
2021-02-02 15:49   ` Tvrtko Ursulin
2021-02-02 15:53     ` Chris Wilson
2021-02-02 16:08       ` Chris Wilson
2021-02-02 16:15   ` [Intel-gfx] [PATCH v2] " Chris Wilson
2021-02-02 16:33     ` Tvrtko Ursulin
2021-02-02 15:14 ` [Intel-gfx] [CI 04/14] drm/i915: Replace engine->schedule() with a known request operation Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 05/14] drm/i915: Restructure priority inheritance Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 06/14] drm/i915/selftests: Measure set-priority duration Chris Wilson
2021-02-02 16:49   ` Tvrtko Ursulin
2021-02-02 15:14 ` [Intel-gfx] [CI 07/14] drm/i915/selftests: Exercise priority inheritance around an engine loop Chris Wilson
2021-02-02 16:44   ` Tvrtko Ursulin
2021-02-02 17:22     ` Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 08/14] drm/i915/selftests: Force a rewind if at first we don't succeed Chris Wilson
2021-02-02 16:52   ` Tvrtko Ursulin
2021-02-02 17:43     ` Chris Wilson
2021-02-02 21:14       ` Chris Wilson
2021-02-02 21:24         ` Chris Wilson
2021-02-02 21:32           ` Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 09/14] drm/i915: Improve DFS for priority inheritance Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 10/14] drm/i915: Extract request submission from execlists Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 11/14] drm/i915: Extract request rewinding " Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 12/14] drm/i915: Extract request suspension from the execlists Chris Wilson
2021-02-02 15:14 ` [Intel-gfx] [CI 13/14] drm/i915: Extract the ability to defer and rerun a request later Chris Wilson
2021-02-02 15:14 ` Chris Wilson [this message]
2021-02-02 18:37 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for series starting with [CI,01/14] drm/i915/gt: Move engine setup out of set_default_submission (rev2) Patchwork

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=20210202151445.20002-14-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.