Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
scGate2Input.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 scGate2Input_h
10 #define scGate2Input_h
11 
12 
13 // These macros are used for benchmarking
14 // The work storage variable are defined as member functions, at the end
15 // Reset is done in constructor; the sum is collected and may be read in destructor
16 // The work storage also usable in derived classes
17 #define MAKE_TIME_BENCHMARKING // uncomment to measure the time with benchmarking macros
18 #include "MacroTimeBenchmarking.h" // Must be after the define to have its effect
19 #define SC_MAKE_TIME_BENCHMARKING // uncomment to measure the time with benchmarking macros
20 #include "MacroScTimeBenchmarking.h" // Must be after the define to have its effect
21 
22 //class scGridPoint;
23 #include "scGridPoint.h"
24 class scGatesProcessor;
25 //extern string sc_time_to_nsec_Get(const int d, const int w, sc_time T);
26 
52 class scGate2Input : public scGridPoint
53 {
54  // friend class scHThread;
55 public:
56 
57 
58  //Channel/Submodule* definitions
59  // TLM-2 socket, defaults to 32-bits wide, base protocol
60  // TLM-2 blocking transport method
61  //virtual
62 // void ICB_b_transport(const ClusterNeighbor Index, unsigned char* data, const int size );
63 
64  // Constructor declaration:
72  scGate2Input(sc_core::sc_module_name nm, // Just the SystemC name
73  scGatesProcessor* Processor, // The present system is prepared for one processor only, but ...
74  const GridPoint GP
75  , bool StandAlone
76  );
77  ~scGate2Input();//{}
78  SC_HAS_PROCESS(scGate2Input); // We have the constructor in the .cpp file
79 
80  struct{
81  sc_core::sc_event
82  InputChanged // One of the inputs changed, recalculate output
83  ;
84  }EVENT_GATE; //< These events are handled at gridpoint level
85  void
86  Reset(void);
87 };
88 #if 0
89  // Group dealing with identification
90  // The physical ID and the corresponding mask cannot be changed
91 /* SC_GRIDPOINT_ID_TYPE
92  FETCHID_Get(void){ return msFETCHTHREADID;} ///< Get internal ID (sequence number) of the scGridPoint
93  SC_GRIDPOINT_ID_TYPE
94  EXECHID_Get(void){ return msEXECTHREADID;} ///< Get internal ID (sequence number) of the scGridPoint
95  */
96  SC_GRIDPOINT_ID_TYPE
97  ID_Get(){return msID;}
98  SC_GRIDPOINT_MASK_TYPE
99  IDMask_Get(void){ return msMask.ID;}
100  // Directly HW-related functionality
101  string
102  Name_Get(void){ return string(name());}
103 
104  void
105  AddHThread(unsigned int H, scHThread* P)
106  { assert(P);
107  assert(H<MAX_HTHREADS);
108  mHThreads[H] = P;}
109  scHThread*
110  AllocateAHThread(void);
111  virtual void
112  CreateThreads(void);
113 
114 
115  void
116  ResetForParent(scGridPoint* Parent);
117  bool
118  Deallocate(void);
119  void
120  RouteMessage(scIGPMessage* Message);
121  void
122  SendDirectMessageTo(scGridPoint* Target, scIGPMessage* Message);
123  scGridPoint*
124  Parent_Get(void) { return msParent;}
125  void
126  Parent_Set(scGridPoint *P) { msParent = P;}
127  // Implement the inter-gridpoint direct and inter-cluster bus communication
128  scIGPCB*
129  IGPCB_Get(ClusterNeighbor index)
130  {
131  assert(!(index<cm_Head || index>=cm_Broadcast));
132  return msIGPCB[index];
133  }
134  scIGPCB*
135  msIGPCB[7]; // The Inter-scGridPoint facilities from (!) Head to NW
136  SC_WORD_TYPE
137  Register_Get(int R){ return HThreadExec_Get()->Register_Get(R);}
138  // direct Slave Interface; mainly for testing without the bus
139  bool
140  direct_read(int *data, unsigned int address);
141  bool
142  direct_write(int *data, unsigned int address);
143  bool
144  direct_read(scIGPMessage* M);
145  bool
146  direct_write(scIGPMessage* M);
147 
148  // Slave Interface, through the bus
149  ClusterBusStatus
150  read(int *data, unsigned int address){return CLUSTER_BUS_OK;}
151  ClusterBusStatus
152  write(int *data, unsigned int address){return CLUSTER_BUS_OK;}
153  ClusterBusStatus
154  read(scIGPMessage* M);
155  ClusterBusStatus
156  write(scIGPMessage* M);
157 
158  // State-bits-related functionality
159  void
160  AllocatedBit_Set(bool V=true);
161  bool
162  AllocatedBit_Get(void) { return msStatus.Allocated;}
163  void
164  PreAllocatedBit_Set(bool V=true);
165  bool // The GridPoints can have own preallocated GridPoints; must be administered both here and at Topology level
166  PreAllocatedBit_Get(void){ return msStatus.PreAllocated;}
167  void
168  DeniedBit_Set(bool P=true);
169  bool
170  DeniedBit_Get(void)
171  { return msStatus.Denied;}
172  bool
173  AvailableBit_Get(void)
174  { return msStatus.Available;}
175  void
176  MetaBit_Set(bool P=true);
177  bool
178  MetaBit_Get(void){ return msStatus.Meta;}
179  void
180  WaitBit_Set(bool P=true);
181  bool
182  WaitBit_Get(void){ return msStatus.Wait;}
183  bool
184  IsAvailable(void)
185  { return AvailableBit_Get();}
186  bool
187  IsAllocated(void) { return AllocatedBit_Get();}
188  bool
189  IsPreAllocated(void) { return PreAllocatedBit_Get();}
190  bool
191  IsDenied(void) { return DeniedBit_Get();}
192  bool
193  IsWaiting(void) { return msStatus.Wait;}
194  struct{
195  sc_core::sc_event
196 // TIMEOUT // The required timeout is over
197 // ,
198  MakeFetch, FetchReady // These event signals the begin and end of the instruction fetch process
199  ,MakeExec, ExecReady // These event signals the begin and end of the instruction execute process
200  ,TransportedToIGPCB // No dedicated method, just wait after sending the message
201  ,SIGNAL_StateBit
202  ,Msg_Reg_Received // The core received a register-type message
203  ,Msg_Qt_Received // The core received a QT-type message
204  ,Msg_Mem_Received // The core received a memory-type message
205  ;
206  }EVENT_GRID; //< These events are handled at gridpoint level
208 // ,NEXT // The required action is carrried ot, may take the next one
209 
210  string
211  StringOfMemoryAddress_Get(void)
212  {
213  ostringstream oss;
214  oss << "0x" << hex << std::setfill('0') << std::setw((FMEMORY_ADDRESS_WIDTH+3)/4) << msMemoryAddress << dec;
215  return oss.str();
216  }
217  // Return a hexa word dscribing the status
218  string
219  StringOfMessage_Get(scIGPMessage* Message);
220 
221  string
222  StringOfStatus_Get(void)
223  {
224  ostringstream oss;
225  oss << "0x" << hex << std::setfill('0') << std::setw(4) << mStatus << dec;
226  return oss.str();
227  }
232  string
233  StringOfClusterAddress_Get(void);
238  void
239  SIGNAL_method(void);
240  void
241  doWriteSignals(void);
242  SC_GRIDPOINT_MASK_TYPE
243  PreAllocatedMask_Get(void);
244  bool
245  PreAllocatedMask_Set(SC_GRIDPOINT_MASK_TYPE Mask);
246  virtual void
247  ProcessMessage(scIGPMessage* Message);
248 
249  void
250  ChildrenMaskBit_Set(scGridPoint* C);
251  void
252  ChildrenMaskBit_Clear( scGridPoint* C);
253  SC_GRIDPOINT_MASK_TYPE
254  ChildrenMask_Get(void) { return msMask.Children;}
255  void
256  ChildrenMask_Set(SC_GRIDPOINT_MASK_TYPE M) { msMask.Children = M;}
257 
258  SC_HTHREAD_MASK_TYPE
259  HThreadsMask_Get(void){SC_HTHREAD_MASK_TYPE MyMask =(int16_t)(msMask.AllocatedHThreads).to_ulong();
260  return MyMask;}
261 
262  void
263  PreAllocatedMaskBit_Set(scGridPoint* C, bool V=true);
264  bool
265  IsPreAllocatedFor(scGridPoint* C);
266  virtual bool
267  IsMorphingInstructionFetched(scHThread* H){return true;}
268  // Bits directly handling signals
269  uint32_t readDataMem(uint32_t addr, int size);
270  void
271  HandleSuspending(void);
277  scHThread*
278  HThread_Get(SC_HTHREAD_ID_TYPE H)
279  { assert((H>=0) && (H<MAX_HTHREADS));
280  return mHThreads[H];}
281 /* void
282  HThread_Set(SC_HTHREAD_ID_TYPE H){ assert((H>=0) && (H<MAX_HTHREADS)); mHThread = mHThreads[H];}/// Set the actual HThread
283 */
284  scHThread*
285  HThreadExec_Get(void) { //assert(mHThreadExec);
286  return mHThreadExec;}
287  scHThread*
288  HThreadFetch_Get(void) { //assert(mHThreadFetch);
289  return mHThreadFetch;}
290  void
291  HThreadExec_Set(scHThread* H){mHThreadExec = H; }
292  void
293  HThreadFetch_Set(scHThread* H){mHThreadFetch = H; }
298  CooperationMode_Get(void) { return msCooperationMode;}
299  void
300  CooperationMode_Set(core_cooperationmode_t M) { msCooperationMode = M;}
301  string
302  PrologString_Get(void);
303  void
304  MemoryAddress_Set(SC_ADDRESS_TYPE MA) { msMemoryAddress = MA;}
305  SC_ADDRESS_TYPE
306  QTOffset_Get(SC_HTHREAD_ID_TYPE H)
307  { assert((H>=0)&(H<MAX_HTHREADS)); return mHThreads[H]->QTOffset_Get();}
308  string
309  StringOfQT_Get(SC_HTHREAD_ID_TYPE H)
310  { assert((H>=0)&(H<MAX_HTHREADS)); return mHThreads[H]->StringOfQT_Get();}
311 
312  bool
313  CatchedAllocationError(scGridPoint* Parent);
314  scGridPoint*
315  AllocateFor(scGridPoint* Parent);
316  scGridPoint*
317  PreAllocateFor(scGridPoint* Parent);
318 
319  scIGPMessage*
320  CreateRegisterMessageTo(scGridPoint* To, SC_GRIDPOINT_MASK_TYPE Mask);
330  scIGPMessage*
331  CreateQtCreateMessageTo(scGridPoint* To, SC_ADDRESS_TYPE PC, SC_GRIDPOINT_MASK_TYPE Mask, SC_GRIDPOINT_MASK_TYPE BackMask);
332  scIGPMessage*
333  CreateQtKillMessageTo(scGridPoint* To);
334  scIGPMessage*
335  CreateSpecialMessageTo(scGridPoint* To, int16_t Key, int8_t RegNo, int32_t R);
336  void
337  Status_Set(uint16_t S) {mStatus = S;}
338  uint16_t
339  Status_Get(void) { return mStatus;}
340  void
341  ConnectToClusterBus(scClusterBus* ClusterBus); // Connect this gridpoint to the inter-cluster bus
342  scIGPMessage*
343  CreateMemoryReadMessage(unsigned int Address, int Length);
344  scIGPMessage*
345  CreateMemoryWriteMessage(unsigned int Address, int Length);
346  int32_t
347  FlagWordLength_Get(void) {return 0;}
348  int32_t
349  ConditionCode_Get(void) {return 0;}
350  void
351  ConditionCode_Set(int32_t C){}
352  SC_GRIDPOINT_MASK_TYPE
353  doWaitMask_Get(SC_ADDRESS_TYPE Offset);
354  virtual scGridPoint*
355  doFindHostToProcess(SC_ADDRESS_TYPE Offs, SC_GRIDPOINT_MASK_TYPE Mask);
356  bool
357  doCanTerminate( SC_GRIDPOINT_MASK_TYPE Address);
358  virtual void
359  doCreateQT(scIGPMessage* Message){};
360  bool
361  doProcessMMessage(scIGPMessage* Message);
362  virtual bool
363  doProcessQMessage(scIGPMessage* Message);
364  bool
365  doProcessRMessage(scIGPMessage* Message);
372  virtual void
373  doSetQTAddresses(scGridPoint* Parent)
374  { }
375 
376  virtual void
377  doSkipQTCode(void){}
378 /* SC_ADDRESS_TYPE
379  PC_Get() { return exec.PC;}
380  void
381  PC_Set(SC_ADDRESS_TYPE P) {exec.PC = P;}
382  void
383  fetchNewPC_Set(SC_ADDRESS_TYPE PC){ fetch.NewPC = PC;} ///< Set the PC of the core for fetching the next instruction
384  SC_ADDRESS_TYPE
385  fetchPC_Get(void) {return fetch.PC;} ///< Get PC of the core where the instruction is/was fetched
386  void
387  fetchPC_Set(SC_ADDRESS_TYPE PC){ fetch.PC = PC;} ///< Set PC of the core where the instruction will be fetched
388 */
393  void
394  FETCH_thread();
400  virtual bool
401  doFetchInstruction(scHThread* H);
406  void
407  EXEC_thread();
413  virtual bool
414  doExecInstruction(scHThread* H);
415  void NotifyThreadOnMemoryArrival()
416  { mHThreadFetch->EVENT_HTHREAD.MemoryContentArrived.notify();}
417 
418  // It is administered in the scGridPoint if a HThread is allocated
419  void
420  HThreadAllocatedBit_Set(SC_HTHREAD_ID_TYPE H, bool B)
421  { assert(H < MAX_HTHREADS); msMask.AllocatedHThreads[H] = B;}
422  bool
423  HThreadAllocatedBit_Get(SC_HTHREAD_ID_TYPE H)
424  { assert(H < MAX_HTHREADS); return msMask.AllocatedHThreads[H];}
425 
426 
427  bool
428  OperatingBit_Get(GridPointOperatingBit_t B);
429  bool
430  OperatingGroup_Get(GridPointOperatingBit_t G);
431  int OperatingBits_Get(void){return mGridPointOperatingStateBit.to_ulong();}
432  bool IsObserved(void)
433  {return mObservedHThreads;}
434  void
435  ObservedHThreadBit_Set(SC_HTHREAD_MASK_TYPE M, bool B);
436  protected:
437  SC_HTHREAD_MASK_TYPE
438  mObservedHThreads;
439  int16_t
440  InstanceCount_Get(void) {return mInstanceCount % 50;}
441 
450  scIGPMessage*
451  CreateMessageTo(scGridPoint* To, IGPMessageType Type, int Length);
452  void
453  AvailableBit_Set(void);
454  void
455  SleepingBit_Set(void);
456  void
457  SetupMessageAddressTo(scGridPoint* GP);
458 
459  SC_GRIDPOINT_ID_TYPE
460  msID;
461 /* SC_HTHREAD_ID_TYPE
462  msFETCHTHREADID, msEXECTHREADID;*/
463  scHThread*
464  mHThreadFetch, *mHThreadExec;
465 /* scHThread*
466  mHThread; /// The actual scHThread
467  */
468  scGridPoint*
469  msParent;
471  msStatus;
473  msSignal;
475  msMask;
476  RegisterLatch_fifo*
477  msRegisterLatch;
478  bool
479  msIsSending;
480  SC_ADDRESS_TYPE
481  msMemoryAddress;
482  SC_ADDRESS_TYPE
483  msWaitOffset; // The offset of the QT we are waiting for
484  sc_time
485  msWaitBegin;
486 
492 // int32_t mMemoryBuffer[MAX_HTHREADS_LIMIT][MAX_IGPCBUFFER_SIZE];
493  // Simple accessor functions
495  msCooperationMode;
496  uint16_t
497  mInstanceCount; // How many times this object was instantiated
498  scHThread*
499  mHThreads[MAX_HTHREADS];
500  void OperatingGroup_Set(GridPointOperatingBit_t G, bool B);
501  void OperatingBit_Set(GridPointOperatingBit_t B, bool V);
502  protected:
503  // -- These bits are used in monitoring (by the simulator) gridpoint
504  std::bitset<gob_Max>
505  mGridPointOperatingStateBit;
506  // -- These variables are used to benchmark the running time spent in the objects
507  chrono::steady_clock::time_point
508  m_running_time; // A work variable, do not touch outside the macros
509  std::chrono::duration< int64_t, nano>
510  m_part_time, m_sum_time; // Work variables, contain actual benchmark duration and their sum
511 
512 }; // of scGridPoint
513 #endif //0
514 #endif // scGate2Input_h
515 
scGatesProcessor
This is a processor class comprising communicating scGridPoint classes. Comprises and handles the scG...
Definition: scGatesProcessor.h:108
cm_Broadcast
@ cm_Broadcast
All cluster members (broadcast)
Definition: Clustering.h:42
GridPoint
This class handles the topological information for the modules. Provides a lot of math-only utility f...
Definition: GridPoint.h:33
scGridPoint.h
Function prototypes for the scEMPA simulator, Core.
GridPointSignal_t
The signals issued by the scGridPoint.
Definition: scGridEnumTypes.h:92
scIGPMessage
The scIGPMessage class.
Definition: scIGPMessage.h:97
scHThread
The scHThread class.
Definition: scHThread.h:138
GridPointMask_t
The set of scGridPoint objects can be defined by by a mask word, the bits corresponding to single mod...
Definition: scGridEnumTypes.h:156
core_cooperationmode_t
core_cooperationmode_t
Codes of mass processing operating modes.
Definition: scGridEnumTypes.h:174
GridPointOperatingBit_t
GridPointOperatingBit_t
the names of the bits in the bitset for operating them
Definition: scGridEnumTypes.h:23
ClusterNeighbor
ClusterNeighbor
The neighborship in the cluster: the members are referred to with their geographic direction.
Definition: Clustering.h:34
scGridPoint
This class implements the autonomous grid point functionality: it is a communicating GridPoint....
Definition: scGridPoint.h:127
GridPointStatusBit_t
The values are stored here, and set through writing into GridPointStatusBitSignal_t.
Definition: scGridEnumTypes.h:113
scGate2Input
This class implements a 2-input gate object, mainly to demonstrate how tho use the system for electro...
Definition: scGate2Input.h:52
scGate2Input::scGate2Input
scGate2Input(sc_core::sc_module_name nm, scGatesProcessor *Processor, const GridPoint GP, bool StandAlone)
scGridPoint Creates simple gate with 2 inputs for Processor at position GP, with name nm
IGPMessageType
The basic message types of scIGPMessage messages.