All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] handle vblank when disabling ctc with interrupt disabled
@ 2019-06-28 12:05 Robert Beckett
  2019-06-28 12:05 ` [PATCH v4 1/2] drm/vblank: warn on sending stale event Robert Beckett
  2019-06-28 12:05 ` [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled." Robert Beckett
  0 siblings, 2 replies; 6+ messages in thread
From: Robert Beckett @ 2019-06-28 12:05 UTC (permalink / raw)
  To: dri-devel
  Cc: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
	Daniel Vetter, linux-kernel, Philipp Zabel, Robert Beckett

Add warning when about to send stale vblank.
Revert change that stops vblank info being updated if interrupts already
disabled. This fixes a stale vblank timestamp issue seen on drm/imx.


Changes since v2:
Split up the patch in to smaller pieces.
Add warning when about to send bogus vblank event.
Update vblank to best guess info during drm_vblank_disable_and_save.

Changes since v3:
Update cover letter text to describe remaining actions.
Drop drm/imx patches as they have now been merged.
Replace vblank info estimation patch with a revert of the issue that
caused the need for estimation.

Robert Beckett (2):
  drm/vblank: warn on sending stale event
  Revert "drm/vblank: Do not update vblank count if interrupts are
    already disabled."

 drivers/gpu/drm/drm_vblank.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

-- 
2.18.0

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

* [PATCH v4 1/2] drm/vblank: warn on sending stale event
  2019-06-28 12:05 [PATCH v4 0/2] handle vblank when disabling ctc with interrupt disabled Robert Beckett
@ 2019-06-28 12:05 ` Robert Beckett
  2019-06-28 12:10   ` Robert Beckett
  2019-06-28 12:05 ` [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled." Robert Beckett
  1 sibling, 1 reply; 6+ messages in thread
From: Robert Beckett @ 2019-06-28 12:05 UTC (permalink / raw)
  To: dri-devel
  Cc: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
	Daniel Vetter, linux-kernel, Philipp Zabel, Robert Beckett

Warn when about to send stale vblank info and add advice to
documentation on how to avoid.

Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
 drivers/gpu/drm/drm_vblank.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 603ab105125d..7dabb2bdb733 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -918,6 +918,19 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
  *
  * See drm_crtc_arm_vblank_event() for a helper which can be used in certain
  * situation, especially to send out events for atomic commit operations.
+ *
+ * Care should be taken to avoid stale timestamps. If:
+ *   - your driver has vblank support (i.e. dev->num_crtcs > 0)
+ *   - the vblank irq is off (i.e. no one called drm_crtc_vblank_get)
+ *   - from the vblank code's pov the pipe is still running (i.e. not
+ *     in-between a drm_crtc_vblank_off()/on() pair)
+ * If all of these conditions hold then drm_crtc_send_vblank_event is
+ * going to give you a garbage timestamp and and sequence number (the last
+ * recorded before the irq was disabled). If you call drm_crtc_vblank_get/put
+ * around it, or after vblank_off, then either of those will have rolled things
+ * forward for you.
+ * So, drivers should call drm_crtc_vblank_off() before this function in their
+ * crtc atomic_disable handlers.
  */
 void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 				struct drm_pending_vblank_event *e)
@@ -925,8 +938,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	u64 seq;
 	unsigned int pipe = drm_crtc_index(crtc);
+	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 	ktime_t now;
 
+	WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank->inmodeset,
+		  "sending stale vblank info\n");
+
 	if (dev->num_crtcs > 0) {
 		seq = drm_vblank_count_and_time(dev, pipe, &now);
 	} else {
-- 
2.18.0

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

* [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled."
  2019-06-28 12:05 [PATCH v4 0/2] handle vblank when disabling ctc with interrupt disabled Robert Beckett
  2019-06-28 12:05 ` [PATCH v4 1/2] drm/vblank: warn on sending stale event Robert Beckett
@ 2019-06-28 12:05 ` Robert Beckett
  2019-06-28 12:13     ` Ville Syrjälä
  1 sibling, 1 reply; 6+ messages in thread
From: Robert Beckett @ 2019-06-28 12:05 UTC (permalink / raw)
  To: dri-devel
  Cc: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
	Daniel Vetter, linux-kernel, Philipp Zabel, Robert Beckett

If interrupts are already disabled, then the timestamp for the vblank
does not get updated, causing a stale timestamp to be reported to
userland while disabling crtcs.

This reverts commit 68036b08b91bc491ccc308f902616a570a49227c.

Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
 drivers/gpu/drm/drm_vblank.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 7dabb2bdb733..aeb9734d7799 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -371,25 +371,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
 
 	/*
-	 * Update vblank count and disable vblank interrupts only if the
-	 * interrupts were enabled. This avoids calling the ->disable_vblank()
-	 * operation in atomic context with the hardware potentially runtime
-	 * suspended.
+	 * Only disable vblank interrupts if they're enabled. This avoids
+	 * calling the ->disable_vblank() operation in atomic context with the
+	 * hardware potentially runtime suspended.
 	 */
-	if (!vblank->enabled)
-		goto out;
+	if (vblank->enabled) {
+		__disable_vblank(dev, pipe);
+		vblank->enabled = false;
+	}
 
 	/*
-	 * Update the count and timestamp to maintain the
+	 * Always update the count and timestamp to maintain the
 	 * appearance that the counter has been ticking all along until
 	 * this time. This makes the count account for the entire time
 	 * between drm_crtc_vblank_on() and drm_crtc_vblank_off().
 	 */
 	drm_update_vblank_count(dev, pipe, false);
-	__disable_vblank(dev, pipe);
-	vblank->enabled = false;
 
-out:
 	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
 }
 
