ompd_get_thread_id() in OMPD implementation

2022-03-25 Thread Ahmed Sayed Mousse via Gcc
Hi everyone,

I was doing a research to help me implement the function
“ompd_get_thread_id” from the OpenMP API specification under section
20.5.5.5.



In this function I need to return a native thread identifier and from
research I found that it’s a “pthread_t” handle which exists inside a
struct named “gomp_thread” of the “libgomp.h” file. The problem is that
this handle isn’t always defined and to show what I mean look at the code
below.



struct gomp_thread

{

…..



#if defined(LIBGOMP_USE_PTHREADS) \

&& (!defined(HAVE_TLS) \

|| !defined(__GLIBC__) \

|| !defined(USING_INITIAL_EXEC_TLS))

#define GOMP_NEEDS_THREAD_HANDLE 1

  pthread_t handle;

#endif

};



I use a macro to calculate the offset of this handle and use the this
offset to get it from memory and I thought I would just check for
GOMP_NEEDS_THREAD_HANDLE before trying to calculate this offset but It
still causes errors and also if that handle isn’t defined then what should
I return as a native identifier?



Thanks for help.


FW: ompd_get_thread_id in OMPD implementation

2022-04-08 Thread Ahmed Sayed Mousse via Gcc
Sorry for the late reply.
I did check gomp_thread_self but I'm still not sure about what I should do,
maybe because I lack experience/knowledge.
Here is where my thinking is going right now and I hope you tell me if I'm
wrong.

in gomp_thread_to_pthread_t there are 4 possible outputs
1 - if LIBGOMP_USE_PTHREADS is enabled
 {
first  pthread_self() if the thread calling is the same thread as the
function input.
or  gomp_thread->handle in case GOMP_NEEDS_THREAD_HANDLE is enabled.
or  pthread_self () + ((uintptr_t) input_thread - (uintptr_t)
calling_thread)
}
2 -if LIBGOMP_USE_PTHREADS not enabled
- empty struct casted to a pthread_t
currently think i should check for the GOMP_NEED_THREAD_HANDLE, if it's
enabled i extract the pthread_t  from the gomp_thread handle given in the
function and return that.
If it's not enabled then I return an empty struct or an rc_unspported
return code.
Note:
The openmp specification doesn't really tell me how things should be
done so I get confused a lot and I think I have a misunderstanding of the
function.
 I would appreciate it a lot if I get any directions to where I can
increase my knowledge around this part.

*From: *Ahmed Sayed Mousse 
*Sent: *Wednesday, March 23, 2022 7:23 PM
*To: *gcc-h...@gcc.gnu.org
*Cc: *ja...@redhat.com
*Subject: *ompd_get_thread_id in OMPD implementation



Hi everyone,

I was doing a research to help me implement the function
“ompd_get_thread_id” from the OpenMP API specification under section
20.5.5.5.



In this function I need to return a native thread identifier and from
research I found that it’s a “pthread_t” handle which exists inside a
struct named “gomp_thread” of the “libgomp.h” file. The problem is that
this handle isn’t always defined and to show what I mean look at the code
below.



struct gomp_thread

{

…..



#if defined(LIBGOMP_USE_PTHREADS) \

&& (!defined(HAVE_TLS) \

|| !defined(__GLIBC__) \

|| !defined(USING_INITIAL_EXEC_TLS))

#define GOMP_NEEDS_THREAD_HANDLE 1

  pthread_t handle;

#endif

};



I use a macro to calculate the offset of this handle and use the this
offset to get it from memory and I thought I would just check for
GOMP_NEEDS_THREAD_HANDLE before trying to calculate this offset but It
still causes errors and also if that handle isn’t defined then what should
I return as a native identifier?



Thanks for help.


mimicking gomp_thead(void) for OMPD-API implementation

2022-06-02 Thread Ahmed Sayed Mousse via Gcc
Hi everyone,

   To implement the function ompd_get_thread_handle (…) from
the OMPD API. I need to get  the gomp_thread struct using thread context
and address space context and in order to do that I want to apply the
functionality of/mimic  gomp_thread(void) from lipgomp.h using callbacks
but I don't know which of those two approaches should I use or whether I
should use both.


#elif defined HAVE_TLS || defined USE_EMUTLS
extern __thread struct gomp_thread gomp_tls_data;
static inline struct gomp_thread *gomp_thread (void)
{
  return &gomp_tls_data;
}
#else
extern pthread_key_t gomp_tls_key;
static inline struct gomp_thread *gomp_thread (void)
{
  return pthread_getspecific (gomp_tls_key);
}
#endif


My current thought is to try looking for the gomp_tls_data symbol and if I
don't find it I go looking for the gomp_tls_key then use
pthread_getspecific() on it.


Here is the current approach I think about using:


lookup('gomp_tls_data')

if return code != ok)

go to try_key

.


go to allocation

try_key:

lookup('gomp_tls_key')


.


allocation:


.


end of function


If I should use both should I save the first lookup by saving the result of
the first condition, if defined HAVE_TLS || defined USE_EMUTLS,  from
runtime in the shared library and then check on that result?


like

#if defined HAVE_TLS || defined USE_EMUTLS

#define GOMPD_USE_TLS

#endif

Thanks.