2 % (c) Kevin Hammond, Parade/AQUA Projects, Glasgow University, February 15th. 1995
4 % This is for GUM only.
6 %************************************************************************
8 \section[Parallel.lh]{Definitions for parallel machines}
10 %************************************************************************
12 Multi-slurp protection:
18 This section contains definitions applicable only to programs compiled
19 to run on a parallel machine. Some of these things can probably be
20 ripped out now that we don't store GAs in closures, but beware that
21 this {\em might} break GranSim, so check first! KH
23 These basic definitions need to be around, one way or the other:
25 #define PAR_FIXED_HDR (GA_HDR_SIZE)
26 #define PAR_HDR_POSN AFTER_INFO_HDR
27 #define AFTER_PAR_HDR (PAR_HDR_POSN+PAR_FIXED_HDR)
29 #define SET_PAR_HDR(closure,ga) /* nothing */
30 #define SET_STATIC_PAR_HDR(closure) /* nothing */
35 # define MAX_PES 256 /* Maximum number of processors */
36 /* MAX_PES is enforced by SysMan, which does not
37 allow more than this many "processors".
38 This is important because PackGA [GlobAddr.lc]
39 **assumes** that a PE# can fit in 8+ bits.
42 extern I_ do_sp_profile;
44 extern P_ PendingFetches;
45 extern GLOBAL_TASK_ID *PEs;
47 extern rtsBool IAmMainThread, GlobalStopPending;
48 extern rtsBool fishing;
49 extern GLOBAL_TASK_ID SysManTask;
50 extern int seed; /*pseudo-random-number generator seed:*/
51 /*Initialised in ParInit*/
52 extern I_ threadId; /*Number of Threads that have existed on a PE*/
53 extern GLOBAL_TASK_ID mytid;
57 extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
59 extern HashTable *pGAtoGALAtable;
60 extern HashTable *LAtoGALAtable;
61 extern GALA *freeIndirections;
62 extern GALA *liveIndirections;
63 extern GALA *freeGALAList;
64 extern GALA *liveRemoteGAs;
67 void RunParallelSystem PROTO((StgPtr program_closure));
68 void initParallelSystem(STG_NO_ARGS);
69 void SynchroniseSystem(STG_NO_ARGS);
71 void registerTask PROTO((GLOBAL_TASK_ID gtid));
72 globalAddr *LAGAlookup PROTO((P_ addr));
73 P_ GALAlookup PROTO((globalAddr *ga));
74 globalAddr *MakeGlobal PROTO((P_ addr, rtsBool preferred));
75 globalAddr *setRemoteGA PROTO((P_ addr, globalAddr *ga, rtsBool preferred));
76 void splitWeight PROTO((globalAddr *to, globalAddr *from));
77 globalAddr *addWeight PROTO((globalAddr *ga));
78 void initGAtables(STG_NO_ARGS);
79 W_ taskIDtoPE PROTO((GLOBAL_TASK_ID gtid));
80 void RebuildLAGAtable(STG_NO_ARGS);
82 void *lookupHashTable PROTO((HashTable *table, StgWord key));
83 void insertHashTable PROTO((HashTable *table, StgWord key, void *data));
84 void freeHashTable PROTO((HashTable *table, void (*freeDataFun) PROTO((void *data))));
85 HashTable *allocHashTable(STG_NO_ARGS);
86 void *removeHashTable PROTO((HashTable *table, StgWord key, void *data));
88 extern void myexit PROTO((I_));
90 # define exit : error : Wrong exit!
97 %************************************************************************
99 \subsection[anti-parallel-SM]{But if we're {\em not} compiling for a parallel system...}
101 %************************************************************************
103 Get this out of the way. These are all null definitions.
106 # if !(defined(GRAN) || defined(PAR))
108 # define GA_HDR_SIZE 0
109 # define GA(closure) /*nothing*/
111 # define SET_GA(closure,ga) /* nothing */
112 # define SET_STATIC_GA(closure) /* nothing */
113 # define SET_GRAN_HDR(closure,pe) /* nothing */
114 # define SET_STATIC_PROCS(closure) /* nothing */
116 # define SET_TASK_ACTIVITY(act) /* nothing */
122 # define GA_HDR_SIZE 1
124 # define PROCS_HDR_POSN PAR_HDR_POSN
125 # define PROCS_HDR_SIZE 1
127 /* Accessing components of the field */
128 # define PROCS(closure) (*((P_)(closure)+PROCS_HDR_POSN))
130 # define SET_PROCS(closure, procs) \
131 PROCS(closure) = (W_)(procs) /* Set closure's location */
132 # define SET_GRAN_HDR(closure,pe) SET_PROCS(closure,pe)
134 # define SET_STATIC_PROCS(closure) , (W_) (Everywhere)
136 # define SET_TASK_ACTIVITY(act) /* nothing */
140 %************************************************************************
142 \subsection[parallel-GAs]{Parallel-only part of fixed headers (global addresses)}
144 %************************************************************************
146 Definitions relating to the entire parallel-only fixed-header field.
148 On GUM, the global addresses for each local closure are stored in a separate
149 hash table, rather then with the closure in the heap. We call @getGA@ to
150 look up the global address associated with a local closure (0 is returned
151 for local closures that have no global address), and @setGA@ to store a new
152 global address for a local closure which did not previously have one.
157 # define GA_HDR_SIZE 0
159 # define GA(closure) getGA(closure)
161 # define SET_GA(closure, ga) setGA(closure,ga)
162 # define SET_STATIC_GA(closure)
163 # define SET_GRAN_HDR(closure,pe)
164 # define SET_STATIC_PROCS(closure)
166 # define MAX_GA_WEIGHT 0 /* Treat as 2^n */
168 W_ PackGA PROTO((W_, int));
169 /* There was a PACK_GA macro here; but we turned it into the PackGA
170 routine [GlobAddr.lc] (because it needs to do quite a bit of
171 paranoia checking. Phil & Will (95/08)
175 At the moment, there is no activity profiling for GUM. This may change.
179 # define SET_TASK_ACTIVITY(act)
183 %************************************************************************
185 \subsection[parallel-heap-objs]{Special parallel-only heap objects (`closures')}
187 %************************************************************************
189 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % NB: The following definitons are BOTH for GUM and GrAnSim -- HWL
191 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 The rest of this file contains definitions for {\it GUM and GrAnSim}.
194 Although we don't create FetchMe nodes in GrAnSim (we simulate it by
195 bitmask twiddling) we use FetchMe_info when converting nodes into RBHs
196 (mainly to keep the code as close to GUM as possible). So, we define all
197 the FetchMe related stuff in GrAnSim, too. % -- HWL
199 %************************************************************************
201 \subsubsection[FETCHME-closures]{@FETCHME@ heap objects (`closures')}
203 %************************************************************************
205 FetchMes are pointers into the global heap. When evaluated, the value
206 they point to is read from the global heap.
208 A FetchMe closure has the form:
213 \begin{tabular}{||l|l||}\hline
214 \tr{FETCHME_info} & junk \\ \hline
220 The argument word is a pointer (outside of the heap) to a globalAddr structure...
221 in particular, the one corresponding to the object to be fetched. Note that
222 we can't just used the LAGA table, because weight-splitting may force us to
223 reassign a local GA to the @FetchMe@ so that we can give out new references.
225 A @FetchMe@ must have a valid @MUT_LINK@ field, because it may act as
226 a transition between an RBH on the OldMutables list and a BQ still on
227 the OldMutables list.
231 # define FETCHME_VHS IND_VHS
232 # define FETCHME_HS IND_HS
234 # define FETCHME_GA_LOCN FETCHME_HS
236 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
237 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
238 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
240 # define SET_FETCHME_HDR(closure,infolbl,cc,size,ptrs) \
241 { SET_FIXED_HDR(closure,FetchMe_info,<bogus CC>); \
242 SET_MUT_RESERVED_WORDS(closure); \
245 # define FETCHME_GA(closure) (((globalAddr **)(closure))[FETCHME_GA_LOCN])
247 EXTFUN(FetchMe_entry);
248 EXTDATA_RO(FetchMe_info);
252 %************************************************************************
254 \subsubsection[BlockedFetch-closures]{@BlockedFetch@ heap objects (`closures')}
256 %************************************************************************
258 @BlockedFetch@s are inbound fetch messages blocked on local closures.
259 They arise as entries in a local blocking queue when a fetch has been
260 received for a local black hole. When awakened, we look at their
261 contents to figure out where to send a resume.
263 A @BlockedFetch@ closure has the form:
268 \begin{tabular}{||l|l|l||}\hline
269 \tr{BF_info} & link & node & gtid & slot & weight \\ \hline
276 # define BF_VHS (GC_MUT_RESERVED_WORDS)
277 # define BF_HS (FIXED_HS + BF_VHS)
279 # define BF_LINK_LOCN (BF_HS)
280 # define BF_NODE_LOCN (BF_HS + 1)
281 # define BF_GTID_LOCN (BF_HS + 2)
282 # define BF_SLOT_LOCN (BF_HS + 3)
283 # define BF_WEIGHT_LOCN (BF_HS + 4)
285 # define BF_CLOSURE_NoPTRS(closure) 2
286 # define BF_CLOSURE_NoNONPTRS(closure) 3
288 # define BF_CLOSURE_SIZE(closure) (BF_VHS + 5)
290 # define BF_LINK(closure) (((PP_)closure)[BF_LINK_LOCN])
291 # define BF_NODE(closure) (((PP_)closure)[BF_NODE_LOCN])
292 # define BF_GTID(closure) (((P_)closure)[BF_GTID_LOCN])
293 # define BF_SLOT(closure) (((P_)closure)[BF_SLOT_LOCN])
294 # define BF_WEIGHT(closure) (((P_)closure)[BF_WEIGHT_LOCN])
296 # define BF_CLOSURE_PTR(closure, no) (((P_)(closure))[BF_HS + (no) - 1])
298 /* std start-filling-in macro: */
299 # define SET_BF_HDR(closure,infolbl,cc) \
300 { SET_FIXED_HDR(closure,infolbl,cc); \
301 SET_MUT_RESERVED_WORDS(closure); \
309 %************************************************************************
311 \subsubsection[FMBQ-closures]{@FMBQ@ (FetchMe with blocking queue) heap objects (`closures')}
313 %************************************************************************
315 FetchMe's with blocking queues are @Fetchme@ nodes which have been entered
316 (and therefore a fetch has been sent), but for which we have not yet received
317 a @Resume@ message. They look just like normal blocking queues, but have
318 a distinguished info pointer.
321 # define FMBQ_VHS BQ_VHS
322 # define FMBQ_HS BQ_HS
324 # define FMBQ_CLOSURE_SIZE(closure) BQ_CLOSURE_SIZE(closure)
325 # define FMBQ_CLOSURE_NoPTRS(closure) BQ_CLOSURE_NoPTRS(closure)
326 # define FMBQ_CLOSURE_NoNONPTRS(closure) BQ_CLOSURE_NoNONPTRS(closure)
327 # define FMBQ_CLOSURE_PTR(closure, no) BQ_CLOSURE_PTR(closure, no)
329 # define FMBQ_ENTRIES(closure) BQ_ENTRIES(closure)
330 # define FMBQ_LINK(closure) BQ_LINK(closure)
333 EXTDATA_RO(FMBQ_info);
336 %************************************************************************
338 \subsection[parallel-info-tables]{Special parallel-only info-table stuff}
340 %************************************************************************
342 %************************************************************************
344 \subsubsection[FETCHME_ITBL]{@FETCHME_ITBL@}
346 %************************************************************************
348 ToDo: delete FetchMe CAT (because we don't profile and parallelize at
349 the same time...) Even better...set things up so that we can profile
350 and parallelize at the same time!
354 # define FETCHME_ITBL(itbl_name,entry_code) \
355 CAT_DECLARE(FetchMe,INTERNAL_KIND,"FetchMe","<FetchMe>") \
356 EXTFUN(entry_code); \
357 EXTDATA_RO(MK_REP_LBL(FetchMe,,)); \
358 const W_ itbl_name[] = { \
360 ,(W_) INFO_OTHER_TAG \
361 ,(W_) MK_REP_REF(FetchMe,,) \
362 INCLUDE_PROFILING_INFO(FetchMe) \
365 # define FETCHME_RTBL() \
366 const W_ MK_REP_LBL(FetchMe,,)[] = { \
367 INCLUDE_TYPE_INFO(FETCHME) \
368 INCLUDE_SIZE_INFO(MIN_UPD_SIZE, 0L) \
370 INCLUDE_COPYING_INFO(_Evacuate_FetchMe,_Scavenge_FetchMe) \
371 INCLUDE_COMPACTING_INFO(_ScanLink_FetchMe,_PRStart_FetchMe,_ScanMove_FetchMe,_PRIn_Error) \
376 %************************************************************************
378 \subsubsection[BF_ITBL]{@BF_ITBL@}
380 %************************************************************************
382 The special info table used for thread state objects (BlockedFetchs).
387 CAT_DECLARE(BF,INTERNAL_KIND,"BlockedFetch","<BlockedFetch>") \
389 EXTDATA_RO(MK_REP_LBL(BF,,)); \
390 const W_ BF_info[] = { \
392 ,(W_) INFO_OTHER_TAG \
393 ,(W_) MK_REP_REF(BF,,) \
394 INCLUDE_PROFILING_INFO(BF) \
398 const W_ MK_REP_LBL(BF,,)[] = { \
399 INCLUDE_TYPE_INFO(BF) \
400 INCLUDE_SIZE_INFO(BF_CLOSURE_SIZE(dummy),BF_CLOSURE_NoPTRS(dummy)) \
402 INCLUDE_COPYING_INFO(_Evacuate_BF,_Scavenge_BF) \
403 INCLUDE_COMPACTING_INFO(_ScanLink_BF,_PRStart_BF,_ScanMove_BF,_PRIn_BF) \
408 %************************************************************************
410 \subsubsection[FMBQ_ITBL]{@FMBQ_ITBL@}
412 %************************************************************************
414 Special info-table for local blocking queues.
417 # define FMBQ_ITBL() \
418 CAT_DECLARE(FMBQ,INTERNAL_KIND,"FMBQ","<FMBQ>") \
419 EXTFUN(FMBQ_entry); \
420 EXTDATA_RO(MK_REP_LBL(FMBQ,,)); \
421 const W_ FMBQ_info[] = { \
423 ,(W_) INFO_OTHER_TAG \
424 ,(W_) MK_REP_REF(FMBQ,,) \
425 INCLUDE_PROFILING_INFO(FMBQ) \
428 # define FMBQ_RTBL() \
429 const W_ MK_REP_LBL(FMBQ,,)[] = { \
430 INCLUDE_TYPE_INFO(FMBQ) \
431 INCLUDE_SIZE_INFO(MIN_UPD_SIZE,INFO_UNUSED) \
433 INCLUDE_COPYING_INFO(_Evacuate_BQ,_Scavenge_BQ) \
434 SPEC_COMPACTING_INFO(_ScanLink_BQ,_PRStart_BQ,_ScanMove_BQ,_PRIn_BQ) \
439 %************************************************************************
441 \subsection[parallel-spark-pool-defs]{Parallel-only Spark pool definitions}
443 %************************************************************************
446 # define HAVE_SPARK ((PendingSparksHd[REQUIRED_POOL] < PendingSparksTl[REQUIRED_POOL]) \
447 || (PendingSparksHd[ADVISORY_POOL] < PendingSparksTl[ADVISORY_POOL]))
449 # define HAVE_WORK (RUNNING_THREAD || HAVE_SPARK)
450 # define RUNNING_THREAD (CurrentTSO != NULL)
453 %************************************************************************
455 \subsection[parallel-pack-defs]{Parallel-only Packing definitions}
457 %************************************************************************
460 Symbolic constants for the packing code.
462 This constant defines how many words of data we can pack into a single
463 packet in the parallel (GUM) system.
466 void InitPackBuffer(STG_NO_ARGS);
467 P_ PackTSO PROTO((P_ tso, W_ *size));
468 P_ PackStkO PROTO((P_ stko, W_ *size));
469 P_ AllocateHeap PROTO((W_ size)); /* Doesn't belong */
471 void InitClosureQueue (STG_NO_ARGS);
472 P_ DeQueueClosure(STG_NO_ARGS);
473 void QueueClosure PROTO((P_ closure));
474 rtsBool QueueEmpty(STG_NO_ARGS);
475 void PrintPacket PROTO((P_ buffer));
477 P_ get_closure_info PROTO((P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type));
479 rtsBool isOffset PROTO((globalAddr *ga)),
480 isFixed PROTO((globalAddr *ga));
482 void doGlobalGC(STG_NO_ARGS);
484 P_ PackNearbyGraph PROTO((P_ closure,W_ *size));
485 P_ UnpackGraph PROTO((W_ *buffer, globalAddr **gamap, W_ *nGAs));
489 # define PACK_HEAP_REQUIRED \
490 ((RTSflags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
492 extern W_ *PackBuffer; /* size: can be set via option */
493 extern long *buffer; /* HWL_ */
494 extern W_ *freeBuffer; /* HWL_ */
495 extern W_ *packBuffer; /* HWL_ */
497 extern void InitPackBuffer(STG_NO_ARGS);
498 extern void InitMoreBuffers(STG_NO_ARGS);
499 extern void InitPendingGABuffer(W_ size);
500 extern void AllocClosureQueue(W_ size);
502 # define MAX_GAS (RTSflags.ParFlags.packBufferSize / PACK_GA_SIZE)
505 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
506 /* Size of a packed fetch-me in words */
507 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
509 # define PACK_HDR_SIZE 1 /* Words of header in a packet */
511 # define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
518 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
519 void InitPackBuffer(STG_NO_ARGS);
520 P_ AllocateHeap PROTO((W_ size)); /* Doesn't belong */
521 P_ PackNearbyGraph PROTO((P_ closure, P_ tso, W_ *packbuffersize));
522 P_ PackOneNode PROTO((P_ closure, P_ tso, W_ *packbuffersize));
523 P_ UnpackGraph PROTO((P_ buffer));
525 void InitClosureQueue (STG_NO_ARGS);
526 P_ DeQueueClosure(STG_NO_ARGS);
527 void QueueClosure PROTO((P_ closure));
528 rtsBool QueueEmpty(STG_NO_ARGS);
529 void PrintPacket PROTO((P_ buffer));
531 P_ get_closure_info PROTO((P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type));
533 /* These are needed in the packing code to get the size of the packet
534 right. The closures itself are never built in GrAnSim. */
535 # define FETCHME_VHS IND_VHS
536 # define FETCHME_HS IND_HS
538 # define FETCHME_GA_LOCN FETCHME_HS
540 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
541 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
542 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
544 # define MAX_GAS (RTSflags.GranFlags.packBufferSize / PACK_GA_SIZE)
545 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
546 /* Size of a packed fetch-me in words */
547 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
548 # define PACK_HDR_SIZE 4 /* Words of header in a packet */
550 # define PACK_HEAP_REQUIRED \
551 ((RTSflags.GranFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
553 # define PACK_FLAG_LOCN 0
554 # define PACK_TSO_LOCN 1
555 # define PACK_UNPACKED_SIZE_LOCN 2
556 # define PACK_SIZE_LOCN 3
557 # define MAGIC_PACK_FLAG 0xfabc
560 #endif /* Parallel_H */