Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
scHThread.h
Go to the documentation of this file.
1 
5 /* @author János Végh (jvegh)
6 * @bug No known bugs.
7 */
8 
9 #ifndef scHThread_h
10 #define scHThread_h
11 
17 class scGridPoint;
18 #include <iomanip> // std::setfill, std::setw
19 #include <systemc>
20 #include <bitset>
21 //#include "BasicConfig.h"
22 #include "GridPoint.h"
23 using namespace sc_core; using namespace std; using namespace sc_dt;
24 
28 typedef enum { hpt_System, hpt_Head, hpt_Same, hpt_Near, hpt_Any} HThreadPreference_t;
33 typedef struct{
35  SC_ADDRESS_TYPE
37  size_t
39  string
40  ID;
42 
46 typedef enum
47 {
54  // The scGridPoint can make ONE fetch at a time, the threads must share its capacity
55  // These two bits describe the status of the scGridPoint
58  // The scThread is executing an instruction on the scGridPoint
64  tob_Max
66 
70 typedef struct{
71  bool
72  okc,okFetch;
73  int8_t
74  byte1,
81  SC_WORD_TYPE
82  immediate;
84 
88 typedef struct{
89  uint32_t PC;
90  uint32_t NewPC;
91  SC_WORD_TYPE* InstBufferPosition;
92  SC_WORD_TYPE* DataBufferPosition;
94  sc_time
98 
102 typedef struct{
103  uint32_t PC;
104 // sc_core::sc_time Delay;///< Remember the time of fetching the instruction
106  uint32_t val,dval;
107  sc_time ExecutionTime;
109 
116 /* \class scHThread The scHThread is the "work horse" of the system
117  *
118  * In order to avoid using an scHThread for two different goals,
119  * it must be activated before directing an instruction stream to it
120  * and must be deactivated after the execution of the stream terminated.
121  * The state flag whether the scHThread is active, is administered in its owner scGridPoint,
122  * with setting the bit corresponding to the scHThread's IDMask.
123  *
124  * A scHThread can be activated either by another scHThread, or the scProcessor
125  * of the scGridpoint owing the scHThread.
126  * The first form is only possible using a morphing instruction,
127  * the latter is possible without morphing (corresponds to the classic computing).
128  * The scProcessor, in this way, can start several scHThread processes,
129  * either the conventional or scHThread-initiated ones.
130 
131  * The OS has the right to allocate and preallocate some scGridPoint and scHThread resources for a task,
132  * and the different tasks do not have the right to activate each other's resources.
133  * There are, however, unallocated resources; and (as a "free pool") the
134  * tasks can activate those resources.
135 
136  */
137 
138 class scHThread : public sc_core::sc_module
139 {
140  friend class scGridPoint;
141  friend class scAbstractCore;
142  friend class Y86Core;
143 
144  public:
169  scHThread(sc_core::sc_module_name nm
170  , scGridPoint* GP, SC_HTHREAD_ID_TYPE ID) ;
171  ~scHThread(void);
172  SC_HAS_PROCESS(scHThread); // We have the constructor in the .cpp file
173  struct{
174  sc_core::sc_event
175  FETCH
176  ,FETCHED //< Fetch finished
177  ,EXEC
178  ,EXECUTED
179  ,NEXT
180  ,TIMEOUT //< The required timeout is over
181  ,MemoryContentArrived //< The physical core informs the the top layer, per HThread
182  ;
183  }EVENT_HTHREAD;
184  bool
185  IsTimedOut(void) const
186  { return mTimedOut;}
187  void
188  Reset(void);
189  void
190  Timeout_Set(sc_time &T)
191  { mTimedOut = false; EVENT_HTHREAD.TIMEOUT.notify(T);}
192  void
193  AllocatedBit_Set(bool B);
194  bool
195  AllocatedBit_Get(bool B);
196 
197  void
198  PreAllocatedBit_Set(bool V=true);
199  // { OperatingBit_Set(tob_PreAllocated,V);}
200  bool
201  PreAllocatedBit_Get(void){ return OperatingBit_Get(tob_PreAllocated);}
202  SC_HTHREAD_ID_TYPE
203  ID_Get(void){return mID;}
204  SC_HTHREAD_MASK_TYPE
205  ID_Mask_Get(void) { return 1 << mID;}
206  string
207  StringOfID_Get(void);
209  ClusterAddress_Get(void);
210 
211  string
212  PrologString_Get(void);
213  // QT handling
214 /* bool
215  QTRegime_Get(void) { return mQT.Regime;}
216  void
217  QTRegime_Set(bool R) { mQT.Regime = R;}*/
218  SC_ADDRESS_TYPE
219  QTOffset_Get(void){ return mQT.Offset;}
220  void
221  QTOffset_Set(SC_ADDRESS_TYPE O){mQT.Offset = O;}
222  size_t
223  QTLength_Get(void){ return mQT.Length;}
224  void
225  QTLength_Set(size_t L){mQT.Length = L;}
226 /* string
227  QTID_Get(void){ return mQT.ID;}
228  void
229  QTID_Set(string S){mQT.ID = S;}
230  string
231  StringOfQT_Get(void); { return mQT.ID;} */
232  string
233  StringOfDefaultName_Get(void);
234  string
235  StringOfClusterName_Get(void);
236  string
237  StringOfAliasName_Get(void){ return mAliasName;}
238  bool
239  StringOfAliasName_Set(string A);
240 // QT_AssembleID( scHThread* Parent);
241  scGridPoint*
242  Owner_Get(void){ return mGridPoint;}
243  // Allocation-related
244  scHThread*
245  Parent_Get(void){ return mParent;}
246  void
247  Parent_Set(scHThread* P){mParent = P;}
248  void
249  ResetForParent(scHThread* Parent);
250  scHThread*
251  AllocateFor(scHThread* Parent);
252  scHThread*
253  PreAllocateFor(scHThread* Parent);
254 
255 
256  // State-bits-related functionality
257  void
258  AllocatedBit_Set(SC_HTHREAD_ID_TYPE H, bool V=true);
259  bool
260  AllocatedBit_Get(void)
261  { return OperatingBit_Get(tob_Allocated); }
262 /* bool
263  IsAllocated(void) { return OperatingBit_Get(tob_Allocated);}*/
264  bool
265  Deallocate(void);
266  SC_WORD_TYPE
267  Register_Get(int R)
268  {assert((R>=0) && (R<32)); return REGS[R];}
269  void
270  Register_Set(int R, SC_WORD_TYPE C)
271  {assert((R>=0) && (R<32)); REGS[R] = C;}
272 
273  SC_ADDRESS_TYPE
274  PC_Get()
275  { assert(((exec.PC>=0) && (exec.PC<FMAX_MEMORY_SIZE)) || (exec.PC==(unsigned)-1));
276  return exec.PC;}
277  void
278  PC_Set(SC_ADDRESS_TYPE P)
279  { assert(((P>=0) && (P<FMAX_MEMORY_SIZE)) || (P==(unsigned)-1));
280  exec.PC = P;}
281  void
282  fetchNewPC_Set(SC_ADDRESS_TYPE PC)
283  { assert((PC>=0) && (PC<FMAX_MEMORY_SIZE));
284  fetch.NewPC = PC;}
285  SC_ADDRESS_TYPE
286  fetchPC_Get(void)
287  { return fetch.PC;}
288  int8_t
289  fetchFunctionCode_Get(void)
290  { return fetch.Stage.FunctCode;}
291  void
292  fetchPC_Set(SC_ADDRESS_TYPE PC){ assert((PC>=0) && (PC<FMAX_MEMORY_SIZE));
293  fetch.PC = PC;}
294  SC_WORD_TYPE
295  fetchImmediate_Get(void)
296  { return fetch.Stage.immediate; }
297  void
299  { OperatingBit_Set(tob_PCAffected,B);}
300  bool
301  PC_Affected_Get(void)
302  { return OperatingBit_Get(tob_PCAffected);}
303  string
304  StringOfPC_Get(void)
305  {
306  ostringstream oss;
307  oss << "0x" << hex << std::setfill('0') << std::setw((FMEMORY_ADDRESS_WIDTH+3)/4) << PC_Get() << dec;
308  return oss.str();
309  }
314  string
315  StringOfClusterAddress_Get(void);
316 
317  bool
318  IsMemoryExpected(void) { return mThreadOperatingBits[tob_MemoryExpected];}
319  bool
320  IsDataMemoryExpected(void) {return mThreadOperatingBits[tob_DataExpected];}
321  void
322  MemoryExpected_Set(bool B, bool D=true)
323  {mThreadOperatingBits[tob_MemoryExpected] = B; mThreadOperatingBits[tob_DataExpected] = D; }
324  SC_WORD_TYPE*
325  InstPositionInBuffer(SC_ADDRESS_TYPE A=CORE_DEFAULT_ADDRESS);
326  SC_WORD_TYPE*
327  DataPositionInBuffer(SC_ADDRESS_TYPE A);
328 
335  virtual void
336  FinishPrefetching(void);
337  void
338  PrepareNextInstruction();
339  virtual bool
340  CatchedAllocationError(scHThread* Parent){return false;}
341  void
342  OperatingBit_Set(ThreadOperatingBits_t B, bool V);
343  bool
344  OperatingBit_Get(ThreadOperatingBits_t B){return mThreadOperatingBits[B];};
345  void
346  ObservedBit_Set(bool B);
347  void
348  Child_Insert(scHThread* C);
349  void
350  Child_Remove(scHThread* C);
351  int
352  ChildCount_Get(void){return mChildren.size();}
353  int
354  Child_Find(scHThread* C);
355  bool
356  Y86doFetchInstruction();
357  bool
358  Y86doExecuteInstruction(void);
359  int16_t
360  InstanceCount_Get(){ return mInstanceCount % 50;;}
361  string
362  StringID_Get(void);
363 
364  void
365  HandleMorphingInstruction();
366  void
367  HandleConventionalInstruction();
372  string
373  StringOfName_Get(void);
374 
375 protected:
376  void
377  TIMEOUT_method(void); //
378  SC_WORD_TYPE*
379  REGS;
384  SC_WORD_TYPE
385  mDataMemoryBuffer[MAX_IGPCBUFFER_SIZE], // This a per thread cache
386  mInstrMemoryBuffer[MAX_IGPCBUFFER_SIZE];
387  SC_ADDRESS_TYPE
388  mDataMemoryAddressBegin, mDataMemoryAddressEnd, // This a per thread cache
389  mInstrMemoryAddressBegin, mInstrMemoryAddressEnd;
390 
396 // void
397 // NEXT_thread(void);
398 
407  void
408  FETCH_method(void);
409 
418  void
419  EXEC_method(void);
420 
429 // void
430 // FETCH_thread(void);
436  void
437  NEXT_method(void);
438  void
439  MemoryContentArrived_method(void);
440  virtual void
441  doGetMemoryContent(void){}
442  bool
444  short int
445  msWaitTimeout; // The waiting can be time-limited; 0 means no wait
446  void
447  AllocationBegin_Set(sc_core::sc_time T)
448  { msAllocationBegin = T;}
449 private:
450  bitset<tob_Max>
451  mThreadOperatingBits;
453  mQT;
454  scGridPoint*
455  mGridPoint;
456  scHThread*
457  mParent;
458  vector<scHThread*>
459  mChildren;
460  SC_ADDRESS_TYPE
461  mMemoryRequestAddress;
462  const SC_HTHREAD_ID_TYPE
463  mID;
464  string
465  mStringID; // Store here
466  bool
467  msPC_Affected;
468  short int
469  mCSR;
470  uint16_t
471  mInstanceCount; // How many times this object was instantiated
472  sc_core::sc_time
473  msAllocationBegin; // When this scHThread was allocated
474  string //
475  mAliasName;
476 }; // of scHThread
478 #endif // scHThread_h
QTattributes_t::ID
string ID
The string ID of the QT.
Definition: scHThread.h:40
CoreExecute_t
Instruction-execution related variables.
Definition: scHThread.h:102
scHThread::PreAllocatedBit_Get
bool PreAllocatedBit_Get(void)
< Get 'PreAllocated' status of HThreadl
Definition: scHThread.h:201
CoreFetch_t::NewPC
uint32_t NewPC
The next PC to fetch.
Definition: scHThread.h:90
scHThread::fetch
CoreFetch_t fetch
All info relating instruction fetch.
Definition: scHThread.h:381
CoreStage_t::RSource2
int8_t RSource2
Second source.
Definition: scHThread.h:79
tob_MorphFetched
@ tob_MorphFetched
The fetched instruction is a morhphing instruction.
Definition: scHThread.h:60
GridPoint.h
Topology information for the electronic modules arranged in a grid.
CoreExecute_t::PC
uint32_t PC
The fetch PC.
Definition: scHThread.h:103
tob_Regime
@ tob_Regime
The thread is working in "Modern" mode.
Definition: scHThread.h:48
CoreStage_t::FunctCode
int8_t FunctCode
Function subcode.
Definition: scHThread.h:76
scHThread
The scHThread class.
Definition: scHThread.h:138
CoreFetch_t::InstBufferPosition
SC_WORD_TYPE * InstBufferPosition
Pointer to the fetched memory content.
Definition: scHThread.h:91
scHThread::IsTimedOut
bool IsTimedOut(void) const
< The HThread can be time, true if the actin timed out
Definition: scHThread.h:185
CoreFetch_t::Stage
CoreStage_t Stage
Fetch related storage.
Definition: scHThread.h:93
tob_DataExpected
@ tob_DataExpected
The core can wait either for data memory or instruction memory.
Definition: scHThread.h:53
HThreadPreference_t
HThreadPreference_t
Definition: scHThread.h:28
QTattributes_t::Offset
SC_ADDRESS_TYPE Offset
Return offset of the code chunk.
Definition: scHThread.h:36
scHThread::exec
CoreExecute_t exec
All information relating to the execution.
Definition: scHThread.h:383
tob_Morphing
@ tob_Morphing
Executing a morphing instruction.
Definition: scHThread.h:61
CoreStage_t::RDest
int8_t RDest
Destination register.
Definition: scHThread.h:80
tob_ExecPending
@ tob_ExecPending
The EXEC for this thread was issued, but not yet terminated.
Definition: scHThread.h:59
scHThread::PC_Affected_Set
void PC_Affected_Set(bool B)
Definition: scHThread.h:298
scGridPoint
This class implements the autonomous grid point functionality: it is a communicating GridPoint....
Definition: scGridPoint.h:127
CoreFetch_t::ExecutionTime
sc_time ExecutionTime
The simulated execution time.
Definition: scHThread.h:96
tob_Observed
@ tob_Observed
The HThread is observed (by the simulator)
Definition: scHThread.h:63
tob_PCAffected
@ tob_PCAffected
If PC is affected by the instruction.
Definition: scHThread.h:62
ClusterAddress_t
A GridPoint can be addressed also by its cluster address of type ClusterAddress_t....
Definition: Clustering.h:58
ThreadOperatingBits_t
ThreadOperatingBits_t
the names of the bits in the bitset
Definition: scHThread.h:46
tob_Blocked
@ tob_Blocked
The HThread is blocked for some reason.
Definition: scHThread.h:51
CoreStage_t::RSource1
int8_t RSource1
First source.
Definition: scHThread.h:78
QTattributes_t::Length
size_t Length
Return length of the code chunk.
Definition: scHThread.h:38
tob_MemoryExpected
@ tob_MemoryExpected
Set when asked for data transfer from memory.
Definition: scHThread.h:52
QTattributes_t
This structure stores the quasi-thread related attributes.
Definition: scHThread.h:34
CoreFetch_t
Instruction-fetching related variables.
Definition: scHThread.h:88
CoreExecute_t::ExecutionTime
sc_time ExecutionTime
The simulated execution time.
Definition: scHThread.h:107
CoreStage_t
Variables passed between fetch/execute.
Definition: scHThread.h:70
scHThread::mInstrMemoryAddressEnd
SC_ADDRESS_TYPE mInstrMemoryAddressEnd
The first/last contents in the cache.
Definition: scHThread.h:389
tob_FetchPending
@ tob_FetchPending
A fetch for this thread event was started, but not yet finished.
Definition: scHThread.h:56
scHThread::mTimedOut
bool mTimedOut
Is set when EVENT_GRID.TIMEOUT.notify() times out.
Definition: scHThread.h:443
tob_PreAllocated
@ tob_PreAllocated
The thread is allocated for another thread.
Definition: scHThread.h:50
scHThread::Timeout_Set
void Timeout_Set(sc_time &T)
< Set timout facility for a thread
Definition: scHThread.h:190
CoreFetch_t::WaitTimeBegin
sc_time WaitTimeBegin
When we started to wait for the FETCH.
Definition: scHThread.h:95
CoreStage_t::FunctCode7
int8_t FunctCode7
Function subcode Funct7.
Definition: scHThread.h:77
CoreFetch_t::PC
uint32_t PC
The fetch PC.
Definition: scHThread.h:89
CoreFetch_t::DataBufferPosition
SC_WORD_TYPE * DataBufferPosition
Pointer to the fetched memory content.
Definition: scHThread.h:92
CoreStage_t::OpCode
int8_t OpCode
The major operation code.
Definition: scHThread.h:75
tob_Allocated
@ tob_Allocated
The thread is allocated for another thread.
Definition: scHThread.h:49
CoreExecute_t::Stage
CoreStage_t Stage
Fetch related storage.
Definition: scHThread.h:105
tob_FetchValid
@ tob_FetchValid
If this thread has a valid prefetched instruction.
Definition: scHThread.h:57