]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
drm/vblank: Add vblank timer
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 16 Sep 2025 08:36:19 +0000 (10:36 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Wed, 1 Oct 2025 06:31:59 +0000 (08:31 +0200)
commit74afeb8128502a529041a2566febd26053a7be11
tree673ea7f1349618b95ba3ef281bdc272f45908fe0
parentb83c30ac9d3d2c15cd7e1d013ec9ff73ef945405
drm/vblank: Add vblank timer

The vblank timer simulates a vblank interrupt for hardware without
support. Rate-limits the display update frequency.

DRM drivers for hardware without vblank support apply display updates
ASAP. A vblank event informs DRM clients of the completed update.
Userspace compositors immediately schedule the next update, which
creates significant load on virtualization outputs. Display updates
are usually fast on virtualization outputs, as their framebuffers are
in regular system memory and there's no hardware vblank interrupt to
throttle the update rate.

The vblank timer is a HR timer that signals the vblank in software.
It limits the update frequency of a DRM driver similar to a hardware
vblank interrupt. The timer is not synchronized to the actual vblank
interval of the display.

The code has been adopted from vkms, which added the funtionality
in commit 3a0709928b17 ("drm/vkms: Add vblank events simulated by
hrtimers").

The new implementation is part of the existing vblank support,
which sets up the timer automatically. Drivers only have to start
and cancel the vblank timer as part of enabling and disabling the
CRTC. The new vblank helper library provides callbacks for struct
drm_crtc_funcs.

The standard way for handling vblank is to call drm_crtc_handle_vblank().
Drivers that require additional processing, such as vkms, can init
handle_vblank_timeout in struct drm_crtc_helper_funcs to refer to
their timeout handler.

There's a possible deadlock between drm_crtc_handle_vblank() and
hrtimer_cancel(). [1] The implementation avoids to call hrtimer_cancel()
directly and instead signals to the timer function to not restart
itself.

v4:
- fix possible race condition between timeout and atomic commit (Michael)
v3:
- avoid deadlock when cancelling timer (Ville, Lyude)
v2:
- implement vblank timer entirely in vblank helpers
- downgrade overrun warning to debug
- fix docs

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Tested-by: Louis Chauvet <louis.chauvet@bootlin.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/all/20250510094757.4174662-1-zengheng4@huawei.com/
Link: https://lore.kernel.org/r/20250916083816.30275-2-tzimmermann@suse.de
Documentation/gpu/drm-kms-helpers.rst
drivers/gpu/drm/Makefile
drivers/gpu/drm/drm_vblank.c
drivers/gpu/drm/drm_vblank_helper.c [new file with mode: 0644]
include/drm/drm_modeset_helper_vtables.h
include/drm/drm_vblank.h
include/drm/drm_vblank_helper.h [new file with mode: 0644]