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

Defines

#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.


Define Documentation

#define THREAD_LOCAL_STORAGE_KEYWORD

Definition at line 16 of file threads.h.


Function Documentation

int _papi_hwi_broadcast_signal ( unsigned int  mytid  ) 

Definition at line 316 of file threads.c.

00317 {
00318     int i, retval, didsomething = 0;
00319     volatile ThreadInfo_t *foo = NULL;
00320 
00321     _papi_hwi_lock( THREADS_LOCK );
00322 
00323     for ( foo = _papi_hwi_thread_head; foo != NULL; foo = foo->next ) {
00324         /* xxxx Should this be hardcoded to index 0 or walk the list or what? */
00325         for ( i = 0; i < papi_num_components; i++ ) {
00326             if ( ( foo->tid != mytid ) && ( foo->running_eventset[i] ) &&
00327                  ( foo->running_eventset[i]->
00328                    state & ( PAPI_OVERFLOWING | PAPI_MULTIPLEXING ) ) ) {
00329                 /* xxxx mpx_info inside _papi_mdi_t _papi_hwi_system_info is commented out.
00330                    See papi_internal.h for details. The multiplex_timer_sig value is now part of that structure */
00331               THRDBG("Thread %ld sending signal %d to thread %ld\n",mytid,foo->tid,
00332                   (foo->running_eventset[i]->state & PAPI_OVERFLOWING ? _papi_hwd[i]->cmp_info.hardware_intr_sig : _papi_os_info.itimer_sig));
00333               retval = (*_papi_hwi_thread_kill_fn)(foo->tid, 
00334                   (foo->running_eventset[i]->state & PAPI_OVERFLOWING ? _papi_hwd[i]->cmp_info.hardware_intr_sig : _papi_os_info.itimer_sig));
00335               if (retval != 0)
00336                 return(PAPI_EMISC);
00337             }
00338         }
00339         if ( foo->next == _papi_hwi_thread_head )
00340           break;
00341     }
00342     _papi_hwi_unlock( THREADS_LOCK );
00343 
00344     return ( PAPI_OK );
00345 }

Here is the call graph for this function:

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 555 of file threads.c.

00556 {
00557     int didsomething = 0;
00558     ThreadInfo_t *foo = NULL;
00559 
00560     _papi_hwi_lock( THREADS_LOCK );
00561 
00562     for ( foo = ( ThreadInfo_t * ) _papi_hwi_thread_head; foo != NULL;
00563           foo = foo->next ) {
00564         /* If we want thread ID's */
00565         if ( where->id )
00566             memcpy( &where->id[didsomething], &foo->tid,
00567                     sizeof ( where->id[didsomething] ) );
00568 
00569         /* If we want data pointers */
00570         if ( where->data )
00571             where->data[didsomething] = foo->thread_storage[tag];
00572 
00573         didsomething++;
00574 
00575         if ( ( where->id ) || ( where->data ) ) {
00576             if ( didsomething >= where->num )
00577                 break;
00578         }
00579 
00580         if ( foo->next == _papi_hwi_thread_head )
00581             break;
00582     }
00583 
00584     where->num = didsomething;
00585     _papi_hwi_unlock( THREADS_LOCK );
00586 
00587     return ( PAPI_OK );
00588 
00589 }

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 528 of file threads.c.

00529 {
00530     int retval;
00531     ThreadInfo_t *tmp;
00532 
00533     _papi_hwi_lock( GLOBAL_LOCK );
00534 
00535 #if defined(HAVE_THREAD_LOCAL_STORAGE)
00536     _papi_hwi_my_thread = NULL;
00537 #endif
00538     _papi_hwi_thread_head = NULL;
00539     _papi_hwi_thread_id_fn = NULL;
00540 #if defined(ANY_THREAD_GETS_SIGNAL)
00541     _papi_hwi_thread_kill_fn = NULL;
00542 #endif
00543 
00544     retval = _papi_hwi_initialize_thread( &tmp , 0);
00545     if ( retval == PAPI_OK ) {
00546        retval = lookup_and_set_thread_symbols(  );
00547     }
00548 
00549     _papi_hwi_unlock( GLOBAL_LOCK );
00550 
00551     return ( retval );
00552 }

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.

