/**************************************************************************** ** 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 : RtsThread.cpp ** ** Description : TAU Profiling Package RTS Layer definitions ** ** for supporting threads ** ** Contact : tau-team@cs.uoregon.edu ** ** Documentation : See http://www.cs.uoregon.edu/research/tau ** ***************************************************************************/ ////////////////////////////////////////////////////////////////////// // Include Files ////////////////////////////////////////////////////////////////////// #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 "Profile/OpenMPLayer.h" #include void TraceCallStack(int tid, Profiler *current); #include #ifdef TAUKTAU #include #ifdef TAUKTAU_MERGE #include #endif //TAUKTAU_MERGE #ifdef TAUKTAU_SHCTR #include #endif //TAUKTAU_SHCTR #endif //TAUKTAU #include int RtsLayer::lockDBcount[TAU_MAX_THREADS]; ////////////////////////////////////////////////////////////////////// // myNode() returns the current node id (0..N-1) ////////////////////////////////////////////////////////////////////// int RtsLayer::myNode(void) { #ifdef TAU_PID_AS_NODE return getpid(); #endif return TheNode(); } ////////////////////////////////////////////////////////////////////// // myContext() returns the current context id (0..N-1) ////////////////////////////////////////////////////////////////////// int RtsLayer::myContext(void) { return TheContext(); } extern "C" int Tau_RtsLayer_myThread(void) { return RtsLayer::myThread(); } ////////////////////////////////////////////////////////////////////// // myNode() returns the current node id (0..N-1) ////////////////////////////////////////////////////////////////////// int RtsLayer::myThread(void) { #ifdef PTHREADS return PthreadLayer::GetThreadId(); #elif TAU_SPROC return SprocLayer::GetThreadId(); #elif TAU_WINDOWS return WindowsThreadLayer::GetThreadId(); #elif TULIPTHREADS return TulipThreadLayer::GetThreadId(); #elif JAVA return JavaThreadLayer::GetThreadId(); // C++ app shouldn't use this unless there's a VM #elif TAU_OPENMP return OpenMPLayer::GetThreadId(); #elif TAU_PAPI_THREADS return PapiThreadLayer::GetThreadId(); #else // if no other thread package is available return 0; #endif // PTHREADS } int RtsLayer::setMyThread(int tid) { #ifdef PTHREADS PthreadLayer::SetThreadId(tid); #endif // PTHREADS return 0; } int RtsLayer::getNumThreads() { return *(RtsLayer::numThreads()); } int *RtsLayer::numThreads() { static int numthreads = 1; return &numthreads; } ////////////////////////////////////////////////////////////////////// // RegisterThread is called before any other profiling function in a // thread that is spawned off ////////////////////////////////////////////////////////////////////// int RtsLayer::RegisterThread() { /* Check the size of threads */ LockEnv(); int numthreads = *(RtsLayer::numThreads()); numthreads ++; if (numthreads >= TAU_MAX_THREADS) { fprintf(stderr, "TAU: RtsLayer: Max thread limit (%d) exceeded. Please re-configure TAU with -useropt=-DTAU_MAX_THREADS=\n", numthreads); } UnLockEnv(); if (TauEnv_get_ebs_enabled()) { Tau_sampling_init(numthreads-1); } #ifdef PTHREADS PthreadLayer::RegisterThread(); #elif TAU_SPROC SprocLayer::RegisterThread(); #elif TAU_WINDOWS WindowsThreadLayer::RegisterThread(); #elif TULIPTHREADS TulipThreadLayer::RegisterThread(); #elif TAU_OPENMP OpenMPLayer::RegisterThread(); #elif TAU_PAPI_THREADS PapiThreadLayer::RegisterThread(); #endif // PTHREADS // Note: Java thread registration is done at the VM layer in TauJava.cpp *(RtsLayer::numThreads()) = *(RtsLayer::numThreads()) + 1; return numthreads; } ////////////////////////////////////////////////////////////////////// // RegisterFork is called before any other profiling function in a // process that is forked off (child process) ////////////////////////////////////////////////////////////////////// void RtsLayer::RegisterFork(int nodeid, enum TauFork_t opcode) { #ifdef PROFILING_ON vector::iterator it; Profiler *current; #endif // PROFILING_ON #ifdef TAUKTAU //If KTAU profiling (esp. merged, but even non-merged) is on //then we ALWAYS do EXCLUDE_PARENT - i.e. KTAU doesnt currently //support INCLUDE_PARENT. Unlike in the case of TAU, there is a // LOT of extra work that needs to be done in KTAU for INCLUDE. // - TODO. : AN opcode = TAU_EXCLUDE_PARENT_DATA; DEBUGPROFMSG("KTAU Profiling On. Currently only supports EXCLUDE-PARENT on RegisterFork." << endl;); #endif //TAUKTAU #ifdef TAU_PAPI // PAPI must be reinitialized in the child PapiLayer::reinitializePAPI(); #endif #ifdef TAUKTAU_SHCTR KtauCounters::RegisterFork(opcode);//forking needs to be tested further #endif // TAUKTAU_SHCTR TAU_PROFILE_SET_NODE(nodeid); // First, set the new id if (opcode == TAU_EXCLUDE_PARENT_DATA) { // If opcode is TAU_EXCLUDE_PARENT_DATA then we clear out the // previous values in the TheFunctionDB() // Get the current time double CurrentTimeOrCounts[TAU_MAX_COUNTERS]; for(int i=0;iSetCalls(tid, 0); (*it)->SetSubrs(tid, 0); (*it)->SetExclTimeZero(tid); (*it)->SetInclTimeZero(tid); /* Do we need to change AlreadyOnStack? No*/ DEBUGPROFMSG("FI Zap: Inside "<< (*it)->GetName() <ResetAllCounters(tid): Func:"<< (*it)->GetName() <GetKtauFuncInfo(tid)->ResetAllCounters(tid); #endif //TAUKTAU_MERGE } #ifdef TAUKTAU_MERGE DEBUGPROFMSG("RtsLayer::RegisterFork: KtauFuncInfo::ResetAllGrpTotals(tid)"<ThisFunction->GetName() <ThisFunction->IncrNumCalls(tid); if (current->ParentProfiler != 0) { // Increment the number of called functions in its parent current->ParentProfiler->ThisFunction->IncrNumSubrs(tid); } for(int j=0;jStartTime[j] = CurrentTimeOrCounts[j]; } current = current->ParentProfiler; } // Until the top of the stack #endif // PROFILING_ON if (TauEnv_get_tracing()) { DEBUGPROFMSG("Tracing Correct: "<ThisKtauProfiler->RegisterFork(TauInternal_CurrentProfiler(tid), tid, nodeid, opcode); } #endif //TAUKTAU } // for tid loop // DONE! } // If it is TAU_INCLUDE_PARENT_DATA then there's no need to do anything. // fork would copy over all the parent data as it is. } bool RtsLayer::initLocks(void) { threadLockDB(); for (int i=0; i