From 459d138fa2f8c0ad3665cbbb393c366b895a4cde Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 16:32:25 +1200 Subject: Add timeout to DRM cleanup This prevents a potential infinite loop preventing us from closing properly. --- include/backend/drm.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/backend/drm.h b/include/backend/drm.h index 342a980c..cc3e621b 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -127,6 +127,7 @@ struct wlr_drm_backend { enum wlr_drm_output_state { WLR_DRM_OUTPUT_DISCONNECTED, WLR_DRM_OUTPUT_NEEDS_MODESET, + WLR_DRM_OUTPUT_CLEANUP, WLR_DRM_OUTPUT_CONNECTED, }; @@ -176,8 +177,8 @@ struct wlr_drm_interface { bool wlr_drm_check_features(struct wlr_drm_backend *drm); bool wlr_drm_resources_init(struct wlr_drm_backend *drm); void wlr_drm_resources_free(struct wlr_drm_backend *drm); -void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore); - +void wlr_drm_restore_outputs(struct wlr_drm_backend *drm); +void wlr_drm_output_cleanup(struct wlr_drm_output *output); void wlr_drm_scan_connectors(struct wlr_drm_backend *state); int wlr_drm_event(int fd, uint32_t mask, void *data); -- cgit v1.2.3 From 025b3ee515aedf008b94eb8aa791ecd7eaf817c9 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 23 Sep 2017 18:27:14 +1200 Subject: Add error recovery for failed page flips --- backend/drm/drm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- include/backend/drm.h | 1 + 2 files changed, 47 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index b34e86fd..53d08291 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -301,8 +301,14 @@ static void wlr_drm_output_swap_buffers(struct wlr_output *_output) { wlr_drm_plane_swap_buffers(renderer, plane); - backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(plane->back), NULL); - output->pageflip_pending = true; + uint32_t fb_id = get_fb_for_bo(plane->back); + + if (backend->iface->crtc_pageflip(backend, output, crtc, fb_id, NULL)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } } static void wlr_drm_output_set_gamma(struct wlr_output *_output, @@ -348,8 +354,12 @@ void wlr_drm_output_start_renderer(struct wlr_drm_output *output) { struct wlr_drm_output_mode *_mode = (struct wlr_drm_output_mode *)output->output.current_mode; drmModeModeInfo *mode = &_mode->mode; - backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode); - output->pageflip_pending = true; + if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } } static void wlr_drm_output_enable(struct wlr_output *_output, bool enable) { @@ -705,6 +715,7 @@ static bool wlr_drm_output_move_cursor(struct wlr_output *_output, static void wlr_drm_output_destroy(struct wlr_output *_output) { struct wlr_drm_output *output = (struct wlr_drm_output *)_output; wlr_drm_output_cleanup(output); + wl_event_source_remove(output->retry_pageflip); free(output); } @@ -721,6 +732,29 @@ static struct wlr_output_impl output_impl = { .get_gamma_size = wlr_drm_output_get_gamma_size, }; +static int retry_pageflip(void *data) { + struct wlr_drm_output *output = data; + struct wlr_drm_backend *backend = + wl_container_of(output->renderer, backend, renderer); + + struct wlr_drm_crtc *crtc = output->crtc; + struct wlr_drm_plane *plane = crtc->primary; + struct gbm_bo *bo = plane->front ? plane->front : plane->back; + + struct wlr_drm_output_mode *wlr_mode = + (struct wlr_drm_output_mode *)output->output.current_mode; + drmModeModeInfo *mode = &wlr_mode->mode; + + if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) { + output->pageflip_pending = true; + } else { + wl_event_source_timer_update(output->retry_pageflip, + output->output.current_mode->refresh); + } + + return 1; +} + static int find_id(const void *item, const void *cmp_to) { const struct wlr_drm_output *output = item; const uint32_t *id = cmp_to; @@ -777,6 +811,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { } wlr_output_init(&output->output, &output_impl); + struct wl_event_loop *ev = wl_display_get_event_loop(backend->display); + output->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, + output); + + output->renderer = &backend->renderer; output->state = WLR_DRM_OUTPUT_DISCONNECTED; output->connector = conn->connector_id; @@ -807,6 +846,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { if (list_add(backend->outputs, output) == -1) { wlr_log_errno(L_ERROR, "Allocation failed"); drmModeFreeConnector(conn); + wl_event_source_remove(output->retry_pageflip); free(output); continue; } @@ -872,6 +912,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { wlr_drm_output_cleanup(output); drmModeFreeCrtc(output->old_crtc); + wl_event_source_remove(output->retry_pageflip); free(output); list_del(backend->outputs, i); @@ -926,7 +967,7 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { wlr_drm_event(drm->fd, 0, NULL); for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_output *output = drm->outputs->items[i]; - if (!output->pageflip_pending) { + if (output->state != WLR_DRM_OUTPUT_CLEANUP || !output->pageflip_pending) { to_close &= ~(1 << i); } } diff --git a/include/backend/drm.h b/include/backend/drm.h index cc3e621b..27ddad6f 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -155,6 +155,7 @@ struct wlr_drm_output { struct wlr_drm_renderer *renderer; bool pageflip_pending; + struct wl_event_source *retry_pageflip; }; // Used to provide atomic or legacy DRM functions -- cgit v1.2.3