Vertical Blanking

Vertical Blanking and Interrupt Handling Functions Reference

Vertical blanking plays a major role in graphics rendering. To achieve tear-free display, users must synchronize page flips and/or rendering to vertical blanking. The DRM API offers ioctls to perform page flips synchronized to vertical blanking and wait for vertical blanking.

The DRM core handles most of the vertical blanking management logic, which involves filtering out spurious interrupts, keeping race-free blanking counters, coping with counter wrap-around and resets and keeping use counts. It relies on the driver to generate vertical blanking interrupts and optionally provide a hardware vertical blanking counter. Drivers must implement the following operations.

Drivers must initialize the vertical blanking handling core with a call to drm_vblank_init in their load operation. The function will set the struct drm_device vblank_disable_allowed field to 0. This will keep vertical blanking interrupts enabled permanently until the first mode set operation, where vblank_disable_allowed is set to 1. The reason behind this is not clear. Drivers can set the field to 1 after calling drm_vblank_init to make vertical blanking interrupts dynamically managed from the beginning.

Vertical blanking interrupts can be enabled by the DRM core or by drivers themselves (for instance to handle page flipping operations). The DRM core maintains a vertical blanking use count to ensure that the interrupts are not disabled while a user still needs them. To increment the use count, drivers call drm_vblank_get. Upon return vertical blanking interrupts are guaranteed to be enabled.

To decrement the use count drivers call drm_vblank_put. Only when the use count drops to zero will the DRM core disable the vertical blanking interrupts after a delay by scheduling a timer. The delay is accessible through the vblankoffdelay module parameter or the drm_vblank_offdelay global variable and expressed in milliseconds. Its default value is 5000 ms. Zero means never disable, and a negative value means disable immediately. Drivers may override the behaviour by setting the drm_device vblank_disable_immediate flag, which when set causes vblank interrupts to be disabled immediately regardless of the drm_vblank_offdelay value. The flag should only be set if there's a properly working hardware vblank counter present.

When a vertical blanking interrupt occurs drivers only need to call the drm_handle_vblank function to account for the interrupt.

Resources allocated by drm_vblank_init must be freed with a call to drm_vblank_cleanup in the driver unload operation handler.

Vertical Blanking and Interrupt Handling Functions Reference

drm_vblank_cleanup — cleanup vblank support
drm_vblank_init — initialize vblank support
drm_irq_install — install IRQ handler
drm_irq_uninstall — uninstall the IRQ handler
drm_calc_timestamping_constants — calculate vblank timestamp constants
drm_calc_vbltimestamp_from_scanoutpos — precise vblank timestamp helper
drm_vblank_count — retrieve cooked vblank counter value
drm_crtc_vblank_count — retrieve cooked vblank counter value
drm_vblank_count_and_time — retrieve cooked vblank counter value and the system timestamp corresponding to that vblank counter value.
drm_send_vblank_event — helper to send vblank event after pageflip
drm_crtc_send_vblank_event — helper to send vblank event after pageflip
drm_vblank_get — get a reference count on vblank events
drm_crtc_vblank_get — get a reference count on vblank events
drm_vblank_put — give up ownership of vblank events
drm_crtc_vblank_put — give up ownership of vblank events
drm_wait_one_vblank — wait for one vblank
drm_crtc_wait_one_vblank — wait for one vblank
drm_vblank_off — disable vblank events on a CRTC
drm_crtc_vblank_off — disable vblank events on a CRTC
drm_crtc_vblank_reset — reset vblank state to off on a CRTC
drm_vblank_on — enable vblank events on a CRTC
drm_crtc_vblank_on — enable vblank events on a CRTC
drm_vblank_pre_modeset — account for vblanks across mode sets
drm_vblank_post_modeset — undo drm_vblank_pre_modeset changes
drm_handle_vblank — handle a vblank event
drm_crtc_handle_vblank — handle a vblank event
drm_crtc_vblank_waitqueue — get vblank waitqueue for the CRTC