Use libgomp to fast tbm_surface copy 30/271430/1
authorJunkyeong, Kim <jk0430.kim@samsung.com>
Mon, 21 Feb 2022 06:29:28 +0000 (15:29 +0900)
committerJunkyeong, Kim <jk0430.kim@samsung.com>
Mon, 21 Feb 2022 06:29:31 +0000 (15:29 +0900)
Change-Id: I9ea654cf536440d7ea155e5f53a612e879df8104
Signed-off-by: Junkyeong, Kim <jk0430.kim@samsung.com>
configure.ac
packaging/e-mod-tizen-rdp.spec
src/Makefile.am
src/e_mod_rdp.c

index a9fb6c6..34488cd 100644 (file)
@@ -93,6 +93,37 @@ if test "${have_wayland_only}" != "xno"; then
         AC_DEFINE_UNQUOTED([HAVE_WAYLAND],[1],[enable wayland support])
 fi
 
+AC_MSG_CHECKING([for OpenMP])
+
+safe_CFLAGS=$CFLAGS
+CFLAGS="-fopenmp $mflag_primary -Werror"
+
+AC_LINK_IFELSE([AC_LANG_SOURCE([
+#include <omp.h>
+int main(int argc, char** argv)
+{
+  omp_set_dynamic(0);
+  return 0;
+}
+])],
+[
+   have_libgomp=yes
+   AC_MSG_RESULT([yes])
+], [
+   have_libgomp=no
+   AC_MSG_RESULT([no])
+])
+CFLAGS=$safe_CFLAGS
+
+if test "x$have_libgomp" != "xno"; then
+AC_DEFINE([HAVE_LIBGOMP], [1], [Enable libgomp])
+   have_libgomp=yes
+else
+AC_DEFINE([HAVE_LIBGOMP], [0], [Disable libgomp])
+   have_libgomp=no
+fi
+AM_CONDITIONAL([HAVE_LIBGOMP], [test "x${have_libgomp}" = "xyes"])
+
 dnl =======================================================================
 
 release=$(pkg-config --variable=release enlightenment)
index f3ac129..2bb0df6 100644 (file)
@@ -6,6 +6,11 @@ URL: http://www.enlightenment.org
 Group: Graphics & UI Framework/Other
 Source0: %{name}-%{version}.tar.gz
 License: BSD-2-Clause
+
+%ifarch %{arm}
+%define LIBGOMP use
+%endif
+
 BuildRequires: pkgconfig(enlightenment)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(wayland-server)
@@ -16,6 +21,10 @@ BuildRequires: pkgconfig(openssl1.1)
 BuildRequires: libopenssl11
 BuildRequires: libopenssl1.1-devel
 
+%if "%{LIBGOMP}" == "use"
+Requires:       libgomp
+%endif
+
 %description
 This package is a enlightenment rdp module for Tizen.
 
index 5bbd890..68ac394 100644 (file)
@@ -15,5 +15,10 @@ module_la_CFLAGS       = @ENLIGHTENMENT_CFLAGS@
 module_la_LDFLAGS      = -module -avoid-version @ENLIGHTENMENT_LIBS@
 module_la_DEPENDENCIES = $(top_builddir)/config.h
 
+if HAVE_LIBGOMP
+module_la_CFLAGS      += -fopenmp
+module_la_LDFLAGS     += -fopenmp
+endif
+
 #uninstall:
 #  rm -rf $(DESTDIR)$(libdir)/enlightenment/modules/$(MODULE)
index da4f682..b88f204 100644 (file)
 #include <tbm_surface_internal.h>
 #include <e_info_server_input.h>
 
+#if HAVE_LIBGOMP
+#include <omp.h>
+#endif
+
 #include "e_mod_main.h"
 #include "e_mod_rdp.h"
 
@@ -783,7 +787,54 @@ _e_rdp_cb_hwc_window_sort(const void *d1, const void *d2)
 static void
 _e_rdp_tbm_surface_copy(tbm_surface_h src_tbm_surface, tbm_surface_info_s *src_info, tbm_surface_h dst_tbm_surface, tbm_surface_info_s *dst_info)
 {
+#if HAVE_LIBGOMP
+# define LIBGOMP_COPY_THREAD_NUM 4
+# define LIBGOMP_COPY_PAGE_SIZE getpagesize()
+# define PAGE_ALIGN(addr) ((addr)&(~((LIBGOMP_COPY_PAGE_SIZE)-1)))
+   if (src_info->planes[0].size > (LIBGOMP_COPY_THREAD_NUM * LIBGOMP_COPY_PAGE_SIZE))
+     {
+        size_t step[2];
+        step[0] = PAGE_ALIGN(src_info->planes[0].size / LIBGOMP_COPY_THREAD_NUM);
+        step[1] = src_info->planes[0].size - (step[0] * (LIBGOMP_COPY_THREAD_NUM - 1));
+
+        omp_set_num_threads(LIBGOMP_COPY_THREAD_NUM);
+        #pragma omp parallel
+        #pragma omp sections
+          {
+             #pragma omp section
+               {
+                  memcpy(dst_info->planes[0].ptr,
+                         src_info->planes[0].ptr,
+                         step[0]);
+               }
+             #pragma omp section
+               {
+                  memcpy(dst_info->planes[0].ptr + step[0],
+                         src_info->planes[0].ptr + step[0],
+                         step[0]);
+               }
+             #pragma omp section
+               {
+                  memcpy(dst_info->planes[0].ptr + (step[0] * 2),
+                         src_info->planes[0].ptr + (step[0] * 2),
+                         step[0]);
+               }
+             #pragma omp section
+               {
+                  memcpy(dst_info->planes[0].ptr + (step[0] * 3),
+                         src_info->planes[0].ptr + (step[0] * 3),
+                         step[1]);
+               }
+          }
+     }
+   else
+     {
+        memcpy(dst_info->planes[0].ptr, src_info->planes[0].ptr, src_info->planes[0].size);
+     }
+
+#else /* HAVE_LIBGOMP */
    memcpy(dst_info->planes[0].ptr, src_info->planes[0].ptr, src_info->planes[0].size);
+#endif /* end of HAVE_LIBGOMP */
 }
 
 static void