PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
threads.h File Reference
Include dependency graph for threads.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ThreadInfo_t
 

Macros

#define THREAD_LOCAL_STORAGE_KEYWORD
 

Functions

int _papi_hwi_initialize_thread (ThreadInfo_t **dest, int tid)
 
int _papi_hwi_init_global_threads (void)
 
int _papi_hwi_shutdown_thread (ThreadInfo_t *thread, int force)
 
int _papi_hwi_shutdown_global_threads (void)
 
int _papi_hwi_broadcast_signal (unsigned int mytid)
 
int _papi_hwi_set_thread_id_fn (unsigned long int(*id_fn)(void))
 
inline_static int _papi_hwi_lock (int lck)
 
inline_static int _papi_hwi_unlock (int lck)
 
inline_static ThreadInfo_t_papi_hwi_lookup_thread (int custom_tid)
 
inline_static int _papi_hwi_lookup_or_create_thread (ThreadInfo_t **here, int tid)
 
void _papi_hwi_shutdown_the_thread_list (void)
 
void _papi_hwi_cleanup_thread_list (void)
 
int _papi_hwi_insert_in_thread_list (ThreadInfo_t *ptr)
 
ThreadInfo_t_papi_hwi_lookup_in_thread_list ()
 
int _papi_hwi_get_thr_context (void **)
 
int _papi_hwi_gather_all_thrspec_data (int tag, PAPI_all_thr_spec_t *where)
 

Variables

volatile ThreadInfo_t_papi_hwi_thread_head
 
unsigned long int(* _papi_hwi_thread_id_fn )(void)
 
int(* _papi_hwi_thread_kill_fn )(int, int)
 

Detailed Description

CVS: $Id$

Author
??

Definition in file threads.h.

Macro Definition Documentation

#define THREAD_LOCAL_STORAGE_KEYWORD

Definition at line 16 of file threads.h.

Function Documentation

int _papi_hwi_broadcast_signal ( unsigned int  mytid)

Here is the caller graph for this function:

void _papi_hwi_cleanup_thread_list ( void  )
int _papi_hwi_gather_all_thrspec_data ( int  tag,
PAPI_all_thr_spec_t where 
)

Definition at line 554 of file threads.c.

555 {
556  int didsomething = 0;
557  ThreadInfo_t *foo = NULL;
558 
560 
561  for ( foo = ( ThreadInfo_t * ) _papi_hwi_thread_head; foo != NULL;
562  foo = foo->next ) {
563  /* If we want thread ID's */
564  if ( where->id )
565  memcpy( &where->id[didsomething], &foo->tid,
566  sizeof ( where->id[didsomething] ) );
567 
568  /* If we want data pointers */
569  if ( where->data )
570  where->data[didsomething] = foo->thread_storage[tag];
571 
572  didsomething++;
573 
574  if ( ( where->id ) || ( where->data ) ) {
575  if ( didsomething >= where->num )
576  break;
577  }
578 
579  if ( foo->next == _papi_hwi_thread_head )
580  break;
581  }
582 
583  where->num = didsomething;
585 
586  return ( PAPI_OK );
587 
588 }
void ** data
Definition: papi.h:561
struct _ThreadInfo * next
Definition: threads.h:27
return PAPI_OK
Definition: linux-nvml.c:458
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
void * thread_storage[PAPI_MAX_TLS]
Definition: threads.h:29
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
unsigned long int tid
Definition: threads.h:25
pthread_attr_t foo
Definition: iozone.c:18592
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
#define THREADS_LOCK
Definition: papi_internal.h:87
PAPI_thread_id_t * id
Definition: papi.h:560
again struct sockaddr sizeof(struct sockaddr_in))

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_get_thr_context ( void **  )
int _papi_hwi_init_global_threads ( void  )

Definition at line 527 of file threads.c.

