00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <pch.h>
00033
00034 #include "Sim/Thread/Thread.h"
00035
00036 #include "Utility/RuntimeError.h"
00037 #include "Sim/Op/Op.h"
00038
00039
00040 using namespace std;
00041 using namespace Onikiri;
00042
00043 Thread::Thread()
00044 {
00045 m_emulator = 0;
00046 m_core = 0;
00047 m_inorderList = 0;
00048 m_checkpointMaster = 0;
00049 m_memOrderManager = 0;
00050 m_regDepPred = 0;
00051 m_memDepPred = 0;
00052
00053 m_localTID = TID_INVALID;
00054 m_active = false;
00055 m_serialOpID = 0;
00056 }
00057
00058 Thread::~Thread()
00059 {
00060 ReleaseParam();
00061 }
00062
00063 void Thread::Initialize(InitPhase phase)
00064 {
00065 if(phase == INIT_PRE_CONNECTION){
00066 LoadParam();
00067 }
00068 else if(phase == INIT_POST_CONNECTION){
00069
00070 CheckNodeInitialized( "checkpointMaster", m_checkpointMaster );
00071 CheckNodeInitialized( "emulator", m_emulator );
00072 CheckNodeInitialized( "inorderList", m_inorderList );
00073 CheckNodeInitialized( "memOrderManager", m_memOrderManager );
00074 CheckNodeInitialized( "checkpointMaster", m_checkpointMaster );
00075 CheckNodeInitialized( "regDepPred", m_regDepPred );
00076 CheckNodeInitialized( "memDepPred", m_memDepPred );
00077 CheckNodeInitialized( "core", m_core );
00078 CheckNodeInitialized( "recoverer", m_recoverer );
00079
00080
00081 m_fetchPC.Initialize(
00082 m_checkpointMaster,
00083 CheckpointMaster::SLOT_FETCH
00084 );
00085
00086 m_retiredOpID.Initialize(
00087 m_checkpointMaster,
00088 CheckpointMaster::SLOT_FETCH
00089 );
00090 m_retiredOpID.GetCurrent() = 0;
00091 }
00092 }
00093
00094 bool Thread::IsActive()
00095 {
00096 return m_active;
00097 }
00098
00099 void Thread::InitializeContext(PC pc)
00100 {
00101 int pcTID = pc.tid;
00102 if( pcTID != GetTID(0) ){
00103 THROW_RUNTIME_ERROR(
00104 "The TID of 'pc' (%d) and the TID of this 'Thread' (%d) are different",
00105 pcTID,
00106 GetTID(0)
00107 );
00108 }
00109
00110 SetFetchPC( pc );
00111 }
00112
00113 int Thread::GetTID()
00114 {
00115 return GetTID(0);
00116 }
00117
00118 int Thread::GetTID( const int index )
00119 {
00120 return PhysicalResourceNode::GetTID( index );
00121 }
00122
00123 void Thread::SetLocalThreadID(int localTID)
00124 {
00125 m_localTID = localTID;
00126 }
00127
00128 int Thread::GetLocalThreadID() const
00129 {
00130 return m_localTID;
00131 }
00132
00133 void Thread::Activate( bool active )
00134 {
00135 m_active = active;
00136 }
00137
00138 void Thread::SetFetchPC(const PC& pc)
00139 {
00140 ASSERT(
00141 pc.tid == GetTID(0),
00142 "The passed pc has invalid tid."
00143 );
00144 *m_fetchPC = pc;
00145 }
00146
00147 PC Thread::GetFetchPC() const
00148 {
00149 return *m_fetchPC;
00150 }
00151
00152 u64 Thread::GetOpRetiredID()
00153 {
00154 return *m_retiredOpID;
00155 }
00156
00157 u64 Thread::GetOpSerialID()
00158 {
00159 return m_serialOpID;
00160 }
00161
00162 void Thread::AddOpRetiredID(u64 num)
00163 {
00164 *m_retiredOpID = *m_retiredOpID + num;
00165 }
00166
00167 void Thread::AddOpSerialID(u64 num)
00168 {
00169 m_serialOpID += num;
00170 }
00171
00172 void Thread::SetThreadCount(const int count)
00173 {
00174 if( count != 1 ){
00175 THROW_RUNTIME_ERROR( "The tid count of the 'Thread' class must be 1" );
00176 }
00177 PhysicalResourceNode::SetThreadCount( count );
00178 }
00179