d543c32f931650d791b8243c74466accd6b530ad
[IRC.git] / Robust / src / Runtime / bamboo / multicoreruntime.h
1 #ifndef BAMBOO_MULTICORE_RUNTIME_H
2 #define BAMBOO_MULTICORE_RUNTIME_H
3 #ifdef MULTICORE
4 #include "structdefs.h"
5 #include "multicore.h"
6 #include "multicoremsg.h"
7 #include "multicoremem.h"
8 #include "multicoretask.h"
9 #include "multicoremgc.h"
10 #include "multicorecache.h"
11
12 //Define the following line if the base object type has pointers
13 //#define OBJECTHASPOINTERS
14
15 #ifdef MULTICORE_GC
16 extern volatile bool gcflag;
17 #define GCCHECK(p) \
18   if(gcflag) gc(p)
19 #else
20 #define GCCHECK(p)
21 #endif // MULTICORE_GC
22
23 ////////////////////////////////////////////////////////////////
24 // global variables                                          //
25 ///////////////////////////////////////////////////////////////
26 // record the starting time
27 unsigned long long bamboo_start_time;
28 bool stall;
29 int totalexetime;
30 #ifndef INTERRUPT
31 bool reside;
32 #endif
33
34 /////////////////////////////////////////////////////////////////////////////////
35 // NOTE: BAMBOO_TOTALCORE -- number of the available cores in the processor.
36 //                           No greater than the number of all the cores in
37 //                           the processor
38 //       NUMCORES -- number of cores chosen to deploy the application. It can
39 //                   be greater than that required to fully parallelize the
40 //                   application. The same as NUMCORES.
41 //       NUMCORESACTIVE -- number of cores that really execute the
42 //                         application. No greater than NUMCORES
43 //       NUMCORES4GC -- number of cores for gc. No greater than NUMCORES.
44 //                      NOTE: currently only support ontinuous cores as gc
45 //                            cores, i.e. 0~NUMCORES4GC-1
46 ////////////////////////////////////////////////////////////////////////////////
47 // data structures of status for termination
48 // only check working cores
49 volatile int corestatus[NUMCORESACTIVE]; // records status of each core
50                                          // 1: running tasks
51                                          // 0: stall
52 volatile int numsendobjs[NUMCORESACTIVE]; // records how many objects a core
53                                           // has sent out
54 volatile int numreceiveobjs[NUMCORESACTIVE]; // records how many objects a
55                                              // core has received
56 volatile int numconfirm;
57 volatile bool waitconfirm;
58 bool busystatus;
59 int self_numsendobjs;
60 int self_numreceiveobjs;
61
62 /////////////////////////////////////////////////////////////
63
64 ////////////////////////////////////////////////////////////
65 // these are functions should be implemented in           //
66 // multicore runtime for any multicore processors         //
67 ////////////////////////////////////////////////////////////
68 void initCommunication(void);
69 void fakeExecution(void);
70 void terminate(void);
71 void initlock(struct ___Object___ * v);
72 #ifdef BAMBOO_MEMPROF
73 void terminatememprof(void);
74 #endif // BAMBOO_MEMPROF
75
76 ///////////////////////////////////////////////////////////
77
78 /////////////////////////////////////////////////////////////////////////////
79 // For each version of BAMBOO runtime, there should be a header file named //
80 // runtim_arch.h defining following MARCOS:                                //
81 // BAMBOO_NUM_OF_CORE: the # of current residing core                      //
82 // BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core        //
83 // BAMBOO_COORDS(c, x, y): convert the cpu # to coords (*x, *y)            //
84 // BAMBOO_COORDS_X(c): convert the cpu # to coords x                       //
85 // BAMBOO_COORDS_Y(c): convert the cpu # to coordsy                        //
86 // BAMBOO_DEBUGPRINT(x): print out integer x                               //
87 // BAMBOO_DEBUGPRINT_REG(x): print out value of variable x                 //
88 // BAMBOO_EXIT_APP(x): exit the whole application                          //
89 // BAMBOO_EXIT(x): error exit routine with file name and line #            //
90 // BAMBOO_DIE(x): error exit routine with error msg                        //
91 // BAMBOO_ASSERT(x) : check if condition x is met                          //
92 // BAMBOO_ASSERTMSG(x.y): check if condition x is met or not, if not, print//
93 //                        out msg y                                        //
94 // BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number       //
95 // BAMBOO_MSG_AVAIL(): checking if there are msgs coming in                //
96 // BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(): change to runtime mode from    //
97 //                                          client mode                    //
98 // BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(): change to client mode from     //
99 //                                          runtime mode                   //
100 // BAMBOO_ENTER_SEND_MODE_FROM_CLIENT(): change to send mode from          //
101 //                                       client mode                       //
102 // BAMBOO_ENTER_CLIENT_MODE_FROM_SEND(): change to client mode from        //
103 //                                       send mode                         //
104 // BAMBOO_ENTER_RUNTIME_MODE_FROM_SEND(): change to runtime mode from      //
105 //                                        send mode                        //
106 // BAMBOO_ENTER_SEND_MODE_FROM_RUNTIME(): change to send mode from         //
107 //                                        runtime mode                     //
108 // BAMBOO_WAITING_FOR_LOCK_I(): routine executed while waiting for lock    //
109 //                            request response                             //
110 // BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of  //
111 //                                whose size in bytes is y on local memory //
112 //                                which is given by the hypervisor         //
113 // BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory         //
114 // BAMBOO_LOCAL_MEM_CLOSE(): close the local heap                          //
115 // BAMBOO_LOCAL_MEM_CALLOC_S(x, y): allocate an array of x elements each of//
116 //                                  whose size in bytes is y on local      //
117 //                                  memory which is not from the hypervisor//
118 //                                  but is allocated from the free memory  //
119 // BAMBOO_LOCAL_MEM_FREE_S(x): free space with ptr x on self-allocated     //
120 //                             local memory                                //
121 // BAMBOO_LOCAL_MEM_CLOSE_S(): close the self-allocated local heap        //
122 // BAMBOO_SHARE_MEM_CALLOC_I(x, y): allocate an array of x elements each of//
123 //                                whose size in bytes is y on shared memory//
124 // BAMBOO_SHARE_MEM_CLOSE(): close the shared heap                         //
125 // BAMBOO_CACHE_LINE_SIZE: the cache line size                             //
126 // BAMBOO_CACHE_LINE_MASK: mask for a cache line                           //
127 // BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with     //
128 //                                 length y                                //
129 // BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary  //
130 // BAMBOO_MEMSET_WH(x, y, z): memset the specified region of memory (start //
131 //                            address x, size z) to value y with write     //
132 //                            hint, the processor will not fetch the       //
133 //                            current content of the memory and directly   //
134 //                            write                                        //
135 // BAMBOO_CLEAN_DTLB(): zero-out all the dtlb entries                      //
136 // BAMBOO_CACHE_FLUSH_L2(): Flush the contents of this tile's L2 back to   //
137 //                          main memory                                    //
138 // BAMBOO_CACHE_FLUSH_RANGE_NO_FENCE(x, y): flush a range of mem without   //
139 //                                          mem fence                      //
140 // BAMBOO_CACHE_MEM_FENCE_INCOHERENT(): fence to guarantee visibility of   //
141 //                                      stores to incoherent memory        //
142 /////////////////////////////////////////////////////////////////////////////
143
144 void handleReturnMem_I(unsigned int cnum, void *heaptop);
145 void handleReturnMem(unsigned int cnum, void *heaptop);
146 void run(int argc, char** argv);
147 void checkCoreStatus();
148 void getprofiledata_I();
149 void recordtotalexetime();
150 void disruntimedata();
151 void initruntimedata();
152 #endif  // #ifdef MULTICORE
153 #endif  // BAMBOO_MULTICORE_RUNTIME_H