drm_crtc_wait_one_vblank() waits uninterruptibly and only gives up after one second. That doesn't suit a wait that userspace asks for, such as FBIO_WAITFORVSYNC: if no vblank interrupt arrives, the task sleeps in D state for the whole second and can't be interrupted, not even by SIGKILL.
Add drm_crtc_wait_one_vblank_interruptible(), a DRM-internal variant of drm_crtc_wait_one_vblank() that a signal can interrupt. It returns -ERESTARTSYS in that case and otherwise behaves like drm_crtc_wait_one_vblank(), which includes ending the wait when vblank is turned off. Move the wait to __drm_crtc_wait_one_vblank(), which implements both functions. drm_crtc_wait_one_vblank() doesn't change, and drivers keep using it. The new function has no user yet. The next patch uses it in drm_client_modeset_wait_for_vblank(). Version update: 1) https://lists.freedesktop.org/archives/dri-devel/2026-November/616727.html Cc: Thomas Zimmermann <[email protected]> Cc: Ville Syrjälä <[email protected]> Assisted-by: Copilot:claude-opus-5.5 Signed-off-by: Prike Liang <[email protected]> --- drivers/gpu/drm/drm_internal.h | 1 + drivers/gpu/drm/drm_vblank.c | 64 ++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index f893b1e3a596..2be21c20eb78 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -115,6 +115,7 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe); int drm_vblank_get(struct drm_device *dev, unsigned int pipe); void drm_vblank_put(struct drm_device *dev, unsigned int pipe); u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe); +int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc); /* drm_vblank_work.c */ static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 54118eb1413c..5e247663978a 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1297,22 +1297,12 @@ void drm_crtc_vblank_put(struct drm_crtc *crtc) } EXPORT_SYMBOL(drm_crtc_vblank_put); -/** - * drm_crtc_wait_one_vblank - wait for one vblank - * @crtc: DRM crtc - * - * This waits for one vblank to pass on @crtc, using the irq driver interfaces. - * It is a failure to call this when the vblank irq for @crtc is disabled, e.g. - * due to lack of driver support or because the crtc is off. The wait also fails - * if drm_crtc_vblank_off() disables the vblank irq before a vblank passes. - * - * Returns: 0 on success, negative error on failures. - */ -int drm_crtc_wait_one_vblank(struct drm_crtc *crtc) +static int __drm_crtc_wait_one_vblank(struct drm_crtc *crtc, bool interruptible) { struct drm_device *dev = crtc->dev; int pipe = drm_crtc_index(crtc); struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc); + long timeout = msecs_to_jiffies(1000); int ret; u64 last; @@ -1323,14 +1313,22 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc) last = drm_vblank_count(dev, pipe); - ret = wait_event_timeout(vblank->queue, - last != drm_vblank_count(dev, pipe) || - !READ_ONCE(vblank->enabled), - msecs_to_jiffies(1000)); + if (interruptible) + timeout = wait_event_interruptible_timeout(vblank->queue, + last != drm_vblank_count(dev, pipe) || + !READ_ONCE(vblank->enabled), + timeout); + else + timeout = wait_event_timeout(vblank->queue, + last != drm_vblank_count(dev, pipe) || + !READ_ONCE(vblank->enabled), + timeout); - drm_WARN(dev, ret == 0, "vblank wait timed out on crtc %i\n", pipe); + drm_WARN(dev, timeout == 0, "vblank wait timed out on crtc %i\n", pipe); - if (!ret) + if (timeout < 0) + ret = timeout; + else if (!timeout) ret = -ETIMEDOUT; else if (last == drm_vblank_count(dev, pipe)) ret = -EINVAL; /* drm_crtc_vblank_off() ended the wait */ @@ -1341,8 +1339,38 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc) return ret; } + +/** + * drm_crtc_wait_one_vblank - wait for one vblank + * @crtc: DRM crtc + * + * This waits for one vblank to pass on @crtc, using the irq driver interfaces. + * It is a failure to call this when the vblank irq for @crtc is disabled, e.g. + * due to lack of driver support or because the crtc is off. The wait also fails + * if drm_crtc_vblank_off() disables the vblank irq before a vblank passes. + * + * Returns: 0 on success, negative error on failures. + */ +int drm_crtc_wait_one_vblank(struct drm_crtc *crtc) +{ + return __drm_crtc_wait_one_vblank(crtc, false); +} EXPORT_SYMBOL(drm_crtc_wait_one_vblank); +/** + * drm_crtc_wait_one_vblank_interruptible - wait for one vblank, interruptibly + * @crtc: DRM crtc + * + * Like drm_crtc_wait_one_vblank(), but a signal interrupts the wait. + * + * Returns: 0 on success, -ERESTARTSYS if a signal interrupted the wait, + * negative error on other failures. + */ +int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc) +{ + return __drm_crtc_wait_one_vblank(crtc, true); +} + /** * drm_crtc_vblank_off - disable vblank events on a CRTC * @crtc: CRTC in question -- 2.34.1
