From: Ville Syrjala <ville.syrjala@linux.intel.com> To: dri-devel@lists.freedesktop.org Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, intel-gfx@lists.freedesktop.org, Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>, Rodrigo Vivi <rodrigo.vivi@intel.com> Subject: [PATCH v2] drm/vblank: Do not store a new vblank timestamp in drm_vblank_restore() Date: Thu, 18 Feb 2021 18:03:05 +0200 [thread overview] Message-ID: <20210218160305.16711-1-ville.syrjala@linux.intel.com> (raw) In-Reply-To: <20210204020400.29628-1-ville.syrjala@linux.intel.com> 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 at all, and instead we just fix up the last recorded hw vblank counter value such that the already stored timestamp/seq number will match. Thus the next time a vblank irq happens it will calculate the correct diff between the current and stored hw vblank counter values. Sidenote: Another possible idea that came to mind would be to do this correction only if the power really was removed since the last time we sampled the hw frame counter. But to do that we would need a robust way to detect when it has occurred. Some possibilities could involve some kind of hardare power well transition counter, or potentially we could store a magic value in a scratch register that lives in the same power well. But I'm not sure either of those exist, so would need an actual investigation to find out. All of that is very hardware specific of course, so would have to be done in the driver code. 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 2bd989688eae..3417e1ac7918 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1478,6 +1478,7 @@ static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe) u64 diff_ns; u32 cur_vblank, diff = 1; int count = DRM_TIMESTAMP_MAXRETRIES; + u32 max_vblank_count = drm_max_vblank_count(dev, pipe); if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) return; @@ -1504,7 +1505,7 @@ static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe) drm_dbg_vbl(dev, "missed %d vblanks in %lld ns, frame duration=%d ns, hw_diff=%d\n", diff, diff_ns, framedur_ns, cur_vblank - vblank->last); - store_vblank(dev, pipe, diff, t_vblank, cur_vblank); + vblank->last = (cur_vblank - diff) & max_vblank_count; } /** -- 2.26.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Ville Syrjala <ville.syrjala@linux.intel.com> To: dri-devel@lists.freedesktop.org Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, intel-gfx@lists.freedesktop.org, Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com> Subject: [Intel-gfx] [PATCH v2] drm/vblank: Do not store a new vblank timestamp in drm_vblank_restore() Date: Thu, 18 Feb 2021 18:03:05 +0200 [thread overview] Message-ID: <20210218160305.16711-1-ville.syrjala@linux.intel.com> (raw) In-Reply-To: <20210204020400.29628-1-ville.syrjala@linux.intel.com> 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 at all, and instead we just fix up the last recorded hw vblank counter value such that the already stored timestamp/seq number will match. Thus the next time a vblank irq happens it will calculate the correct diff between the current and stored hw vblank counter values. Sidenote: Another possible idea that came to mind would be to do this correction only if the power really was removed since the last time we sampled the hw frame counter. But to do that we would need a robust way to detect when it has occurred. Some possibilities could involve some kind of hardare power well transition counter, or potentially we could store a magic value in a scratch register that lives in the same power well. But I'm not sure either of those exist, so would need an actual investigation to find out. All of that is very hardware specific of course, so would have to be done in the driver code. 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 2bd989688eae..3417e1ac7918 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1478,6 +1478,7 @@ static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe) u64 diff_ns; u32 cur_vblank, diff = 1; int count = DRM_TIMESTAMP_MAXRETRIES; + u32 max_vblank_count = drm_max_vblank_count(dev, pipe); if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) return; @@ -1504,7 +1505,7 @@ static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe) drm_dbg_vbl(dev, "missed %d vblanks in %lld ns, frame duration=%d ns, hw_diff=%d\n", diff, diff_ns, framedur_ns, cur_vblank - vblank->last); - store_vblank(dev, pipe, diff, t_vblank, cur_vblank); + vblank->last = (cur_vblank - diff) & max_vblank_count; } /** -- 2.26.2 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2021-02-18 16:03 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 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 ` Ville Syrjala [this message] 2021-02-18 16:03 ` [Intel-gfx] [PATCH v2] drm/vblank: Do not store a new vblank timestamp in drm_vblank_restore() 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210218160305.16711-1-ville.syrjala@linux.intel.com \ --to=ville.syrjala@linux.intel.com \ --cc=daniel.vetter@ffwll.ch \ --cc=dhinakaran.pandiyan@intel.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=rodrigo.vivi@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.