PAPI 7.1.0.0
Loading...
Searching...
No Matches
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)
 
unsigned long _papi_gettid (void)
 
unsigned long _papi_getpid (void)
 

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

◆ THREAD_LOCAL_STORAGE_KEYWORD

#define THREAD_LOCAL_STORAGE_KEYWORD

Definition at line 16 of file threads.h.

Function Documentation

◆ _papi_getpid()

unsigned long _papi_getpid ( void  )

Definition at line 634 of file threads.c.

635{
636 return (unsigned long) getpid();
637}
Here is the caller graph for this function:

◆ _papi_gettid()

unsigned long _papi_gettid ( void  )

Definition at line 613 of file threads.c.

614 {
615 return (unsigned long)(gettid());
616 }
Here is the caller graph for this function:

◆ _papi_hwi_broadcast_signal()

int _papi_hwi_broadcast_signal ( unsigned int  mytid)
Here is the caller graph for this function:

◆ _papi_hwi_cleanup_thread_list()

void _papi_hwi_cleanup_thread_list ( void  )

◆ _papi_hwi_gather_all_thrspec_data()

int _papi_hwi_gather_all_thrspec_data ( int  tag,
PAPI_all_thr_spec_t where 
)

Definition at line 568 of file threads.c.

569{
570 int didsomething = 0;
571 ThreadInfo_t *foo = NULL;
572
574
575 for ( foo = ( ThreadInfo_t * ) _papi_hwi_thread_head; foo != NULL;
576 foo = foo->next ) {
577 /* If we want thread ID's */
578 if ( where->id )
579 memcpy( &where->id[didsomething], &foo->tid,
580 sizeof ( where->id[didsomething] ) );
581
582 /* If we want data pointers */
583 if ( where->data )
584 where->data[didsomething] = foo->thread_storage[tag];
585
586 didsomething++;
587
588 if ( ( where->id ) || ( where->data ) ) {
589 if ( didsomething >= where->num )
590 break;
591 }
592
593 if ( foo->next == _papi_hwi_thread_head )
594 break;
595 }
596
597 where->num = didsomething;
599
600 return ( PAPI_OK );
601
602}
#define PAPI_OK
Definition: f90papi.h:73
#define THREADS_LOCK
Definition: papi_internal.h:87
PAPI_thread_id_t * id
Definition: papi.h:569
void ** data
Definition: papi.h:570
unsigned long int tid
Definition: threads.h:25
void * thread_storage[PAPI_MAX_TLS]
Definition: threads.h:29
struct _ThreadInfo * next
Definition: threads.h:27
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:69
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_get_thr_context()

int _papi_hwi_get_thr_context ( void **  )

◆ _papi_hwi_init_global_threads()

int _papi_hwi_init_global_threads ( void  )

Definition at line 541 of file threads.c.

542{
543 int retval;
545
547
548#if defined(HAVE_THREAD_LOCAL_STORAGE)
549 _papi_hwi_my_thread = NULL;
550#endif
553#if defined(ANY_THREAD_GETS_SIGNAL)
555#endif
556
558 if ( retval == PAPI_OK ) {
560 }
561
563
564 return ( retval );
565}
double tmp
#define GLOBAL_LOCK
Definition: papi_internal.h:91
THREAD_LOCAL_STORAGE_KEYWORD ThreadInfo_t * _papi_hwi_my_thread
Definition: threads.c:37
unsigned long(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
Definition: threads.c:278
static int lookup_and_set_thread_symbols(void)
Definition: threads.c:55
int(* _papi_hwi_thread_kill_fn)(int, int)
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_initialize_thread()

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 /* init event memory variables, used by papi_internal.c */
290 thread->tls_papi_event_code = -1;
291 thread->tls_papi_event_code_changed = -1;
292
293 /* Call the component to fill in anything special. */
294
295 for ( i = 0; i < papi_num_components; i++ ) {
296 if (_papi_hwd[i]->cmp_info.disabled &&
297 _papi_hwd[i]->cmp_info.disabled != PAPI_EDELAY_INIT)
298 continue;
299 retval = _papi_hwd[i]->init_thread( thread->context[i] );
300 if ( retval ) {
302 *dest = NULL;
303 return retval;
304 }
305 }
306
307 insert_thread( thread, tid );
308
309 *dest = thread;
310 return PAPI_OK;
311}
int i
struct papi_vectors * _papi_hwd[]
#define PAPI_EDELAY_INIT
Definition: f90papi.h:271
#define PAPI_ENOMEM
Definition: f90papi.h:16
void * thread(void *arg)
Definition: kufrin.c:38
int papi_num_components
static void insert_thread(ThreadInfo_t *entry, int tid)
Definition: threads.c:186
static ThreadInfo_t * allocate_thread(int tid)
Definition: threads.c:96
static void free_thread(ThreadInfo_t **thread)
Definition: threads.c:164
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_insert_in_thread_list()

