This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 3ea81dbdb020d1439531d282d97946bd140f8c29
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Nov 23 20:12:56 2026 -0600
ecore_drm2: do not resubmit a flip the kernel still owns
When a flip event took more than a second, the timeout committed the
flip again and spun on EBUSY until the original commit finished. That
second commit was then accepted, so the kernel sent two events for
the one flip EFL was tracking. The second event found no pending fb
and set the current fb to NULL.
Without a current fb, ecore_drm2_fb_flip(NULL, output) has nothing to
flip to, and that call is what generates the next tick and restarts
rendering after a VT switch. The compositor keeps running but never
draws again, and the screen stays black when coming back to its
session. Seen with Enlightenment on Wayland on an RK3399 eDP panel,
where a flip can stall for over a second, for instance when the
panel wakes from DPMS.
The timeout now commits again only when the event really looks lost:
EBUSY means the kernel still holds the flip and a readable fd means
its event has arrived, so in both cases it waits for that event.
Dropping the retry altogether would lose the recovery from a driver
that never sends the event.
A commit can still finish between the check and the new commit, so
an event with no flip pending is now ignored rather than clearing
the current fb.
The non-atomic path keeps its own EBUSY loop in _fb_flip().
The tests build the flip code against a fake libdrm, as no test
machine can be made to delay a real flip event. On the RK3399, a
stalled flip now goes through repeated EBUSY timeouts and completes.
The extra event case was only exercised by the tests.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGDCUNx4FapHb7KHPMmrVN
---
src/lib/ecore_drm2/ecore_drm2_fb.c | 55 ++++++--
src/tests/ecore/ecore_suite.c | 3 +
src/tests/ecore/ecore_suite.h | 1 +
src/tests/ecore/ecore_test_ecore_drm2_fb.c | 217 +++++++++++++++++++++++++++++
src/tests/ecore/meson.build | 7 +-
5 files changed, 273 insertions(+), 10 deletions(-)
diff --git a/src/lib/ecore_drm2/ecore_drm2_fb.c b/src/lib/ecore_drm2/ecore_drm2_fb.c
index e2ef2e8a2f..a90d13bbf6 100644
--- a/src/lib/ecore_drm2/ecore_drm2_fb.c
+++ b/src/lib/ecore_drm2/ecore_drm2_fb.c
@@ -1,5 +1,7 @@
#include "ecore_drm2_private.h"
+#include <poll.h>
+
#define FLIP_TIMEOUT 1.0
static Eina_Bool
@@ -280,7 +282,15 @@ ecore_drm2_fb_flip_complete(Ecore_Drm2_Output *output)
ecore_main_loop_thread_safe_call_async
(_cb_mainloop_async_timer_del, output);
}
- if (!output->pending.fb) fprintf(stderr, "XXX--XXX eeeeek pending fb is NULL so current would become null ----------------------------------\n");
+ /* A flip resubmitted by _cb_flip_timeout() can race with the event of the
+ * original one, and the kernel then sends one event per accepted commit.
+ * current.fb must survive the extra one: ecore_drm2_fb_flip(NULL, output)
+ * needs it to generate the next tick. */
+ if (!output->pending.fb)
+ {
+ WRN("Flip event received with no flip pending");
+ return !!output->next.fb;
+ }
if (output->current.fb && (output->current.fb != output->pending.fb))
_ecore_drm2_fb_buffer_release(output, &output->current);
@@ -474,18 +484,40 @@ err:
return EINA_FALSE;
}
-static int _fb_atomic_flip(Ecore_Drm2_Output *output);
+static int _fb_atomic_commit(Ecore_Drm2_Output *output, int tries);
static int _fb_flip(Ecore_Drm2_Output *output);
+static Eina_Bool
+_fb_flip_event_queued(const Ecore_Drm2_Output *output)
+{
+ struct pollfd pfd = { .fd = output->fd, .events = POLLIN };
+
+ return poll(&pfd, 1, 0) > 0;
+}
+
static Eina_Bool
_cb_flip_timeout(void *data)
{
Ecore_Drm2_Output *output = data;
+ Eina_Bool wait_for_event;
output->flip_timeout = NULL;
+ if (!output->pending.fb) return EINA_FALSE;
+
ERR("flip event callback timout %0.2fsec - try again", FLIP_TIMEOUT);
- if (_ecore_drm2_use_atomic) _fb_atomic_flip(output);
- else _fb_flip(output);
+ /* EBUSY means the kernel still owns the flip we are waiting for, and a
+ * readable fd means its event is already there. Committing again in either
+ * case would produce a second event for a single pending flip. */
+ wait_for_event = _fb_flip_event_queued(output);
+ if (!wait_for_event)
+ {
+ if (_ecore_drm2_use_atomic)
+ wait_for_event = (_fb_atomic_commit(output, 1) == -EBUSY);
+ else
+ _fb_flip(output);
+ }
+ if (wait_for_event)
+ output->flip_timeout = ecore_timer_add(FLIP_TIMEOUT, _cb_flip_timeout, output);
return EINA_FALSE;
}
@@ -497,8 +529,9 @@ _cb_mainloop_async_timer_reset(void *data)
output->flip_timeout = ecore_timer_add(FLIP_TIMEOUT, _cb_flip_timeout, output);
}
+/* Returns 0, or the negative errno of the last failed commit. */
static int
-_fb_atomic_flip(Ecore_Drm2_Output *output)
+_fb_atomic_commit(Ecore_Drm2_Output *output, int tries)
{
int res = 0;
uint32_t flags =
@@ -516,7 +549,7 @@ _fb_atomic_flip(Ecore_Drm2_Output *output)
// sometimes we get a EBUSY ... so try again a few times.
int i;
- for (i = 0; i < 10; i++)
+ for (i = 0; i < tries; i++)
{
res =
sym_drmModeAtomicCommit(output->fd, output->prep.atomic_req, flags,
@@ -528,8 +561,8 @@ _fb_atomic_flip(Ecore_Drm2_Output *output)
if (res < 0)
{
- ERR("Failed Atomic Commit: %m");
- return -1;
+ ERR("Failed Atomic Commit: %s", strerror(-res));
+ return res;
}
else
{
@@ -541,6 +574,12 @@ _fb_atomic_flip(Ecore_Drm2_Output *output)
return 0;
}
+static int
+_fb_atomic_flip(Ecore_Drm2_Output *output)
+{
+ return _fb_atomic_commit(output, 10) ? -1 : 0;
+}
+
static int
_fb_flip(Ecore_Drm2_Output *output)
{
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index f697d1b608..2aa1b856bb 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -24,6 +24,9 @@ static const Efl_Test_Case etc[] = {
{ "Eina_Thread_Queue", ecore_test_ecore_thread_eina_thread_queue2 },
#if HAVE_ECORE_FB
{ "Ecore_Fb", ecore_test_ecore_fb },
+#endif
+#ifdef BUILD_ECORE_DRM2_TESTS
+ { "Ecore_Drm2_Fb", ecore_test_ecore_drm2_fb },
#endif
{ "Ecore_Input", ecore_test_ecore_input },
{ "Ecore_File", ecore_test_ecore_file },
diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h
index 2621535f59..dc5b3adb4f 100644
--- a/src/tests/ecore/ecore_suite.h
+++ b/src/tests/ecore/ecore_suite.h
@@ -18,6 +18,7 @@ void ecore_test_animator(TCase *tc);
void ecore_test_ecore_thread_eina_thread_queue(TCase *tc);
void ecore_test_ecore_thread_eina_thread_queue2(TCase *tc);
void ecore_test_ecore_fb(TCase *tc);
+void ecore_test_ecore_drm2_fb(TCase *tc);
void ecore_test_ecore_input(TCase *tc);
void ecore_test_ecore_file(TCase *tc);
void ecore_test_ecore_job(TCase *tc);
diff --git a/src/tests/ecore/ecore_test_ecore_drm2_fb.c b/src/tests/ecore/ecore_test_ecore_drm2_fb.c
new file mode 100644
index 0000000000..ee01ceff3c
--- /dev/null
+++ b/src/tests/ecore/ecore_test_ecore_drm2_fb.c
@@ -0,0 +1,217 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ecore_suite.h"
+
+/* The flip state machine is driven by kernel events that no test machine can
+ * be asked to delay, so its source is built here against a fake libdrm. */
+#include "ecore_drm2_fb.c"
+
+int _ecore_drm2_log_dom = -1;
+Eina_Bool _ecore_drm2_use_atomic = EINA_TRUE;
+
+static int _commit_attempts = 0;
+static int _commits_accepted = 0;
+static int _commit_result = 0;
+static char _fake_atomic_req;
+
+static int
+_fake_atomic_commit(int fd EINA_UNUSED, drmModeAtomicReqPtr req EINA_UNUSED, uint32_t flags,
+ void *user_data EINA_UNUSED)
+{
+ if (flags & DRM_MODE_ATOMIC_TEST_ONLY) return 0;
+
+ _commit_attempts++;
+ if (_commit_result) return _commit_result;
+ _commits_accepted++;
+ return 0;
+}
+
+static void *
+_fake_atomic_alloc(void)
+{
+ return &_fake_atomic_req;
+}
+
+static void
+_fake_atomic_free(drmModeAtomicReqPtr req EINA_UNUSED)
+{
+}
+
+static int
+_fake_atomic_add_property(drmModeAtomicReqPtr req EINA_UNUSED, uint32_t object_id EINA_UNUSED,
+ uint32_t property_id EINA_UNUSED, uint64_t value EINA_UNUSED)
+{
+ return 1;
+}
+
+static void
+_fake_atomic_set_cursor(drmModeAtomicReqPtr req EINA_UNUSED, int cursor EINA_UNUSED)
+{
+}
+
+static int
+_fake_rm_fb(int fd EINA_UNUSED, uint32_t id EINA_UNUSED)
+{
+ return 0;
+}
+
+int (*sym_drmIoctl)(int fd, unsigned long request, void *arg) = NULL;
+void *(*sym_drmModeAtomicAlloc)(void) = _fake_atomic_alloc;
+void (*sym_drmModeAtomicFree)(drmModeAtomicReqPtr req) = _fake_atomic_free;
+int (*sym_drmModeAtomicAddProperty)(drmModeAtomicReqPtr req, uint32_t object_id, uint32_t property_id, uint64_t value) = _fake_atomic_add_property;
+int (*sym_drmModeAtomicCommit)(int fd, drmModeAtomicReqPtr req, uint32_t flags, void *user_data) = _fake_atomic_commit;
+void (*sym_drmModeAtomicSetCursor)(drmModeAtomicReqPtr req, int cursor) = _fake_atomic_set_cursor;
+int (*sym_drmModeSetCrtc)(int fd, uint32_t crtcId, uint32_t bufferId, uint32_t x, uint32_t y, uint32_t *connectors, int count, drmModeModeInfoPtr mode) = NULL;
+int (*sym_drmModeAddFB)(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id) = NULL;
+int (*sym_drmModeAddFB2)(int fd, uint32_t width, uint32_t height, uint32_t pixel_format, uint32_t bo_handles[4], uint32_t pitches[4], uint32_t offsets[4], uint32_t *buf_id, uint32_t flags) = NULL;
+int (*sym_drmModeRmFB)(int fd, uint32_t bufferId) = _fake_rm_fb;
+int (*sym_drmModePageFlip)(int fd, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, void *user_data) = NULL;
+int (*sym_drmModeDirtyFB)(int fd, uint32_t bufferId, drmModeClipPtr clips, uint32_t num_clips) = NULL;
+int (*sym_drmPrimeFDToHandle)(int fd, int prime_fd, uint32_t *handle) = NULL;
+
+typedef struct _Flip_Fixture
+{
+ Ecore_Drm2_Output output;
+ Ecore_Drm2_Crtc_State crtc;
+ Ecore_Drm2_Output_Mode mode;
+ Ecore_Drm2_Fb *fb;
+ int event_fds[2];
+} Flip_Fixture;
+
+/* Leaves one accepted flip of f->fb waiting for its event. */
+static void
+_flip_fixture_init(Flip_Fixture *f)
+{
+ ecore_init();
+ _ecore_drm2_log_dom = EINA_LOG_DOMAIN_GLOBAL;
+ _commit_attempts = 0;
+ _commits_accepted = 0;
+ _commit_result = 0;
+
+ memset(f, 0, sizeof(Flip_Fixture));
+ ck_assert_int_eq(pipe(f->event_fds), 0);
+ f->output.fd = f->event_fds[0];
+ f->output.enabled = EINA_TRUE;
+ f->output.current_mode = &f->mode;
+ f->output.crtc_state = &f->crtc;
+
+ f->fb = calloc(1, sizeof(Ecore_Drm2_Fb));
+ ck_assert_ptr_nonnull(f->fb);
+ f->fb->ref = 1;
+ f->fb->gbm = EINA_TRUE;
+
+ ck_assert_int_eq(ecore_drm2_fb_flip(f->fb, &f->output), 0);
+ ck_assert_ptr_eq(f->output.pending.fb, f->fb);
+ ck_assert_int_eq(_commits_accepted, 1);
+}
+
+static void
+_flip_fixture_shutdown(Flip_Fixture *f)
+{
+ if (f->output.flip_timeout) ecore_timer_del(f->output.flip_timeout);
+ if (f->output.pending.fb)
+ _ecore_drm2_fb_buffer_release(&f->output, &f->output.pending);
+ if (f->output.current.fb)
+ _ecore_drm2_fb_buffer_release(&f->output, &f->output.current);
+ ecore_drm2_fb_discard(f->fb);
+ close(f->event_fds[0]);
+ close(f->event_fds[1]);
+ ecore_shutdown();
+}
+
+static void
+_flip_timeout_fire(Flip_Fixture *f)
+{
+ if (f->output.flip_timeout) ecore_timer_del(f->output.flip_timeout);
+ _cb_flip_timeout(&f->output);
+}
+
+EFL_START_TEST(ecore_test_drm2_fb_extra_flip_event_keeps_current)
+{
+ Flip_Fixture f;
+
+ _flip_fixture_init(&f);
+
+ ecore_drm2_fb_flip_complete(&f.output);
+ ecore_drm2_fb_flip_complete(&f.output);
+ ck_assert_ptr_eq(f.output.current.fb, f.fb);
+
+ ck_assert_int_eq(ecore_drm2_fb_flip(NULL, &f.output), 0);
+ ck_assert_int_eq(_commits_accepted, 2);
+ ecore_drm2_fb_flip_complete(&f.output);
+
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
+EFL_START_TEST(ecore_test_drm2_fb_timeout_waits_while_busy)
+{
+ Flip_Fixture f;
+
+ _flip_fixture_init(&f);
+
+ _commit_result = -EBUSY;
+ _flip_timeout_fire(&f);
+ ck_assert_int_eq(_commit_attempts, 2);
+ ck_assert_int_eq(_commits_accepted, 1);
+ ck_assert_ptr_nonnull(f.output.flip_timeout);
+ ck_assert_ptr_eq(f.output.pending.fb, f.fb);
+
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
+EFL_START_TEST(ecore_test_drm2_fb_timeout_leaves_queued_event)
+{
+ Flip_Fixture f;
+
+ _flip_fixture_init(&f);
+
+ ck_assert_int_eq(write(f.event_fds[1], "e", 1), 1);
+ _flip_timeout_fire(&f);
+ ck_assert_int_eq(_commit_attempts, 1);
+ ck_assert_ptr_nonnull(f.output.flip_timeout);
+
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
+EFL_START_TEST(ecore_test_drm2_fb_timeout_recovers_lost_event)
+{
+ Flip_Fixture f;
+
+ _flip_fixture_init(&f);
+
+ _flip_timeout_fire(&f);
+ ck_assert_int_eq(_commits_accepted, 2);
+ ck_assert_ptr_nonnull(f.output.flip_timeout);
+
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
+EFL_START_TEST(ecore_test_drm2_fb_timeout_after_completion_is_ignored)
+{
+ Flip_Fixture f;
+
+ _flip_fixture_init(&f);
+
+ ecore_drm2_fb_flip_complete(&f.output);
+ _cb_flip_timeout(&f.output);
+ ck_assert_int_eq(_commit_attempts, 1);
+
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
+void
+ecore_test_ecore_drm2_fb(TCase *tc)
+{
+ tcase_add_test(tc, ecore_test_drm2_fb_extra_flip_event_keeps_current);
+ tcase_add_test(tc, ecore_test_drm2_fb_timeout_waits_while_busy);
+ tcase_add_test(tc, ecore_test_drm2_fb_timeout_leaves_queued_event);
+ tcase_add_test(tc, ecore_test_drm2_fb_timeout_recovers_lost_event);
+ tcase_add_test(tc, ecore_test_drm2_fb_timeout_after_completion_is_ignored);
+}
diff --git a/src/tests/ecore/meson.build b/src/tests/ecore/meson.build
index 9f107c9842..4ba58c33b9 100644
--- a/src/tests/ecore/meson.build
+++ b/src/tests/ecore/meson.build
@@ -59,8 +59,11 @@ if get_option('fb')
ecore_suite_src += 'ecore_test_ecore_fb.c'
endif
+ecore_suite_drm2_args = []
if get_option('drm')
- ecore_suite_deps += ecore_drm2
+ ecore_suite_deps += [ecore_drm2] + ecore_drm2_deps + ecore_drm2_ext_deps
+ ecore_suite_src += 'ecore_test_ecore_drm2_fb.c'
+ ecore_suite_drm2_args += '-DBUILD_ECORE_DRM2_TESTS'
endif
if get_option('x11')
@@ -71,7 +74,7 @@ endif
ecore_suite = executable('ecore_suite',
ecore_suite_src,
dependencies: [ecore_suite_deps, check],
- c_args : [
+ c_args : ecore_suite_drm2_args + [
'-DTESTS_BUILD_DIR="'+meson.current_build_dir()+'"',
'-DTESTS_SRC_DIR="'+meson.current_source_dir()+'"']
)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.