All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/vblank: Avoid storing a timestamp for the same frame twice
@ 2021-02-04  2:04 ` Ville Syrjala
  0 siblings, 0 replies; 43+ messages in thread
From: Ville Syrjala @ 2021-02-04  2:04 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, intel-gfx, Dhinakaran Pandiyan, Rodrigo Vivi

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

drm_vblank_restore() exists because certain power saving states
can clobber the hardware frame counter. The way it does this is
by guesstimating how many frames were missed purely based on
the difference between the last stored timestamp vs. a newly
sampled timestamp.

If we should call this function before a full frame has
elapsed since we sampled the last timestamp we would end up
with a possibly slightly different timestamp value for the
same frame. Currently we will happily overwrite the already
stored timestamp for the frame with the new value. This
could cause userspace to observe two different timestamps
for the same frame (and the timestamp could even go
backwards depending on how much error we introduce when
correcting the timestamp based on the scanout position).

To avoid that let's not update the stored timestamp unless we're
also incrementing the sequence counter. We do still want to update
vblank->last with the freshly sampled hw frame counter value so
that subsequent vblank irqs/queries can actually use the hw frame
counter to determine how many frames have elapsed.

Cc: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_vblank.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 893165eeddf3..e127a7db2088 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -176,6 +176,17 @@ static void store_vblank(struct drm_device *dev, unsigned int pipe,
 
 	vblank->last = last;
 
+	/*
+	 * drm_vblank_restore() wants to always update
+	 * vblank->last since we can't trust the frame counter
+	 * across power saving states. But we don't want to alter
+	 * the stored timestamp for the same frame number since
+	 * that would cause userspace to potentially observe two
+	 * different timestamps for the same frame.
+	 */
+	if (vblank_count_inc == 0)
+		return;
+
 	write_seqlock(&vblank->seqlock);
 	vblank->time = t_vblank;
 	atomic64_add(vblank_count_inc, &vblank->count);
-- 
2.26.2

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

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

end of thread, other threads:[~2021-02-21  5:41 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04  2:04 [PATCH] drm/vblank: Avoid storing a timestamp for the same frame twice Ville Syrjala
2021-02-04  2:04 ` [Intel-gfx] " Ville Syrjala
2021-02-04  3:12 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2021-02-04  5:44 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2021-02-04 15:32 ` [PATCH] " Daniel Vetter
2021-02-04 15:32   ` [Intel-gfx] " Daniel Vetter
2021-02-04 15:55   ` Ville Syrjälä
2021-02-04 15:55     ` [Intel-gfx] " Ville Syrjälä
2021-02-05 15:46     ` Daniel Vetter
2021-02-05 15:46       ` [Intel-gfx] " Daniel Vetter
2021-02-05 16:24       ` Ville Syrjälä
2021-02-05 16:24         ` [Intel-gfx] " Ville Syrjälä
2021-02-05 21:19         ` Ville Syrjälä
2021-02-05 21:19           ` [Intel-gfx] " Ville Syrjälä
2021-02-08  9:56           ` Daniel Vetter
2021-02-08  9:56             ` [Intel-gfx] " Daniel Vetter
2021-02-08 16:58             ` Ville Syrjälä
2021-02-08 16:58               ` [Intel-gfx] " Ville Syrjälä
2021-02-08 17:43               ` Daniel Vetter
2021-02-08 17:43                 ` [Intel-gfx] " Daniel Vetter
2021-02-08 18:05                 ` Ville Syrjälä
2021-02-08 18:05                   ` [Intel-gfx] " Ville Syrjälä
2021-02-09 10:07 ` Daniel Vetter
2021-02-09 10:07   ` [Intel-gfx] " Daniel Vetter
2021-02-09 15:40   ` Ville Syrjälä
2021-02-09 15:40     ` [Intel-gfx] " Ville Syrjälä
2021-02-09 16:44     ` Daniel Vetter
2021-02-09 16:44       ` [Intel-gfx] " Daniel Vetter
2021-02-18 16:03 ` [PATCH v2] drm/vblank: Do not store a new vblank timestamp in drm_vblank_restore() Ville Syrjala
2021-02-18 16:03   ` [Intel-gfx] " Ville Syrjala
2021-02-18 16:10   ` Ville Syrjälä
2021-02-18 16:10     ` [Intel-gfx] " Ville Syrjälä
2021-02-19 15:08   ` Daniel Vetter
2021-02-19 15:08     ` [Intel-gfx] " Daniel Vetter
2021-02-19 15:47     ` Ville Syrjälä
2021-02-19 15:47       ` [Intel-gfx] " Ville Syrjälä
2021-02-18 19:08 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for drm/vblank: Avoid storing a timestamp for the same frame twice (rev2) Patchwork
2021-02-18 19:22   ` Ville Syrjälä
2021-02-18 19:51     ` Vudum, Lakshminarayana
2021-02-18 19:29 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2021-02-18 20:58 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2021-02-21  4:18 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/vblank: Avoid storing a timestamp for the same frame twice (rev3) Patchwork
2021-02-21  5:41 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

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.