dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/vblank: Document drm_crtc_vblank_restore constraints
@ 2021-02-09 10:15 Daniel Vetter
  2021-02-09 15:36 ` Ville Syrjälä
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Vetter @ 2021-02-09 10:15 UTC (permalink / raw)
  To: DRI Development; +Cc: Daniel Vetter, Intel Graphics Development, Daniel Vetter

I got real badly confused when trying to review a fix from Ville for
this. Let's try to document better what's required for this, and check
the minimal settings at runtime - we can't check ofc that there's
indeed no races in the driver callback.

Also noticed that the drm_vblank_restore version is unused, so lets
unexport that while at it.

Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/gpu/drm/drm_vblank.c | 25 ++++++++++---------------
 include/drm/drm_vblank.h     |  1 -
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index c914b14cfb43..05f4d4c078fd 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -1471,20 +1471,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc)
 }
 EXPORT_SYMBOL(drm_crtc_vblank_on);
 
-/**
- * drm_vblank_restore - estimate missed vblanks and update vblank count.
- * @dev: DRM device
- * @pipe: CRTC index
- *
- * Power manamement features can cause frame counter resets between vblank
- * disable and enable. Drivers can use this function in their
- * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
- * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
- * vblank counter.
- *
- * This function is the legacy version of drm_crtc_vblank_restore().
- */
-void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
+static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
 {
 	ktime_t t_vblank;
 	struct drm_vblank_crtc *vblank;
@@ -1520,7 +1507,6 @@ void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
 		    diff, diff_ns, framedur_ns, cur_vblank - vblank->last);
 	store_vblank(dev, pipe, diff, t_vblank, cur_vblank);
 }
-EXPORT_SYMBOL(drm_vblank_restore);
 
 /**
  * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
@@ -1531,9 +1517,18 @@ EXPORT_SYMBOL(drm_vblank_restore);
  * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
  * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
  * vblank counter.
+ *
+ * Note that drivers must have race-free high-precision timestamping support,
+ * i.e.  &drm_crtc_funcs.get_vblank_timestamp must be hooked up and
+ * &drm_driver.vblank_disable_immediate must be set to indicate the
+ * time-stamping functions are race-free against vblank hardware counter
+ * increments.
  */
 void drm_crtc_vblank_restore(struct drm_crtc *crtc)
 {
+	WARN_ON_ONCE(!crtc->funcs->get_vblank_timestamp);
+	WARN_ON_ONCE(!crtc->dev->vblank_disable_immediate);
+
 	drm_vblank_restore(crtc->dev, drm_crtc_index(crtc));
 }
 EXPORT_SYMBOL(drm_crtc_vblank_restore);
diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
index dd125f8c766c..733a3e2d1d10 100644
--- a/include/drm/drm_vblank.h
+++ b/include/drm/drm_vblank.h
@@ -247,7 +247,6 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc);
 void drm_crtc_vblank_reset(struct drm_crtc *crtc);
 void drm_crtc_vblank_on(struct drm_crtc *crtc);
 u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
-void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
 void drm_crtc_vblank_restore(struct drm_crtc *crtc);
 
 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
-- 
2.30.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/vblank: Document drm_crtc_vblank_restore constraints
  2021-02-09 10:15 [PATCH] drm/vblank: Document drm_crtc_vblank_restore constraints Daniel Vetter
@ 2021-02-09 15:36 ` Ville Syrjälä
  2021-02-10 11:39   ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: Ville Syrjälä @ 2021-02-09 15:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Daniel Vetter, Intel Graphics Development, DRI Development