int _papi_hwi_insert_in_thread_list ( ThreadInfo_t ptr)

◆ _papi_hwi_lock()

inline_static int _papi_hwi_lock ( int  lck)

Definition at line 69 of file threads.h.

70{
72 _papi_hwd_lock( lck );
73 THRDBG( "Lock %d\n", lck );
74 } else {
75 ( void ) lck; /* unused if !defined(DEBUG) */
76 THRDBG( "Skipped lock %d\n", lck );
77 }
78
79 return ( PAPI_OK );
80}
#define _papi_hwd_lock(lck)
Definition: aix-lock.h:6
#define THRDBG(format, args...)
Definition: papi_debug.h:67
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42

◆ _papi_hwi_lookup_in_thread_list()

ThreadInfo_t * _papi_hwi_lookup_in_thread_list ( )

◆ _papi_hwi_lookup_or_create_thread()

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

Definition at line 150 of file threads.h.

151{
153 int retval = PAPI_OK;
154
155 if ( tmp == NULL )
157
158 if ( retval == PAPI_OK )
159 *here = tmp;
160
161 return ( retval );
162}
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:97
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:

◆ _papi_hwi_lookup_thread()

inline_static ThreadInfo_t * _papi_hwi_lookup_thread ( int  custom_tid)

Definition at line 97 of file threads.h.

