[patch] libgompd: Add thread handles

2022-06-30 Thread Ahmed Sayed Mousse via Gcc-patches
/This patch is the initial implementation of OpenMP-API specs book section //20.5.5 with title "Thread Handles". /libgomp/ChangeLog /2022-07-01 
Ahmed Sayed  //	* Makefile.am 
(libgompd_la_SOURCES): Add ompd-threads.c.///* Makefile.in: Regenerate. * team.c ( gomp_free_thread ): Called 
ompd_bp_thread_end ()./* ompd-support.c ( gompd_thread_initial_tls_bias 
): New Variable. (gompd_load): Initialize gompd_thread_initial_tls_bias.///
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..23f5bede1bf 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c
 
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..8bbc46cca25 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -133,21 +133,8 @@ target_triplet = @target@
 @USE_FORTRAN_TRUE@am__append_7 = openacc.f90
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
-   $(top_srcdir)/../config/ax_count_cpus.m4 \
-   $(top_srcdir)/../config/depstand.m4 \
-   $(top_srcdir)/../config/enable.m4 \
-   $(top_srcdir)/../config/futex.m4 \
-   $(top_srcdir)/../config/lead-dot.m4 \
-   $(top_srcdir)/../config/lthostflags.m4 \
-   $(top_srcdir)/../config/multi.m4 \
-   $(top_srcdir)/../config/override.m4 \
-   $(top_srcdir)/../config/tls.m4 \
-   $(top_srcdir)/../config/toolexeclibdir.m4 \
-   $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
-   $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-   $(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
-   $(top_srcdir)/../config/cet.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+   $(top_srcdir)/../libtool.m4 $(top_srcdir)/../config/cet.m4 \
$(top_srcdir)/plugin/configfrag.ac $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
@@ -233,7 +220,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+   ompd-threads.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -485,7 +473,6 @@ dvidir = @dvidir@
 enable_shared = @enable_shared@
 enable_static = @enable_static@
 exec_prefix = @exec_prefix@
-get_gcc_base_ver = @get_gcc_base_ver@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -501,10 +488,8 @@ libtool_VERSION = @libtool_VERSION@
 link_gomp = @link_gomp@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
-multi_basedir = @multi_basedir@
 offload_additional_lib_paths = @offload_additional_lib_paths@
 offload_additional_options = @offload_additional_options@
 offload_plugins = @offload_plugins@
@@ -514,6 +499,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -583,7 +569,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -801,6 +787,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-threads.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/aclocal.m4 b/libgomp/aclocal.m4
index 55d9d71895a..41915216beb 100644
--- a/libgomp/aclocal.m4
+++ b/libgomp/aclocal.m4
@@ -626,6 +626,25 @@ if test x"${install_sh+set

[patch] libgompd: Add thread handles

2022-07-04 Thread Ahmed Sayed Mousse via Gcc-patches
*This patch is the initial implementation of OpenMP-API specs book section
**20.5.5 with title "Thread Handles".*

*I have fixed the first version after revising the notes on it.*

*libgomp/ChangeLog

2022-07-01  Ahmed Sayed  >
*

** Makefile.am (libgompd_la_SOURCES): Add ompd-threads.c.*

** Makefile.in: Regenerate.*

** team.c ( gomp_free_thread ): Called ompd_bp_thread_end ().*

** ompd-support.c ( gompd_thread_initial_tls_bias ): New Variable.*

* (gompd_load): Initialize gompd_thread_initial_tls_bias.*

** ompd-threads.c: New File.*
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..23f5bede1bf 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c
 
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..8bbc46cca25 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -133,21 +133,8 @@ target_triplet = @target@
 @USE_FORTRAN_TRUE@am__append_7 = openacc.f90
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
-   $(top_srcdir)/../config/ax_count_cpus.m4 \
-   $(top_srcdir)/../config/depstand.m4 \
-   $(top_srcdir)/../config/enable.m4 \
-   $(top_srcdir)/../config/futex.m4 \
-   $(top_srcdir)/../config/lead-dot.m4 \
-   $(top_srcdir)/../config/lthostflags.m4 \
-   $(top_srcdir)/../config/multi.m4 \
-   $(top_srcdir)/../config/override.m4 \
-   $(top_srcdir)/../config/tls.m4 \
-   $(top_srcdir)/../config/toolexeclibdir.m4 \
-   $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
-   $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-   $(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
-   $(top_srcdir)/../config/cet.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+   $(top_srcdir)/../libtool.m4 $(top_srcdir)/../config/cet.m4 \
$(top_srcdir)/plugin/configfrag.ac $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
@@ -233,7 +220,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+   ompd-threads.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -485,7 +473,6 @@ dvidir = @dvidir@
 enable_shared = @enable_shared@
 enable_static = @enable_static@
 exec_prefix = @exec_prefix@
-get_gcc_base_ver = @get_gcc_base_ver@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -501,10 +488,8 @@ libtool_VERSION = @libtool_VERSION@
 link_gomp = @link_gomp@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
-multi_basedir = @multi_basedir@
 offload_additional_lib_paths = @offload_additional_lib_paths@
 offload_additional_options = @offload_additional_options@
 offload_plugins = @offload_plugins@
@@ -514,6 +499,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -583,7 +569,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -801,6 +787,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-threads.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/aclocal.m4 b/libgomp/aclocal.m4
index 55d9d71895a..

[patch] libgompd: Add thread handles

2022-09-26 Thread Ahmed Sayed Mousse via Gcc-patches
/This patch is the initial implementation of OpenMP-API specs book section //20.5.5 with title "Thread Handles". //libgomp/ChangeLog ///2022-07-01 Ahmed Sayed  ///* Makefile.am (libgompd_la_SOURCES): Add ompd-threads.c.///* Makefile.in: Regenerate. * team.c (gomp_free_thread): Call 
ompd_bp_thread_end./* ompd-support.c (gompd_thread_initial_tls_bias): 
New variable. (gompd_load): Initialize gompd_thread_initial_tls_bias. * 
ompd-threads.c: New file.///
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..23f5bede1bf 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c
 
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..7acdcbf31d5 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -233,7 +233,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+   ompd-threads.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -583,7 +584,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -801,6 +802,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-threads.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/ompd-support.c b/libgomp/ompd-support.c
index 27c5ad148e0..5b1afd37788 100644
--- a/libgomp/ompd-support.c
+++ b/libgomp/ompd-support.c
@@ -33,6 +33,8 @@ const unsigned short gompd_sizeof_gomp_thread_handle
   __attribute__ ((used)) OMPD_SECTION = 0;
 #endif
 
+unsigned long gompd_thread_initial_tls_bias __attribute__ ((used));
+
 /* Get offset of the member m in struct t.  */
 #define gompd_get_offset(t, m) \
   const unsigned short gompd_access_##t##_##m __attribute__ ((used)) \
