Updates to support multicore version runtime of Tilera. Also fix a bug in BuildCodeMu...
[IRC.git] / Robust / src / Runtime / multicoreruntime.h
1 #ifndef MULTICORE_RUNTIME
2 #define MULTICORE_RUNTIME
3
4 ////////////////////////////////////////////////////////////////
5 // global variables                                          //
6 ///////////////////////////////////////////////////////////////
7
8 // data structures for msgs
9 int msgdata[30];
10 int msgtype;
11 int msgdataindex;
12 int msglength;
13 int outmsgdata[30];
14 int outmsgindex;
15 int outmsglast;
16 int outmsgleft;
17 bool isMsgHanging;
18 volatile bool isMsgSending;
19
20 // data structures of status for termination
21 int corestatus[NUMCORES]; // records status of each core
22                           // 1: running tasks
23                           // 0: stall
24 int numsendobjs[NUMCORES]; // records how many objects a core has sent out
25 int numreceiveobjs[NUMCORES]; // records how many objects a core has received
26 int numconfirm;
27 bool waitconfirm;
28 bool busystatus;
29 int self_numsendobjs;
30 int self_numreceiveobjs;
31
32 // data structures for locking
33 struct RuntimeHash locktable;
34 static struct RuntimeHash* locktbl = &locktable;
35 struct LockValue {
36         int redirectlock;
37         int value;
38 };
39 struct RuntimeHash * objRedirectLockTbl;
40 int lockobj;
41 int lock2require;
42 int lockresult;
43 bool lockflag;
44
45 // data structures for waiting objs
46 struct Queue objqueue;
47
48 // data structures for profile mode
49 #ifdef PROFILE
50
51 #define TASKINFOLENGTH 10000
52 //#define INTERRUPTINFOLENGTH 500
53
54 bool stall;
55 //bool isInterrupt;
56 int totalexetime;
57
58 typedef struct task_info {
59   char* taskName;
60   int startTime;
61   int endTime;
62   int exitIndex;
63   struct Queue * newObjs; 
64 } TaskInfo;
65
66 /*typedef struct interrupt_info {
67    int startTime;
68    int endTime;
69    } InterruptInfo;*/
70
71 TaskInfo * taskInfoArray[TASKINFOLENGTH];
72 int taskInfoIndex;
73 bool taskInfoOverflow;
74 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
75    int interruptInfoIndex;
76    bool interruptInfoOverflow;*/
77 int profilestatus[NUMCORES]; // records status of each core
78                              // 1: running tasks
79                              // 0: stall
80 #endif // #ifdef PROFILE
81
82 #ifndef INTERRUPT
83 bool reside;
84 #endif
85 /////////////////////////////////////////////////////////////
86
87 ////////////////////////////////////////////////////////////
88 // these are functions should be implemented in           //
89 // multicore runtime for any multicore processors         //
90 ////////////////////////////////////////////////////////////
91 #ifdef TASK
92 #ifdef MULTICORE
93 inline void initialization(void) __attribute__((always_inline));
94 inline void initCommunication(void) __attribute__((always_inline));
95 inline void fakeExecution(void) __attribute__((always_inline));
96 inline void terminate(void) __attribute__((always_inline));
97
98 inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
99 inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
100 inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
101 inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
102 inline void send_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
103 inline void send_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
104 inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
105 inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
106 inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
107 inline void cache_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
108 inline void transferObject(struct transObjInfo * transObj);
109 inline int receiveMsg(void) __attribute__((always_inline));
110
111 #ifdef PROFILE
112 inline void profileTaskStart(char * taskname) __attribute__((always_inline));
113 inline void profileTaskEnd(void) __attribute__((always_inline));
114 #endif  // #ifdef PROFILE
115 ///////////////////////////////////////////////////////////
116
117 //////////////////////////////////////////////////////////////////////////////////////
118 //  For each version of BAMBOO runtime, there should be a header file named        //
119 //  runtim_arch.h defining following MARCOS:                                       //
120 //  BAMBOO_TOTALCORE: the total # of cores available in the processor              //
121 //  BAMBOO_NUM_OF_CORE: the # of current residing core                             //
122 //  BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core               //
123 //  BAMBOO_DEBUGPRINT(x): print out integer x                                      //
124 //  BAMBOO_DEBUGPRINT_REG(x): print out value of variable x                        //
125 //  BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
126 //                                 size in bytes is y on local memory              //
127 //  BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
128 //                                 size in bytes is y on shared memory             //
129 //  BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE()                                      //
130 //  BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures    //
131 //                                             related to obj queue                //
132 //  BAMBOO_START_CRITICAL_SECTION_STATUS()                                         //
133 //  BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures       //
134 //                                          related to status data                 //
135 //  BAMBOO_START_CRITICAL_SECTION_MSG()                                            //
136 //  BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related  //
137 //                                       to msg data                               //
138 //  BAMBOO_START_CRITICAL_SECTION_LOCK()                                           //
139 //  BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
140 //                                        to lock table                            //
141 //  BAMBOO_START_CRITICAL_SECTION_MEM()                                            //
142 //  BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory               //
143 //  BAMBOO_START_CRITICAL_SECTION()                                                //
144 //  BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures          //
145 //  BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request     //
146 //                             response                                            //
147 //  BAMBOO_CACHE_LINE_SIZE: the cache line size                                    //
148 //  BAMBOO_CACHE_LINE_MASK: mask for a cache line                                  //
149 //  BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y   //
150 //  BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary         //
151 //  BAMBOO_EXIT(x): exit routine                                                   //
152 //  BAMBOO_MSG_AVAIL(): checking if there are msgs coming in                       //
153 //  BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number              //
154 /////////////////////////////////////////////////////////////////////////////////////
155
156 #endif  // #ifdef MULTICORE
157 #endif  // #ifdef TASK
158 #endif  // #ifndef MULTICORE_RUNTIME