528 {
529  int retval;
530  ThreadInfo_t *tmp;
531 
533 
534 #if defined(HAVE_THREAD_LOCAL_STORAGE)
535  _papi_hwi_my_thread = NULL;
536 #endif
537  _papi_hwi_thread_head = NULL;
538  _papi_hwi_thread_id_fn = NULL;
539 #if defined(ANY_THREAD_GETS_SIGNAL)
541 #endif
542 
543  retval = _papi_hwi_initialize_thread( &tmp , 0);
544  if ( retval == PAPI_OK ) {
545  retval = lookup_and_set_thread_symbols( );
546  }
547 
549 
550  return ( retval );
551 }
static int lookup_and_set_thread_symbols(void)
Definition: threads.c:55
return PAPI_OK
Definition: linux-nvml.c:458
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
int(* _papi_hwi_thread_kill_fn)(int, int)
#define GLOBAL_LOCK
Definition: papi_internal.h:91
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
Definition: threads.c:278

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_initialize_thread ( ThreadInfo_t **  dest,
int  tid 
)

Definition at line 278 of file threads.c.

279 {
280  int retval;
282  int i;
283 
284  if ( ( thread = allocate_thread( tid ) ) == NULL ) {
285  *dest = NULL;
286  return PAPI_ENOMEM;
287  }
288 
289  /* Call the component to fill in anything special. */
290 
291  for ( i = 0; i < papi_num_components; i++ ) {
292  if (_papi_hwd[i]->cmp_info.disabled) continue;
293  retval = _papi_hwd[i]->init_thread( thread->context[i] );
294  if ( retval ) {
295  free_thread( &thread );
296  *dest = NULL;
297  return retval;
298  }
299  }
300 
301  insert_thread( thread, tid );
302 
303  *dest = thread;
304  return PAPI_OK;
305 }
static void free_thread(ThreadInfo_t **thread)
Definition: threads.c:164
return PAPI_OK
Definition: linux-nvml.c:458
papi_vector_t * _papi_hwd[]
static ThreadInfo_t * allocate_thread(int tid)
Definition: threads.c:96
int i
Definition: fileop.c:140
hwd_context_t ** context
Definition: threads.h:28
void * thread(void *arg)
Definition: kufrin.c:31
void *long long tid
Definition: iozone.c:18586
static void insert_thread(ThreadInfo_t *entry, int tid)
Definition: threads.c:186
#define PAPI_ENOMEM
Definition: papi.h:252
int papi_num_components
int(* init_thread)(hwd_context_t *)
Definition: papi_vector.h:36
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_insert_in_thread_list ( ThreadInfo_t ptr)
inline_static int _papi_hwi_lock ( int  lck)

Definition at line 64 of file threads.h.

65 {
66  if ( _papi_hwi_thread_id_fn ) {
67  _papi_hwd_lock( lck );
68  THRDBG( "Lock %d\n", lck );
69  } else {
70  ( void ) lck; /* unused if !defined(DEBUG) */
71  THRDBG( "Skipped lock %d\n", lck );
72  }
73 
74  return ( PAPI_OK );
75 }
return PAPI_OK
Definition: linux-nvml.c:458
#define THRDBG(format, args...)
Definition: papi_debug.h:66
void
Definition: iozone.c:18627
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
#define _papi_hwd_lock(lck)
Definition: aix-lock.h:6

Here is the caller graph for this function:

ThreadInfo_t* _papi_hwi_lookup_in_thread_list ( )
inline_static int _papi_hwi_lookup_or_create_thread ( ThreadInfo_t **  here,
int  tid 
)

Definition at line 145 of file threads.h.

146 {
148  int retval = PAPI_OK;
149 
150  if ( tmp == NULL )
151  retval = _papi_hwi_initialize_thread( &tmp, tid );
152 
153  if ( retval == PAPI_OK )
154  *here = tmp;
155 
156  return ( retval );
157 }
return PAPI_OK
Definition: linux-nvml.c:458
void *long long tid
Definition: iozone.c:18586
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:92
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
Definition: threads.c:278

Here is the call graph for this function:

Here is the caller graph for this function:

inline_static ThreadInfo_t* _papi_hwi_lookup_thread ( int  custom_tid)

