From 1dfa65c723c1854f8904dfbe47b48d7074f45122 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Oct 2021 16:24:28 -0400 Subject: [PATCH 1/5] backend/drm: DRM_CAP_TIMESTAMP_MONOTONIC is now required Kernels below 2.6.39 are now unsupported See https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#c.DRM_CAP_TIMESTAMP_MONOTONIC --- backend/drm/drm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 191ad064da..98726c6534 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -72,6 +72,11 @@ bool check_drm_features(struct wlr_drm_backend *drm) { return false; } + if (drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap) || !cap) { + wlr_log(WLR_ERROR, "DRM_CAP_TIMESTAMP_MONOTONIC unsupported"); + return false; + } + const char *no_atomic = getenv("WLR_DRM_NO_ATOMIC"); if (no_atomic && strcmp(no_atomic, "1") == 0) { wlr_log(WLR_DEBUG, @@ -86,14 +91,13 @@ bool check_drm_features(struct wlr_drm_backend *drm) { drm->iface = &atomic_iface; } - int ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap); - drm->clock = (ret == 0 && cap == 1) ? CLOCK_MONOTONIC : CLOCK_REALTIME; + drm->clock = CLOCK_MONOTONIC; const char *no_modifiers = getenv("WLR_DRM_NO_MODIFIERS"); if (no_modifiers != NULL && strcmp(no_modifiers, "1") == 0) { wlr_log(WLR_DEBUG, "WLR_DRM_NO_MODIFIERS set, disabling modifiers"); } else { - ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap); + int ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap); drm->addfb2_modifiers = ret == 0 && cap == 1; wlr_log(WLR_DEBUG, "ADDFB2 modifiers %s", drm->addfb2_modifiers ? "supported" : "unsupported"); From 76f03b17fbfab1f29bb871459bad7227aa580256 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Oct 2021 16:26:38 -0400 Subject: [PATCH 2/5] backend/drm: remove get_presentation_clock from impl The value is always CLOCK_MONOTONIC --- backend/drm/backend.c | 6 ------ backend/drm/drm.c | 2 -- include/backend/drm/drm.h | 1 - 3 files changed, 9 deletions(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 9ae4dbf0ff..4c59c20e67 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -66,11 +66,6 @@ static void backend_destroy(struct wlr_backend *backend) { free(drm); } -static clockid_t backend_get_presentation_clock(struct wlr_backend *backend) { - struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); - return drm->clock; -} - static int backend_get_drm_fd(struct wlr_backend *backend) { struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); @@ -88,7 +83,6 @@ static uint32_t drm_backend_get_buffer_caps(struct wlr_backend *backend) { static const struct wlr_backend_impl backend_impl = { .start = backend_start, .destroy = backend_destroy, - .get_presentation_clock = backend_get_presentation_clock, .get_drm_fd = backend_get_drm_fd, .get_buffer_caps = drm_backend_get_buffer_caps, }; diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 98726c6534..3ae86dbbb9 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -91,8 +91,6 @@ bool check_drm_features(struct wlr_drm_backend *drm) { drm->iface = &atomic_iface; } - drm->clock = CLOCK_MONOTONIC; - const char *no_modifiers = getenv("WLR_DRM_NO_MODIFIERS"); if (no_modifiers != NULL && strcmp(no_modifiers, "1") == 0) { wlr_log(WLR_DEBUG, "WLR_DRM_NO_MODIFIERS set, disabling modifiers"); diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 6d70d844df..dc7173e946 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -57,7 +57,6 @@ struct wlr_drm_backend { struct wlr_drm_backend *parent; const struct wlr_drm_interface *iface; - clockid_t clock; bool addfb2_modifiers; int fd; From cfe746a1ebe57559a93363b9cf80d7684f3d20d1 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Oct 2021 16:30:38 -0400 Subject: [PATCH 3/5] types/wlr_presentation_time: send CLOCK_MONOTONIC only --- include/wlr/types/wlr_presentation_time.h | 1 - types/wlr_presentation_time.c | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/wlr/types/wlr_presentation_time.h b/include/wlr/types/wlr_presentation_time.h index 51570c04e7..7861a1444f 100644 --- a/include/wlr/types/wlr_presentation_time.h +++ b/include/wlr/types/wlr_presentation_time.h @@ -20,7 +20,6 @@ struct wlr_output_event_present; struct wlr_presentation { struct wl_global *global; struct wl_list feedbacks; // wlr_presentation_feedback::link - clockid_t clock; struct { struct wl_signal destroy; diff --git a/types/wlr_presentation_time.c b/types/wlr_presentation_time.c index 4e3c4919be..6f57af39ff 100644 --- a/types/wlr_presentation_time.c +++ b/types/wlr_presentation_time.c @@ -1,7 +1,8 @@ -#define _POSIX_C_SOURCE 199309L +#define _POSIX_C_SOURCE 200809L #include #include #include +#include #include #include #include @@ -159,7 +160,7 @@ static void presentation_bind(struct wl_client *client, void *data, wl_resource_set_implementation(resource, &presentation_impl, presentation, NULL); - wp_presentation_send_clock_id(resource, (uint32_t)presentation->clock); + wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC); } static void handle_display_destroy(struct wl_listener *listener, void *data) { @@ -186,8 +187,6 @@ struct wlr_presentation *wlr_presentation_create(struct wl_display *display, return NULL; } - presentation->clock = wlr_backend_get_presentation_clock(backend); - wl_list_init(&presentation->feedbacks); wl_signal_init(&presentation->events.destroy); From 53bab3458885dbfadfa6b35e6519e8206c2c6665 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Oct 2021 16:32:05 -0400 Subject: [PATCH 4/5] types/wlr_output: get time from CLOCK_MONOTONIC --- types/wlr_output.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index b6167d6d02..907786f214 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -961,9 +961,8 @@ void wlr_output_send_present(struct wlr_output *output, if (event->presented && event->when == NULL) { struct timespec now; - clockid_t clock = wlr_backend_get_presentation_clock(output->backend); errno = 0; - if (clock_gettime(clock, &now) != 0) { + if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { wlr_log_errno(WLR_ERROR, "failed to send output present event: " "failed to read clock"); return; From 8d18e2b2adf8363b65c320a906ea539b6dd853e5 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Oct 2021 16:33:23 -0400 Subject: [PATCH 5/5] backend: remove get_presentation_clock from interface Since 1367a4a1c0f44fe69d9f809a35f872f6ef18b7a9, only CLOCK_MONOTONIC is supported. --- backend/backend.c | 7 ------- backend/multi/backend.c | 15 --------------- include/wlr/backend/interface.h | 1 - 3 files changed, 23 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index ed6ae2d651..63d9cb34f0 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -153,13 +153,6 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) { return session; } -clockid_t wlr_backend_get_presentation_clock(struct wlr_backend *backend) { - if (backend->impl->get_presentation_clock) { - return backend->impl->get_presentation_clock(backend); - } - return CLOCK_MONOTONIC; -} - int wlr_backend_get_drm_fd(struct wlr_backend *backend) { if (!backend->impl->get_drm_fd) { return -1; diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 7c74959eb0..e7500e25b8 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -82,20 +82,6 @@ static struct wlr_session *multi_backend_get_session( return backend->session; } -static clockid_t multi_backend_get_presentation_clock( - struct wlr_backend *backend) { - struct wlr_multi_backend *multi = multi_backend_from_backend(backend); - - struct subbackend_state *sub; - wl_list_for_each(sub, &multi->backends, link) { - if (sub->backend->impl->get_presentation_clock) { - return wlr_backend_get_presentation_clock(sub->backend); - } - } - - return CLOCK_MONOTONIC; -} - static int multi_backend_get_drm_fd(struct wlr_backend *backend) { struct wlr_multi_backend *multi = multi_backend_from_backend(backend); @@ -114,7 +100,6 @@ static const struct wlr_backend_impl backend_impl = { .destroy = multi_backend_destroy, .get_renderer = multi_backend_get_renderer, .get_session = multi_backend_get_session, - .get_presentation_clock = multi_backend_get_presentation_clock, .get_drm_fd = multi_backend_get_drm_fd, }; diff --git a/include/wlr/backend/interface.h b/include/wlr/backend/interface.h index 529f8f87a7..bb3fb25102 100644 --- a/include/wlr/backend/interface.h +++ b/include/wlr/backend/interface.h @@ -18,7 +18,6 @@ struct wlr_backend_impl { void (*destroy)(struct wlr_backend *backend); struct wlr_renderer *(*get_renderer)(struct wlr_backend *backend); struct wlr_session *(*get_session)(struct wlr_backend *backend); - clockid_t (*get_presentation_clock)(struct wlr_backend *backend); int (*get_drm_fd)(struct wlr_backend *backend); uint32_t (*get_buffer_caps)(struct wlr_backend *backend); };