2 Time-stamp: <Tue Mar 06 2001 00:09:10 Stardate: [-30]6285.03 hwloidl>
3 $Id: Parallel.h,v 1.4 2001/03/22 03:51:09 hwloidl Exp $
5 Definitions for GUM i.e. running on a parallel machine.
7 This section contains definitions applicable only to programs compiled
8 to run on a parallel machine, i.e. on GUM. Some of these definitions
9 are also used when simulating parallel execution, i.e. on GranSim.
15 #if defined(PAR) || defined(GRAN) /* whole file */
17 //@node Parallel definitions, End of File
18 //@section Parallel definitions
21 //* Basic definitions::
26 //@node Basic definitions, GUM, Parallel definitions, Parallel definitions
27 //@subsection Basic definitions
29 /* This clashes with TICKY, but currently TICKY and PAR hate each other anyway */
30 #define _HS sizeofW(StgHeader)
32 /* SET_PAR_HDR and SET_STATIC_PAR_HDR now live in ClosureMacros.h */
34 /* Needed for dumping routines */
36 # define NODE_STR_LEN 20
37 # define TIME_STR_LEN 120
39 # define CURRENT_TIME (msTime() - startTime)
40 # define TIME_ON_PROC(p) (msTime() - startTime)
41 # define CURRENT_PROC thisPE
42 # define BINARY_STATS RtsFlags.ParFlags.ParStats.Binary
44 # define NODE_STR_LEN 20
45 # define TIME_STR_LEN 120
47 # define CURRENT_TIME CurrentTime[CurrentProc]
48 # define TIME_ON_PROC(p) CurrentTime[p]
49 # define CURRENT_PROC CurrentProc
50 # define BINARY_STATS RtsFlags.GranFlags.GranSimStats.Binary
54 # define MAX_PES 256 /* Maximum number of processors */
55 /* MAX_PES is enforced by SysMan, which does not
56 allow more than this many "processors".
57 This is important because PackGA [GlobAddr.lc]
58 **assumes** that a PE# can fit in 8+ bits.
61 # define SPARK_POOLS 2 /* no. of spark pools */
62 # define REQUIRED_POOL 0 /* idx of pool of mandatory sparks (concurrency) */
63 # define ADVISORY_POOL 1 /* idx of pool of advisory sparks (parallelism) */
72 //@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
94 /* Sparks and spark queues */
95 typedef StgClosure *rtsSpark;
96 typedef rtsSpark *rtsSparkQ;
98 typedef struct rtsPackBuffer_ {
100 StgInt /* nat */ size;
101 StgInt /* nat */ unpacked_size;
106 #define PACK_BUFFER_HDR_SIZE 4
108 //@node Externs, Prototypes, Types, GUM
109 //@subsubsection Externs
111 // extern rtsBool do_sp_profile;
113 extern globalAddr theGlobalFromGA, theGlobalToGA;
114 extern StgBlockedFetch *PendingFetches;
115 extern GlobalTaskId *allPEs;
117 extern rtsBool IAmMainThread, GlobalStopPending;
118 //extern rtsBool fishing;
119 extern rtsTime last_fish_arrived_at;
120 extern nat outstandingFishes;
121 extern GlobalTaskId SysManTask;
122 extern int seed; /* pseudo-random-number generator seed: */
123 /* Initialised in ParInit */
124 extern StgInt threadId; /* Number of Threads that have existed on a PE */
125 extern GlobalTaskId mytid;
127 extern GlobalTaskId *allPEs;
129 extern nat sparksIgnored, sparksCreated, threadsIgnored, threadsCreated;
130 extern nat advisory_thread_count;
132 extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
134 extern ullong startTime; /* start of comp; in RtsStartup.c */
136 /* the spark pools proper */
137 extern rtsSpark *pending_sparks_hd[]; /* ptr to start of a spark pool */
138 extern rtsSpark *pending_sparks_tl[]; /* ptr to end of a spark pool */
139 extern rtsSpark *pending_sparks_lim[];
140 extern rtsSpark *pending_sparks_base[];
141 extern nat spark_limit[];
143 extern rtsPackBuffer *PackBuffer; /* size: can be set via option */
144 extern rtsPackBuffer *buffer;
145 extern rtsPackBuffer *freeBuffer;
146 extern rtsPackBuffer *packBuffer;
147 extern rtsPackBuffer *gumPackBuffer;
152 extern GALA *freeGALAList;
153 extern GALA *freeIndirections;
154 extern GALA *liveIndirections;
155 extern GALA *liveRemoteGAs;
158 //@node Prototypes, Macros, Externs, GUM
159 //@subsubsection Prototypes
162 void initParallelSystem(void);
163 void SynchroniseSystem(void);
164 void par_exit(StgInt n);
166 PEs taskIDtoPE (GlobalTaskId gtid);
167 void registerTask (GlobalTaskId gtid);
168 globalAddr *LAGAlookup (StgClosure *addr);
169 StgClosure *GALAlookup (globalAddr *ga);
170 //static GALA *allocIndirection (StgPtr addr);
171 globalAddr *makeGlobal (StgClosure *addr, rtsBool preferred);
172 globalAddr *setRemoteGA (StgClosure *addr, globalAddr *ga, rtsBool preferred);
173 void splitWeight (globalAddr *to, globalAddr *from);
174 globalAddr *addWeight (globalAddr *ga);
175 void initGAtables (void);
176 void RebuildLAGAtable (void);
177 StgWord PackGA (StgWord pe, int slot);
181 /* highest_slot breaks the abstraction of the slot counter for GAs; it is
182 only used for sanity checking and should used nowhere else */
183 StgInt highest_slot (void);
186 //@node Macros, , Prototypes, GUM
187 //@subsubsection Macros
189 /* delay (in us) between dying fish returning and sending out a new fish */
190 #define FISH_DELAY 1000
191 /* max no. of outstanding spark steals */
194 // ToDo: check which of these is actually needed!
196 # define PACK_HEAP_REQUIRED ((RtsFlags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _HS) * (MIN_UPD_SIZE + 2))
198 # define MAX_GAS (RtsFlags.ParFlags.packBufferSize / PACK_GA_SIZE)
201 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
202 /* Size of a packed fetch-me in words */
203 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + _HS)
205 # define PACK_HDR_SIZE 1 /* Words of header in a packet */
207 # define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
210 Definitions relating to the entire parallel-only fixed-header field.
212 On GUM, the global addresses for each local closure are stored in a
213 separate hash table, rather then with the closure in the heap. We call
214 @getGA@ to look up the global address associated with a local closure (0
215 is returned for local closures that have no global address), and @setGA@
216 to store a new global address for a local closure which did not
217 previously have one. */
219 # define GA_HDR_SIZE 0
221 # define GA(closure) getGA(closure)
223 # define SET_GA(closure, ga) setGA(closure,ga)
224 # define SET_STATIC_GA(closure)
225 # define SET_GRAN_HDR(closure,pe)
226 # define SET_STATIC_PROCS(closure)
228 # define MAX_GA_WEIGHT 0 /* Treat as 2^n */
230 /* At the moment, there is no activity profiling for GUM. This may change. */
231 # define SET_TASK_ACTIVITY(act) /* nothing */
234 The following macros are only needed for sanity checking (see Sanity.c).
237 /* NB: this is PVM specific and should be updated for MPI etc
238 in PVM a task id (tid) is split into 2 parts: the id for the
239 physical processor it is running on and an index of tasks running
240 on a processor; PVM_PE_MASK indicates which part of a tid holds the
241 id of the physical processor (the other part of the word holds the
242 index on that processor)
243 MAX_PVM_PES and MAX_PVM_TIDS are maximal values for these 2 components
244 in GUM we have an upper bound for the total number of PVM PEs allowed:
245 it's MAX_PE defined in Parallel.h
246 to check the slot field of a GA we call a fct highest_slot which just
247 returns the internal counter
249 #define PVM_PE_MASK 0xfffc0000
250 #define MAX_PVM_PES MAX_PES
251 #define MAX_PVM_TIDS MAX_PES
254 #define LOOKS_LIKE_TID(tid) (((tid & PVM_PE_MASK) != 0) && \
255 (((tid & PVM_PE_MASK) + (tid & ~PVM_PE_MASK)) < MAX_PVM_TIDS))
256 #define LOOKS_LIKE_SLOT(slot) (slot<=highest_slot())
258 #define LOOKS_LIKE_GA(ga) (LOOKS_LIKE_TID((ga)->payload.gc.gtid) && \
259 LOOKS_LIKE_SLOT((ga)->payload.gc.slot))
261 rtsBool looks_like_tid(StgInt tid);
262 rtsBool looks_like_slot(StgInt slot);
263 rtsBool looks_like_ga(globalAddr *ga);
264 #define LOOKS_LIKE_TID(tid) looks_like_tid(tid)
265 #define LOOKS_LIKE_GA(ga) looks_like_ga(ga)
270 //@node GranSim, , GUM, Parallel definitions
271 //@subsection GranSim
274 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
283 //@node Types, Prototypes, GranSim, GranSim
284 //@subsubsection Types
286 typedef StgWord *StgBuffer;
287 typedef struct rtsPackBuffer_ {
289 StgInt /* nat */ size;
290 StgInt /* nat */ unpacked_size;
295 //@node Macros, , Prototypes, GranSim
296 //@subsubsection Macros
298 /* max no. of outstanding spark steals */
301 /* These are needed in the packing code to get the size of the packet
302 right. The closures itself are never built in GrAnSim. */
303 # define FETCHME_VHS IND_VHS
304 # define FETCHME_HS IND_HS
306 # define FETCHME_GA_LOCN FETCHME_HS
308 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
309 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
310 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
312 # define MAX_GAS (RtsFlags.GranFlags.packBufferSize / PACK_GA_SIZE)
313 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
314 /* Size of a packed fetch-me in words */
315 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + _HS)
316 # define PACK_HDR_SIZE 4 /* Words of header in a packet */
318 # define PACK_HEAP_REQUIRED \
319 (RtsFlags.GranFlags.packBufferSize * sizeofW(StgClosure*) + \
320 2 * sizeofW(StgInt) + sizeofW(StgTSO*))
322 # define PACK_FLAG_LOCN 0
323 # define PACK_TSO_LOCN 1
324 # define PACK_UNPACKED_SIZE_LOCN 2
325 # define PACK_SIZE_LOCN 3
326 # define MAGIC_PACK_FLAG 0xfabc
328 # define GA_HDR_SIZE 1
330 # define PROCS_HDR_POSN PAR_HDR_POSN
331 # define PROCS_HDR_SIZE 1
333 /* Accessing components of the field */
334 # define PROCS(closure) ((closure)->header.gran.procs)
335 /* SET_PROCS is now SET_GRAN_HEADER in ClosureMacros.h. */
339 //@node End of File, , Parallel definitions
340 //@section End of File
342 #endif /* defined(PAR) || defined(GRAN) whole file */
344 #endif /* Parallel_H */