2 Time-stamp: <Mon Oct 04 1999 14:50:28 Stardate: [-30]3692.88 hwloidl>
4 Definitions for parallel machines.
6 This section contains definitions applicable only to programs compiled
7 to run on a parallel machine, i.e. on GUM. Some of these definitions
8 are also used when simulating parallel execution, i.e. on GranSim.
12 ToDo: Check the PAR specfic part of this file
13 Move stuff into Closures.h and ClosureMacros.h
14 Clean-up GRAN specific code
21 #if defined(PAR) || defined(GRAN) /* whole file */
25 //#include "ClosureTypes.h"
28 //* Basic definitions::
29 //* Externs and types::
31 //* Par specific fixed headers::
32 //* Parallel only heap objects::
33 //* Packing definitions::
38 //@node Basic definitions, Externs and types
39 //@section Basic definitions
41 /* SET_PAR_HDR and SET_STATIC_PAR_HDR now live in ClosureMacros.h */
43 /* Needed for dumping routines */
46 # define CURRENT_TIME msTime()
47 # define TIME_ON_PROC(p) msTime()
48 # define CURRENT_PROC thisPE
49 # define BINARY_STATS RtsFlags.ParFlags.granSimStats_Binary
52 # define CURRENT_TIME CurrentTime[CurrentProc]
53 # define TIME_ON_PROC(p) CurrentTime[p]
54 # define CURRENT_PROC CurrentProc
55 # define BINARY_STATS RtsFlags.GranFlags.granSimStats_Binary
59 # define MAX_PES 256 /* Maximum number of processors */
60 /* MAX_PES is enforced by SysMan, which does not
61 allow more than this many "processors".
62 This is important because PackGA [GlobAddr.lc]
63 **assumes** that a PE# can fit in 8+ bits.
67 //@node Externs and types, Dummy defs, Basic definitions
68 //@section Externs and types
71 /* GUM: one spark queue on each PE, and each PE sees only its own spark queue */
72 extern rtsSparkQ pending_sparks_hd;
73 extern rtsSparkQ pending_sparks_tl;
75 /* GranSim: a globally visible array of spark queues */
76 extern rtsSparkQ pending_sparks_hds[];
77 extern rtsSparkQ pending_sparks_tls[];
79 extern unsigned int /* nat */ spark_queue_len(PEs proc);
81 extern StgInt SparksAvail; /* How many sparks are available */
83 /* prototypes of spark routines */
84 /* ToDo: check whether all have to be visible -- HWL */
86 rtsSpark *newSpark(StgClosure *node, StgInt name, StgInt gran_info, StgInt size_info, StgInt par_info, StgInt local);
87 void disposeSpark(rtsSpark *spark);
88 void disposeSparkQ(rtsSparkQ spark);
89 void add_to_spark_queue(rtsSpark *spark);
90 void delete_from_spark_queue (rtsSpark *spark);
93 #define STATS_FILENAME_MAXLEN 128
95 /* Where to write the log file */
96 //extern FILE *gr_file;
97 extern char gr_filename[STATS_FILENAME_MAXLEN];
100 int init_gr_simulation(char *rts_argv[], int rts_argc, char *prog_argv[], int prog_argc);
101 void end_gr_simulation(void);
105 extern I_ do_sp_profile;
107 extern P_ PendingFetches;
108 extern GLOBAL_TASK_ID *PEs;
110 extern rtsBool IAmMainThread, GlobalStopPending;
111 extern rtsBool fishing;
112 extern GLOBAL_TASK_ID SysManTask;
113 extern int seed; /*pseudo-random-number generator seed:*/
114 /*Initialised in ParInit*/
115 extern I_ threadId; /*Number of Threads that have existed on a PE*/
116 extern GLOBAL_TASK_ID mytid;
120 extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
122 extern HashTable *pGAtoGALAtable;
123 extern HashTable *LAtoGALAtable;
124 extern GALA *freeIndirections;
125 extern GALA *liveIndirections;
126 extern GALA *freeGALAList;
127 extern GALA *liveRemoteGAs;
130 void RunParallelSystem (StgPtr program_closure);
131 void initParallelSystem();
132 void SynchroniseSystem();
134 void registerTask (GLOBAL_TASK_ID gtid);
135 globalAddr *LAGAlookup (P_ addr);
136 P_ GALAlookup (globalAddr *ga);
137 globalAddr *MakeGlobal (P_ addr, rtsBool preferred);
138 globalAddr *setRemoteGA (P_ addr, globalAddr *ga, rtsBool preferred);
139 void splitWeight (globalAddr *to, globalAddr *from);
140 globalAddr *addWeight (globalAddr *ga);
142 W_ taskIDtoPE (GLOBAL_TASK_ID gtid);
143 void RebuildLAGAtable();
145 void *lookupHashTable (HashTable *table, StgWord key);
146 void insertHashTable (HashTable *table, StgWord key, void *data);
147 void freeHashTable (HashTable *table, void (*freeDataFun) ((void *data)));
148 HashTable *allocHashTable();
149 void *removeHashTable (HashTable *table, StgWord key, void *data);
152 /* Interface for dumping routines (i.e. writing to log file) */
153 void DumpGranEvent(GranEventType name, StgTSO *tso);
154 void DumpRawGranEvent(PEs proc, PEs p, GranEventType name,
155 StgTSO *tso, StgClosure *node, StgInt sparkname, StgInt len);
156 //void DumpEndEvent(PEs proc, StgTSO *tso, rtsBool mandatory_thread);
158 //@node Dummy defs, Par specific fixed headers, Externs and types
159 //@section Dummy defs
162 Get this out of the way. These are all null definitions.
166 //# define GA_HDR_SIZE 0
167 //# define GA(closure) /*nothing */
169 //# define SET_GA(closure,ga) /* nothing */
170 //# define SET_STATIC_GA(closure) /* nothing */
171 //# define SET_GRAN_HDR(closure,pe) /* nothing */
172 //# define SET_STATIC_PROCS(closure) /* nothing */
174 //# define SET_TASK_ACTIVITY(act) /* nothing */
178 # define GA_HDR_SIZE 1
180 # define PROCS_HDR_POSN PAR_HDR_POSN
181 # define PROCS_HDR_SIZE 1
183 /* Accessing components of the field */
184 # define PROCS(closure) ((closure)->header.gran.procs)
185 /* SET_PROCS is now SET_GRAN_HEADER in ClosureMacros.h. */
189 //@node Par specific fixed headers, Parallel only heap objects, Dummy defs
190 //@section Par specific fixed headers
193 Definitions relating to the entire parallel-only fixed-header field.
195 On GUM, the global addresses for each local closure are stored in a separate
196 hash table, rather then with the closure in the heap. We call @getGA@ to
197 look up the global address associated with a local closure (0 is returned
198 for local closures that have no global address), and @setGA@ to store a new
199 global address for a local closure which did not previously have one.
204 # define GA_HDR_SIZE 0
206 # define GA(closure) getGA(closure)
208 # define SET_GA(closure, ga) setGA(closure,ga)
209 # define SET_STATIC_GA(closure)
210 # define SET_GRAN_HDR(closure,pe)
211 # define SET_STATIC_PROCS(closure)
213 # define MAX_GA_WEIGHT 0 /* Treat as 2^n */
215 W_ PackGA ((W_, int));
216 /* There was a PACK_GA macro here; but we turned it into the PackGA
217 routine [GlobAddr.lc] (because it needs to do quite a bit of
218 paranoia checking. Phil & Will (95/08)
221 /* At the moment, there is no activity profiling for GUM. This may change. */
222 # define SET_TASK_ACTIVITY(act) /* nothing */
225 //@node Parallel only heap objects, Packing definitions, Par specific fixed headers
226 //@section Parallel only heap objects
228 // NB: The following definitons are BOTH for GUM and GrAnSim -- HWL
230 /* All in Closures.h and CLosureMacros.h */
232 //@node Packing definitions, End of File, Parallel only heap objects
233 //@section Packing definitions
241 //@node GUM, GranSim, Packing definitions, Packing definitions
246 Symbolic constants for the packing code.
248 This constant defines how many words of data we can pack into a single
249 packet in the parallel (GUM) system.
259 //@node Externs, Prototypes, GUM, GUM
260 //@subsubsection Externs
262 extern W_ *PackBuffer; /* size: can be set via option */
263 extern long *buffer; /* HWL_ */
264 extern W_ *freeBuffer; /* HWL_ */
265 extern W_ *packBuffer; /* HWL_ */
267 extern void InitPackBuffer(STG_NO_ARGS);
268 extern void InitMoreBuffers(STG_NO_ARGS);
269 extern void InitPendingGABuffer(W_ size);
270 extern void AllocClosureQueue(W_ size);
272 //@node Prototypes, Macros, Externs, GUM
273 //@subsubsection Prototypes
275 void InitPackBuffer();
276 P_ PackTSO (P_ tso, W_ *size);
277 P_ PackStkO (P_ stko, W_ *size);
278 P_ AllocateHeap (W_ size); /* Doesn't belong */
280 void InitClosureQueue ();
282 void QueueClosure (P_ closure);
283 rtsBool QueueEmpty();
284 void PrintPacket (P_ buffer);
286 P_ get_closure_info (P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type);
288 rtsBool isOffset (globalAddr *ga),
289 isFixed (globalAddr *ga);
293 P_ PackNearbyGraph (P_ closure,W_ *size);
294 P_ UnpackGraph (W_ *buffer, globalAddr **gamap, W_ *nGAs);
297 //@node Macros, , Prototypes, GUM
298 //@subsubsection Macros
300 # define PACK_HEAP_REQUIRED \
301 ((RtsFlags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
303 # define MAX_GAS (RtsFlags.ParFlags.packBufferSize / PACK_GA_SIZE)
306 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
307 /* Size of a packed fetch-me in words */
308 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
310 # define PACK_HDR_SIZE 1 /* Words of header in a packet */
312 # define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
316 //@node GranSim, , GUM, Packing definitions
317 //@subsection GranSim
320 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
329 //@node Types, Prototypes, GranSim, GranSim
330 //@subsubsection Types
332 typedef struct rtsPackBuffer_ {
333 StgInt /* nat */ size;
334 StgInt /* nat */ unpacked_size;
339 //@node Prototypes, Macros, Types, GranSim
340 //@subsubsection Prototypes
343 /* main packing functions */
345 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, nat *packbuffersize);
346 rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso, nat *packbuffersize);
347 void PrintPacket(rtsPackBuffer *buffer);
348 StgClosure *UnpackGraph(rtsPackBuffer* buffer);
350 /* important auxiliary functions */
352 //StgInfoTable *get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, nat *vhs, char *info_hdr_ty);
353 int IS_BLACK_HOLE(StgClosure* node);
354 StgClosure *IS_INDIRECTION(StgClosure* node);
355 int IS_THUNK(StgClosure* closure);
356 char *display_info_type(StgClosure* closure, char *str);
360 void InitPackBuffer(void);
361 P_ AllocateHeap (W_ size);
362 P_ PackNearbyGraph (P_ closure, P_ tso, W_ *packbuffersize);
363 P_ PackOneNode (P_ closure, P_ tso, W_ *packbuffersize);
364 P_ UnpackGraph (P_ buffer);
366 void InitClosureQueue (void);
367 P_ DeQueueClosure(void);
368 void QueueClosure (P_ closure);
369 // rtsBool QueueEmpty();
370 void PrintPacket (P_ buffer);
373 // StgInfoTable *get_closure_info(StgClosure* node, unsigned int /* nat */ *size, unsigned int /* nat */ *ptrs, unsigned int /* nat */ *nonptrs, unsigned int /* nat */ *vhs, char *info_hdr_ty);
374 // int /* rtsBool */ IS_BLACK_HOLE(StgClosure* node) ;
376 //@node Macros, , Prototypes, GranSim
377 //@subsubsection Macros
379 /* These are needed in the packing code to get the size of the packet
380 right. The closures itself are never built in GrAnSim. */
381 # define FETCHME_VHS IND_VHS
382 # define FETCHME_HS IND_HS
384 # define FETCHME_GA_LOCN FETCHME_HS
386 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
387 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
388 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
390 # define MAX_GAS (RtsFlags.GranFlags.packBufferSize / PACK_GA_SIZE)
391 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
392 /* Size of a packed fetch-me in words */
393 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
394 # define PACK_HDR_SIZE 4 /* Words of header in a packet */
396 # define PACK_HEAP_REQUIRED \
397 (RtsFlags.GranFlags.packBufferSize * sizeofW(StgClosure*) + \
398 2 * sizeofW(StgInt) + sizeofW(StgTSO*))
400 # define PACK_FLAG_LOCN 0
401 # define PACK_TSO_LOCN 1
402 # define PACK_UNPACKED_SIZE_LOCN 2
403 # define PACK_SIZE_LOCN 3
404 # define MAGIC_PACK_FLAG 0xfabc
408 //@node End of File, , Packing definitions
409 //@section End of File
411 #endif /* defined(PAR) || defined(GRAN) whole file */
412 #endif /* Parallel_H */