From: Liu Ying <victor.liu@nxp.com>
To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch
Subject: [PATCH] drm/vblank: Fix vbl time for IRQ fired at the end of display active region
Date: Wed, 18 Jun 2025 13:56:03 +0800 [thread overview]
Message-ID: <20250618055603.2644430-1-victor.liu@nxp.com> (raw)
Helper drm_crtc_vblank_helper_get_vblank_timestamp_internal() aims to
return the timestamp for end of vblank from the vblank_time pointer.
For vblank interrupt fired at the end of vblank, it's fine to subtract
time delta(as a positive value) according to scanout position from
etime to get the timestamp. However, for vblank interrupt fired at
the end of display active region, the read-out scanout position could
be at the horizontal blank region of the last display active line,
which causes the calculated timestamp to be one frame eariler. To fix
this, subtract the time duration of an entire frame from the time delta
for the problematic case so that the final timestamp moves forward for
one frame.
This fixes weston assertion on backward timestamp when comparing
timestamps for consecutive frames. The issue can be seen with a display
controller which fires off vblank interrupt at the end of display active
region. The display controller driver is not yet upstreamed though.
Signed-off-by: Liu Ying <victor.liu@nxp.com>
---
drivers/gpu/drm/drm_vblank.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 46f59883183d..c228d327bf17 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -782,6 +782,15 @@ drm_crtc_vblank_helper_get_vblank_timestamp_internal(
delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos),
mode->crtc_clock);
+ /*
+ * For vblank interrupt fired off at the end of display active region,
+ * subtract time duration of an entire frame if vpos happens to be the
+ * display active lines(hpos is in the horizontal blank region).
+ */
+ if (in_vblank_irq && vpos == mode->crtc_vdisplay)
+ delta_ns -= div_u64(1000000LL * mode->crtc_htotal * mode->crtc_vtotal,
+ mode->crtc_clock);
+
/* Subtract time delta from raw timestamp to get final
* vblank_time timestamp for end of vblank.
*/
--
2.34.1
next reply other threads:[~2025-06-18 5:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 5:56 Liu Ying [this message]
2025-07-28 5:41 ` Liu Ying
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=20250618055603.2644430-1-victor.liu@nxp.com \
--to=victor.liu@nxp.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®