36#if defined(HAVE_THREAD_LOCAL_STORAGE)
46#ifdef ANY_THREAD_GETS_SIGNAL
57#if defined(ANY_THREAD_GETS_SIGNAL)
59 char *error_ptc = NULL, *error_ptk = NULL;
60 void *symbol_ptc = NULL, *symbol_ptk = NULL, *
handle = NULL;
62 handle = dlopen( NULL, RTLD_LAZY );
69 symbol_ptc = dlsym(
handle,
"pthread_self" );
70 if ( symbol_ptc == NULL ) {
71 error_ptc = dlerror( );
72 THRDBG(
"dlsym(%p,pthread_self) returned NULL: %s\n",
73 ( error_ptc ? error_ptc :
"No error, NULL symbol!" ) );
76 symbol_ptk = dlsym(
handle,
"pthread_kill" );
77 if ( symbol_ptk == NULL ) {
78 error_ptk = dlerror( );
79 THRDBG(
"dlsym(%p,pthread_kill) returned NULL: %s\n",
80 ( error_ptk ? error_ptk :
"No error, NULL symbol!" ) );
117 thread->running_eventset =
120 if ( !
thread->running_eventset ) {
129 thread->running_eventset[
i] = NULL;
130 if (
thread->context[
i] == NULL ) {
131 for (
i--;
i >= 0;
i-- )
137 memset(
thread->context[
i], 0x00,
142 thread->tid = ( *_papi_hwi_thread_id_fn ) ( );
156 THRDBG(
"Allocated thread %ld at %p, allocator: %ld\n",
thread->tid,
167 THRDBG(
"Freeing thread %ld at %p\n", ( *thread )->tid, *
thread );
170 if ( ( *thread )->context[
i] )
174 if ( ( *thread )->context )
177 if ( ( *thread )->running_eventset )
178 papi_free( ( *thread )->running_eventset );
191 THRDBG(
"_papi_hwi_thread_head is NULL\n" );
194 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
200 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
208 THRDBG(
"_papi_hwi_thread_head now thread %ld at %p\n",
213#if defined(HAVE_THREAD_LOCAL_STORAGE)
217 THRDBG(
"TLS for thread %ld is now %p\n", entry->
tid,
232 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
239 ( entry !=
tmp ) || ( prev == NULL );
tmp =
tmp->next ) {
243 if (
tmp != entry ) {
244 THRDBG(
"Thread %ld at %p was not found in the thread list!\n",
254 THRDBG(
"_papi_hwi_thread_head now NULL\n" );
256 prev->next =
tmp->next;
260 THRDBG(
"_papi_hwi_thread_head now thread %ld at %p\n",
263 THRDBG(
"Removed thread %p from list\n",
tmp );
268#if defined(HAVE_THREAD_LOCAL_STORAGE)
270 THRDBG(
"TLS for thread %ld is now %p\n", entry->
tid,
290 thread->tls_papi_event_code = -1;
291 thread->tls_papi_event_code_changed = -1;
313#if defined(ANY_THREAD_GETS_SIGNAL)
324 int i,
retval, didsomething = 0;
337 THRDBG(
"Thread %ld sending signal %d to thread %ld\n",mytid,foo->
tid,
339 retval = (*_papi_hwi_thread_kill_fn)(foo->
tid,
360#if !defined(ANY_THREAD_GETS_SIGNAL)
374 THRDBG(
"Set new thread id function to %p\n", id_fn );
383 THRDBG(
"Skipping set of thread id function\n" );
403 if ( ( ESI ) && (ESI->
master!=NULL) ) {
405 if ( ESI->
master == master ) {
431 thread->tls_papi_event_code = -1;
432 thread->tls_papi_event_code_changed = -1;
436 tid = ( *_papi_hwi_thread_id_fn ) ( );
438 tid = (
unsigned long ) getpid( );
440 THRDBG(
"Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
445 if ((
thread->tid==tid) || (
thread->allocator_tid == tid ) || force_shutdown) {
462 THRDBG(
"Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
474 unsigned long our_tid;
479 THRDBG(
"Did not find my thread for shutdown!\n" );
486 THRDBG(
"Shutting down %ld\n",our_tid);
508 THRDBG(
"looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
509 i,
tmp->tid,our_tid,
tmp->allocator_tid);
511 THRDBG(
"Also removing thread %ld\n",
tmp->tid);
528#if defined(HAVE_THREAD_LOCAL_STORAGE)
533#if defined(ANY_THREAD_GETS_SIGNAL)
548#if defined(HAVE_THREAD_LOCAL_STORAGE)
553#if defined(ANY_THREAD_GETS_SIGNAL)
570 int didsomething = 0;
579 memcpy( &where->
id[didsomething], &foo->
tid,
580 sizeof ( where->
id[didsomething] ) );
588 if ( ( where->
id ) || ( where->
data ) ) {
589 if ( didsomething >= where->
num )
597 where->
num = didsomething;
604#if defined(__NR_gettid) && !defined(HAVE_GETTID)
609 return (
unsigned long)(syscall(__NR_gettid));
611#elif defined(HAVE_GETTID)
612 #include <sys/types.h>
615 return (
unsigned long)(gettid());
617#elif defined(HAVE_SYSCALL_GETTID)
619 #include <sys/types.h>
622 return (
unsigned long)(syscall(SYS_gettid));
625 #include <sys/types.h>
630 return (
unsigned long)(getpid());
636 return (
unsigned long) getpid();
static papi_handle_t handle
PAPI_os_info_t _papi_os_info
struct papi_vectors * _papi_hwd[]
#define PAPI_MULTIPLEXING
Return codes and api definitions.
#define THRDBG(format, args...)
void _papi_hwi_free_EventSet(EventSetInfo_t *ESI)
void PAPIERROR(char *format,...)
papi_mdi_t _papi_hwi_system_info
EventSetInfo_t ** dataSlotArray
struct _ThreadInfo * master
EventSetInfo_t ** running_eventset
void * thread_storage[PAPI_MAX_TLS]
struct _ThreadInfo * next
DynamicArray_t global_eventset_map
static int remove_thread(ThreadInfo_t *entry)
THREAD_LOCAL_STORAGE_KEYWORD ThreadInfo_t * _papi_hwi_my_thread
static void insert_thread(ThreadInfo_t *entry, int tid)
int _papi_hwi_init_global_threads(void)
unsigned long(* _papi_hwi_thread_id_fn)(void)
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
unsigned long _papi_gettid(void)
unsigned long _papi_getpid(void)
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
static int _papi_hwi_thread_free_eventsets(long tid)
static ThreadInfo_t * allocate_thread(int tid)
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
static int lookup_and_set_thread_symbols(void)
static void free_thread(ThreadInfo_t **thread)
volatile ThreadInfo_t * _papi_hwi_thread_head
int _papi_hwi_shutdown_global_threads(void)
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
int(* _papi_hwi_thread_kill_fn)(int, int)
inline_static int _papi_hwi_lock(int lck)
int _papi_hwi_broadcast_signal(unsigned int mytid)
#define THREAD_LOCAL_STORAGE_KEYWORD
inline_static int _papi_hwi_unlock(int lck)