-- 
2.18.0

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

* Re: [PATCH v4 1/2] drm/vblank: warn on sending stale event
  2019-06-28 12:05 ` [PATCH v4 1/2] drm/vblank: warn on sending stale event Robert Beckett
@ 2019-06-28 12:10   ` Robert Beckett
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Beckett @ 2019-06-28 12:10 UTC (permalink / raw)
  To: dri-devel; +Cc: Maxime Ripard, linux-kernel, David Airlie, Sean Paul

Nak - I forgot the requested doc changes. Ill re-send

On Fri, 2019-06-28 at 13:05 +0100, Robert Beckett wrote:
> Warn when about to send stale vblank info and add advice to
> documentation on how to avoid.
> 
> Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c
> b/drivers/gpu/drm/drm_vblank.c
> index 603ab105125d..7dabb2bdb733 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -918,6 +918,19 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
>   *
>   * See drm_crtc_arm_vblank_event() for a helper which can be used in
> certain
>   * situation, especially to send out events for atomic commit
> operations.
> + *
> + * Care should be taken to avoid stale timestamps. If:
> + *   - your driver has vblank support (i.e. dev->num_crtcs > 0)
> + *   - the vblank irq is off (i.e. no one called
> drm_crtc_vblank_get)
> + *   - from the vblank code's pov the pipe is still running (i.e.
> not
> + *     in-between a drm_crtc_vblank_off()/on() pair)
> + * If all of these conditions hold then drm_crtc_send_vblank_event
> is
> + * going to give you a garbage timestamp and and sequence number
> (the last
> + * recorded before the irq was disabled). If you call
> drm_crtc_vblank_get/put
> + * around it, or after vblank_off, then either of those will have
> rolled things
> + * forward for you.
> + * So, drivers should call drm_crtc_vblank_off() before this
> function in their
> + * crtc atomic_disable handlers.
>   */
>  void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
>  				struct drm_pending_vblank_event *e)
> @@ -925,8 +938,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc
> *crtc,
>  	struct drm_device *dev = crtc->dev;
>  	u64 seq;
>  	unsigned int pipe = drm_crtc_index(crtc);
> +	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
>  	ktime_t now;
>  
> +	WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank-
> >inmodeset,
> +		  "sending stale vblank info\n");
> +
>  	if (dev->num_crtcs > 0) {
>  		seq = drm_vblank_count_and_time(dev, pipe, &now);
>  	} else {

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

* Re: [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled."
  2019-06-28 12:05 ` [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled." Robert Beckett
@ 2019-06-28 12:13     ` Ville Syrjälä
  0 siblings, 0 replies; 6+ messages in thread
From: Ville Syrjälä @ 2019-06-28 12:13 UTC (permalink / raw)
  To: Robert Beckett
  Cc: Maxime Ripard, David Airlie, Sean Paul, linux-kernel, dri-devel

On Fri, Jun 28, 2019 at 01:05:32PM +0100, Robert Beckett wrote:
> If interrupts are already disabled, then the timestamp for the vblank
> does not get updated, causing a stale timestamp to be reported to
> userland while disabling crtcs.
> 
> This reverts commit 68036b08b91bc491ccc308f902616a570a49227c.

Please cc the people involved in that. And I'd drop the lkml cc.

> 
> Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 7dabb2bdb733..aeb9734d7799 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -371,25 +371,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
>  	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
>  
>  	/*
> -	 * Update vblank count and disable vblank interrupts only if the
> -	 * interrupts were enabled. This avoids calling the ->disable_vblank()
> -	 * operation in atomic context with the hardware potentially runtime
> -	 * suspended.
> +	 * Only disable vblank interrupts if they're enabled. This avoids
> +	 * calling the ->disable_vblank() operation in atomic context with the
> +	 * hardware potentially runtime suspended.
>  	 */
> -	if (!vblank->enabled)
> -		goto out;
> +	if (vblank->enabled) {
> +		__disable_vblank(dev, pipe);
> +		vblank->enabled = false;
> +	}
>  
>  	/*
> -	 * Update the count and timestamp to maintain the
> +	 * Always update the count and timestamp to maintain the
>  	 * appearance that the counter has been ticking all along until
>  	 * this time. This makes the count account for the entire time
>  	 * between drm_crtc_vblank_on() and drm_crtc_vblank_off().
>  	 */
>  	drm_update_vblank_count(dev, pipe, false);
> -	__disable_vblank(dev, pipe);
> -	vblank->enabled = false;
>  
> -out:
>  	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
>  }
>  
> -- 
> 2.18.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
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] 6+ messages in thread

