drm/i915: Page flip stuff
Subsystems (2)
cover drm/i915: Page flip stuff
This is my quick attempt at aliminating i915_gem_execbuffer_wait_for_flips().
While doing that I noticed that intel_pipe_set_base() never actually waited for pending flips, while it probably should.
I also spotted another possible problem, for which I didn't provide a patch. We wait on the pending_flip_queue based on two different variables. One is the unpin_work, which indicates pending flips, and the other is mm.wedged, which seems to indicate that the GPU is stuck. I noticed that we don't seem to call wake_up(pending_flip_queue) after clearing mm.wedged. Is that a bug, or did I just miss something?
PATCH 1/2 drm/i915: Kill i915_gem_execbuffer_wait_for_flips()
From: Ville Syrjälä <[email protected]>
As per Chris Wilson's suggestion makei915_gem_execbuffer_wait_for_flips() go away.
This was used to stall the GPU ring while there are pending page flips involving the relevant BO. Ie. while the BO is still being scanned out by the display controller.
The recommended alternative is to use the page flip events to wait for the page flips to fully complete before reusing the BO of the old front buffer. Or use more buffers.
--- drivers/gpu/drm/i915/i915_drv.h | 7 ---- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 42 ---------------------------- drivers/gpu/drm/i915/intel_display.c | 12 +------- 3 files changed, 1 insertions(+), 60 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -7
@@ -1053,13 +1053,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_intel_bo (x) container_of(x, struct drm_i915_gem_object, base)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -42
62 lines not on this page · raw message
drivers/gpu/drm/i915/intel_display.c +1 -11
@@ -2177,8 +2177,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)int ret;wait_event (dev_priv->pending_flip_queue, -atomic_read (&dev_priv->mm.wedged) || -atomic_read (&obj->pending_flip) ==0 ); +atomic_read (&dev_priv->mm.wedged));/* Big Hammer, we also need to ensure that any pending * MI_WAIT_FOR_EVENT inside a user batch buffer on the
@@ -6758,9 +6757,6 @@ static void do_intel_finish_page_flip(struct drm_device *dev, obj = work->old_fb_obj; -atomic_clear_mask (1 << intel_crtc->plane, - &obj->pending_flip.counter); -wake_up (&dev_priv->pending_flip_queue);schedule_work (&work->work);
@@ -7102,11 +7098,6 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, work->enable_stall_check = true; -/* Block clients from rendering to the new back buffer until -* the flip occurs and the object is no longer visible. -*/ -atomic_add (1 << intel_crtc->plane, &work->old_fb_obj->pending_flip); - ret = dev_priv->display.queue_flip (dev, crtc, fb, obj);if (ret) goto cleanup_pending;
@@ -7120,7 +7111,6 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,return 0 ; cleanup_pending: -atomic_sub (1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);drm_gem_object_unreference (&work->old_fb_obj->base);drm_gem_object_unreference (&obj->base);mutex_unlock (&dev->struct_mutex);
Signature · 6 lines
1.7.8.6 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 1/2] drm/i915: Kill i915_gem_execbuffer_wait_for_flips()
drivers/gpu/drm/i915/intel_display.c intel_finish_fb(struct drm_framebuffer *old_fb) · line 2180
Quoted 11 lines · On Wed, Oct 31, 2012 at 07:38:40PM +0200, [email protected] wrote:
drivers/gpu/drm/i915/intel_display.c +1
-2@@ -2177,8 +2177,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)int ret;wait_event (dev_priv->pending_flip_queue, -atomic_read (&dev_priv->mm.wedged) || -atomic_read (&obj->pending_flip) ==0 ); +atomic_read (&dev_priv->mm.wedged));
And of course this bit is total nonsense now. I had the logic inverted in my mind. So this guy actually wants to stop waiting when the GPU hangs, not the other way around. So I need to drop the whole wait_event() here.
Stand by for v2...
Signature · 2 lines
Ville Syrjälä Intel OTC
Re: [PATCH 1/2] drm/i915: Kill i915_gem_execbuffer_wait_for_flips()
In reply to [email protected]Quoted 5 lines · [email protected] writes:
From: Ville Syrjälä <[email protected]>
As per Chris Wilson's suggestion make
i915_gem_execbuffer_wait_for_flips()go away.
Quoted 7 lines
This was used to stall the GPU ring while there are pending page flips involving the relevant BO. Ie. while the BO is still being scanned out by the display controller.
The recommended alternative is to use the page flip events to wait for the page flips to fully complete before reusing the BO of the old front buffer. Or use more buffers.
So, after this change, if userland submits an execbuf between having requested a pageflip and the vblank that the flip shows up on, does that exec block?
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 1/2] drm/i915: Kill i915_gem_execbuffer_wait_for_flips()
Quoted 11 lines · Eric Anholt
Quoted 9 lines · [email protected] writes:
From: Ville Syrjälä <[email protected]>
As per Chris Wilson's suggestion make
i915_gem_execbuffer_wait_for_flips()go away.This was used to stall the GPU ring while there are pending page flips involving the relevant BO. Ie. while the BO is still being scanned out by the display controller.
Quoted 7 lines
Quoted 3 lines
The recommended alternative is to use the page flip events to wait for the page flips to fully complete before reusing the BO of the old front buffer. Or use more buffers.
So, after this change, if userland submits an execbuf between having requested a pageflip and the vblank that the flip shows up on, does that exec block?
The code itself is dysfunctional and would cause a GPU hang on snb/ivb. Why should the kernel be imposing a policy upon userspace where none is required?
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 drm/i915: Wait for pending flips in intel_pipe_set_base()
In reply to [email protected]From: Ville Syrjälä <[email protected]>
intel_pipe_set_base() never actually waited for any pending page flips on the CRTC. It looks like it tried to, by calling intel_finish_fb() on the current front buffer. But the pending flips were actually tracked in the BO of the previous front buffer, so the call to intel_finish_fb() never did anything useful.
Now even the pending_flip counter is gone, so we should just use intel_crtc_wait_for_pending_flips(), but since we're already holding struct_mutex when we would call that function, we need another version of it, that itself doesn't lock struct_mutex.
--- drivers/gpu/drm/i915/intel_display.c | 54 ++++++++++++++++++++-------------- 1 files changed, 32 insertions(+), 22 deletions(-)
drivers/gpu/drm/i915/intel_display.c +32 -22
@@ -2176,9 +2176,6 @@ intel_finish_fb(struct drm_framebuffer *old_fb)bool was_interruptible = dev_priv->mm.interruptible;int ret; -wait_event (dev_priv->pending_flip_queue, -atomic_read (&dev_priv->mm.wedged)); -/* 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
@@ -2221,6 +2218,37 @@ 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; +unsigned long flags; +bool pending; + +if (atomic_read (&dev_priv->mm.wedged)) +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_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 ; + +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)
@@ -2254,8 +2282,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) {
@@ -2865,23 +2892,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; -unsigned long flags; -bool pending; - -if (atomic_read (&dev_priv->mm.wedged)) -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.8.6 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: Wait for pending flips in intel_pipe_set_base()
Quoted 8 lines · On Wed, 31 Oct 2012 19:38:41 +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
intel_pipe_set_base()never actually waited for any pending page flips on the CRTC. It looks like it tried to, by callingintel_finish_fb()on the current front buffer. But the pending flips were actually tracked in the BO of the previous front buffer, so the call tointel_finish_fb()never did anything useful.
Quoted 4 lines
Now even the
pending_flipcounter is gone, so we should just useintel_crtc_wait_for_pending_flips(), but since we're already holdingstruct_mutexwhen we would call that function, we need another version of it, that itself doesn't lockstruct_mutex.
That function call is now superfluous as you pointed out in an earlier review...
But yes, not waking up the pending_flip_queue after a GPU hang is a recent bug, and could explain the lockup in
https://bugs.freedesktop.org/show_bug.cgi?id=56337.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: Wait for pending flips in intel_pipe_set_base()
Quoted 9 lines · Chris Wilson
Quoted 8 lines · On Wed, 31 Oct 2012 19:38:41 +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
intel_pipe_set_base()never actually waited for any pending page flips on the CRTC. It looks like it tried to, by callingintel_finish_fb()on the current front buffer. But the pending flips were actually tracked in the BO of the previous front buffer, so the call tointel_finish_fb()never did anything useful.
Quoted 7 lines
Quoted 4 lines
Now even the
pending_flipcounter is gone, so we should just useintel_crtc_wait_for_pending_flips(), but since we're already holdingstruct_mutexwhen we would call that function, we need another version of it, that itself doesn't lockstruct_mutex.That function call is now superfluous as you pointed out in an earlier review...
I think we still need it when we're not doing a full modeset. Without it, intel_pipe_set_base() could overtake the flip.
So the call could be moved outside of intel_pipe_set_base() so that it wouldn't be called for the full modeset path. But I suppose it's a bit more efficient to do it after we've pinned the new buffer, so simply moving it might not be the best idea.
Quoted 3 lines
But yes, not waking up the
pending_flip_queueafter a GPU hang is a recent bug, and could explain the lockup in
https://bugs.freedesktop.org/show_bug.cgi?id=56337.
OK. I suppose I'll cook up a quick patch for that as well.
Signature · 2 lines
Ville Syrjälä Intel OTC