All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/i915: Snapshot seqno of most recently submitted request.
@ 2015-07-09 14:30 Tomas Elf
  2015-07-09 15:07 ` Chris Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Tomas Elf @ 2015-07-09 14:30 UTC (permalink / raw)
  To: Intel-GFX

The hang checker needs to inspect whether or not the ring request list is empty
as well as if the given engine has reached or passed the most recently
submitted request. The problem with this is that the hang checker cannot grab
the struct_mutex, which is required in order to safely inspect requests since
requests might be deallocated during inspection. In the past we've had kernel
panics due to this very unsynchronized access in the hang checker.

One solution to this problem is to not inspect the requests directly since
we're only interested in the seqno of the most recently submitted request - not
the request itself. Instead the seqno of the most recently submitted request is
stored separately, which the hang checker then inspects, circumventing the
issue of synchronization from the hang checker entirely.

v2 (Chris Wilson):
- Pass current engine seqno to ring_idle() from i915_hangcheck_elapsed() rather
than compute it over again.
- Remove extra whitespace.

Issue: VIZ-5998
Signed-off-by: Tomas Elf <tomas.elf@intel.com>
---
 drivers/gpu/drm/i915/i915_gem.c         |  1 +
 drivers/gpu/drm/i915/i915_irq.c         | 13 +++----------
 drivers/gpu/drm/i915/intel_ringbuffer.h |  7 +++++++
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index a0bff41..a871be4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2549,6 +2549,7 @@ void __i915_add_request(struct drm_i915_gem_request *request,
 	request->batch_obj = obj;
 
 	request->emitted_jiffies = jiffies;
+	ring->last_submitted_seqno = request->seqno;
 	list_add_tail(&request->list, &ring->request_list);
 
 	trace_i915_gem_request_add(request);
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index a6fbe64..0d0741f 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -2484,18 +2484,11 @@ static void gen8_disable_vblank(struct drm_device *dev, int pipe)
 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
 }
 
-static struct drm_i915_gem_request *
-ring_last_request(struct intel_engine_cs *ring)
-{
-	return list_entry(ring->request_list.prev,
-			  struct drm_i915_gem_request, list);
-}
-
 static bool
-ring_idle(struct intel_engine_cs *ring)
+ring_idle(struct intel_engine_cs *ring, u32 seqno)
 {
 	return (list_empty(&ring->request_list) ||
-		i915_gem_request_completed(ring_last_request(ring), false));
+		i915_seqno_passed(seqno, ring->last_submitted_seqno));
 }
 
 static bool
@@ -2717,7 +2710,7 @@ static void i915_hangcheck_elapsed(struct work_struct *work)
 		acthd = intel_ring_get_active_head(ring);
 
 		if (ring->hangcheck.seqno == seqno) {
-			if (ring_idle(ring)) {
+			if (ring_idle(ring, seqno)) {
 				ring->hangcheck.action = HANGCHECK_IDLE;
 
 				if (waitqueue_active(&ring->irq_queue)) {
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 0ea89ea..2e85fda 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -292,6 +292,13 @@ struct  intel_engine_cs {
 	 */
 	struct list_head request_list;
 
+	/**
+	 * Seqno of request most recently submitted to request_list.
+	 * Used exclusively by hang checker to avoid grabbing lock while
+	 * inspecting request list.
+	 */
+	u32 last_submitted_seqno;
+
 	bool gpu_caches_dirty;
 
 	wait_queue_head_t irq_queue;
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/i915: Snapshot seqno of most recently submitted request.
  2015-07-09 14:30 [PATCH v2] drm/i915: Snapshot seqno of most recently submitted request Tomas Elf
@ 2015-07-09 15:07 ` Chris Wilson
  2015-07-09 16:17   ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Wilson @ 2015-07-09 15:07 UTC (permalink / raw)
  To: Tomas Elf; +Cc: Intel-GFX

On Thu, Jul 09, 2015 at 03:30:57PM +0100, Tomas Elf wrote:
> The hang checker needs to inspect whether or not the ring request list is empty
> as well as if the given engine has reached or passed the most recently
> submitted request. The problem with this is that the hang checker cannot grab
> the struct_mutex, which is required in order to safely inspect requests since
> requests might be deallocated during inspection. In the past we've had kernel
> panics due to this very unsynchronized access in the hang checker.
> 
> One solution to this problem is to not inspect the requests directly since
> we're only interested in the seqno of the most recently submitted request - not
> the request itself. Instead the seqno of the most recently submitted request is
> stored separately, which the hang checker then inspects, circumventing the
> issue of synchronization from the hang checker entirely.
> 
> v2 (Chris Wilson):
> - Pass current engine seqno to ring_idle() from i915_hangcheck_elapsed() rather
> than compute it over again.
> - Remove extra whitespace.
> 
> Issue: VIZ-5998
> Signed-off-by: Tomas Elf <tomas.elf@intel.com>

Yup, that is a nice simple fix by partially reverting the
s/seqno/requests/ change (and improving upon it in the process).

We should mention

Fixes commit 44cdd6d219bc64f6810b8ed0023a4d4db9e0fe68
Author: John Harrison <John.C.Harrison@Intel.com>
Date:   Mon Nov 24 18:49:40 2014 +0000

    drm/i915: Convert 'ring_idle()' to use requests not seqnos

and
Cc: stable@vger.kernel.org
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/i915: Snapshot seqno of most recently submitted request.
  2015-07-09 15:07 ` Chris Wilson
@ 2015-07-09 16:17   ` Daniel Vetter
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2015-07-09 16:17 UTC (permalink / raw)
  To: Chris Wilson, Tomas Elf, Intel-GFX

On Thu, Jul 09, 2015 at 04:07:05PM +0100, Chris Wilson wrote:
> On Thu, Jul 09, 2015 at 03:30:57PM +0100, Tomas Elf wrote:
> > The hang checker needs to inspect whether or not the ring request list is empty
> > as well as if the given engine has reached or passed the most recently
> > submitted request. The problem with this is that the hang checker cannot grab
> > the struct_mutex, which is required in order to safely inspect requests since
> > requests might be deallocated during inspection. In the past we've had kernel
> > panics due to this very unsynchronized access in the hang checker.
> > 
> > One solution to this problem is to not inspect the requests directly since
> > we're only interested in the seqno of the most recently submitted request - not
> > the request itself. Instead the seqno of the most recently submitted request is
> > stored separately, which the hang checker then inspects, circumventing the
> > issue of synchronization from the hang checker entirely.
> > 
> > v2 (Chris Wilson):
> > - Pass current engine seqno to ring_idle() from i915_hangcheck_elapsed() rather
> > than compute it over again.
> > - Remove extra whitespace.
> > 
> > Issue: VIZ-5998
> > Signed-off-by: Tomas Elf <tomas.elf@intel.com>
> 
> Yup, that is a nice simple fix by partially reverting the
> s/seqno/requests/ change (and improving upon it in the process).
> 
> We should mention
> 
> Fixes commit 44cdd6d219bc64f6810b8ed0023a4d4db9e0fe68
> Author: John Harrison <John.C.Harrison@Intel.com>
> Date:   Mon Nov 24 18:49:40 2014 +0000
> 
>     drm/i915: Convert 'ring_idle()' to use requests not seqnos
> 
> and
> Cc: stable@vger.kernel.org
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Added and applied to -fixes, thanks.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-09 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-09 14:30 [PATCH v2] drm/i915: Snapshot seqno of most recently submitted request Tomas Elf
2015-07-09 15:07 ` Chris Wilson
2015-07-09 16:17   ` Daniel Vetter

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.