98{
99
100 unsigned long int tid;
102
103
104 if (custom_tid==0) {
105#ifdef HAVE_THREAD_LOCAL_STORAGE
106 THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
107 return ( _papi_hwi_my_thread );
108#else
109 if ( _papi_hwi_thread_id_fn == NULL ) {
110 THRDBG( "Threads not initialized, returning master thread at %p\n",
112 return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
113 }
114
115 tid = ( *_papi_hwi_thread_id_fn ) ( );
116#endif
117 }
118 else {
119 tid=custom_tid;
120 }
121 THRDBG( "Threads initialized, looking for thread %#lx\n", tid );
122
124
126 while ( tmp != NULL ) {
127 THRDBG( "Examining thread tid %#lx at %p\n", tmp->tid, tmp );
128 if ( tmp->tid == tid )
129 break;
130 tmp = tmp->next;
131 if ( tmp == _papi_hwi_thread_head ) {
132 tmp = NULL;
133 break;
134 }
135 }
136
137 if ( tmp ) {
139 THRDBG( "Found thread %ld at %p\n", tid, tmp );
140 } else {
141 THRDBG( "Did not find tid %ld\n", tid );
142 }
143
145 return ( tmp );
146
147}
volatile ThreadInfo_t * _papi_hwi_thread_head
Definition: threads.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_set_thread_id_fn()

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

◆ _papi_hwi_shutdown_global_threads()

int _papi_hwi_shutdown_global_threads ( void  )

Definition at line 470 of file threads.c.

471{
472 int err,num_threads,i;
473 ThreadInfo_t *tmp,*next;
474 unsigned long our_tid;
475
477
478 if ( tmp == NULL ) {
479 THRDBG( "Did not find my thread for shutdown!\n" );
480 err = PAPI_EBUG;
481 }
482 else {
483 our_tid=tmp->tid;
484 (void)our_tid;
485
486 THRDBG("Shutting down %ld\n",our_tid);
487
488 err = _papi_hwi_shutdown_thread( tmp, 1 );
489
490 /* count threads */
492 num_threads=0;
493 while(tmp!=NULL) {
494 num_threads++;
495 if (tmp->next==_papi_hwi_thread_head) break;
496 tmp=tmp->next;
497 }
498
499 /* Shut down all threads allocated by this thread */
500 /* Urgh it's a circular list where we removed in the loop */
501 /* so the only sane way to do it is get a count in advance */
503
504 for(i=0;i<num_threads;i++) {
505
506 next=tmp->next;
507
508 THRDBG("looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
509 i,tmp->tid,our_tid,tmp->allocator_tid);
510
511 THRDBG("Also removing thread %ld\n",tmp->tid);
512 err = _papi_hwi_shutdown_thread( tmp, 1 );
513
514 tmp=next;
515
516 }
517 }
518
519
520#ifdef DEBUG
521 if ( ISLEVEL( DEBUG_THREADS ) ) {
522 if ( _papi_hwi_thread_head ) {
523 THRDBG( "Thread head %p still exists!\n", _papi_hwi_thread_head );
524 }
525 }
526#endif
527
528#if defined(HAVE_THREAD_LOCAL_STORAGE)
529 _papi_hwi_my_thread = NULL;
530#endif
533#if defined(ANY_THREAD_GETS_SIGNAL)
535#endif
536
537 return err;
538}
#define PAPI_EBUG
Definition: f90papi.h:176
static int num_threads
#define ISLEVEL(a)
Definition: papi_debug.h:55
#define DEBUG_THREADS
Definition: papi_debug.h:30
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
Definition: threads.c:424
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_shutdown_the_thread_list()

void _papi_hwi_shutdown_the_thread_list ( void  )

◆ _papi_hwi_shutdown_thread()

int _papi_hwi_shutdown_thread ( ThreadInfo_t thread,
int  force 
)

Definition at line 424 of file threads.c.

425{
426 int retval = PAPI_OK;
427 unsigned long tid;
428 int i, failure = 0;
429
430 /* Clear event memory variables */
431 thread->tls_papi_event_code = -1;
432 thread->tls_papi_event_code_changed = -1;
433
434 /* Get thread id */
436 tid = ( *_papi_hwi_thread_id_fn ) ( );
437 else
438 tid = ( unsigned long ) getpid( );
439
440 THRDBG("Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
441 thread->tid,
442 thread->allocator_tid,
443 tid);
444
445 if ((thread->tid==tid) || ( thread->allocator_tid == tid ) || force_shutdown) {
446
448
450 THRDBG( "Shutting down thread %ld at %p\n", thread->tid, thread );
451 for( i = 0; i < papi_num_components; i++ ) {
452 if (_papi_hwd[i]->cmp_info.disabled &&
453 _papi_hwd[i]->cmp_info.disabled != PAPI_EDELAY_INIT)
454 continue;
455 retval = _papi_hwd[i]->shutdown_thread( thread->context[i]);
456 if ( retval != PAPI_OK ) failure = retval;
457 }
459 return ( failure );
460 }
461
462 THRDBG( "Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
463 thread->tid, thread, tid );
464 return PAPI_EBUG;
465}
long long int long long
Definition: sde_internal.h:85
static int remove_thread(ThreadInfo_t *entry)
Definition: threads.c:226
static int _papi_hwi_thread_free_eventsets(long tid)
Definition: threads.c:390
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_unlock()

inline_static int _papi_hwi_unlock ( int  lck)

Definition at line 83 of file threads.h.

84{
86 _papi_hwd_unlock( lck );
87 THRDBG( "Unlock %d\n", lck );
88 } else {
89 ( void ) lck; /* unused if !defined(DEBUG) */
90 THRDBG( "Skipped unlock %d\n", lck );
91 }
92
93 return ( PAPI_OK );
94}
#define _papi_hwd_unlock(lck)
Definition: aix-lock.h:11

Variable Documentation

◆ _papi_hwi_thread_head

volatile ThreadInfo_t* _papi_hwi_thread_head
extern

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

Definition at line 32 of file threads.c.

◆ _papi_hwi_thread_id_fn

unsigned long int(* _papi_hwi_thread_id_fn) (void) ( void  )
extern

Function that returns an unsigned long int thread identifier

Definition at line 42 of file threads.c.

◆ _papi_hwi_thread_kill_fn

int(* _papi_hwi_thread_kill_fn) (int, int) ( int  ,
int   
)
extern

Function that sends a signal to other threads