On Tue, Feb 09, 2021 at 11:15:23AM +0100, Daniel Vetter wrote:
> I got real badly confused when trying to review a fix from Ville for
> this. Let's try to document better what's required for this, and check
> the minimal settings at runtime - we can't check ofc that there's
> indeed no races in the driver callback.
> 
> Also noticed that the drm_vblank_restore version is unused, so lets
> unexport that while at it.
> 
> Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 25 ++++++++++---------------
>  include/drm/drm_vblank.h     |  1 -
>  2 files changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index c914b14cfb43..05f4d4c078fd 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -1471,20 +1471,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc)
>  }
>  EXPORT_SYMBOL(drm_crtc_vblank_on);
>  
> -/**
> - * drm_vblank_restore - estimate missed vblanks and update vblank count.
> - * @dev: DRM device
> - * @pipe: CRTC index
> - *
> - * Power manamement features can cause frame counter resets between vblank
> - * disable and enable. Drivers can use this function in their
> - * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
> - * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
> - * vblank counter.
> - *
> - * This function is the legacy version of drm_crtc_vblank_restore().
> - */
> -void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
> +static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
>  {
>  	ktime_t t_vblank;
>  	struct drm_vblank_crtc *vblank;
> @@ -1520,7 +1507,6 @@ void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
>  		    diff, diff_ns, framedur_ns, cur_vblank - vblank->last);
>  	store_vblank(dev, pipe, diff, t_vblank, cur_vblank);
>  }
> -EXPORT_SYMBOL(drm_vblank_restore);
>  
>  /**
>   * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
> @@ -1531,9 +1517,18 @@ EXPORT_SYMBOL(drm_vblank_restore);
>   * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
>   * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
>   * vblank counter.
> + *
> + * Note that drivers must have race-free high-precision timestamping support,
> + * i.e.  &drm_crtc_funcs.get_vblank_timestamp must be hooked up and
> + * &drm_driver.vblank_disable_immediate must be set to indicate the
> + * time-stamping functions are race-free against vblank hardware counter
> + * increments.

Looks good. Might prevent someone from shooting themselves in
the foot.

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

>   */
>  void drm_crtc_vblank_restore(struct drm_crtc *crtc)
>  {
> +	WARN_ON_ONCE(!crtc->funcs->get_vblank_timestamp);
> +	WARN_ON_ONCE(!crtc->dev->vblank_disable_immediate);
> +
>  	drm_vblank_restore(crtc->dev, drm_crtc_index(crtc));
>  }
>  EXPORT_SYMBOL(drm_crtc_vblank_restore);
> diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
> index dd125f8c766c..733a3e2d1d10 100644
> --- a/include/drm/drm_vblank.h
> +++ b/include/drm/drm_vblank.h
> @@ -247,7 +247,6 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc);
>  void drm_crtc_vblank_reset(struct drm_crtc *crtc);
>  void drm_crtc_vblank_on(struct drm_crtc *crtc);
>  u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
> -void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
>  void drm_crtc_vblank_restore(struct drm_crtc *crtc);
>  
>  void drm_calc_timestamping_constants(struct drm_crtc *crtc,
> -- 
> 2.30.0

-- 
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/vblank: Document drm_crtc_vblank_restore constraints
  2021-02-09 15:36 ` Ville Syrjälä
@ 2021-02-10 11:39   ` Daniel Vetter
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2021-02-10 11:39 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, Intel Graphics Development, DRI Development,
	Daniel Vetter

On Tue, Feb 09, 2021 at 05:36:07PM +0200, Ville Syrjälä wrote:
> On Tue, Feb 09, 2021 at 11:15:23AM +0100, Daniel Vetter wrote:
> > I got real badly confused when trying to review a fix from Ville for
> > this. Let's try to document better what's required for this, and check
> > the minimal settings at runtime - we can't check ofc that there's
> > indeed no races in the driver callback.
> > 
> > Also noticed that the drm_vblank_restore version is unused, so lets
> > unexport that while at it.
> > 
> > Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  drivers/gpu/drm/drm_vblank.c | 25 ++++++++++---------------
> >  include/drm/drm_vblank.h     |  1 -
> >  2 files changed, 10 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> > index c914b14cfb43..05f4d4c078fd 100644
> > --- a/drivers/gpu/drm/drm_vblank.c
> > +++ b/drivers/gpu/drm/drm_vblank.c
> > @@ -1471,20 +1471,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc)
> >  }
> >  EXPORT_SYMBOL(drm_crtc_vblank_on);
> >  
> > -/**
> > - * drm_vblank_restore - estimate missed vblanks and update vblank count.
> > - * @dev: DRM device
> > - * @pipe: CRTC index
> > - *
> > - * Power manamement features can cause frame counter resets between vblank
> > - * disable and enable. Drivers can use this function in their
> > - * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
> > - * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
> > - * vblank counter.
> > - *
> > - * This function is the legacy version of drm_crtc_vblank_restore().
> > - */
> > -void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
> > +static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
> >  {
> >  	ktime_t t_vblank;
> >  	struct drm_vblank_crtc *vblank;
> > @@ -1520,7 +1507,6 @@ void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
> >  		    diff, diff_ns, framedur_ns, cur_vblank - vblank->last);
> >  	store_vblank(dev, pipe, diff, t_vblank, cur_vblank);
> >  }
> > -EXPORT_SYMBOL(drm_vblank_restore);
> >  
> >  /**
> >   * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
> > @@ -1531,9 +1517,18 @@ EXPORT_SYMBOL(drm_vblank_restore);
> >   * &drm_crtc_funcs.enable_vblank implementation to estimate missed vblanks since
> >   * the last &drm_crtc_funcs.disable_vblank using timestamps and update the
> >   * vblank counter.
> > + *
> > + * Note that drivers must have race-free high-precision timestamping support,
> > + * i.e.  &drm_crtc_funcs.get_vblank_timestamp must be hooked up and
> > + * &drm_driver.vblank_disable_immediate must be set to indicate the
> > + * time-stamping functions are race-free against vblank hardware counter
> > + * increments.
> 
> Looks good. Might prevent someone from shooting themselves in
> the foot.

Yeah hopefully, maybe even me :-)


> 
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Thanks for your review, I pushed to drm-misc-next.
-Daniel

> 
> >   */
> >  void drm_crtc_vblank_restore(struct drm_crtc *crtc)
> >  {
> > +	WARN_ON_ONCE(!crtc->funcs->get_vblank_timestamp);
> > +	WARN_ON_ONCE(!crtc->dev->vblank_disable_immediate);
> > +
> >  	drm_vblank_restore(crtc->dev, drm_crtc_index(crtc));
> >  }
> >  EXPORT_SYMBOL(drm_crtc_vblank_restore);
> > diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
> > index dd125f8c766c..733a3e2d1d10 100644
> > --- a/include/drm/drm_vblank.h
> > +++ b/include/drm/drm_vblank.h
> > @@ -247,7 +247,6 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc);
> >  void drm_crtc_vblank_reset(struct drm_crtc *crtc);
> >  void drm_crtc_vblank_on(struct drm_crtc *crtc);
> >  u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
> > -void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
> >  void drm_crtc_vblank_restore(struct drm_crtc *crtc);
> >  
> >  void drm_calc_timestamping_constants(struct drm_crtc *crtc,
> > -- 
> > 2.30.0
> 
> -- 
> Ville Syrjälä
> Intel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2021-02-10 11:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 10:15 [PATCH] drm/vblank: Document drm_crtc_vblank_restore constraints Daniel Vetter
2021-02-09 15:36 ` Ville Syrjälä
2021-02-10 11:39   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).