diff mbox

[4/5] drm: Allow reenabling of vblank interrupts even if refcount>0

Message ID 1393009415-27651-5-git-send-email-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ville Syrjälä Feb. 21, 2014, 7:03 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

If someone holds a vblank reference across the modeset, and after/during
the modeset someone tries to grab a vblank reference, the current code
won't re-enable the vblank interrupts. That's not good, so instead allow
the driver to choose whether drm_vblank_get() should always enable the
interrupts regardless of the refcount.

Combined with the drm_vblank_off/drm_vblank_on reject mechanism, this
can also be used to allow drivers to use vblank interrupts during
modeset, whether or not someone is currently holding a vblank reference.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_irq.c | 3 ++-
 include/drm/drmP.h        | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

Comments

Jesse Barnes Feb. 26, 2014, 7:44 p.m. UTC | #1
On Fri, 21 Feb 2014 21:03:34 +0200
ville.syrjala@linux.intel.com wrote:

> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> If someone holds a vblank reference across the modeset, and after/during
> the modeset someone tries to grab a vblank reference, the current code
> won't re-enable the vblank interrupts. That's not good, so instead allow
> the driver to choose whether drm_vblank_get() should always enable the
> interrupts regardless of the refcount.
> 
> Combined with the drm_vblank_off/drm_vblank_on reject mechanism, this
> can also be used to allow drivers to use vblank interrupts during
> modeset, whether or not someone is currently holding a vblank reference.
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_irq.c | 3 ++-
>  include/drm/drmP.h        | 6 ++++++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 6e5d820..d613b6f 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -897,7 +897,8 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
>  	}
>  
>  	/* Going from 0->1 means we have to enable interrupts again */
> -	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1) {
> +	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1 ||
> +	    dev->vblank_always_enable_on_get) {
>  		spin_lock(&dev->vblank_time_lock);
>  		if (!dev->vblank[crtc].enabled) {
>  			/* Enable vblank irqs under vblank_time_lock protection.
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index ee40483..3eca0ee 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -1156,6 +1156,12 @@ struct drm_device {
>  	 */
>  	bool vblank_disable_allowed;
>  
> +	/*
> +	 * Should a non-rejected drm_vblank_get() always enable the
> +	 * vblank interrupt regardless of the current refcount?
> +	 */
> +	bool vblank_always_enable_on_get;
> +
>  	/* array of size num_crtcs */
>  	struct drm_vblank_crtc *vblank;
>  

This seems like the sort of thing it would be good to have a test
for... I'm surprised we haven't hit it yet.  But in looking at the code
I don't see where we'd re-enable things properly in this situation, so
I guess it's a real bug.

Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Daniel Vetter March 4, 2014, 9:16 a.m. UTC | #2
On Fri, Feb 21, 2014 at 09:03:34PM +0200, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> If someone holds a vblank reference across the modeset, and after/during
> the modeset someone tries to grab a vblank reference, the current code
> won't re-enable the vblank interrupts. That's not good, so instead allow
> the driver to choose whether drm_vblank_get() should always enable the
> interrupts regardless of the refcount.
> 
> Combined with the drm_vblank_off/drm_vblank_on reject mechanism, this
> can also be used to allow drivers to use vblank interrupts during
> modeset, whether or not someone is currently holding a vblank reference.
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_irq.c | 3 ++-
>  include/drm/drmP.h        | 6 ++++++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 6e5d820..d613b6f 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -897,7 +897,8 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
>  	}
>  
>  	/* Going from 0->1 means we have to enable interrupts again */
> -	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1) {
> +	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1 ||
> +	    dev->vblank_always_enable_on_get) {
>  		spin_lock(&dev->vblank_time_lock);
>  		if (!dev->vblank[crtc].enabled) {
>  			/* Enable vblank irqs under vblank_time_lock protection.
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index ee40483..3eca0ee 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -1156,6 +1156,12 @@ struct drm_device {
>  	 */
>  	bool vblank_disable_allowed;
>  
> +	/*
> +	 * Should a non-rejected drm_vblank_get() always enable the
> +	 * vblank interrupt regardless of the current refcount?
> +	 */
> +	bool vblank_always_enable_on_get;

Nack for this hack. Why can't drm_vblank_on not just re-enable the vblank
interrupt if we still have a vblank reference?
-Daniel

> +
>  	/* array of size num_crtcs */
>  	struct drm_vblank_crtc *vblank;
>  
> -- 
> 1.8.3.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Ville Syrjälä March 5, 2014, 12:33 p.m. UTC | #3
On Tue, Mar 04, 2014 at 10:16:02AM +0100, Daniel Vetter wrote:
> On Fri, Feb 21, 2014 at 09:03:34PM +0200, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > If someone holds a vblank reference across the modeset, and after/during
> > the modeset someone tries to grab a vblank reference, the current code
> > won't re-enable the vblank interrupts. That's not good, so instead allow
> > the driver to choose whether drm_vblank_get() should always enable the
> > interrupts regardless of the refcount.
> > 
> > Combined with the drm_vblank_off/drm_vblank_on reject mechanism, this
> > can also be used to allow drivers to use vblank interrupts during
> > modeset, whether or not someone is currently holding a vblank reference.
> > 
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/drm_irq.c | 3 ++-
> >  include/drm/drmP.h        | 6 ++++++
> >  2 files changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > index 6e5d820..d613b6f 100644
> > --- a/drivers/gpu/drm/drm_irq.c
> > +++ b/drivers/gpu/drm/drm_irq.c
> > @@ -897,7 +897,8 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
> >  	}
> >  
> >  	/* Going from 0->1 means we have to enable interrupts again */
> > -	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1) {
> > +	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1 ||
> > +	    dev->vblank_always_enable_on_get) {
> >  		spin_lock(&dev->vblank_time_lock);
> >  		if (!dev->vblank[crtc].enabled) {
> >  			/* Enable vblank irqs under vblank_time_lock protection.
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index ee40483..3eca0ee 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -1156,6 +1156,12 @@ struct drm_device {
> >  	 */
> >  	bool vblank_disable_allowed;
> >  
> > +	/*
> > +	 * Should a non-rejected drm_vblank_get() always enable the
> > +	 * vblank interrupt regardless of the current refcount?
> > +	 */
> > +	bool vblank_always_enable_on_get;
> 
> Nack for this hack. Why can't drm_vblank_on not just re-enable the vblank
> interrupt if we still have a vblank reference?

Hmm. Yeah that seems like a nicer way to go about it.
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 6e5d820..d613b6f 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -897,7 +897,8 @@  int drm_vblank_get(struct drm_device *dev, int crtc)
 	}
 
 	/* Going from 0->1 means we have to enable interrupts again */
-	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1) {
+	if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1 ||
+	    dev->vblank_always_enable_on_get) {
 		spin_lock(&dev->vblank_time_lock);
 		if (!dev->vblank[crtc].enabled) {
 			/* Enable vblank irqs under vblank_time_lock protection.
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index ee40483..3eca0ee 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1156,6 +1156,12 @@  struct drm_device {
 	 */
 	bool vblank_disable_allowed;
 
+	/*
+	 * Should a non-rejected drm_vblank_get() always enable the
+	 * vblank interrupt regardless of the current refcount?
+	 */
+	bool vblank_always_enable_on_get;
+
 	/* array of size num_crtcs */
 	struct drm_vblank_crtc *vblank;