fix bugs in multicore version runtime
[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 shared memory allocation
49 bool smemflag;
50 struct bamboo_shared_mem {
51         mspace msp;
52         struct bamboo_shared_mem * next;
53 };
54 struct bamboo_smem_list {
55         struct bamboo_shared_mem * head;
56         struct bamboo_shared_mem * tail;
57 };
58 struct bamboo_smem_list * bamboo_free_msps;
59 mspace bamboo_cur_msp;
60 int bamboo_smem_size;
61
62 // data structures for profile mode
63 #ifdef PROFILE
64
65 #define TASKINFOLENGTH 10000
66 //#define INTERRUPTINFOLENGTH 500
67
68 bool stall;
69 //bool isInterrupt;
70 int totalexetime;
71
72 typedef struct task_info {
73   char* taskName;
74   unsigned long long startTime;
75   unsigned long long endTime;
76   unsigned long long exitIndex;
77   struct Queue * newObjs; 
78 } TaskInfo;
79
80 /*typedef struct interrupt_info {
81    int startTime;
82    int endTime;
83    } InterruptInfo;*/
84
85 TaskInfo * taskInfoArray[TASKINFOLENGTH];
86 int taskInfoIndex;
87 bool taskInfoOverflow;
88 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
89    int interruptInfoIndex;
90    bool interruptInfoOverflow;*/
91 int profilestatus[NUMCORES]; // records status of each core
92                              // 1: running tasks
93                              // 0: stall
94 #endif // #ifdef PROFILE
95
96 #ifndef INTERRUPT
97 bool reside;
98 #endif
99 /////////////////////////////////////////////////////////////
100
101 ////////////////////////////////////////////////////////////
102 // these are functions should be implemented in           //
103 // multicore runtime for any multicore processors         //
104 ////////////////////////////////////////////////////////////
105 #ifdef TASK
106 #ifdef MULTICORE
107 inline void initialization(void) __attribute__((always_inline));
108 inline void initCommunication(void) __attribute__((always_inline));
109 inline void fakeExecution(void) __attribute__((always_inline));
110 inline void terminate(void) __attribute__((always_inline));
111
112 inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
113 inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
114 inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
115 inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
116 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));
117 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));
118 inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
119 inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
120 inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
121 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));
122 inline void transferObject(struct transObjInfo * transObj);
123 inline int receiveMsg(void) __attribute__((always_inline));
124
125 #ifdef PROFILE
126 inline void profileTaskStart(char * taskname) __attribute__((always_inline));
127 inline void profileTaskEnd(void) __attribute__((always_inline));
128 void outputProfileData();
129 #endif  // #ifdef PROFILE
130 ///////////////////////////////////////////////////////////
131
132 //////////////////////////////////////////////////////////////////////////////////////
133 //  For each version of BAMBOO runtime, there should be a header file named        //
134 //  runtim_arch.h defining following MARCOS:                                       //
135 //  BAMBOO_TOTALCORE: the total # of cores available in the processor              //
136 //  BAMBOO_NUM_OF_CORE: the # of current residing core                             //
137 //  BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core               //
138 //  BAMBOO_DEBUGPRINT(x): print out integer x                                      //
139 //  BAMBOO_DEBUGPRINT_REG(x): print out value of variable x                        //
140 //  BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
141 //                                 size in bytes is y on local memory              //
142 //  BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
143 //                                 size in bytes is y on shared memory             //
144 //  BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE()                                      //
145 //  BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures    //
146 //                                             related to obj queue                //
147 //  BAMBOO_START_CRITICAL_SECTION_STATUS()                                         //
148 //  BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures       //
149 //                                          related to status data                 //
150 //  BAMBOO_START_CRITICAL_SECTION_MSG()                                            //
151 //  BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related  //
152 //                                       to msg data                               //
153 //  BAMBOO_START_CRITICAL_SECTION_LOCK()                                           //
154 //  BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
155 //                                        to lock table                            //
156 //  BAMBOO_START_CRITICAL_SECTION_MEM()                                            //
157 //  BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory               //
158 //  BAMBOO_START_CRITICAL_SECTION()                                                //
159 //  BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures          //
160 //  BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request     //
161 //                             response                                            //
162 //  BAMBOO_CACHE_LINE_SIZE: the cache line size                                    //
163 //  BAMBOO_CACHE_LINE_MASK: mask for a cache line                                  //
164 //  BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y   //
165 //  BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary         //
166 //  BAMBOO_EXIT(x): exit routine                                                   //
167 //  BAMBOO_MSG_AVAIL(): checking if there are msgs coming in                       //
168 //  BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number              //
169 /////////////////////////////////////////////////////////////////////////////////////
170
171 #endif  // #ifdef MULTICORE
172 #endif  // #ifdef TASK
173 #endif  // #ifndef MULTICORE_RUNTIME