/**************************************************************************** ** TAU Portable Profiling Package ** ** http://www.cs.uoregon.edu/research/tau ** ***************************************************************************** ** Copyright 1997 ** ** Department of Computer and Information Science, University of Oregon ** ** Advanced Computing Laboratory, Los Alamos National Laboratory ** ****************************************************************************/ /*************************************************************************** ** File : PthreadLayer.cpp ** ** Description : TAU Profiling Package RTS Layer definitions ** ** for supporting pthreads ** ** Contact : tau-team@cs.uoregon.edu ** ** Documentation : See http://www.cs.uoregon.edu/research/tau ** ***************************************************************************/ // This needs to go at the top because the ordering of include files here // makes a difference on Cray systems and we get an error with RTLD_NEXT // not being defined #ifdef TAU_PTHREAD_PRELOAD #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #endif ////////////////////////////////////////////////////////////////////// // Include Files ////////////////////////////////////////////////////////////////////// //#define DEBUG_PROF #ifdef TAU_DOT_H_LESS_HEADERS #include using namespace std; #else /* TAU_DOT_H_LESS_HEADERS */ #include #endif /* TAU_DOT_H_LESS_HEADERS */ #include "Profile/Profiler.h" #include #ifdef TAU_CHARM extern "C" { #include } #else #include #endif ///////////////////////////////////////////////////////////////////////// // Member Function Definitions For class PthreadLayer // This allows us to get thread ids from 0..N-1 instead of long nos // as generated by pthread_self() ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // Define the static private members of PthreadLayer ///////////////////////////////////////////////////////////////////////// pthread_key_t PthreadLayer::tauPthreadId; pthread_mutex_t PthreadLayer::tauThreadcountMutex; pthread_mutexattr_t PthreadLayer::tauThreadcountAttr; pthread_mutex_t PthreadLayer::tauDBMutex; pthread_mutex_t PthreadLayer::tauEnvMutex; pthread_mutexattr_t PthreadLayer::tauDBAttr; int PthreadLayer::tauThreadCount = 0; //////////////////////////////////////////////////////////////////////// // RegisterThread() should be called before any profiling routines are // invoked. This routine sets the thread id that is used by the code in // FunctionInfo and Profiler classes. This should be the first routine a // thread should invoke from its wrapper. Note: main() thread shouldn't // call this routine. //////////////////////////////////////////////////////////////////////// int PthreadLayer::RegisterThread(void) { int *id = (int *) pthread_getspecific(tauPthreadId); if (id != NULL) { return 0; } int *threadId = new int; pthread_mutex_lock(&tauThreadcountMutex); tauThreadCount ++; // A thread should call this routine exactly once. *threadId = tauThreadCount; DEBUGPROFMSG("Thread id "<< tauThreadCount<< " Created! "<id != -1) { TAU_PROFILE_SET_THREAD(pack->id); } else { TAU_REGISTER_THREAD(); } return pack->start_routine(pack->arg); } extern "C" int tau_pthread_create (pthread_t * threadp, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { tau_pthread_pack *pack = (tau_pthread_pack*) malloc (sizeof(tau_pthread_pack)); pack->start_routine = start_routine; pack->arg = arg; pack->id = -1; // none specified return pthread_create(threadp, (pthread_attr_t*) attr, tau_pthread_function, (void*)pack); } extern "C" void tau_pthread_exit (void *value_ptr) { TAU_PROFILE_EXIT("pthread_exit"); pthread_exit(value_ptr); } extern "C" int tau_track_pthread_create (pthread_t * threadp, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, int id) { tau_pthread_pack *pack = (tau_pthread_pack*) malloc (sizeof(tau_pthread_pack)); pack->start_routine = start_routine; pack->arg = arg; pack->id = id; // set to the specified id return pthread_create(threadp, (pthread_attr_t*) attr, tau_pthread_function, (void*)pack); } #ifdef TAU_PTHREAD_BARRIER_AVAILABLE extern "C" int tau_track_pthread_barrier_wait(pthread_barrier_t *barrier) { int retval; TAU_PROFILE_TIMER(timer, "pthread_barrier_wait", "", TAU_DEFAULT); TAU_PROFILE_START(timer); retval = pthread_barrier_wait (barrier); TAU_PROFILE_STOP(timer); return retval; } #endif /* TAU_PTHREAD_BARRIER_AVAILABLE */ /*************************************************************************** * $RCSfile: PthreadLayer.cpp,v $ $Author: amorris $ * $Revision: 1.25 $ $Date: 2010/05/11 22:57:50 $ * POOMA_VERSION_ID: $Id: PthreadLayer.cpp,v 1.25 2010/05/11 22:57:50 amorris Exp $ ***************************************************************************/