Definition at line 92 of file threads.h.

93 {
94 
95  unsigned long int tid;
97 
98 
99  if (custom_tid==0) {
100 #ifdef HAVE_THREAD_LOCAL_STORAGE
101  THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
102  return ( _papi_hwi_my_thread );
103 #else
104  if ( _papi_hwi_thread_id_fn == NULL ) {
105  THRDBG( "Threads not initialized, returning master thread at %p\n",
107  return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
108  }
109 
110  tid = ( *_papi_hwi_thread_id_fn ) ( );
111 #endif
112  }
113  else {
114  tid=custom_tid;
115  }
116  THRDBG( "Threads initialized, looking for thread %#lx\n", tid );
117 
119 
121  while ( tmp != NULL ) {
122  THRDBG( "Examining thread tid %#lx at %p\n", tmp->tid, tmp );
123  if ( tmp->tid == tid )
124  break;
125  tmp = tmp->next;
126  if ( tmp == _papi_hwi_thread_head ) {
127  tmp = NULL;
128  break;
129  }
130  }
131 
132  if ( tmp ) {
134  THRDBG( "Found thread %ld at %p\n", tid, tmp );
135  } else {
136  THRDBG( "Did not find tid %ld\n", tid );
137  }
138 
140  return ( tmp );
141 
142 }
struct _ThreadInfo * next
Definition: threads.h:27
#define THRDBG(format, args...)
Definition: papi_debug.h:66
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
unsigned long int tid
Definition: threads.h:25
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
void *long long tid
Definition: iozone.c:18586
#define THREADS_LOCK
Definition: papi_internal.h:87
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_set_thread_id_fn ( unsigned long int(*)(void id_fn)
int _papi_hwi_shutdown_global_threads ( void  )

Definition at line 457 of file threads.c.

458 {
459  int err,num_threads,i;
461  unsigned long our_tid;
462 
463  tmp = _papi_hwi_lookup_thread( 0 );
464 
465  if ( tmp == NULL ) {
466  THRDBG( "Did not find my thread for shutdown!\n" );
467  err = PAPI_EBUG;
468  }
469  else {
470  our_tid=tmp->tid;
471 
472  THRDBG("Shutting down %ld\n",our_tid);
473 
474  err = _papi_hwi_shutdown_thread( tmp, 1 );
475 
476  /* count threads */
478  num_threads=0;
479  while(tmp!=NULL) {
480  num_threads++;
481  if (tmp->next==_papi_hwi_thread_head) break;
482  tmp=tmp->next;
483  }
484 
485  /* Shut down all threads allocated by this thread */
486  /* Urgh it's a circular list where we removed in the loop */
487  /* so the only sane way to do it is get a count in advance */
489 
490  for(i=0;i<num_threads;i++) {
491 
492  next=tmp->next;
493 
494  THRDBG("looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
495  i,tmp->tid,our_tid,tmp->allocator_tid);
496 
497  THRDBG("Also removing thread %ld\n",tmp->tid);
498  err = _papi_hwi_shutdown_thread( tmp, 1 );
499 
500  tmp=next;
501 
502  }
503  }
504 
505 
506 #ifdef DEBUG
507  if ( ISLEVEL( DEBUG_THREADS ) ) {
508  if ( _papi_hwi_thread_head ) {
509  THRDBG( "Thread head %p still exists!\n", _papi_hwi_thread_head );
510  }
511  }
512 #endif
513 
514 #if defined(HAVE_THREAD_LOCAL_STORAGE)
515  _papi_hwi_my_thread = NULL;
516 #endif
517  _papi_hwi_thread_head = NULL;
518  _papi_hwi_thread_id_fn = NULL;
519 #if defined(ANY_THREAD_GETS_SIGNAL)
521 #endif
522 
523  return err;
524 }
struct _ThreadInfo * next
Definition: threads.h:27
#define PAPI_EBUG
Definition: papi.h:257
#define THRDBG(format, args...)
Definition: papi_debug.h:66
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
err
Definition: linux-cuda.c:323
int i
Definition: fileop.c:140
unsigned long int tid
Definition: threads.h:25
int num_threads
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
nsize_list next
Definition: iozone.c:20053
unsigned long int allocator_tid
Definition: threads.h:26
int(* _papi_hwi_thread_kill_fn)(int, int)
#define ISLEVEL(a)
Definition: papi_debug.h:54
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:92
#define DEBUG_THREADS
Definition: papi_debug.h:30
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
Definition: threads.c:418
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

Here is the caller graph for this function:

void _papi_hwi_shutdown_the_thread_list ( void  )
int _papi_hwi_shutdown_thread ( ThreadInfo_t thread,
int  force 
)

Definition at line 418 of file threads.c.

419 {
420  int retval = PAPI_OK;
421  unsigned long tid;
422  int i, failure = 0;
423 
425  tid = ( *_papi_hwi_thread_id_fn ) ( );
426  else
427  tid = ( unsigned long ) getpid( );
428 
429  THRDBG("Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
430  thread->tid,
431  thread->allocator_tid,
432  tid);
433 
434  if ((thread->tid==tid) || ( thread->allocator_tid == tid ) || force_shutdown) {
435 
437 
438  remove_thread( thread );
439  THRDBG( "Shutting down thread %ld at %p\n", thread->tid, thread );
440  for( i = 0; i < papi_num_components; i++ ) {
441  if (_papi_hwd[i]->cmp_info.disabled) continue;
442  retval = _papi_hwd[i]->shutdown_thread( thread->context[i]);
443  if ( retval != PAPI_OK ) failure = retval;
444  }
445  free_thread( &thread );
446  return ( failure );
447  }
448 
449  THRDBG( "Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
450  thread->tid, thread, tid );
451  return PAPI_EBUG;
452 }
static void free_thread(ThreadInfo_t **thread)
Definition: threads.c:164
#define PAPI_EBUG
Definition: papi.h:257
return PAPI_OK
Definition: linux-nvml.c:458
#define THRDBG(format, args...)
Definition: papi_debug.h:66
papi_vector_t * _papi_hwd[]
int(* shutdown_thread)(hwd_context_t *)
Definition: papi_vector.h:53
int i
Definition: fileop.c:140
unsigned long int tid
Definition: threads.h:25
hwd_context_t ** context
Definition: threads.h:28
void *long long tid
Definition: iozone.c:18586
long long
Definition: iozone.c:19827
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
unsigned long int allocator_tid
Definition: threads.h:26
static int _papi_hwi_thread_free_eventsets(long tid)
Definition: threads.c:384
int papi_num_components
ssize_t retval
Definition: libasync.c:338
static int remove_thread(ThreadInfo_t *entry)
Definition: threads.c:226

Here is the call graph for this function:

Here is the caller graph for this function:

inline_static int _papi_hwi_unlock ( int  lck)

Definition at line 78 of file threads.h.

79 {
80  if ( _papi_hwi_thread_id_fn ) {
81  _papi_hwd_unlock( lck );
82  THRDBG( "Unlock %d\n", lck );
83  } else {
84  ( void ) lck; /* unused if !defined(DEBUG) */
85  THRDBG( "Skipped unlock %d\n", lck );
86  }
87 
88  return ( PAPI_OK );
89 }
return PAPI_OK
Definition: linux-nvml.c:458
#define THRDBG(format, args...)
Definition: papi_debug.h:66
void
Definition: iozone.c:18627
#define _papi_hwd_unlock(lck)
Definition: aix-lock.h:11
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42

Here is the caller graph for this function:

Variable Documentation

volatile ThreadInfo_t* _papi_hwi_thread_head

The list of threads, gets initialized to master process with TID of getpid()

Definition at line 32 of file threads.c.

unsigned long int( * _papi_hwi_thread_id_fn)(void)

Function that returns an unsigned long int thread identifier

Definition at line 42 of file threads.c.

int( * _papi_hwi_thread_kill_fn)(int, int)

Function that sends a signal to other threads