drm/i915: Avoid stuck page flip waiters on GPU reset
Subsystems (2)
cover drm/i915: Avoid stuck page flip waiters on GPU reset
Someone mentioned on irc that intel_crtc_wait_for_pending_flips() was getting stuck in some cases. This rang a bell since I was poking around that stuff last year.
The issue that I'm trying to fix here is processes getting stuck in D state when a GPU reset happens while page flips have been scheduled.
Testing is easy 1) fire up 'glxgears -fullscreen', run 'gem_hang 0', try to VT switch. Without this series X and some kworker soon get stuck in D state and you're left with a useless box. With the patch set, you wait a while, the GPU hangcheck kicks in, and you get your console back.
The irc discussion was apparently about [1], but since the dmesg there doesn't show a GPU hang, I don't see this patch set fixing it. Frankly, I have no idea what's happening there.
Additional work after this would involve sending out pending page flip events. Currently if you don't do the VT switch after a hang, glxgears remains stuck because the X server didn't get the page flip event from the kernel. Also we should probably do an explicit intel_pipe_set_base() with the current fb, to make sure we show the correct fb after the hang. But I'm not going to touch these right now. Actually I'm hoping someone else will volunteer for these tasks ;)
[1] https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/1097315
PATCH 1/6 drm/i915: Kill obj->pending_flip
From: Ville Syrjälä <[email protected]>
The pending flip mask no longer set anywhere, so trying to wait for while it's non-zero is a no-op. Remove it completely.
--- drivers/gpu/drm/i915/i915_drv.h | 7 ------- drivers/gpu/drm/i915/intel_display.c | 6 ------ 2 files changed, 13 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -7
@@ -1208,13 +1208,6 @@ struct drm_i915_gem_object {/** for phy allocated objects */ struct drm_i915_gem_phys_object *phys_obj; - -/** -* Number of crtcs where this object is currently the fb, but -* will be page flipped away on the next vblank. When it -* reaches 0, dev_priv->pending_flip_queue will be woken up. -*/ -atomic_t pending_flip; };#define to_gem_object (obj) (&((struct drm_i915_gem_object *)(obj))->base)
drivers/gpu/drm/i915/intel_display.c +0 -6
@@ -2220,12 +2220,6 @@ intel_finish_fb(struct drm_framebuffer *old_fb)bool was_interruptible = dev_priv->mm.interruptible;int ret; -WARN_ON (waitqueue_active (&dev_priv->pending_flip_queue)); - -wait_event (dev_priv->pending_flip_queue, -i915_reset_in_progress (&dev_priv->gpu_error) || -atomic_read (&obj->pending_flip) ==0 ); -/* Big Hammer, we also need to ensure that any pending * MI_WAIT_FOR_EVENT inside a user batch buffer on the * current scanout is retired before unpinning the old
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 1/6] drm/i915: Kill obj->pending_flip
Quoted 6 lines · On Tue, Jan 29, 2013 at 06:13:33PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
The pending flip mask no longer set anywhere, so trying to wait for while it's non-zero is a no-op. Remove it completely.
Signed-off-by Ville Syrjälä <[email protected]>
Signature · 1 line
Damien
Daniel Vetter
AppliedRe: [PATCH 1/6] drm/i915: Kill obj->pending_flip
Quoted 9 lines · Damien Lespiau
Quoted 6 lines · On Tue, Jan 29, 2013 at 06:13:33PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
The pending flip mask no longer set anywhere, so trying to wait for while it's non-zero is a no-op. Remove it completely.
Signed-off-by Ville Syrjälä <[email protected]>Reviewed-by Damien Lespiau <[email protected]>
Queued for -next, thanks for the patch.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 2/6 drm/i915: Don't wait for page flips if there was GPU reset
In reply to [email protected]From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the reset_counter before the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the current reset_counter value.
--- drivers/gpu/drm/i915/intel_display.c | 14 +++++++++++++- drivers/gpu/drm/i915/intel_drv.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_display.c +13 -1
@@ -2862,10 +2862,12 @@ static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc);unsigned long flags;bool pending; -if (i915_reset_in_progress (&dev_priv->gpu_error)) +if (i915_reset_in_progress (&dev_priv->gpu_error) || + intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter))return false;spin_lock_irqsave (&dev->event_lock, flags);
@@ -6912,6 +6914,8 @@ static int intel_gen2_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +/* Can't queue multiple flips, so wait for the previous * one to finish before executing the next. */
@@ -6956,6 +6960,8 @@ static int intel_gen3_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +if (intel_crtc->plane) flip_mask =MI_WAIT_FOR_PLANE_B_FLIP ;else
@@ -6997,6 +7003,8 @@ static int intel_gen4_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +/* i965+ uses the linear or tiled offsets from the * Display Registers (which do not change across a page-flip) * so we need only reprogram the base address.
@@ -7045,6 +7053,8 @@ static int intel_gen6_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP |MI_DISPLAY_FLIP_PLANE (intel_crtc->plane));intel_ring_emit (ring, fb->pitches[0 ] | obj->tiling_mode);
@@ -7111,6 +7121,8 @@ static int intel_gen7_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP_I915 | plane_bit);intel_ring_emit (ring, (fb->pitches[0 ] | obj->tiling_mode));intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
drivers/gpu/drm/i915/intel_drv.h +3 -0
@@ -235,6 +235,9 @@ struct intel_crtc {/* We can share PLLs across outputs if the timings match */ struct intel_pch_pll *pch_pll;uint32_t ddi_pll_sel; + +/* reset counter value when the last flip was submitted */ +unsigned int reset_counter; };struct intel_plane {
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
Quoted 10 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.Signed-off-by Ville Syrjälä <[email protected]>
You might want to rename reset_counter to flip_reset_counter to indicate this field is specific to the flipping code. Other parts of the code might need something similar as well?
Signature · 1 line
Damien
Re: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
Quoted 10 lines · Damien Lespiau
Quoted 9 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.
Quoted 7 lines
Quoted 1 line
Signed-off-by Ville Syrjälä <[email protected]>Reviewed-by Damien Lespiau <[email protected]>You might want to rename
reset_countertoflip_reset_counterto indicate this field is specific to the flipping code. Other parts of the code might need something similar as well?
IIRC I used flip_reset_counter initially but then I decided it's too long and dropped the flip_ part. I can change it back if that's what people prefer.
Signature · 2 lines
Ville Syrjälä Intel OTC
Re: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
Quoted 15 lines · Ville Syrjälä
Quoted 14 lines · Damien Lespiau
Quoted 10 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.Signed-off-by Ville Syrjälä <[email protected]>Reviewed-by Damien Lespiau <[email protected]>
Quoted 7 lines
Quoted 3 lines
You might want to rename
reset_countertoflip_reset_counterto indicate this field is specific to the flipping code. Other parts of the code might need something similar as well?IIRC I used
flip_reset_counterinitially but then I decided it's too long and dropped theflip_part. I can change it back if that's what people prefer.
Imo the generic reset_counter name is ok. At least as long as we don't need to keep track of more than one of these per crtc for different things (or if we ever start to add more fine-grained reset domains). -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
In reply to [email protected]Quoted 34 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 14 +++++++++++++- drivers/gpu/drm/i915/intel_drv.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/intel_display.c +3
-1@@ -2862,10 +2862,12 @@ static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc);unsigned long flags;bool pending; -if (i915_reset_in_progress (&dev_priv->gpu_error)) +if (i915_reset_in_progress (&dev_priv->gpu_error) || + intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter))return false;spin_lock_irqsave (&dev->event_lock, flags);
drivers/gpu/drm/i915/intel_display.c static int intel_gen2_queue_flip(struct drm_device *dev, · line 6917
Quoted 4 lines
drivers/gpu/drm/i915/intel_display.c +1
-0@@ -6912,6 +6914,8 @@ static int intel_gen2_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter);
Ok no bikeshed about ->reset_counter, but a different one: Why does this need to be in the per-gen callback? Can't we just grab this before we call down into these callbacks? Imo races wrt the reset/hang code don't matter that much as long as we don't wait forever for a pageflip which won't happen. Hanging the gpu concurrently to pageflipping is undefined anyway right now ...
-Daniel
Quoted 61 lines
drivers/gpu/drm/i915/intel_display.c +9
-0+/* Can't queue multiple flips, so wait for the previous * one to finish before executing the next. */ @@ -6956,6 +6960,8 @@ static int intel_gen3_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +if (intel_crtc->plane) flip_mask =MI_WAIT_FOR_PLANE_B_FLIP ;else @@ -6997,6 +7003,8 @@ static int intel_gen4_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +/* i965+ uses the linear or tiled offsets from the * Display Registers (which do not change across a page-flip) * so we need only reprogram the base address. @@ -7045,6 +7053,8 @@ static int intel_gen6_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP |MI_DISPLAY_FLIP_PLANE (intel_crtc->plane));intel_ring_emit (ring, fb->pitches[0 ] | obj->tiling_mode);@@ -7111,6 +7121,8 @@ static int intel_gen7_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP_I915 | plane_bit);intel_ring_emit (ring, (fb->pitches[0 ] | obj->tiling_mode));intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset);drivers/gpu/drm/i915/intel_drv.h +3
-0@@ -235,6 +235,9 @@ struct intel_crtc {/* We can share PLLs across outputs if the timings match */ struct intel_pch_pll *pch_pll;uint32_t ddi_pll_sel; + +/* reset counter value when the last flip was submitted */ +unsigned int reset_counter; };struct intel_plane {Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
Quoted 38 lines · Daniel Vetter
Quoted 37 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 14 +++++++++++++- drivers/gpu/drm/i915/intel_drv.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/intel_display.c +3
-1@@ -2862,10 +2862,12 @@ static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc);unsigned long flags;bool pending; -if (i915_reset_in_progress (&dev_priv->gpu_error)) +if (i915_reset_in_progress (&dev_priv->gpu_error) || + intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter))return false;spin_lock_irqsave (&dev->event_lock, flags);@@ -6912,6 +6914,8 @@ static int intel_gen2_queue_flip(struct drm_device *dev,if (ret) goto err_unpin;
Quoted 8 lines
drivers/gpu/drm/i915/intel_display.c static int intel_gen2_queue_flip(struct drm_device *dev, · line 6917
Quoted 1 line
drivers/gpu/drm/i915/intel_display.c +1
-0+ intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter);Ok no bikeshed about ->reset_counter, but a different one: Why does this need to be in the per-gen callback? Can't we just grab this before we call down into these callbacks? Imo races wrt the reset/hang code don't matter that much as long as we don't wait forever for a pageflip which won't happen. Hanging the gpu concurrently to pageflipping is undefined anyway right now ...
Yeah. It could be moved to happen a little earlier, and thus avoid the duplication.
Quoted 68 lines
-Daniel
Quoted 61 lines
drivers/gpu/drm/i915/intel_display.c +9
-0+/* Can't queue multiple flips, so wait for the previous * one to finish before executing the next. */ @@ -6956,6 +6960,8 @@ static int intel_gen3_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +if (intel_crtc->plane) flip_mask =MI_WAIT_FOR_PLANE_B_FLIP ;else @@ -6997,6 +7003,8 @@ static int intel_gen4_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +/* i965+ uses the linear or tiled offsets from the * Display Registers (which do not change across a page-flip) * so we need only reprogram the base address. @@ -7045,6 +7053,8 @@ static int intel_gen6_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP |MI_DISPLAY_FLIP_PLANE (intel_crtc->plane));intel_ring_emit (ring, fb->pitches[0 ] | obj->tiling_mode);@@ -7111,6 +7121,8 @@ static int intel_gen7_queue_flip(struct drm_device *dev,if (ret) goto err_unpin; + intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter); +intel_ring_emit (ring,MI_DISPLAY_FLIP_I915 | plane_bit);intel_ring_emit (ring, (fb->pitches[0 ] | obj->tiling_mode));intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset);drivers/gpu/drm/i915/intel_drv.h +3
-0@@ -235,6 +235,9 @@ struct intel_crtc {/* We can share PLLs across outputs if the timings match */ struct intel_pch_pll *pch_pll;uint32_t ddi_pll_sel; + +/* reset counter value when the last flip was submitted */ +unsigned int reset_counter; };struct intel_plane {Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfxSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 2 lines
Ville Syrjälä Intel OTC
Daniel Vetter
AppliedRe: [PATCH 2/6] drm/i915: Don't wait for page flips if there was GPU reset
Quoted 48 lines · Ville Syrjälä
Quoted 38 lines · Daniel Vetter
Quoted 37 lines · On Tue, Jan 29, 2013 at 06:13:34PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
If a GPU reset occurs while a page flip has been submitted to the ring, the flip will never complete once the ring has been reset.
The GPU reset can be detected by sampling the
reset_counterbefore the flip is submitted, and then while waiting for the flip, the sampled counter is compared with the currentreset_countervalue.Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 14 +++++++++++++- drivers/gpu/drm/i915/intel_drv.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/intel_display.c +3
-1@@ -2862,10 +2862,12 @@ static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc);unsigned long flags;bool pending; -if (i915_reset_in_progress (&dev_priv->gpu_error)) +if (i915_reset_in_progress (&dev_priv->gpu_error) || + intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter))return false;spin_lock_irqsave (&dev->event_lock, flags);@@ -6912,6 +6914,8 @@ static int intel_gen2_queue_flip(struct drm_device *dev,if (ret) goto err_unpin;Quoted 8 lines
drivers/gpu/drm/i915/intel_display.c static int intel_gen2_queue_flip(struct drm_device *dev, · line 6917
Quoted 1 line
drivers/gpu/drm/i915/intel_display.c +1
-0+ intel_crtc->reset_counter =atomic_read (&dev_priv->gpu_error.reset_counter);Ok no bikeshed about ->reset_counter, but a different one: Why does this need to be in the per-gen callback? Can't we just grab this before we call down into these callbacks? Imo races wrt the reset/hang code don't matter that much as long as we don't wait forever for a pageflip which won't happen. Hanging the gpu concurrently to pageflipping is undefined anyway right now ...
Quoted 2 lines
Yeah. It could be moved to happen a little earlier, and thus avoid the duplication.
Applied the patch and moved the assignment around a bit, thanks. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 3/6 drm/i915: Wake up pending_flip_queue as part of reset handling
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Someone may be waiting for a flip that will never complete due to a GPU reset. Wake up all such waiters when the hang is first detected, and after the reset processing has finished.
--- drivers/gpu/drm/i915/i915_irq.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_irq.c +4 -0
@@ -915,6 +915,8 @@ static void i915_error_work_func(struct work_struct *work)for_each_ring (ring, dev_priv, i)wake_up_all (&ring->irq_queue); +wake_up_all (&dev_priv->pending_flip_queue); +wake_up_all (&dev_priv->gpu_error.reset_queue); } }
@@ -1540,6 +1542,8 @@ void i915_handle_error(struct drm_device *dev, bool wedged)*/ for_each_ring (ring, dev_priv, i)wake_up_all (&ring->irq_queue); + +wake_up_all (&dev_priv->pending_flip_queue); }queue_work (dev_priv->wq, &dev_priv->gpu_error.work);
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/6] drm/i915: Wake up pending_flip_queue as part of reset handling
Quoted 7 lines · On Tue, Jan 29, 2013 at 06:13:35PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Someone may be waiting for a flip that will never complete due to a GPU reset. Wake up all such waiters when the hang is first detected, and after the reset processing has finished.
Signed-off-by Ville Syrjälä <[email protected]>
Signature · 1 line
Damien
Re: [PATCH 3/6] drm/i915: Wake up pending_flip_queue as part of reset handling
In reply to [email protected]Quoted 25 lines · On Tue, Jan 29, 2013 at 06:13:35PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Someone may be waiting for a flip that will never complete due to a GPU reset. Wake up all such waiters when the hang is first detected, and after the reset processing has finished.
Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/i915_irq.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/i915/i915_irq.c +2
-0@@ -915,6 +915,8 @@ static void i915_error_work_func(struct work_struct *work)for_each_ring (ring, dev_priv, i)wake_up_all (&ring->irq_queue); +wake_up_all (&dev_priv->pending_flip_queue); +wake_up_all (&dev_priv->gpu_error.reset_queue); } }
drivers/gpu/drm/i915/i915_irq.c void i915_handle_error(struct drm_device *dev, bool wedged) · line 1546
Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +2
-0@@ -1540,6 +1542,8 @@ void i915_handle_error(struct drm_device *dev, bool wedged)*/ for_each_ring (ring, dev_priv, i)wake_up_all (&ring->irq_queue); + +wake_up_all (&dev_priv->pending_flip_queue);
I don't quite follow why we need this one here. The wake up for the ring irq queues is to get people off the dev->struct_mutex lock, which the reset handler needs to acquire to do its job. But process stalling for pageflips to complete already can't hold dev->struct_mutex, since otherwise they'd block out the pageflip completion works and so would deadlock already.
Is there another reason why we need to kick waiters before the reset has completed that I'm missing here? One potential issue would be clarifying what exactly happens when the gpu hangs while pageflipping, i.e. whether the kernel should go out of it's way and re-issue the pageflip if it died meanwhile. But even that could be scheduled from a workqueue I think. And even if that'd require us to kick waiters of the pending flip queue I'd prefer to only add it once we really need it (plus a big comment explaining the tricks).
-Daniel
Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +0
-0}queue_work (dev_priv->wq, &dev_priv->gpu_error.work);Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 4/6 drm/i915: Move intel_crtc_has_pending_flip() earlier
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Just shuffle the code around. No functional changes.
--- drivers/gpu/drm/i915/intel_display.c | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/gpu/drm/i915/intel_display.c +19 -19
@@ -2262,6 +2262,25 @@ static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y) } } +static bool intel_crtc_has_pending_flip (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +unsigned long flags; +bool pending; + +if (i915_reset_in_progress (&dev_priv->gpu_error) || + intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter)) +return false; + +spin_lock_irqsave (&dev->event_lock, flags); + pending =to_intel_crtc (crtc)->unpin_work !=NULL ; +spin_unlock_irqrestore (&dev->event_lock, flags); + +return pending; +} +static int intel_pipe_set_base (struct drm_crtc *crtc,int x,int y,struct drm_framebuffer *fb)
@@ -2858,25 +2877,6 @@ static void ironlake_fdi_disable(struct drm_crtc *crtc)udelay (100 ); } -static bool intel_crtc_has_pending_flip (struct drm_crtc *crtc) -{ -struct drm_device *dev = crtc->dev; -struct drm_i915_private *dev_priv = dev->dev_private; -struct intel_crtc *intel_crtc =to_intel_crtc (crtc); -unsigned long flags; -bool pending; - -if (i915_reset_in_progress (&dev_priv->gpu_error) || - intel_crtc->reset_counter !=atomic_read (&dev_priv->gpu_error.reset_counter)) -return false; - -spin_lock_irqsave (&dev->event_lock, flags); - pending =to_intel_crtc (crtc)->unpin_work !=NULL ; -spin_unlock_irqrestore (&dev->event_lock, flags); - -return pending; -} -static void intel_crtc_wait_for_pending_flips (struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev;
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 4/6] drm/i915: Move intel_crtc_has_pending_flip() earlier
Quoted 5 lines · On Tue, Jan 29, 2013 at 06:13:36PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Just shuffle the code around. No functional changes.
Signed-off-by Ville Syrjälä <[email protected]>
Mastering the art of small orthognal commits :)
Signature · 1 line
Damien
PATCH 5/6 drm/i915: Add intel_crtc_wait_for_pending_flips_locked()
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Move the functionality of intel_crtc_wait_for_pending_flips() into intel_crtc_wait_for_pending_flips_locked().
intel_crtc_wait_for_pending_flips() is now just a wrapper that grab struct_mutex and calls intel_crtc_wait_for_pending_flips_locked().
This changes the behaviour of intel_crtc_wait_for_pending_flips() so that it now holds struct_mutex while waiting for pending flips.
--- drivers/gpu/drm/i915/intel_display.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/intel_display.c +17 -7
@@ -2281,6 +2281,22 @@ static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)return pending; } +static void intel_crtc_wait_for_pending_flips_locked (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; + +if (crtc->fb ==NULL ) +return ; + +WARN_ON (waitqueue_active (&dev_priv->pending_flip_queue)); + +wait_event (dev_priv->pending_flip_queue, + !intel_crtc_has_pending_flip (crtc)); + +intel_finish_fb (crtc->fb); +} +static int intel_pipe_set_base (struct drm_crtc *crtc,int x,int y,struct drm_framebuffer *fb)
@@ -2880,18 +2896,12 @@ static void ironlake_fdi_disable(struct drm_crtc *crtc)static void intel_crtc_wait_for_pending_flips (struct drm_crtc *crtc) {struct drm_device *dev = crtc->dev; -struct drm_i915_private *dev_priv = dev->dev_private;if (crtc->fb ==NULL )return ; -WARN_ON (waitqueue_active (&dev_priv->pending_flip_queue)); - -wait_event (dev_priv->pending_flip_queue, - !intel_crtc_has_pending_flip (crtc)); -mutex_lock (&dev->struct_mutex); -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc);mutex_unlock (&dev->struct_mutex); }
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/6] drm/i915: Add intel_crtc_wait_for_pending_flips_locked()
Quoted 5 lines · On Tue, Jan 29, 2013 at 06:13:37PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Move the functionality of
intel_crtc_wait_for_pending_flips()intointel_crtc_wait_for_pending_flips_locked().
Quoted 7 lines
intel_crtc_wait_for_pending_flips()is now just a wrapper that grabstruct_mutexand callsintel_crtc_wait_for_pending_flips_locked().This changes the behaviour of
intel_crtc_wait_for_pending_flips()so that it now holdsstruct_mutexwhile waiting for pending flips.Signed-off-by Ville Syrjälä <[email protected]>
Signature · 1 line
Damien
PATCH 6/6 drm/i915: Really wait for pending flips in intel_pipe_set_base()
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Since obj->pending_flips was never set, intel_pipe_set_base() never actually waited for pending page flips to complete.
We really do want to wait for the pending flips, because otherwise the mmio surface base address update could overtake the flip, and you could end up with an old frame on the screen once the flip really completes.
Just call intel_crtc_wait_pending_flips_locked() instead of intel_finish_fb() from intel_pipe_set_base() to achieve the desired result.
--- drivers/gpu/drm/i915/intel_display.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +1 -2
@@ -2330,8 +2330,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,return ret; } -if (crtc->fb) -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc); ret = dev_priv->display.update_plane (crtc, fb, x, y);if (ret) {
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
Quoted 10 lines · On Tue, Jan 29, 2013 at 06:13:38PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Since
obj->pending_flipswas never set,intel_pipe_set_base()never actually waited for pending page flips to complete.We really do want to wait for the pending flips, because otherwise the mmio surface base address update could overtake the flip, and you could end up with an old frame on the screen once the flip really completes.
Quoted 5 lines
Just call
intel_crtc_wait_pending_flips_locked()instead ofintel_finish_fb()fromintel_pipe_set_base()to achieve the desired result.Signed-off-by Ville Syrjälä <[email protected]>
Signature · 1 line
Damien
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
In reply to [email protected]Quoted 24 lines · On Tue, Jan 29, 2013 at 06:13:38PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Since
obj->pending_flipswas never set,intel_pipe_set_base()never actually waited for pending page flips to complete.We really do want to wait for the pending flips, because otherwise the mmio surface base address update could overtake the flip, and you could end up with an old frame on the screen once the flip really completes.
Just call
intel_crtc_wait_pending_flips_locked()instead ofintel_finish_fb()fromintel_pipe_set_base()to achieve the desired result.Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/i915/intel_display.c +0
-0
drivers/gpu/drm/i915/intel_display.c intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, · line 2333
Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +1
-2@@ -2330,8 +2330,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,return ret; } -if (crtc->fb) -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc);
Ah, I see now why you grab dev->struct_mutex and need to kick waiters from the pending flip queue. I think grabbing the mutex twice isn't a major offense, since both the crtc disable code and set_base are slowpaths used rarely. So what about simply calling wait_for_pending_flips before grabbing the mutex in intel_pipe_set_base? We could then also inline finish_fb into it's only callsite ...
-Daniel
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +0
-0ret = dev_priv->display.update_plane (crtc, fb, x, y);if (ret) {Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
Quoted 28 lines · Daniel Vetter
Quoted 27 lines · On Tue, Jan 29, 2013 at 06:13:38PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Since
obj->pending_flipswas never set,intel_pipe_set_base()never actually waited for pending page flips to complete.We really do want to wait for the pending flips, because otherwise the mmio surface base address update could overtake the flip, and you could end up with an old frame on the screen once the flip really completes.
Just call
intel_crtc_wait_pending_flips_locked()instead ofintel_finish_fb()fromintel_pipe_set_base()to achieve the desired result.Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/i915/intel_display.c +0
-0@@ -2330,8 +2330,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,return ret; }
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, · line 2333
Quoted 3 lines
drivers/gpu/drm/i915/intel_display.c +1
-2-if (crtc->fb) -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc);Ah, I see now why you grab
dev->struct_mutexand need to kick waiters from the pending flip queue. I think grabbing the mutex twice isn't a major offense, since both the crtc disable code andset_baseare slowpaths used rarely. So what about simply callingwait_for_pending_flipsbefore grabbing the mutex inintel_pipe_set_base? We could then also inlinefinish_fbinto it's only callsite ...
I didn't want to slow down intel_pipe_set_base() too much. If we wait for pending flips before pinning the new fb, we can never achieve any parallelism there. But if no-one cares about that, we can reorder.
Signature · 2 lines
Ville Syrjälä Intel OTC
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
Quoted 19 lines · Ville Syrjälä
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_display.c +0
-0@@ -2330,8 +2330,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,return ret; }Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, · line 2333
Quoted 3 lines
drivers/gpu/drm/i915/intel_display.c +1
-2-if (crtc->fb) -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc);Ah, I see now why you grab
dev->struct_mutexand need to kick waiters from the pending flip queue. I think grabbing the mutex twice isn't a major offense, since both the crtc disable code andset_baseare slowpaths used rarely. So what about simply callingwait_for_pending_flipsbefore grabbing the mutex inintel_pipe_set_base? We could then also inlinefinish_fbinto it's only callsite ...
Quoted 3 lines
I didn't want to slow down
intel_pipe_set_base()too much. If we wait for pending flips before pinning the new fb, we can never achieve any parallelism there. But if no-one cares about that, we can reorder.
I'm confused here - where can we extract parallelism in set_base between waiting for pending flips and the pinning? And imo set_base isn't really critical: It's officially a synchronous thing (we have a vblank wait in there), and if we want to fix that imo the nuclear pageflip should be the answer.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
Quoted 25 lines · Daniel Vetter
Quoted 19 lines · Ville Syrjälä
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_display.c +0
-0@@ -2330,8 +2330,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,return ret; }Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, · line 2333
Quoted 3 lines
drivers/gpu/drm/i915/intel_display.c +1
-2-if (crtc->fb) -intel_finish_fb (crtc->fb); +intel_crtc_wait_for_pending_flips_locked (crtc);Ah, I see now why you grab
dev->struct_mutexand need to kick waiters from the pending flip queue. I think grabbing the mutex twice isn't a major offense, since both the crtc disable code andset_baseare slowpaths used rarely. So what about simply callingwait_for_pending_flipsbefore grabbing the mutex inintel_pipe_set_base? We could then also inlinefinish_fbinto it's only callsite ...Quoted 3 lines
I didn't want to slow down
intel_pipe_set_base()too much. If we wait for pending flips before pinning the new fb, we can never achieve any parallelism there. But if no-one cares about that, we can reorder.
Quoted 5 lines
I'm confused here - where can we extract parallelism in
set_basebetween waiting for pending flips and the pinning? And imoset_baseisn't really critical: It's officially a synchronous thing (we have a vblank wait in there), and if we want to fix that imo the nuclear pageflip should be the answer.
The flip is making progress on the GPU side, and at the same time the CPU side can make some progress with the pin operation. At least that was my theory.
Signature · 2 lines
Ville Syrjälä Intel OTC
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
Quoted 3 lines · Ville Syrjälä
The flip is making progress on the GPU side, and at the same time the CPU side can make some progress with the pin operation. At least that was my theory.
The pin should be a no-op when moving a given framebuffer around. It's only really expensive when we need to clflush (and lesser so when we need to rewrite ptes), which should only happen on fresh framebuffers. As long as userspace does it's job and caches scanout buffers we should be fine. The other thing is waiting for outstanding rendering (to avoid hanging on an MI_WAIT_SCANLINE cmd), which just blocks. So doesn't really matter imo.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 6/6] drm/i915: Really wait for pending flips in intel_pipe_set_base()
In reply to Daniel VetterQuoted 5 lines · Daniel Vetter
I'm confused here - where can we extract parallelism in
set_basebetween waiting for pending flips and the pinning? And imoset_baseisn't really critical: It's officially a synchronous thing (we have a vblank wait in there), and if we want to fix that imo the nuclear pageflip should be the answer.
Speaking of which I've had a patch to remove that extra synchronous wait for over a year...
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 11 lines · On Tue, Jan 29, 2013 at 06:13:32PM +0200, [email protected] wrote:
Someone mentioned on irc that
intel_crtc_wait_for_pending_flips()was getting stuck in some cases. This rang a bell since I was poking around that stuff last year.The issue that I'm trying to fix here is processes getting stuck in D state when a GPU reset happens while page flips have been scheduled.
Testing is easy 1) fire up 'glxgears -fullscreen', run '
gem_hang0', try to VT switch. Without this series X and some kworker soon get stuck in D state and you're left with a useless box. With the patch set, you wait a while, the GPU hangcheck kicks in, and you get your console back.
Broken record maintainer request: Can you please bake that into an i-g-t? I think (hope) that running one of the delayed flip tests vs. the hangman (gem_hang is a bit evil since it can kill boxes for real) should do the trick. Then maybe also run one of the wf-vblank tests vs. hangman to check that we cancel those correctly, too.
Quoted 11 lines
The irc discussion was apparently about [1], but since the dmesg there doesn't show a GPU hang, I don't see this patch set fixing it. Frankly, I have no idea what's happening there.
Additional work after this would involve sending out pending page flip events. Currently if you don't do the VT switch after a hang, glxgears remains stuck because the X server didn't get the page flip event from the kernel. Also we should probably do an explicit
intel_pipe_set_base()with the current fb, to make sure we show the correct fb after the hang. But I'm not going to touch these right now. Actually I'm hoping someone else will volunteer for these tasks ;)
Hm ... I guess we need to walk the file_priv event list somewhere an fire them all off, indicating somehow that things went kaboom. I think we should aim for a drm generic way to singal those even. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 13 lines · Daniel Vetter
Quoted 11 lines · On Tue, Jan 29, 2013 at 06:13:32PM +0200, [email protected] wrote:
Someone mentioned on irc that
intel_crtc_wait_for_pending_flips()was getting stuck in some cases. This rang a bell since I was poking around that stuff last year.The issue that I'm trying to fix here is processes getting stuck in D state when a GPU reset happens while page flips have been scheduled.
Testing is easy 1) fire up 'glxgears -fullscreen', run '
gem_hang0', try to VT switch. Without this series X and some kworker soon get stuck in D state and you're left with a useless box. With the patch set, you wait a while, the GPU hangcheck kicks in, and you get your console back.
Quoted 5 lines
Broken record maintainer request: Can you please bake that into an i-g-t? I think (hope) that running one of the delayed flip tests vs. the hangman (
gem_hangis a bit evil since it can kill boxes for real) should do the trick. Then maybe also run one of the wf-vblank tests vs. hangman to check that we cancel those correctly, too.
Actually for the case you're fixing here we probably need a delayed flip vs. modeset (without flip event checks) against a simulated gpu hang. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch