PAPI  5.0.1.0
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 _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

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:

< Used with setting up array

< Used with setting up array

< No error

Definition at line 557 of file threads.c.

{
    int didsomething = 0;
    ThreadInfo_t *foo = NULL;

    _papi_hwi_lock( THREADS_LOCK );

    for ( foo = ( ThreadInfo_t * ) _papi_hwi_thread_head; foo != NULL;
          foo = foo->next ) {
        /* If we want thread ID's */
        if ( where->id )
            memcpy( &where->id[didsomething], &foo->tid,
                    sizeof ( where->id[didsomething] ) );

        /* If we want data pointers */
        if ( where->data )
            where->data[didsomething] = foo->thread_storage[tag];

        didsomething++;

        if ( ( where->id ) || ( where->data ) ) {
            if ( didsomething >= where->num )
                break;
        }

        if ( foo->next == _papi_hwi_thread_head )
            break;
    }

    where->num = didsomething;
    _papi_hwi_unlock( THREADS_LOCK );

    return ( PAPI_OK );

}

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_hwi_get_thr_context ( void **  )

< Used with setting up array

< No error

< Used with setting up array

Definition at line 530 of file threads.c.

{
    int retval;
    ThreadInfo_t *tmp;

    _papi_hwi_lock( GLOBAL_LOCK );

#if defined(HAVE_THREAD_LOCAL_STORAGE)
    _papi_hwi_my_thread = NULL;
#endif
    _papi_hwi_thread_head = NULL;
    _papi_hwi_thread_id_fn = NULL;
#if defined(ANY_THREAD_GETS_SIGNAL)
    _papi_hwi_thread_kill_fn = NULL;
#endif

    retval = _papi_hwi_initialize_thread( &tmp , 0);
    if ( retval == PAPI_OK ) {
       retval = lookup_and_set_thread_symbols(  );
    }

    _papi_hwi_unlock( GLOBAL_LOCK );

    return ( retval );
}

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 
)

< Insufficient memory

< No error

Definition at line 276 of file threads.c.

{
    int retval;
    ThreadInfo_t *thread;
    int i;

    if ( ( thread = allocate_thread( tid  ) ) == NULL ) {
        *dest = NULL;
        return PAPI_ENOMEM;
    }

    /* Call the component to fill in anything special. */

    for ( i = 0; i < papi_num_components; i++ ) {
        if (_papi_hwd[i]->cmp_info.disabled) continue;
        retval = _papi_hwd[i]->init_thread( thread->context[i] );
        if ( retval ) {
           free_thread( &thread );
           *dest = NULL;
           return retval;
        }
    }

    insert_thread( thread, tid );

    *dest = thread;
    return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

inline_static int _papi_hwi_lock ( int  lck)

Definition at line 64 of file threads.h.

{
    if ( _papi_hwi_thread_id_fn ) {
        _papi_hwd_lock( lck );
        THRDBG( "Lock %d\n", lck );
    } else {
        ( void ) lck;        /* unused if !defined(DEBUG) */
        THRDBG( "Skipped lock %d\n", lck );
    }

    return ( PAPI_OK );
}

Here is the caller graph for this function:

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

Definition at line 145 of file threads.h.

{
    ThreadInfo_t *tmp = _papi_hwi_lookup_thread( tid );
    int retval = PAPI_OK;

    if ( tmp == NULL )
      retval = _papi_hwi_initialize_thread( &tmp, tid );

    if ( retval == PAPI_OK )
        *here = tmp;

    return ( retval );
}

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.

{

    unsigned long int tid;
    ThreadInfo_t *tmp;


    if (custom_tid==0) {
#ifdef HAVE_THREAD_LOCAL_STORAGE
       THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
       return ( _papi_hwi_my_thread );
#else
       if ( _papi_hwi_thread_id_fn == NULL ) {
          THRDBG( "Threads not initialized, returning master thread at %p\n",
                _papi_hwi_thread_head );
          return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
       }

       tid = ( *_papi_hwi_thread_id_fn ) (  );
#endif
    }
    else {
      tid=custom_tid;
    }
    THRDBG( "Threads initialized, looking for thread 0x%lx\n", tid );

    _papi_hwi_lock( THREADS_LOCK );

    tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
    while ( tmp != NULL ) {
        THRDBG( "Examining thread tid 0x%lx at %p\n", tmp->tid, tmp );
        if ( tmp->tid == tid )
            break;
        tmp = tmp->next;
        if ( tmp == _papi_hwi_thread_head ) {
            tmp = NULL;
            break;
        }
    }

    if ( tmp ) {
        _papi_hwi_thread_head = tmp;
        THRDBG( "Found thread %ld at %p\n", tid, tmp );
    } else {
        THRDBG( "Did not find tid %ld\n", tid );
    }

    _papi_hwi_unlock( THREADS_LOCK );
    return ( tmp );

}

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)

< Internal error, please send mail to the developers

Definition at line 457 of file threads.c.

{
        int err,num_threads,i;
    ThreadInfo_t *tmp,*next;
    unsigned long our_tid;

    tmp = _papi_hwi_lookup_thread( 0 );

    if ( tmp == NULL ) {
       THRDBG( "Did not find my thread for shutdown!\n" );
       err = PAPI_EBUG;
    }
    else {
       our_tid=tmp->tid;

       THRDBG("Shutting down %ld\n",our_tid);

       err = _papi_hwi_shutdown_thread( tmp );


       /* count threads */
       tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
       num_threads=0;
       while(tmp!=NULL) {
          num_threads++;
          if (tmp->next==_papi_hwi_thread_head) break;
          tmp=tmp->next;
       }

       /* Shut down all threads allocated by this thread */
       /* Urgh it's a circular list where we removed in the loop  */
       /* so the only sane way to do it is get a count in advance */
       tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;

       for(i=0;i<num_threads;i++) {

          next=tmp->next;

          THRDBG("looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
             i,tmp->tid,our_tid,tmp->allocator_tid);
        
          if (tmp->allocator_tid==our_tid) {
         THRDBG("Also removing thread %ld\n",tmp->tid);
             err = _papi_hwi_shutdown_thread( tmp );
          }
  
          tmp=next;

       }
    }


#ifdef DEBUG
    if ( ISLEVEL( DEBUG_THREADS ) ) {
        if ( _papi_hwi_thread_head ) {
            THRDBG( "Thread head %p still exists!\n", _papi_hwi_thread_head );
        }
    }
#endif

#if defined(HAVE_THREAD_LOCAL_STORAGE)
    _papi_hwi_my_thread = NULL;
#endif
    _papi_hwi_thread_head = NULL;
    _papi_hwi_thread_id_fn = NULL;
#if defined(ANY_THREAD_GETS_SIGNAL)
    _papi_hwi_thread_kill_fn = NULL;
#endif

    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

< No error

< No error

< Internal error, please send mail to the developers

Definition at line 418 of file threads.c.

{
    int retval = PAPI_OK;
    unsigned long tid;
    int i, failure = 0;

    if ( _papi_hwi_thread_id_fn )
        tid = ( *_papi_hwi_thread_id_fn ) (  );
    else
        tid = ( unsigned long ) getpid(  );

        THRDBG("Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
           thread->tid,
           thread->allocator_tid,
           tid);

    if ((thread->tid==tid) || ( thread->allocator_tid == tid )) {

                _papi_hwi_thread_free_eventsets(tid);

        remove_thread( thread );
        THRDBG( "Shutting down thread %ld at %p\n", thread->tid, thread );
        for( i = 0; i < papi_num_components; i++ ) {
           if (_papi_hwd[i]->cmp_info.disabled) continue;
           retval = _papi_hwd[i]->shutdown_thread( thread->context[i]);
           if ( retval != PAPI_OK ) failure = retval;
        }
        free_thread( &thread );
        return ( failure );
    }

    THRDBG( "Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
            thread->tid, thread, tid );
    return PAPI_EBUG;
}

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.

{
    if ( _papi_hwi_thread_id_fn ) {
        _papi_hwd_unlock( lck );
        THRDBG( "Unlock %d\n", lck );
    } else {
        ( void ) lck;        /* unused if !defined(DEBUG) */
        THRDBG( "Skipped unlock %d\n", lck );
    }

    return ( PAPI_OK );
}

Here is the caller graph for this function:


Variable Documentation

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

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines