2 Definitions for GUM i.e. running on a parallel machine.
4 This section contains definitions applicable only to programs compiled
5 to run on a parallel machine, i.e. on GUM. Some of these definitions
6 are also used when simulating parallel execution, i.e. on GranSim.
12 #if defined(PAR) || defined(GRAN) /* whole file */
15 * @node Parallel definitions, End of File
16 * @section Parallel definitions
19 * * Basic definitions::
24 * @node Basic definitions, GUM, Parallel definitions, Parallel definitions
25 * @subsection Basic definitions
28 /* This clashes with TICKY, but currently TICKY and PAR hate each other anyway */
29 #define _HS sizeofW(StgHeader)
31 /* SET_PAR_HDR and SET_STATIC_PAR_HDR now live in ClosureMacros.h */
33 /* Needed for dumping routines */
35 # define NODE_STR_LEN 20
36 # define TIME_STR_LEN 120
38 # define CURRENT_TIME (msTime() - startTime)
39 # define TIME_ON_PROC(p) (msTime() - startTime)
40 # define CURRENT_PROC thisPE
41 # define BINARY_STATS RtsFlags.ParFlags.ParStats.Binary
43 # define NODE_STR_LEN 20
44 # define TIME_STR_LEN 120
46 # define CURRENT_TIME CurrentTime[CurrentProc]
47 # define TIME_ON_PROC(p) CurrentTime[p]
48 # define CURRENT_PROC CurrentProc
49 # define BINARY_STATS RtsFlags.GranFlags.GranSimStats.Binary
53 # define MAX_PES 256 /* Maximum number of processors */
54 /* MAX_PES is enforced by SysMan, which does not
55 allow more than this many "processors".
56 This is important because PackGA [GlobAddr.lc]
57 **assumes** that a PE# can fit in 8+ bits.
60 # define SPARK_POOLS 2 /* no. of spark pools */
61 # define REQUIRED_POOL 0 /* idx of pool of mandatory sparks (concurrency) */
62 # define ADVISORY_POOL 1 /* idx of pool of advisory sparks (parallelism) */
71 * @node GUM, GranSim, Basic definitions, Parallel definitions
77 Symbolic constants for the packing code.
79 This constant defines how many words of data we can pack into a single
80 packet in the parallel (GUM) system.
91 * @node Types, Externs, GUM, GUM
92 * @subsubsection Types
95 /* Sparks and spark queues */
96 typedef StgClosure *rtsSpark;
97 typedef rtsSpark *rtsSparkQ;
99 typedef struct rtsPackBuffer_ {
101 StgInt /* nat */ size;
102 StgInt /* nat */ unpacked_size;
107 #define PACK_BUFFER_HDR_SIZE 4
110 * @node Externs, Prototypes, Types, GUM
111 * @subsubsection Externs
114 /* extern rtsBool do_sp_profile; */
116 extern globalAddr theGlobalFromGA, theGlobalToGA;
117 extern StgBlockedFetch *PendingFetches;
118 extern GlobalTaskId *allPEs;
120 extern rtsBool IAmMainThread, GlobalStopPending;
121 /*extern rtsBool fishing; */
122 extern rtsTime last_fish_arrived_at;
123 extern nat outstandingFishes;
124 extern GlobalTaskId SysManTask;
125 extern int seed; /* pseudo-random-number generator seed: */
126 /* Initialised in ParInit */
127 extern StgInt threadId; /* Number of Threads that have existed on a PE */
128 extern GlobalTaskId mytid;
130 extern GlobalTaskId *allPEs;
132 extern nat sparksIgnored, sparksCreated, threadsIgnored, threadsCreated;
133 extern nat advisory_thread_count;
135 extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
137 extern ullong startTime; /* start of comp; in RtsStartup.c */
139 /* the spark pools proper */
140 extern rtsSpark *pending_sparks_hd[]; /* ptr to start of a spark pool */
141 extern rtsSpark *pending_sparks_tl[]; /* ptr to end of a spark pool */
142 extern rtsSpark *pending_sparks_lim[];
143 extern rtsSpark *pending_sparks_base[];
144 extern nat spark_limit[];
146 extern rtsPackBuffer *PackBuffer; /* size: can be set via option */
147 extern rtsPackBuffer *buffer;
148 extern rtsPackBuffer *freeBuffer;
149 extern rtsPackBuffer *packBuffer;
150 extern rtsPackBuffer *gumPackBuffer;
155 extern GALA *freeGALAList;
156 extern GALA *freeIndirections;
157 extern GALA *liveIndirections;
158 extern GALA *liveRemoteGAs;
162 * @node Prototypes, Macros, Externs, GUM
163 * @subsubsection Prototypes
167 void initParallelSystem(void);
168 void SynchroniseSystem(void);
169 void par_exit(StgInt n);
171 PEs taskIDtoPE (GlobalTaskId gtid);
172 void registerTask (GlobalTaskId gtid);
173 globalAddr *LAGAlookup (StgClosure *addr);
174 StgClosure *GALAlookup (globalAddr *ga);
175 /*static GALA *allocIndirection (StgPtr addr); */
176 globalAddr *makeGlobal (StgClosure *addr, rtsBool preferred);
177 globalAddr *setRemoteGA (StgClosure *addr, globalAddr *ga, rtsBool preferred);
178 void splitWeight (globalAddr *to, globalAddr *from);
179 globalAddr *addWeight (globalAddr *ga);
180 void initGAtables (void);
181 void RebuildLAGAtable (void);
182 StgWord PackGA (StgWord pe, int slot);
186 /* highest_slot breaks the abstraction of the slot counter for GAs; it is
187 only used for sanity checking and should used nowhere else */
188 StgInt highest_slot (void);
192 * @node Macros, , Prototypes, GUM
193 * @subsubsection Macros
196 /* delay (in us) between dying fish returning and sending out a new fish */
197 #define FISH_DELAY 1000
198 /* max no. of outstanding spark steals */
201 /* ToDo: check which of these is actually needed! */
203 # define PACK_HEAP_REQUIRED ((RtsFlags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _HS) * (MIN_UPD_SIZE + 2))
205 # define MAX_GAS (RtsFlags.ParFlags.packBufferSize / PACK_GA_SIZE)
208 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
209 /* Size of a packed fetch-me in words */
210 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + _HS)
212 # define PACK_HDR_SIZE 1 /* Words of header in a packet */
214 # define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
217 Definitions relating to the entire parallel-only fixed-header field.
219 On GUM, the global addresses for each local closure are stored in a
220 separate hash table, rather then with the closure in the heap. We call
221 @getGA@ to look up the global address associated with a local closure (0
222 is returned for local closures that have no global address), and @setGA@
223 to store a new global address for a local closure which did not
224 previously have one. */
226 # define GA_HDR_SIZE 0
228 # define GA(closure) getGA(closure)
230 # define SET_GA(closure, ga) setGA(closure,ga)
231 # define SET_STATIC_GA(closure)
232 # define SET_GRAN_HDR(closure,pe)
233 # define SET_STATIC_PROCS(closure)
235 # define MAX_GA_WEIGHT 0 /* Treat as 2^n */
237 /* At the moment, there is no activity profiling for GUM. This may change. */
238 # define SET_TASK_ACTIVITY(act) /* nothing */
241 The following macros are only needed for sanity checking (see Sanity.c).
244 /* NB: this is PVM specific and should be updated for MPI etc
245 in PVM a task id (tid) is split into 2 parts: the id for the
246 physical processor it is running on and an index of tasks running
247 on a processor; PVM_PE_MASK indicates which part of a tid holds the
248 id of the physical processor (the other part of the word holds the
249 index on that processor)
250 MAX_PVM_PES and MAX_PVM_TIDS are maximal values for these 2 components
251 in GUM we have an upper bound for the total number of PVM PEs allowed:
252 it's MAX_PE defined in Parallel.h
253 to check the slot field of a GA we call a fct highest_slot which just
254 returns the internal counter
256 #define PVM_PE_MASK 0xfffc0000
257 #define MAX_PVM_PES MAX_PES
258 #define MAX_PVM_TIDS MAX_PES
261 #define LOOKS_LIKE_TID(tid) (((tid & PVM_PE_MASK) != 0) && \
262 (((tid & PVM_PE_MASK) + (tid & ~PVM_PE_MASK)) < MAX_PVM_TIDS))
263 #define LOOKS_LIKE_SLOT(slot) (slot<=highest_slot())
265 #define LOOKS_LIKE_GA(ga) (LOOKS_LIKE_TID((ga)->payload.gc.gtid) && \
266 LOOKS_LIKE_SLOT((ga)->payload.gc.slot))
268 rtsBool looks_like_tid(StgInt tid);
269 rtsBool looks_like_slot(StgInt slot);
270 rtsBool looks_like_ga(globalAddr *ga);
271 #define LOOKS_LIKE_TID(tid) looks_like_tid(tid)
272 #define LOOKS_LIKE_GA(ga) looks_like_ga(ga)
278 * @node GranSim, , GUM, Parallel definitions
279 * @subsection GranSim
283 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
292 * @node Types, Prototypes, GranSim, GranSim
293 * @subsubsection Types
296 typedef StgWord *StgBuffer;
297 typedef struct rtsPackBuffer_ {
299 StgInt /* nat */ size;
300 StgInt /* nat */ unpacked_size;
306 * @node Macros, , Prototypes, GranSim
307 * @subsubsection Macros
310 /* max no. of outstanding spark steals */
313 /* These are needed in the packing code to get the size of the packet
314 right. The closures itself are never built in GrAnSim. */
315 # define FETCHME_VHS IND_VHS
316 # define FETCHME_HS IND_HS
318 # define FETCHME_GA_LOCN FETCHME_HS
320 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
321 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
322 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
324 # define MAX_GAS (RtsFlags.GranFlags.packBufferSize / PACK_GA_SIZE)
325 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
326 /* Size of a packed fetch-me in words */
327 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + _HS)
328 # define PACK_HDR_SIZE 4 /* Words of header in a packet */
330 # define PACK_HEAP_REQUIRED \
331 (RtsFlags.GranFlags.packBufferSize * sizeofW(StgClosure*) + \
332 2 * sizeofW(StgInt) + sizeofW(StgTSO*))
334 # define PACK_FLAG_LOCN 0
335 # define PACK_TSO_LOCN 1
336 # define PACK_UNPACKED_SIZE_LOCN 2
337 # define PACK_SIZE_LOCN 3
338 # define MAGIC_PACK_FLAG 0xfabc
340 # define GA_HDR_SIZE 1
342 # define PROCS_HDR_POSN PAR_HDR_POSN
343 # define PROCS_HDR_SIZE 1
345 /* Accessing components of the field */
346 # define PROCS(closure) ((closure)->header.gran.procs)
347 /* SET_PROCS is now SET_GRAN_HEADER in ClosureMacros.h. */
352 * @node End of File, , Parallel definitions
353 * @section End of File
356 #endif /* defined(PAR) || defined(GRAN) whole file */
358 #endif /* Parallel_H */