@@ -67,6 +69,11 @@ gompd_load (void)
   gompd_state |= OMPD_ENABLED;
   ompd_dll_locations = &ompd_dll_locations_array[0];
   ompd_dll_locations_valid ();
+
+  #if defined(LIBGOMP_USE_PTHREADS) && !defined(GOMP_NEEDS_THREAD_HANDLE)
+  gompd_thread_initial_tls_bias = (unsigned long) ((char *) &gomp_tls_data
+  - (char *) pthread_self ());
+  #endif
 }
 
 #ifndef __ELF__
diff --git a/libgomp/ompd-threads.c b/libgomp/ompd-threads.c
new file mode 100644
index 000..723ef740181
--- /dev/null
+++ b/libgomp/ompd-threads.c
@@ -0,0 +1,222 @@
+/* Copyright (C) The GNU Toolchain Authors.
+   Contributed by Ahmed Sayed .
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   .  */
+
+/* This file contai

Re: [patch] libgompd: Add thread handles

2022-09-26 Thread Ahmed Sayed Mousse via Gcc-patches
For some reason my mail client keeps missing things up. Maybe it is my 
fault.


Anyway this is it again with the right format I hope.

/This patch is the initial implementation of OpenMP-API specs book section //20.5.5 with title "Thread Handles". //libgomp/ChangeLog ///2022-07-01 Ahmed Sayed  ///* Makefile.am (libgompd_la_SOURCES): Add ompd-threads.c.///* Makefile.in: Regenerate. * team.c (gomp_free_thread): Call 
ompd_bp_thread_end./* ompd-support.c (gompd_thread_initial_tls_bias): 
New variable. (gompd_load): Initialize gompd_thread_initial_tls_bias. * 
ompd-threads.c: New file.///
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..23f5bede1bf 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c
 
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..7acdcbf31d5 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -233,7 +233,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+   ompd-threads.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -583,7 +584,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -801,6 +802,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-threads.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/ompd-support.c b/libgomp/ompd-support.c
index 27c5ad148e0..5b1afd37788 100644
--- a/libgomp/ompd-support.c
+++ b/libgomp/ompd-support.c
@@ -33,6 +33,8 @@ const unsigned short gompd_sizeof_gomp_thread_handle
   __attribute__ ((used)) OMPD_SECTION = 0;
 #endif
 
+unsigned long gompd_thread_initial_tls_bias __attribute__ ((used));
+
 /* Get offset of the member m in struct t.  */
 #define gompd_get_offset(t, m) \
   const unsigned short gompd_access_##t##_##m __attribute__ ((used)) \