00279 {
00280     int retval;
00281     ThreadInfo_t *thread;
00282     int i;
00283 
00284     if ( ( thread = allocate_thread( tid  ) ) == NULL ) {
00285         *dest = NULL;
00286         return PAPI_ENOMEM;
00287     }
00288 
00289     /* Call the component to fill in anything special. */
00290 
00291     for ( i = 0; i < papi_num_components; i++ ) {
00292         if (_papi_hwd[i]->cmp_info.disabled) continue;
00293         retval = _papi_hwd[i]->init_thread( thread->context[i] );
00294         if ( retval ) {
00295            free_thread( &thread );
00296            *dest = NULL;
00297            return retval;
00298         }
00299     }
00300 
00301     insert_thread( thread, tid );
00302 
00303     *dest = thread;
00304     return PAPI_OK;
00305 }

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.

00065 {
00066     if ( _papi_hwi_thread_id_fn ) {
00067         _papi_hwd_lock( lck );
00068         THRDBG( "Lock %d\n", lck );
00069     } else {
00070         ( void ) lck;        /* unused if !defined(DEBUG) */
00071         THRDBG( "Skipped lock %d\n", lck );
00072     }
00073 
00074     return ( PAPI_OK );
00075 }

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.

00146 {
00147     ThreadInfo_t *tmp = _papi_hwi_lookup_thread( tid );
00148     int retval = PAPI_OK;
00149 
00150     if ( tmp == NULL )
00151       retval = _papi_hwi_initialize_thread( &tmp, tid );
00152 
00153     if ( retval == PAPI_OK )
00154         *here = tmp;
00155 
00156     return ( retval );
00157 }

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.

00093 {
00094 
00095     unsigned long int tid;
00096     ThreadInfo_t *tmp;
00097 
00098 
00099     if (custom_tid==0) {
00100 #ifdef HAVE_THREAD_LOCAL_STORAGE
00101        THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
00102        return ( _papi_hwi_my_thread );
00103 #else
00104        if ( _papi_hwi_thread_id_fn == NULL ) {
00105           THRDBG( "Threads not initialized, returning master thread at %p\n",
00106                 _papi_hwi_thread_head );
00107           return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
00108        }
00109 
00110        tid = ( *_papi_hwi_thread_id_fn ) (  );
00111 #endif
00112     }
00113     else {
00114       tid=custom_tid;
00115     }
00116     THRDBG( "Threads initialized, looking for thread %#lx\n", tid );
00117 
00118     _papi_hwi_lock( THREADS_LOCK );
00119 
00120     tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
00121     while ( tmp != NULL ) {
00122         THRDBG( "Examining thread tid %#lx at %p\n", tmp->tid, tmp );
00123         if ( tmp->tid == tid )
00124             break;
00125         tmp = tmp->next;
00126         if ( tmp == _papi_hwi_thread_head ) {
00127             tmp = NULL;
00128             break;
00129         }
00130     }
00131 
00132     if ( tmp ) {
00133         _papi_hwi_thread_head = tmp;
00134         THRDBG( "Found thread %ld at %p\n", tid, tmp );
00135     } else {
00136         THRDBG( "Did not find tid %ld\n", tid );
00137     }
00138 
00139     _papi_hwi_unlock( THREADS_LOCK );
00140     return ( tmp );
00141 
00142 }

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.

