/**************************************************************************** ** 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 : SprocLayer.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 ** ***************************************************************************/ ////////////////////////////////////////////////////////////////////// // Include Files ////////////////////////////////////////////////////////////////////// //#define DEBUG_PROF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef TAU_DOT_H_LESS_HEADERS #include #include using namespace std; #else /* TAU_DOT_H_LESS_HEADERS */ #include #include #endif /* TAU_DOT_H_LESS_HEADERS */ #include "Profile/Profiler.h" #define TAU_SYNC_SPROC ///////////////////////////////////////////////////////////////////////// // Member Function Definitions For class SprocLayer // This allows us to get thread ids from 0..N-1 instead of long nos // as generated by getpid() ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // Define the static private members of SprocLayer ///////////////////////////////////////////////////////////////////////// usptr_t * SprocLayer::tauArena = NULL; int SprocLayer::tauThreadCount = 0; usema_t * SprocLayer::tauDBMutex = NULL; usema_t * SprocLayer::tauEnvMutex = NULL; usema_t * SprocLayer::tauThreadCountMutex = NULL; map >& TheTauPidSprocMap(void) { static map > TauPidMap; return TauPidMap; } //////////////////////////////////////////////////////////////////////// // 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 SprocLayer::RegisterThread(void) { if (uspsema(tauThreadCountMutex) == -1) perror("TAU ERROR: SprocLayer.cpp: SprocLayer::RegisterThread uspsema"); TheTauPidSprocMap()[getpid()] = ++SprocLayer::tauThreadCount; if (usvsema(tauThreadCountMutex) == -1) perror("TAU ERROR: SprocLayer.cpp: SprocLayer::RegisterThread usvsema"); DEBUGPROFMSG("Thread id "<< tauThreadCount<< " Created! "< >::iterator it; int pid = getpid(); int tid; // Each sproc thread has a unique pid (not in 0..N-1 range) // This method converts it to that range as follows: #ifdef TAU_SYNC_SPROC if (uspsema(tauThreadCountMutex) == -1) perror("TAU ERROR: SprocLayer.cpp: SprocLayer::GetThreadId uspsema"); #endif /* TAU_SYNC_SPROC */ if ((it = TheTauPidSprocMap().find(pid))== TheTauPidSprocMap().end()) tid = 0; // Main thread doesn't do RegsiterThread else tid = TheTauPidSprocMap()[pid]; // Threads 1..N-1 #ifdef TAU_SYNC_SPROC if (usvsema(tauThreadCountMutex) == -1) perror("TAU ERROR: SprocLayer.cpp: SprocLayer::GetThreadId usvsema"); #endif /* TAU_SYNC_SPROC */ return tid; } //////////////////////////////////////////////////////////////////////// // InitializeThreadData is called before any thread operations are performed. // It sets the default values for static private data members of the // SprocLayer class. //////////////////////////////////////////////////////////////////////// int SprocLayer::InitializeThreadData(void) { static int flag = 0; if (flag == 0) { flag = 1; // Initialize the mutex tauArena = usinit("/dev/zero"); if (!tauArena) perror("TAU ERROR: SprocLayer.cpp InitializeThreadData(): Arena /dev/zero not initialized!"); tauDBMutex = usnewsema(tauArena, 1); tauEnvMutex = usnewsema(tauArena, 1); tauThreadCountMutex = usnewsema(tauArena, 1); DEBUGPROFMSG("SprocLayer::Initialize() done! " <