* Re: [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled."
@ 2019-06-28 12:13     ` Ville Syrjälä
  0 siblings, 0 replies; 6+ messages in thread
From: Ville Syrjälä @ 2019-06-28 12:13 UTC (permalink / raw)
  To: Robert Beckett
  Cc: dri-devel, Maxime Ripard, linux-kernel, David Airlie, Sean Paul

On Fri, Jun 28, 2019 at 01:05:32PM +0100, Robert Beckett wrote:
> If interrupts are already disabled, then the timestamp for the vblank
> does not get updated, causing a stale timestamp to be reported to
> userland while disabling crtcs.
> 
> This reverts commit 68036b08b91bc491ccc308f902616a570a49227c.

Please cc the people involved in that. And I'd drop the lkml cc.

> 
> Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 7dabb2bdb733..aeb9734d7799 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -371,25 +371,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
>  	spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
>  
>  	/*
> -	 * Update vblank count and disable vblank interrupts only if the
> -	 * interrupts were enabled. This avoids calling the ->disable_vblank()
> -	 * operation in atomic context with the hardware potentially runtime
> -	 * suspended.
> +	 * Only disable vblank interrupts if they're enabled. This avoids
> +	 * calling the ->disable_vblank() operation in atomic context with the
> +	 * hardware potentially runtime suspended.
>  	 */
> -	if (!vblank->enabled)
> -		goto out;
> +	if (vblank->enabled) {
> +		__disable_vblank(dev, pipe);
> +		vblank->enabled = false;
> +	}
>  
>  	/*
> -	 * Update the count and timestamp to maintain the
> +	 * Always update the count and timestamp to maintain the
>  	 * appearance that the counter has been ticking all along until
>  	 * this time. This makes the count account for the entire time
>  	 * between drm_crtc_vblank_on() and drm_crtc_vblank_off().
>  	 */
>  	drm_update_vblank_count(dev, pipe, false);
> -	__disable_vblank(dev, pipe);
> -	vblank->enabled = false;
>  
> -out:
>  	spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
>  }
>  
> -- 
> 2.18.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel

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

end of thread, other threads:[~2019-06-28 12:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-28 12:05 [PATCH v4 0/2] handle vblank when disabling ctc with interrupt disabled Robert Beckett
2019-06-28 12:05 ` [PATCH v4 1/2] drm/vblank: warn on sending stale event Robert Beckett
2019-06-28 12:10   ` Robert Beckett
2019-06-28 12:05 ` [PATCH v4 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled." Robert Beckett
2019-06-28 12:13   ` Ville Syrjälä
2019-06-28 12:13     ` Ville Syrjälä

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.