00458 {
00459         int err,num_threads,i;
00460     ThreadInfo_t *tmp,*next;
00461     unsigned long our_tid;
00462 
00463     tmp = _papi_hwi_lookup_thread( 0 );
00464 
00465     if ( tmp == NULL ) {
00466        THRDBG( "Did not find my thread for shutdown!\n" );
00467        err = PAPI_EBUG;
00468     }
00469     else {
00470        our_tid=tmp->tid;
00471        (void)our_tid;
00472 
00473        THRDBG("Shutting down %ld\n",our_tid);
00474 
00475        err = _papi_hwi_shutdown_thread( tmp, 1 );
00476 
00477        /* count threads */
00478        tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
00479        num_threads=0;
00480        while(tmp!=NULL) {
00481           num_threads++;
00482           if (tmp->next==_papi_hwi_thread_head) break;
00483           tmp=tmp->next;
00484        }
00485 
00486        /* Shut down all threads allocated by this thread */
00487        /* Urgh it's a circular list where we removed in the loop  */
00488        /* so the only sane way to do it is get a count in advance */
00489        tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
00490 
00491        for(i=0;i<num_threads;i++) {
00492 
00493           next=tmp->next;
00494 
00495           THRDBG("looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
00496              i,tmp->tid,our_tid,tmp->allocator_tid);
00497 
00498          THRDBG("Also removing thread %ld\n",tmp->tid);
00499              err = _papi_hwi_shutdown_thread( tmp, 1 );
00500 
00501           tmp=next;
00502 
00503        }
00504     }
00505 
00506 
00507 #ifdef DEBUG
00508     if ( ISLEVEL( DEBUG_THREADS ) ) {
00509         if ( _papi_hwi_thread_head ) {
00510             THRDBG( "Thread head %p still exists!\n", _papi_hwi_thread_head );
00511         }
00512     }
00513 #endif
00514 
00515 #if defined(HAVE_THREAD_LOCAL_STORAGE)
00516     _papi_hwi_my_thread = NULL;
00517 #endif
00518     _papi_hwi_thread_head = NULL;
00519     _papi_hwi_thread_id_fn = NULL;
00520 #if defined(ANY_THREAD_GETS_SIGNAL)
00521     _papi_hwi_thread_kill_fn = NULL;
00522 #endif
00523 
00524     return err;
00525 }

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.

00419 {
00420     int retval = PAPI_OK;
00421     unsigned long tid;
00422     int i, failure = 0;
00423 
00424     if ( _papi_hwi_thread_id_fn )
00425         tid = ( *_papi_hwi_thread_id_fn ) (  );
00426     else
00427         tid = ( unsigned long ) getpid(  );
00428 
00429         THRDBG("Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
00430            thread->tid,
00431            thread->allocator_tid,
00432            tid);
00433 
00434     if ((thread->tid==tid) || ( thread->allocator_tid == tid ) || force_shutdown) {
00435 
00436                 _papi_hwi_thread_free_eventsets(tid);
00437 
00438         remove_thread( thread );
00439         THRDBG( "Shutting down thread %ld at %p\n", thread->tid, thread );
00440         for( i = 0; i < papi_num_components; i++ ) {
00441            if (_papi_hwd[i]->cmp_info.disabled) continue;
00442            retval = _papi_hwd[i]->shutdown_thread( thread->context[i]);
00443            if ( retval != PAPI_OK ) failure = retval;
00444         }
00445         free_thread( &thread );
00446         return ( failure );
00447     }
00448 
00449     THRDBG( "Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
00450             thread->tid, thread, tid );
00451     return PAPI_EBUG;
00452 }

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.

00079 {
00080     if ( _papi_hwi_thread_id_fn ) {
00081         _papi_hwd_unlock( lck );
00082         THRDBG( "Unlock %d\n", lck );
00083     } else {
00084         ( void ) lck;        /* unused if !defined(DEBUG) */
00085         THRDBG( "Skipped unlock %d\n", lck );
00086     }
00087 
00088     return ( PAPI_OK );
00089 }

Here is the caller graph for this function:


Variable Documentation

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

For internal use only.

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

For internal use only.

int( * _papi_hwi_thread_kill_fn)(int, int)

Function that sends a signal to other threads

For internal use only.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1