From 2dedc1fe5d55dafe9254e104b58bac1ab342003b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Apr 2020 16:41:59 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 12/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 From c3516d1de7e02d41852dd05ff441f796de0f9335 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 14 May 2020 19:07:14 +0900 Subject: [PATCH 13/16] Fixed to unref tbm_surface even when enqueue failed. Change-Id: I99a3e93833430a652cb653d8343a6dfd1a2d2342 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index f3a0fc9..5ca8691 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -598,16 +598,8 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, tsq_err = tbm_surface_queue_enqueue(wayland_egl_surface->tbm_queue, tbm_surface); - if (tsq_err == TBM_SURFACE_QUEUE_ERROR_NONE) { - /* - * If tbm_surface_queue has not been reset, tbm_surface_queue_enqueue - * will return ERROR_NONE. Otherwise, queue has been reset - * this tbm_surface may have only one ref_count. So we need to - * unreference this tbm_surface after getting ERROR_NONE result from - * tbm_surface_queue_enqueue in order to prevent destruction. - */ + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { tbm_surface_internal_unref(tbm_surface); - } else { TPL_ERR("Failed to enqueue tbm_surface(%p). tsq_err=%d", tbm_surface, tsq_err); TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name); @@ -615,6 +607,8 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, return TPL_ERROR_INVALID_OPERATION; } + tbm_surface_internal_unref(tbm_surface); + TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name); TPL_OBJECT_UNLOCK(wayland_egl_surface); -- 2.7.4 From 85995920898b3bd0c86824383180c4d8f5aaf79c Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 27 May 2020 16:13:11 +0900 Subject: [PATCH 14/16] Changed the default log output from LOGD to LOGI. Change-Id: I26d2328a119dfe23523f279f9b72eab7ba9ea552 Signed-off-by: Joonbum Ko --- src/tpl_utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 89854a1..26b696e 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -80,10 +80,10 @@ inline char *tpl_getenv(const char *name) #endif #ifdef DLOG_DEFAULT_ENABLE -#define tpl_log_f(t, f, x...) LOGD(FONT_GREEN t FONT_DEFAULT " " f, ##x) -#define tpl_log_b(t, f, x...) LOGD(FONT_BLUE t FONT_DEFAULT " " f, ##x) -#define tpl_log_d(t, f, x...) LOGD(FONT_MAGENTA t FONT_DEFAULT " " f, ##x) -#define tpl_log_t(t, f, x...) LOGD(FONT_CYAN t FONT_DEFAULT " " f, ##x) +#define tpl_log_f(t, f, x...) LOGI(FONT_GREEN t FONT_DEFAULT " " f, ##x) +#define tpl_log_b(t, f, x...) LOGI(FONT_BLUE t FONT_DEFAULT " " f, ##x) +#define tpl_log_d(t, f, x...) LOGI(FONT_MAGENTA t FONT_DEFAULT " " f, ##x) +#define tpl_log_t(t, f, x...) LOGI(FONT_CYAN t FONT_DEFAULT " " f, ##x) #define tpl_log_e(t, f, x...) LOGE(FONT_RED t " " f FONT_DEFAULT, ##x) #define tpl_log_w(t, f, x...) LOGW(FONT_YELLOW t " " f FONT_DEFAULT, ##x) #else /* DLOG_DEFAULT_ENABLE */ -- 2.7.4 From b4dcff113ae780d2049053b3b067202401c0fe7a Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 28 May 2020 12:52:09 +0900 Subject: [PATCH 15/16] Enhanced the error logs. Change-Id: I0ec3e186f1318a050c75fe1596b60803191f8100 Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 5ca8691..15697a4 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -448,7 +448,7 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface) static tpl_result_t __tpl_wl_egl_surface_set_rotation_capability(tpl_surface_t *surface, - tpl_bool_t set) + tpl_bool_t set) { tpl_wayland_egl_surface_t *wayland_egl_surface = NULL; @@ -459,8 +459,8 @@ __tpl_wl_egl_surface_set_rotation_capability(tpl_surface_t *surface, wayland_egl_surface = (tpl_wayland_egl_surface_t *)surface->backend.data; if (!wayland_egl_surface) { - TPL_ERR("Invalid parameter. wayland_egl_surface(%p)", - wayland_egl_surface); + TPL_ERR("Invalid parameter. surface(%p) wayland_egl_surface(%p)", + surface, wayland_egl_surface); return TPL_ERROR_INVALID_PARAMETER; } @@ -478,7 +478,7 @@ __tpl_wl_egl_surface_set_rotation_capability(tpl_surface_t *surface, static tpl_result_t __tpl_wl_egl_surface_set_post_interval(tpl_surface_t *surface, - int post_interval) + int post_interval) { tpl_wayland_egl_surface_t *wayland_egl_surface = NULL; @@ -489,8 +489,8 @@ __tpl_wl_egl_surface_set_post_interval(tpl_surface_t *surface, wayland_egl_surface = (tpl_wayland_egl_surface_t *)surface->backend.data; if (!wayland_egl_surface) { - TPL_ERR("Invalid parameter. wayland_egl_surface(%p)", - wayland_egl_surface); + TPL_ERR("Invalid parameter. surface(%p) wayland_egl_surface(%p)", + surface, wayland_egl_surface); return TPL_ERROR_INVALID_PARAMETER; } @@ -527,8 +527,8 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)); if (!wayland_egl_surface) { - TPL_ERR("Invalid parameter. wayland_egl_surface(%p)", - wayland_egl_surface); + TPL_ERR("Invalid parameter. surface(%p) wayland_egl_surface(%p)", + surface, wayland_egl_surface); TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name); TPL_OBJECT_UNLOCK(wayland_egl_surface); return TPL_ERROR_INVALID_PARAMETER; @@ -600,8 +600,8 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { tbm_surface_internal_unref(tbm_surface); - TPL_ERR("Failed to enqueue tbm_surface(%p). tsq_err=%d", - tbm_surface, tsq_err); + TPL_ERR("Failed to enqueue tbm_surface(%p). tpl_surface(%p) tsq_err=%d", + tbm_surface, surface, tsq_err); TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name); TPL_OBJECT_UNLOCK(wayland_egl_surface); return TPL_ERROR_INVALID_OPERATION; @@ -655,7 +655,8 @@ __tpl_wl_egl_surface_cancel_dequeued_buffer(tpl_surface_t *surface, tsq_err = tbm_surface_queue_cancel_dequeue(wayland_egl_surface->tbm_queue, tbm_surface); if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { - TPL_ERR("Failed to release tbm_surface(%p)", tbm_surface); + TPL_ERR("Failed to release tbm_surface(%p) surface(%p)", + tbm_surface, surface); return TPL_ERROR_INVALID_OPERATION; } @@ -701,11 +702,12 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, lock_ret = twe_display_lock(wayland_egl_display->twe_display); if (tsq_err == TBM_SURFACE_QUEUE_ERROR_TIMEOUT) { - TPL_ERR("[CAN_DEQUEUE_TIMEOUT] queue(%p) will be reset", - wayland_egl_surface->tbm_queue); + TPL_ERR("[CAN_DEQUEUE_TIMEOUT] queue(%p) will be reset. surface(%p)", + wayland_egl_surface->tbm_queue, surface); if (twe_surface_queue_force_flush(wayland_egl_surface->twe_surface) != TPL_ERROR_NONE) { - TPL_ERR("Failed to timeout reset. tbm_queue(%p)", wayland_egl_surface->tbm_queue); + TPL_ERR("Failed to timeout reset. tbm_queue(%p) surface(%p)", + wayland_egl_surface->tbm_queue, surface); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_egl_display->twe_display); return NULL; @@ -715,7 +717,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, } if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { - TPL_ERR("Failed to query can_dequeue. tbm_queue(%p)", wayland_egl_surface->tbm_queue); + TPL_ERR("Failed to query can_dequeue. tbm_queue(%p) surface(%p)", + wayland_egl_surface->tbm_queue, surface); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_egl_display->twe_display); return NULL; @@ -766,8 +769,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, tsq_err = tbm_surface_queue_dequeue(wayland_egl_surface->tbm_queue, &tbm_surface); if (!tbm_surface) { - TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d", - tsq_err); + TPL_ERR("Failed to dequeue from tbm_queue(%p) surface(%p)| tsq_err = %d", + wayland_egl_surface->tbm_queue, surface, tsq_err); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_egl_display->twe_display); return NULL; -- 2.7.4 From 773e37bd4f9b80d116a75f2f664917f31165b61e Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 28 May 2020 13:29:30 +0900 Subject: [PATCH 16/16] Package version up to 1.7.7 Change-Id: I059dad443fb17d301aaeb10aa870fb23be999c86 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 4c3c68b..3609994 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 6 +%define TPL_VERSION_PATCH 7 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4