[Intel-gfx] [PATCH 6/9] drm: Avoid random vblank counter jumps if the hardware counter has been reset

Daniel Vetter daniel at ffwll.ch
Mon May 26 15:28:21 CEST 2014


On Mon, May 26, 2014 at 02:46:29PM +0300, ville.syrjala at linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
> 
> When drm_vblank_on() is called the hardware vblank counter may have
> been reset, so we can't trust that the old values sampled prior to
> drm_vblank_off() have anything to do with the new values.
> 
> So update the .last count in drm_vblank_on() to make the first
> drm_vblank_enable() consider that as the reference point. This
> will correct the user space visible counter to account for the
> time between drm_vblank_on() and the first drm_vblank_enable()
> calls.
> 
> For extra safety subtract one from the .last count in drm_vblank_on()
> to make sure that user space will never see the same counter value
> before and after modeset.
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>

Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> ---
>  drivers/gpu/drm/drm_irq.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index bb64f0f..54cb85d 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -1095,6 +1095,18 @@ void drm_vblank_on(struct drm_device *dev, int crtc)
>  		atomic_dec(&dev->vblank[crtc].refcount);
>  		dev->vblank[crtc].inmodeset = 0;
>  	}
> +
> +	/*
> +	 * sample the current counter to avoid random jumps
> +	 * when drm_vblank_enable() applies the diff
> +	 *
> +	 * -1 to make sure user will never see the same
> +	 * vblank counter value before and after a modeset
> +	 */
> +	dev->vblank[crtc].last =
> +		(dev->driver->get_vblank_counter(dev, crtc) - 1) &
> +		dev->max_vblank_count;
> +
>  	/* re-enable interrupts if there's are users left */
>  	if (atomic_read(&dev->vblank[crtc].refcount) != 0)
>  		WARN_ON(drm_vblank_enable(dev, crtc));
> -- 
> 1.8.5.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch



More information about the Intel-gfx mailing list