@@ -67,6 +69,11 @@ gompd_load (void)
   gompd_state |= OMPD_ENABLED;
   ompd_dll_locations = &ompd_dll_locations_array[0];
   ompd_dll_locations_valid ();
+
+  #if defined(LIBGOMP_USE_PTHREADS) && !defined(GOMP_NEEDS_THREAD_HANDLE)
+  gompd_thread_initial_tls_bias = (unsigned long) ((char *) &gomp_tls_data
+  - (char *) pthread_self ());
+  #endif
 }
 
 #ifndef __ELF__
diff --git a/libgomp/ompd-threads.c b/libgomp/ompd-threads.c
new file mode 100644
index 000..723ef740181
--- /dev/null
+++ b/libgomp/ompd-threads.c
@@ -0,0 +1,222 @@
+/* Copyright (C) The GNU Toolchain Authors.
+   Contributed by Ahmed Sayed .
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;

[patch] libgompd: Add thread handles

2022-06-06 Thread Ahmed Sayed Mousse via Gcc-patches
This patch is the initial implementation of OpenMP-API specs book section
20.5.5 with title "Thread Handles"

libgomp/ChangeLog

2022-05-06 Ahmed Sayed 

* Makefile.am (libgompd_la_SOURCES): Add ompd-threads.c.

* Makefile.in: Regenerate.

* ompd-support.h ( gompd_thread_initial_tls_bias ): New Variable.

* ompd-support.c ( gompd_thread_initial_tls_bias ): New Variable.

( gompd_load ): ( gompd_thread_initial_tls_bias ): Initialized with
&gomp_tls_data - pthread_self ().

* ompd-threads.c: New.
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 6d913a93e7f..23f5bede1bf 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -94,7 +94,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c

-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c

 include $(top_srcdir)/plugin/Makefrag.am

diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 40f896b5f03..7acdcbf31d5 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -233,7 +233,8 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
oacc-target.lo ompd-support.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
-am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo
+am_libgompd_la_OBJECTS = ompd-init.lo ompd-helper.lo ompd-icv.lo \
+   ompd-threads.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -583,7 +584,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
oacc-target.c ompd-support.c $(am__append_7)
-libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c
+libgompd_la_SOURCES = ompd-init.c ompd-helper.c ompd-icv.c ompd-threads.c

 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -801,6 +802,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-icv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-init.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-support.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-threads.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@
diff --git a/libgomp/ompd-support.c b/libgomp/ompd-support.c
index d8a7174b2f3..c7da3ef98a6 100644
--- a/libgomp/ompd-support.c
+++ b/libgomp/ompd-support.c
@@ -36,6 +36,10 @@
 const char **ompd_dll_locations = NULL;
 __UINT64_TYPE__ gompd_state;

+#if (defined HAVE_TLS || defined USE_EMUTLS)
+__UINT64_TYPE__ gompd_thread_initial_tls_bias;
+#endif
+
 void
 gompd_load (void)
 {
@@ -61,7 +65,11 @@ gompd_load (void)
   = (__UINT64_TYPE__) & (((struct gomp_thread *) NULL)->handle);
 __UINT64_TYPE__ gompd_sizeof_gomp_thread_handle
   = sizeof (((struct gomp_thread *) NULL)->handle);
+  #elif (defined HAVE_TLS || defined USE_EMUTLS)
+gompd_thread_initial_tls_bias = (__UINT64_TYPE__) \
+(&gomp_tls_data - pthread_self ());
   #endif
+
   gomp_debug (2, "OMP OMPD active\n");
   static const char *ompd_dll_locations_array[2]
 = {"libgompd" SONAME_SUFFIX (1) , NULL};
diff --git a/libgomp/ompd-support.h b/libgomp/ompd-support.h
index 39d55161132..2dd88af2d73 100644
--- a/libgomp/ompd-support.h
+++ b/libgomp/ompd-support.h
@@ -69,6 +69,10 @@
 void gompd_load (void);
 extern __UINT64_TYPE__ gompd_state;

+#if (defined HAVE_TLS || defined USE_EMUTLS)
+extern __UINT64_TYPE__ gompd_thread_initial_tls_bias;
+#endif
+
 #define OMPD_ENABLED 0x1

 #define GOMPD_FOREACH_ACCESS(gompd_access) \
diff --git a/libgomp/ompd-support.h.gch b/libgomp/ompd-support.h.gch
new file mode 100644
index 000..ee98f7091c0
Binary files /dev/null and b/libgomp/ompd-support.h.gch differ
diff --git a/libgomp/ompd-threads.c b/libgomp/ompd-threads.c
new file mode 100644
index 000..bc370e1af9c
--- /dev/null
+++ b/libgomp/ompd-threads.c
@@ -0,0 +1,310 @@
+/* Copyright (C) The GNU Toolchain Authors.
+   Contributed by Ahmed Sayed .
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+