Commit 11ae2a30 authored by Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot Committed by Pekka Paalanen

compositor-drm: pageflip timeout implementation

Weston will not repaint until previous update has been acked by a
pageflip event coming from the drm driver. However, some buggy drivers
won’t return those events or will stop sending them at some point and
Weston output repaints will completely freeze. To ease developers’ task
in testing their drivers, this patch makes compositor-drm use a timer
to detect cases where those pageflip events stop coming.

This timeout implementation is software only and includes basic
features usually found in a watchdog. We simply exit Weston gracefully
with a log message and an exit code when the timout is reached.

The timeout value can be set via weston.ini by adding a
pageflip-timeout=<MILLISECONDS> entry under [core]
section. Setting it to 0 disables the timeout feature.

- Made sure we would get both the pageflip and the vblank events before
  stopping the timer.
- Reordered the error and success cases in
  drm_output_pageflip_timer_create() to be more in line with the rest
  of the code.

- Reordered (de)arming of the timer with the code around it to avoid it
  being rearmed before the current dearming.
- Return the proper value for the dispatcher in the pageflip_timeout
- Also display the output name in case the timer fires.

- Reordered a forgotten timer rearming after its drmModePageFlip().

Signed-off-by: Frederic Plourde <frederic.plourde at>
Signed-off-by: default avatarEmmanuel Gil Peyrot <>
Reviewed-by: Daniel Stone's avatarDaniel Stone <>
Reviewed-by: Pekka Paalanen's avatarPekka Paalanen <>
parent 8a888a5f
......@@ -1235,6 +1235,8 @@ load_drm_backend(struct weston_compositor *c,
"gbm-format", &config.gbm_format,
weston_config_section_get_uint(section, "pageflip-timeout",
&config.pageflip_timeout, 0);
config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
config.base.struct_size = sizeof(struct weston_drm_backend_config);
......@@ -119,6 +119,7 @@ struct drm_backend {
int32_t cursor_height;
uint32_t connector;
uint32_t pageflip_timeout;
struct drm_mode {
......@@ -182,6 +183,8 @@ struct drm_output {
struct vaapi_recorder *recorder;
struct wl_listener recorder_frame_listener;
struct wl_event_source *pageflip_timer;
......@@ -225,6 +228,45 @@ to_drm_backend(struct weston_compositor *base)
return container_of(base->backend, struct drm_backend, base);
static int
pageflip_timeout(void *data) {
* Our timer just went off, that means we're not receiving drm
* page flip events anymore for that output. Let's gracefully exit
* weston with a return value so devs can debug what's going on.
struct drm_output *output = data;
struct weston_compositor *compositor = output->base.compositor;
weston_log("Pageflip timeout reached on output %s, your "
"driver is probably buggy! Exiting.\n",
weston_compositor_exit_with_code(compositor, EXIT_FAILURE);
return 0;
/* Creates the pageflip timer. Note that it isn't armed by default */
static int
drm_output_pageflip_timer_create(struct drm_output *output)
struct wl_event_loop *loop = NULL;
struct weston_compositor *ec = output->base.compositor;
loop = wl_display_get_event_loop(ec->wl_display);
output->pageflip_timer = wl_event_loop_add_timer(loop,
if (output->pageflip_timer == NULL) {
weston_log("creating drm pageflip timer failed: %m\n");
return -1;
return 0;
static void
drm_output_set_cursor(struct drm_output *output);
......@@ -758,6 +800,10 @@ drm_output_repaint(struct weston_output *output_base,
output->page_flip_pending = 1;
if (output->pageflip_timer)
......@@ -878,6 +924,10 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
goto finish_frame;
if (output->pageflip_timer)
......@@ -916,6 +966,10 @@ vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec,
s->next = NULL;
if (!output->page_flip_pending) {
/* Stop the pageflip timer instead of rearming it here */
if (output->pageflip_timer)
wl_event_source_timer_update(output->pageflip_timer, 0);
ts.tv_sec = sec;
ts.tv_nsec = usec * 1000;
weston_output_finish_frame(&output->base, &ts, flags);
......@@ -953,6 +1007,10 @@ page_flip_handler(int fd, unsigned int frame,
else if (output->disable_pending)
else if (!output->vblank_pending) {
/* Stop the pageflip timer instead of rearming it here */
if (output->pageflip_timer)
wl_event_source_timer_update(output->pageflip_timer, 0);
ts.tv_sec = sec;
ts.tv_nsec = usec * 1000;
weston_output_finish_frame(&output->base, &ts, flags);
......@@ -2418,6 +2476,9 @@ drm_output_enable(struct weston_output *base)
output->dpms_prop = drm_get_prop(b->drm.fd, output->connector, "DPMS");
if (b->pageflip_timeout)
if (b->use_pixman) {
if (drm_output_init_pixman(output, b) < 0) {
weston_log("Failed to init output pixman state\n");
......@@ -2532,6 +2593,9 @@ drm_output_destroy(struct weston_output *base)
if (output->pageflip_timer)
......@@ -3309,6 +3373,7 @@ drm_backend_create(struct weston_compositor *compositor,
b->sprites_are_broken = 1;
b->compositor = compositor;
b->use_pixman = config->use_pixman;
b->pageflip_timeout = config->pageflip_timeout;
if (parse_gbm_format(config->gbm_format, GBM_FORMAT_XRGB8888, &b->gbm_format) < 0)
goto err_compositor;
......@@ -138,6 +138,13 @@ struct weston_drm_backend_config {
void (*configure_device)(struct weston_compositor *compositor,
struct libinput_device *device);
/** Maximum duration for a pageflip event to arrive, after which the
* compositor will consider the DRM driver crashed and will try to exit
* cleanly.
* It is exprimed in milliseconds, 0 means disabled. */
uint32_t pageflip_timeout;
#ifdef __cplusplus
......@@ -162,6 +162,11 @@ By default, xrgb8888 is used.
sets Weston's idle timeout in seconds. This idle timeout is the time
after which Weston will enter an "inactive" mode and screen will fade to
black. A value of 0 disables the timeout.
.TP 7
.BI "pageflip-timeout="milliseconds
sets Weston's pageflip timeout in milliseconds. This sets a timer to exit
gracefully with a log message and an exit code of 1 in case the DRM driver is
non-responsive. Setting it to 0 disables this feature.
.IR Important
: This option may also be set via Weston's '-i' command
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment