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 v2] drm/i915: Trim the retired request queue after submitting
Date: Tue, 16 Jan 2018 13:30:18 +0000	[thread overview]
Message-ID: <20180116133018.13053-1-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <f775003b-5555-ee63-f21e-dc7c31334fef@linux.intel.com>

If we submit a request and see that the previous request on this
timeline was already signaled, we first do not need to add the
dependency tracker for that completed request and secondly we know that
we there is then a large backlog in retiring requests affecting this
timeline. Given that we just submitted more work to the HW, now would be
a good time to catch up on those retirements.

v2: Try to sum up the compromises involved in flushing the retirement
queue after submission.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_request.c | 34 ++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c
index a0f451b4a4e8..77c2eba490e9 100644
--- a/drivers/gpu/drm/i915/i915_gem_request.c
+++ b/drivers/gpu/drm/i915/i915_gem_request.c
@@ -983,7 +983,8 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 	lockdep_assert_held(&request->i915->drm.struct_mutex);
 	trace_i915_gem_request_add(request);
 
-	/* Make sure that no request gazumped us - if it was allocated after
+	/*
+	 * Make sure that no request gazumped us - if it was allocated after
 	 * our i915_gem_request_alloc() and called __i915_add_request() before
 	 * us, the timeline will hold its seqno which is later than ours.
 	 */
@@ -1010,7 +1011,8 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 		WARN(err, "engine->emit_flush() failed: %d!\n", err);
 	}
 
-	/* Record the position of the start of the breadcrumb so that
+	/*
+	 * Record the position of the start of the breadcrumb so that
 	 * should we detect the updated seqno part-way through the
 	 * GPU processing the request, we never over-estimate the
 	 * position of the ring's HEAD.
@@ -1019,7 +1021,8 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 	GEM_BUG_ON(IS_ERR(cs));
 	request->postfix = intel_ring_offset(request, cs);
 
-	/* Seal the request and mark it as pending execution. Note that
+	/*
+	 * Seal the request and mark it as pending execution. Note that
 	 * we may inspect this state, without holding any locks, during
 	 * hangcheck. Hence we apply the barrier to ensure that we do not
 	 * see a more recent value in the hws than we are tracking.
@@ -1027,7 +1030,7 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 
 	prev = i915_gem_active_raw(&timeline->last_request,
 				   &request->i915->drm.struct_mutex);
-	if (prev) {
+	if (prev && !i915_gem_request_completed(prev)) {
 		i915_sw_fence_await_sw_fence(&request->submit, &prev->submit,
 					     &request->submitq);
 		if (engine->schedule)
@@ -1047,7 +1050,8 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 	list_add_tail(&request->ring_link, &ring->request_list);
 	request->emitted_jiffies = jiffies;
 
-	/* Let the backend know a new request has arrived that may need
+	/*
+	 * Let the backend know a new request has arrived that may need
 	 * to adjust the existing execution schedule due to a high priority
 	 * request - i.e. we may want to preempt the current request in order
 	 * to run a high priority dependency chain *before* we can execute this
@@ -1063,6 +1067,26 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches)
 	local_bh_disable();
 	i915_sw_fence_commit(&request->submit);
 	local_bh_enable(); /* Kick the execlists tasklet if just scheduled */
+
+	/*
+	 * In typical scenarios, we do not expect the previous request on
+	 * the timeline to be still tracked by timeline->last_request if it
+	 * has been completed. If the completed request is still here, that
+	 * implies that request retirement is a long way behind submission,
+	 * suggesting that we haven't been retiring frequently enough from
+	 * the combination of retire-before-alloc, waiters and the background
+	 * retirement worker. So if the last request on this timeline was
+	 * already completed, do a catch up pass, flushing the retirement queue
+	 * up to this client. Since we have now moved the heaviest operations
+	 * during retirement onto secondary workers, such as freeing objects
+	 * or contexts, retiring a bunch of requests is mostly list management
+	 * (and cache misses), and so we should not be overly penalizing this
+	 * client by performing excess work, though we may still performing
+	 * work on behalf of others -- but instead we should benefit from
+	 * improved resource management. (Well, that's the theory at least.)
+	 */
+	if (prev && i915_gem_request_completed(prev))
+		i915_gem_request_retire_upto(prev);
 }
 
 static unsigned long local_clock_us(unsigned int *cpu)
-- 
2.15.1

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

  parent reply	other threads:[~2018-01-16 13:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15 21:24 Prevent trivial oom from gem_exec_nop/sequential Chris Wilson
2018-01-15 21:24 ` [PATCH 01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs Chris Wilson
2018-01-17 10:29   ` Tvrtko Ursulin
2018-01-18  9:16     ` Chris Wilson
2018-01-18  9:19     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 02/10] drm/i915: Move i915_gem_retire_work_handler Chris Wilson
2018-01-17 10:33   ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 03/10] drm/i915: Shrink the GEM kmem_caches upon idling Chris Wilson
2018-01-16 10:00   ` Tvrtko Ursulin
2018-01-16 10:19     ` Chris Wilson
2018-01-16 13:05     ` [PATCH v2] " Chris Wilson
2018-01-16 15:12       ` Tvrtko Ursulin
2018-01-16 15:16         ` Tvrtko Ursulin
2018-01-16 15:21         ` Chris Wilson
2018-01-16 17:25           ` Tvrtko Ursulin
2018-01-16 17:36             ` Chris Wilson
2018-01-17 10:18               ` Tvrtko Ursulin
2018-01-18 18:06                 ` Chris Wilson
2018-01-15 21:24 ` [PATCH 04/10] drm/i915: Shrink the request kmem_cache on allocation error Chris Wilson
2018-01-16 10:10   ` Tvrtko Ursulin
2018-01-16 10:26     ` Chris Wilson
2018-01-16 13:15     ` [PATCH v2] " Chris Wilson
2018-01-16 15:19       ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 05/10] drm/i915: Trim the retired request queue after submitting Chris Wilson
2018-01-16 10:18   ` Tvrtko Ursulin
2018-01-16 10:32     ` Chris Wilson
2018-01-17 10:23       ` Tvrtko Ursulin
2018-01-16 13:30     ` Chris Wilson [this message]
2018-01-15 21:24 ` [PATCH 06/10] drm/i915/breadcrumbs: Drop request reference for the signaler thread Chris Wilson
2018-01-15 21:24 ` [PATCH 07/10] drm/i915: Reduce spinlock hold time during notify_ring() interrupt Chris Wilson
2018-01-17 10:45   ` Tvrtko Ursulin
2018-01-18 18:08     ` Chris Wilson
2018-01-18 18:10     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 08/10] drm/i915: Move the irq_counter inside the spinlock Chris Wilson
2018-01-17 12:12   ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 09/10] drm/i915: Only signal from interrupt when requested Chris Wilson
2018-01-17 12:22   ` Tvrtko Ursulin
2018-01-18 18:12     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 10/10] drm/i915/breadcrumbs: Reduce signaler rbtree to a sorted list Chris Wilson
2018-01-15 22:04 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs Patchwork
2018-01-16  9:21 ` ✓ Fi.CI.IGT: " Patchwork
2018-01-16  9:52 ` Prevent trivial oom from gem_exec_nop/sequential Tvrtko Ursulin
2018-01-16 10:02   ` Chris Wilson
2018-01-16 13:10   ` Chris Wilson
2018-01-16 13:42 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs (rev3) Patchwork
2018-01-16 14:02 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs (rev4) Patchwork
2018-01-16 15:29 ` ✓ Fi.CI.IGT: " 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=20180116133018.13053-1-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.