From 0f9bdedeaac4bcd2f7f537a707decfce2ab2f4fd Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 9 Apr 2020 18:13:15 +0900 Subject: [PATCH 01/16] Changed to do not print error logs when last_error is already set. Change-Id: Ib5b4ec852930a55089864eeaf28e7b095295bc50 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 4f6acf1..48c9507 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -81,6 +81,7 @@ struct _twe_wl_disp_source { twe_thread *thread; GMutex wl_event_mutex; + int last_error; /* errno of the last wl_display error*/ /* TODO : surface list */ }; @@ -606,6 +607,9 @@ _twe_display_print_err(twe_wl_disp_source *disp_source, char buf[1024]; strerror_r(errno, buf, sizeof(buf)); + if (disp_source->last_error == errno) + return; + TPL_ERR("falied to %s. error:%d(%s)", func_name, errno, buf); dpy_err = wl_display_get_error(disp_source->disp); @@ -618,6 +622,8 @@ _twe_display_print_err(twe_wl_disp_source *disp_source, TPL_ERR("[Protocol Error] interface: %s, error_code: %d, proxy_id: %d", err_interface->name, err_code, err_proxy_id); } + + disp_source->last_error = errno; } static gboolean @@ -1000,6 +1006,7 @@ twe_display_add(twe_thread* thread, } source->disp = display; + source->last_error = 0; source->ev_queue = ev_queue; source->wl_tbm_client = wl_tbm_client; source->prepared = TPL_FALSE; -- 2.7.4 From 155d98f2a79866bce7b3ebf307e3e6c959d50c1a Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 17 Apr 2020 15:56:10 +0900 Subject: [PATCH 02/16] Added an error type to tpl_result_t to indicate display error. - new error type TPL_ERROR_INVALID_CONNECTION /* Invalid display connection */ - When some error occurs in the wayland display, it will be used to distinguish the error. Change-Id: I9f0813d64d10b522dae1224a0bf699328d479f27 Signed-off-by: Joonbum Ko --- src/tpl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tpl.h b/src/tpl.h index aaf6998..7250315 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -209,7 +209,8 @@ typedef enum { TPL_ERROR_INVALID_PARAMETER, /* Invalid parmeter */ TPL_ERROR_INVALID_OPERATION, /* Invalid operation */ TPL_ERROR_OUT_OF_MEMORY, /* Out of memory */ - TPL_ERROR_TIME_OUT /* Time out error */ + TPL_ERROR_TIME_OUT, /* Time out error */ + TPL_ERROR_INVALID_CONNECTION /* Invalid display connection */ } tpl_result_t; /** -- 2.7.4 From 2bb448c9e99fc22b38c3e96a8a1a9df1bf22f02b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 14:57:42 +0900 Subject: [PATCH 03/16] Deleted unnecessary checks for gsource is destroyed. Change-Id: I03d527cfd0b1986a32f14e8b106e5f83bddefa16 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 64 -------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 48c9507..29af684 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -252,13 +252,6 @@ _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) g_mutex_lock(&_twe_ctx->thread_mutex); - if (g_source_is_destroyed(source)) { - TPL_ERR("del_source(%p) already destroyed.", source); - g_cond_signal(&_twe_ctx->thread_cond); - g_mutex_unlock(&_twe_ctx->thread_mutex); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, del_source->tag); if (cond & G_IO_IN) { @@ -315,11 +308,6 @@ _twe_thread_del_source_trigger(twe_del_source *del_source) uint64_t value = 1; int ret; - if (!del_source || g_source_is_destroyed(&del_source->gsource)) { - TPL_ERR("del_source(%p) is already destroyed.", del_source); - return; - } - ret = write(del_source->event_fd, &value, sizeof(uint64_t)); if (ret == -1) { TPL_ERR("failed to send delete event. twe_del_source(%p)", @@ -382,11 +370,6 @@ _twe_thread_tdm_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) tdm_error tdm_err = TDM_ERROR_NONE; GIOCondition cond; - if (!source || g_source_is_destroyed(source)) { - TPL_ERR("TDM source(%p) already destroyed.", source); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, tdm_source->tag); if (cond & G_IO_IN) { @@ -490,11 +473,6 @@ _twe_thread_tdm_source_destroy(void *source) { twe_tdm_source *tdm_source = (twe_tdm_source *)source; - if (!tdm_source || g_source_is_destroyed(&tdm_source->gsource)) { - TPL_ERR("TDM source(%p) already destroyed.", tdm_source); - return; - } - _twe_ctx->tdm_source = NULL; g_source_remove_unix_fd(&tdm_source->gsource, tdm_source->tag); @@ -657,13 +635,6 @@ _twe_thread_wl_disp_check(GSource *source) twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; gboolean ret = FALSE; - if (g_source_is_destroyed(source)) { - if (disp_source && disp_source->disp && disp_source->prepared) - wl_display_cancel_read(disp_source->disp); - TPL_ERR("display source(%p) already destroyed.", source); - return ret; - } - if (!disp_source->prepared) return ret; @@ -686,11 +657,6 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; - if (g_source_is_destroyed(source)) { - TPL_ERR("display source(%p) already destroyed.", source); - return G_SOURCE_REMOVE; - } - g_mutex_lock(&disp_source->wl_event_mutex); if (disp_source->gfd.revents & G_IO_IN) { if (wl_display_dispatch_queue_pending(disp_source->disp, @@ -2357,11 +2323,6 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; GIOCondition cond; - if (g_source_is_destroyed(source)) { - TPL_ERR("surface source(%p) already destroyed.", source); - return G_SOURCE_REMOVE; - } - cond = g_source_query_unix_fd(source, surf_source->tag); if (cond & G_IO_IN) { @@ -2907,11 +2868,6 @@ twe_surface_create_swapchain(twe_surface_h twe_surface, tbm_bufmgr bufmgr = NULL; unsigned int capability; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - if (surf_source->tbm_queue) { TPL_LOG_B(BACKEND, "[REUSE SWAPCHAIN] surf_source(%p) tbm_queue(%p)", surf_source, surf_source->tbm_queue); @@ -3040,11 +2996,6 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - TPL_LOG_T(BACKEND, "[SWAPCHAIN_DESTROY] twe_surface(%p) tbm_queue(%p)", twe_surface, surf_source->tbm_queue); @@ -3090,11 +3041,6 @@ twe_surface_get_swapchain_buffers(twe_surface_h twe_surface, twe_wl_disp_source *disp_source = NULL; int ret = 1; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("twe_surface(%p) is invalid.", twe_surface); - return TPL_ERROR_INVALID_PARAMETER; - } - if (!buffer_count) { TPL_ERR("Invalid parameter. buffer_count is NULL."); return TPL_ERROR_INVALID_PARAMETER; @@ -3435,11 +3381,6 @@ twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) twe_wl_disp_source *disp_source = NULL; gint64 end_time; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); - return TPL_ERROR_INVALID_PARAMETER; - } - disp_source = surf_source->disp_source; if (timeout_ns != UINT64_MAX) @@ -3588,11 +3529,6 @@ twe_surface_set_post_interval(twe_surface_h twe_surface, int post_interval) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) { - TPL_ERR("Invalid parameter. surf_source(%p)", surf_source); - return TPL_ERROR_INVALID_PARAMETER; - } - surf_source->post_interval = post_interval; TPL_LOG_T(BACKEND, "surf_source(%p) post_interval(%d)", -- 2.7.4 From 5b1e179267322b2bca0457e53fbf563b5512b0bd Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:37:29 +0900 Subject: [PATCH 04/16] Deleted unused function commit_without_enqueue. Change-Id: I35f8b16c4acb98153277f3613e0c2e106f11465d Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 25 ------------------------- src/tpl_wayland_egl_thread.h | 4 ---- 2 files changed, 29 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 29af684..ea58f4c 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -3191,31 +3191,6 @@ twe_surface_check_commit_needed(twe_surface_h twe_surface, return buf_info->need_to_commit; } -void -twe_surface_commit_without_enqueue(twe_surface_h twe_surface, - tbm_surface_h tbm_surface) -{ - twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; - - if (!surf_source) { - TPL_ERR("Invalid parameter. twe_surface(%p)", twe_surface); - return; - } - - if (!tbm_surface || !tbm_surface_internal_is_valid(tbm_surface)) { - TPL_ERR("Invalid parameter. tbm_surface(%p)", tbm_surface); - return; - } - - g_mutex_lock(&surf_source->surf_mutex); - if (!surf_source->is_destroying) - _twe_thread_wl_surface_commit(surf_source, tbm_surface); - else - TPL_WARN("surf_source(%p) native window is already destroyed.", - surf_source); - g_mutex_unlock(&surf_source->surf_mutex); -} - static gboolean _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) { diff --git a/src/tpl_wayland_egl_thread.h b/src/tpl_wayland_egl_thread.h index 3a17305..9252fa9 100755 --- a/src/tpl_wayland_egl_thread.h +++ b/src/tpl_wayland_egl_thread.h @@ -80,10 +80,6 @@ tpl_bool_t twe_surface_check_commit_needed(twe_surface_h twe_surface, tbm_surface_h tbm_surface); -void -twe_surface_commit_without_enqueue(twe_surface_h twe_surface, - tbm_surface_h tbm_surface); - tpl_result_t twe_surface_set_damage_region(tbm_surface_h tbm_surface, int num_rects, const int *rects); -- 2.7.4 From 2dedc1fe5d55dafe9254e104b58bac1ab342003b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:41:59 +0900 Subject: [PATCH 05/16] Protected the access of surf_source's event_fd with surf_mutex. Change-Id: Icd081e7adf27c047e64b3f6bfabb06c1b85e6906 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index ea58f4c..121a1da 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1719,14 +1719,19 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h surface_queue, uint64_t value = 1; int ret; + g_mutex_lock(&surf_source->surf_mutex); + if (!surf_source->use_sync_fence) { ret = write(surf_source->event_fd, &value, sizeof(uint64_t)); if (ret == -1) { TPL_ERR("failed to send acquirable event. twe_wl_surf_source(%p)", surf_source); + g_mutex_unlock(&surf_source->surf_mutex); return; } } + + g_mutex_unlock(&surf_source->surf_mutex); } static void __cb_tbm_queue_trace_callback(tbm_surface_queue_h tbm_queue, @@ -2323,6 +2328,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; GIOCondition cond; + g_mutex_lock(&surf_source->surf_mutex); + cond = g_source_query_unix_fd(source, surf_source->tag); if (cond & G_IO_IN) { @@ -2342,6 +2349,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) TPL_ASSERT((cond & G_IO_IN)); } + g_mutex_unlock(&surf_source->surf_mutex); + return G_SOURCE_CONTINUE; } -- 2.7.4 From a2e1ab6fe7e2a4463c452579f2a6522945a7bc25 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:52:07 +0900 Subject: [PATCH 06/16] Excluded the case of abort due to eventfd problem. - Remove poll fd(event_fd) of main loop, but keep gsource. Change-Id: I3759d24672895b355e3541e7b8b6d2a2de7dab6d Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 121a1da..2742986 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -268,9 +268,11 @@ _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) } else { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", del_source->event_fd, cond); - g_cond_signal(&_twe_ctx->thread_cond); - g_mutex_unlock(&_twe_ctx->thread_mutex); - TPL_ASSERT((cond & G_IO_IN)); + + g_source_remove_unix_fd(del_source->event_fd, del_source->tag); + close(del_source->event_fd); + del_source->tag = NULL; + del_source->event_fd = -1; } g_cond_signal(&_twe_ctx->thread_cond); @@ -2346,7 +2348,10 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) } else { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", surf_source->event_fd, cond); - TPL_ASSERT((cond & G_IO_IN)); + g_source_remove_unix_fd(source, surf_source->tag); + close(surf_source->event_fd); + surf_source->tag = NULL; + surf_source->event_fd = -1; } g_mutex_unlock(&surf_source->surf_mutex); -- 2.7.4 From 09aa0b74e9c487e65a26676d04dcee96edb93998 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 21 Apr 2020 18:30:15 +0900 Subject: [PATCH 07/16] gsource is automatically restored when a problem occurs in eventfd. - Problems caused from other libraries that attempt to use the wrong fd often affect the eventfd of surf_source or del_source. - In such a case, in the past, assert checking was used to generate abort and it was not good. - So I made it possible to regenerate eventfd to minimize the abort generated by libtpl-egl and overcome the problem situation. Change-Id: I4cb23a022b40c48f864de402f3beabd2fec29a64 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 57 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 2742986..f5d8bc3 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -248,6 +248,7 @@ static gboolean _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_del_source *del_source = (twe_del_source *)source; + tpl_result_t res = TPL_ERROR_NONE; GIOCondition cond; g_mutex_lock(&_twe_ctx->thread_mutex); @@ -259,20 +260,39 @@ _twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data) uint64_t u; s = read(del_source->event_fd, &u, sizeof(uint64_t)); - if (s != sizeof(uint64_t)) + if (s != sizeof(uint64_t)) { TPL_ERR("Failed to read from event_fd(%d)", del_source->event_fd); + res = TPL_ERROR_INVALID_CONNECTION; + } if (del_source->destroy_target_source_func) del_source->destroy_target_source_func(del_source->target_source); - } else { + } + + if (cond && !(cond & G_IO_IN)) { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", del_source->event_fd, cond); + res = TPL_ERROR_INVALID_CONNECTION; + } + + if (res != TPL_ERROR_NONE) { + g_source_remove_unix_fd(source, del_source->tag); + + TPL_WARN("event_fd(%d) of del_source(%p) has been closed. it will be recreated.", + del_source->event_fd, del_source); - g_source_remove_unix_fd(del_source->event_fd, del_source->tag); close(del_source->event_fd); - del_source->tag = NULL; - del_source->event_fd = -1; + + del_source->event_fd = eventfd(0, EFD_CLOEXEC); + if (del_source->event_fd < 0) { + TPL_ERR("Failed to create eventfd. errno(%d)", errno); + } else { + del_source->tag = g_source_add_unix_fd(&del_source->gsource, + del_source->event_fd, + G_IO_IN); + } + TPL_DEBUG("[RECREATED] eventfd(%d) tag(%p)", del_source->event_fd, del_source->tag); } g_cond_signal(&_twe_ctx->thread_cond); @@ -2328,6 +2348,7 @@ static gboolean _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)source; + tpl_result_t res = TPL_ERROR_NONE; GIOCondition cond; g_mutex_lock(&surf_source->surf_mutex); @@ -2339,19 +2360,37 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) uint64_t u; s = read(surf_source->event_fd, &u, sizeof(uint64_t)); - if (s != sizeof(uint64_t)) + if (s != sizeof(uint64_t)) { TPL_ERR("Failed to read from event_fd(%d)", surf_source->event_fd); + res = TPL_ERROR_INVALID_CONNECTION; + } _twe_thread_wl_surface_acquire_and_commit(surf_source); - } else { + } + + if (cond && !(cond & G_IO_IN)) { TPL_ERR("eventfd(%d) cannot wake up with other condition. cond(%d)", surf_source->event_fd, cond); + res = TPL_ERROR_INVALID_CONNECTION; + } + + if (res != TPL_ERROR_NONE) { g_source_remove_unix_fd(source, surf_source->tag); close(surf_source->event_fd); - surf_source->tag = NULL; - surf_source->event_fd = -1; + + TPL_WARN("event_fd of surf_source(%p) has been closed. it will be recreated.", + surf_source); + surf_source->event_fd = eventfd(0, EFD_CLOEXEC); + if (surf_source->event_fd < 0) { + TPL_ERR("Failed to create eventfd. errno(%d)", errno); + } else { + surf_source->tag = g_source_add_unix_fd(&surf_source->gsource, + surf_source->event_fd, + G_IO_IN); + } + TPL_DEBUG("[RECREATED] eventfd(%d) tag(%p)", surf_source->event_fd, surf_source->tag); } g_mutex_unlock(&surf_source->surf_mutex); -- 2.7.4 From 0437c96dd04b938676271c5acce56682fc56c557 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 22 Apr 2020 12:31:52 +0900 Subject: [PATCH 08/16] Fixed to be removed from g_main_loop when error occurs in wl_display. - This is a minimal measure to ensure that abort does not occur in twe_thread. but is not perfect. - disp_source will be removed from main_loop, but other problems may arise because it affects the remaining surf_source. Change-Id: I04f2be6888cab077c3997bbd1bd38d92eda6b842 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index f5d8bc3..a5801ec 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -635,6 +635,12 @@ _twe_thread_wl_disp_prepare(GSource *source, gint *time) if (disp_source->prepared) return FALSE; + /* If there is a last_error, there is no need to poll, + * so skip directly to dispatch. + * prepare -> dispatch */ + if (disp_source->last_error) + return TRUE; + while (wl_display_prepare_read_queue(disp_source->disp, disp_source->ev_queue) != 0) { if (wl_display_dispatch_queue_pending(disp_source->disp, @@ -660,6 +666,16 @@ _twe_thread_wl_disp_check(GSource *source) if (!disp_source->prepared) return ret; + /* If prepared, but last_error is set, + * cancel_read is executed and FALSE is returned. + * That can lead to G_SOURCE_REMOVE by calling disp_prepare again + * and skipping disp_check from prepare to disp_dispatch. + * check -> prepare -> dispatch -> G_SOURCE_REMOVE */ + if (disp_source->prepared && disp_source->last_error) { + wl_display_cancel_read(disp_source->disp); + return ret; + } + if (disp_source->gfd.revents & G_IO_IN) { if (wl_display_read_events(disp_source->disp) == -1) _twe_display_print_err(disp_source, "read_event."); @@ -679,6 +695,13 @@ _twe_thread_wl_disp_dispatch(GSource *source, GSourceFunc cb, gpointer data) { twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source; + /* If there is last_error, G_SOURCE_REMOVE should be returned + * to remove the gsource from the main loop. + * This is because disp_source is not valid since last_error was set.*/ + if (disp_source->last_error) { + return G_SOURCE_REMOVE; + } + g_mutex_lock(&disp_source->wl_event_mutex); if (disp_source->gfd.revents & G_IO_IN) { if (wl_display_dispatch_queue_pending(disp_source->disp, -- 2.7.4 From e3abe714c3c477c97853f9c23f2020fca5e8c640 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 22 Apr 2020 16:43:42 +0900 Subject: [PATCH 09/16] Fixed to unuse sync_fd when frontbuffer rendering. Change-Id: Iad53c0071df08eb3cac63481eff4b7cde491fe3f Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index e20801a..fac6875 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -580,6 +580,11 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, */ if (surface->frontbuffer == tbm_surface) wayland_egl_surface->need_to_enqueue = TPL_FALSE; + + if (sync_fence != -1) { + close(sync_fence); + sync_fence = -1; + } } if (sync_fence != -1) { -- 2.7.4 From a4ff35ab481c0276f675c6ddbfa25067ca5d5b50 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 24 Apr 2020 13:21:27 +0900 Subject: [PATCH 10/16] Fixed to print fence fd passed by enqueue_buffer. Change-Id: Iaceb87b819e8fbad1539e5abc94bb3d5d525b8a3 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index fac6875..f3a0fc9 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -545,8 +545,8 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, TRACE_MARK("[ENQ] BO_NAME:%d", bo_name); TPL_LOG_T("WL_EGL", - "[ENQ] wayland_egl_surface(%p) tbm_surface(%p) bo(%d)", - wayland_egl_surface, tbm_surface, bo_name); + "[ENQ] wayland_egl_surface(%p) tbm_surface(%p) bo(%d) fence(%d)", + wayland_egl_surface, tbm_surface, bo_name, sync_fence); /* If there are received region information, * save it to buf_info in tbm_surface user_data using below API. */ -- 2.7.4 From 2aa72bf3285da6b14a918b8738fe7e42d65470c2 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 27 Apr 2020 16:29:50 +0900 Subject: [PATCH 11/16] Fixed a bug that could cause deadlock. Change-Id: Idb231c020b08e60aa3e2368562551a7e06cfd61b Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index a5801ec..f815193 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -2294,7 +2294,6 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, (void **)&buf_info); - g_mutex_lock(&surf_source->surf_mutex); if (!disp_source->is_vulkan_dpy) { /* wayland_egl */ if (surf_source->vblank_done) { TPL_LOG_T(BACKEND, "[ACQ] tbm_surface(%p) bo(%d)", @@ -2363,7 +2362,6 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) break; } } - g_mutex_unlock(&surf_source->surf_mutex); } } @@ -3289,13 +3287,13 @@ _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer TRACE_ASYNC_END((int)wait_source, "FENCE WAIT fd(%d)", wait_source->fence_fd); + g_mutex_lock(&surf_source->surf_mutex); /* Since this source is going to be removed, acquire_and_commit must be * executed even in a situation other than G_IO_IN. * Nevertheless, there may be room for improvement. */ _twe_thread_wl_surface_acquire_and_commit(surf_source); tbm_surface_internal_unref(tbm_surface); - g_mutex_lock(&surf_source->surf_mutex); __tpl_list_remove_data(surf_source->fence_waiting_sources, (void *)wait_source, TPL_FIRST, NULL); g_mutex_unlock(&surf_source->surf_mutex); -- 2.7.4 From aca218df76453a2484bd9e938e823063a04e1834 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 27 Apr 2020 18:45:03 +0900 Subject: [PATCH 12/16] Changed getenv() for TPL_WAIT_VBLANK to be called from main thread. Change-Id: I9e5143492d35ed7e6c1722af3c0b7888ff918aa8 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index f815193..79bcb91 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -42,6 +42,7 @@ struct _twe_thread_context { int ref_cnt; + tpl_bool_t use_wait_vblank; twe_tdm_source *tdm_source; twe_del_source *tdm_del_source; @@ -216,12 +217,9 @@ _twe_thread_loop(gpointer data) { twe_thread_context *ctx = data; - char *env = NULL; - g_mutex_lock(&ctx->thread_mutex); - env = getenv("TPL_WAIT_VBLANK"); - if (env == NULL || atoi(env)) { + if (ctx->use_wait_vblank) { twe_tdm_source *tdm_source = _twe_thread_tdm_source_create(); if (tdm_source) { @@ -506,6 +504,7 @@ twe_thread* twe_thread_create(void) { twe_thread *thread = NULL; + char *env = NULL; thread = calloc(1, sizeof(twe_thread)); if (!thread) { @@ -531,6 +530,13 @@ twe_thread_create(void) g_mutex_init(&_twe_ctx->thread_mutex); g_cond_init(&_twe_ctx->thread_cond); + _twe_ctx->use_wait_vblank = TPL_TRUE; + + env = getenv("TPL_WAIT_VBLANK"); + if (env && !atoi(env)) { + _twe_ctx->use_wait_vblank = TPL_FALSE; + } + g_mutex_lock(&_twe_ctx->thread_mutex); _twe_ctx->twe_thread = g_thread_new("twe_thread", _twe_thread_loop, _twe_ctx); -- 2.7.4 From 544f32c939a2ea99d7a33a96582cfa58ff5ff8d3 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 27 Apr 2020 19:07:02 +0900 Subject: [PATCH 13/16] Added inline function tpl_getenv() to replace getenv. Change-Id: I1018d6f7c11bba4aaaee3e29cc53dd1660f70593 Signed-off-by: Joonbum Ko --- src/tpl.c | 2 ++ src/tpl_utils.h | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/tpl.c b/src/tpl.c index 2a19d8d..8107b8f 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -2,6 +2,8 @@ unsigned int tpl_log_lvl = 0; unsigned int tpl_log_initialized = 0; +unsigned int tpl_getenv_initialized = 0; +unsigned int tpl_getenv_enabled = 0; unsigned int tpl_dump_lvl = 0; struct _tpl_runtime { diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 7f55fec..9e0369f 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -6,6 +6,7 @@ #include #include #include +#include #if defined(__GNUC__) && __GNUC__ >= 4 # define TPL_API __attribute__ ((visibility("default"))) @@ -53,8 +54,33 @@ /* 0:uninitialized, 1:initialized,no log, 2:user log */ extern unsigned int tpl_log_lvl; extern unsigned int tpl_log_initialized; +extern unsigned int tpl_getenv_initialized; +extern unsigned int tpl_getenv_enabled; extern unsigned int tpl_dump_lvl; +#define TPL_GETENV_INIT() \ + { \ + if (!tpl_getenv_initialized) \ + { \ + int ret = access("/opt/usr/tpl_env", F_OK); \ + if (ret == 0) \ + tpl_getenv_enabled = 1; \ + else \ + tpl_getenv_enabled = 0; \ + tpl_getenv_initialized = 1; \ + } \ + } + +inline char *tpl_getenv(const char *name) +{ + TPL_GETENV_INIT(); + if (tpl_getenv_enabled) + return getenv(name); + else + return NULL; +} + + #define FONT_DEFAULT "\033[0m" /* for reset to default color */ #define FONT_RED "\033[31m" /* for error logs */ #define FONT_YELLOW "\033[33m" /* for warning logs */ @@ -289,7 +315,6 @@ extern unsigned int tpl_dump_lvl; } #endif - typedef struct _tpl_list_node tpl_list_node_t; typedef struct _tpl_list tpl_list_t; typedef struct tpl_util_map_entry tpl_util_map_entry_t; -- 2.7.4 From 039117dfaac098322e6177e8bc0d3f8e5a707adc Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 27 Apr 2020 20:36:18 +0900 Subject: [PATCH 14/16] Replaced all getenv() by tpl_getenv() to reduce unnecessary calls. - In libtpl-egl, getenv() is using for debugging purposes only. - In most situations, it was frequently called getenv() which is not thread-safe, even though it is unnecessary. - It is difficult to make getenv() completely disabled, but replaced it with tpl_getenv() so that it can only be used in debugging situations. - tpl_getenv() returns the result of calling getenv() only if '/opt/usr/tpl_env' file exists, otherwise NULL. - example 1. $ export TPL_LOG_LEVEL=3 2. $ run gl app -> libtpl-egl will not get the env TPL_LOG_LEVEL 3. $ touch /opt/usr/tpl_env 4. $ run gl app -> TPL_LOG_LEVEL=3 will be accepted Change-Id: I4d40e1beb2f4c34e17b7694f96db5d237cb33bfe Signed-off-by: Joonbum Ko --- src/tpl.c | 4 ++-- src/tpl_object.c | 2 +- src/tpl_utils.h | 4 ++-- src/tpl_wayland_egl.c | 2 +- src/tpl_wayland_egl_thread.c | 2 +- src/tpl_x11_dri2.c | 4 ++-- src/tpl_x11_dri3.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 8107b8f..e6d90f0 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -231,11 +231,11 @@ __tpl_display_choose_backend(tpl_handle_t native_dpy) int wl_egl_thread = 0; #endif - thread = getenv("TPL_WL_EGL_THREAD"); + thread = tpl_getenv("TPL_WL_EGL_THREAD"); if (thread) wl_egl_thread = atoi(thread); - plat_name = getenv("EGL_PLATFORM"); + plat_name = tpl_getenv("EGL_PLATFORM"); if (plat_name) { #ifdef TPL_WINSYS_DRI2 diff --git a/src/tpl_object.c b/src/tpl_object.c index cf66cb0..4eb48c6 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -11,7 +11,7 @@ __tpl_object_hash_init(void) char *val; tpl_obj_hash_check = TPL_FALSE; - val = getenv("TPL_OBJECT_HASH_CHECK"); + val = tpl_getenv("TPL_OBJECT_HASH_CHECK"); if ((val) && (!strcmp(val, "1")) && (!tpl_obj_hash)) { tpl_obj_hash_check = TPL_TRUE; tpl_obj_hash = __tpl_hashlist_create(); diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 9e0369f..92cb6a0 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -152,7 +152,7 @@ inline char *tpl_getenv(const char *name) { \ if (!tpl_log_initialized) \ { \ - char *env = getenv("TPL_LOG_LEVEL"); \ + char *env = tpl_getenv("TPL_LOG_LEVEL"); \ if (env == NULL) \ tpl_log_lvl = 0; \ else \ @@ -303,7 +303,7 @@ inline char *tpl_getenv(const char *name) } \ else \ { \ - char *env = getenv("TPL_DUMP_LEVEL"); \ + char *env = tpl_getenv("TPL_DUMP_LEVEL"); \ if (env == NULL) \ tpl_dump_lvl = 0; \ else \ diff --git a/src/tpl_wayland_egl.c b/src/tpl_wayland_egl.c index d3d4d38..19611a7 100755 --- a/src/tpl_wayland_egl.c +++ b/src/tpl_wayland_egl.c @@ -173,7 +173,7 @@ __tpl_wayland_egl_display_init(tpl_display_t *display) (struct wl_display *)display->native_handle; wayland_egl_display->wl_tbm_client = wayland_tbm_client_init((struct wl_display *) wl_dpy); - char *env = getenv("TPL_WAIT_VBLANK"); + char *env = tpl_getenv("TPL_WAIT_VBLANK"); if (!wayland_egl_display->wl_tbm_client) { TPL_ERR("Wayland TBM initialization failed!"); diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 79bcb91..6722970 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -532,7 +532,7 @@ twe_thread_create(void) _twe_ctx->use_wait_vblank = TPL_TRUE; - env = getenv("TPL_WAIT_VBLANK"); + env = tpl_getenv("TPL_WAIT_VBLANK"); if (env && !atoi(env)) { _twe_ctx->use_wait_vblank = TPL_FALSE; } diff --git a/src/tpl_x11_dri2.c b/src/tpl_x11_dri2.c index c38f2c7..e5480a7 100644 --- a/src/tpl_x11_dri2.c +++ b/src/tpl_x11_dri2.c @@ -207,10 +207,10 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) global.bufmgr = tbm_bufmgr_init(global.bufmgr_fd); /* Initialize swap type configuration. */ - __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME), + __tpl_x11_swap_str_to_swap_type(tpl_getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME), &global.win_swap_type); - __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_FB_SWAP_TYPE_ENV_NAME), + __tpl_x11_swap_str_to_swap_type(tpl_getenv(EGL_X11_FB_SWAP_TYPE_ENV_NAME), &global.fb_swap_type); } diff --git a/src/tpl_x11_dri3.c b/src/tpl_x11_dri3.c index 076446b..3f90de3 100644 --- a/src/tpl_x11_dri3.c +++ b/src/tpl_x11_dri3.c @@ -1237,7 +1237,7 @@ __tpl_x11_dri3_display_init(tpl_display_t *display) { const char *backend_env = NULL; int count = 0; - backend_env = getenv("MALI_EGL_DRI3_BUF_NUM"); + backend_env = tpl_getenv("MALI_EGL_DRI3_BUF_NUM"); /* 2015-05-13 joonbum.ko@samsung.com */ /* Change the value of dri3_max_back 5 to 3 */ if (!backend_env || strlen(backend_env) == 0) -- 2.7.4 From 9ed760f3c77d58726ba5921a64649cfa34c374a3 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 29 Apr 2020 15:04:23 +0900 Subject: [PATCH 15/16] Moved tpl_getenv init to tpl_init Change-Id: I825862911ca1fe4054908cc678d9e960aa5e75c7 Signed-off-by: Joonbum Ko --- src/tpl.c | 10 ++++++++++ src/tpl_utils.h | 15 --------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index e6d90f0..50e19af 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -31,6 +31,16 @@ __tpl_runtime_init() static void __attribute__((constructor)) __tpl_init(void) { + if (!tpl_getenv_initialized) + { + int ret = access("/opt/usr/tpl_env", F_OK); + if (ret == 0) + tpl_getenv_enabled = 1; + else + tpl_getenv_enabled = 0; + tpl_getenv_initialized = 1; + } + TPL_DEBUG("[libtpl-egl] loaded"); #ifdef OBJECT_HASH_CHECK __tpl_object_hash_init(); diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 92cb6a0..89854a1 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -54,26 +54,11 @@ /* 0:uninitialized, 1:initialized,no log, 2:user log */ extern unsigned int tpl_log_lvl; extern unsigned int tpl_log_initialized; -extern unsigned int tpl_getenv_initialized; extern unsigned int tpl_getenv_enabled; extern unsigned int tpl_dump_lvl; -#define TPL_GETENV_INIT() \ - { \ - if (!tpl_getenv_initialized) \ - { \ - int ret = access("/opt/usr/tpl_env", F_OK); \ - if (ret == 0) \ - tpl_getenv_enabled = 1; \ - else \ - tpl_getenv_enabled = 0; \ - tpl_getenv_initialized = 1; \ - } \ - } - inline char *tpl_getenv(const char *name) { - TPL_GETENV_INIT(); if (tpl_getenv_enabled) return getenv(name); else -- 2.7.4 From e61ae4b4270b0b5000b4f4238e6b916696474b48 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 6 May 2020 18:44:54 +0900 Subject: [PATCH 16/16] Package version up to 1.7.6 Change-Id: I4ad491a190a0b18521a272d623738cd17cd0fa83 Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 98712ac..4c3c68b 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 5 +%define TPL_VERSION_PATCH 6 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4