[project @ 2000-01-14 14:56:40 by simonmar]
[ghc-hetmet.git] / ghc / rts / parallel / ParallelRts.h
1 /* --------------------------------------------------------------------------
2    Time-stamp: <Wed Jan 12 2000 16:22:43 Stardate: [-30]4194.45 hwloidl>
3    $Id: ParallelRts.h,v 1.2 2000/01/13 14:34:09 hwloidl Exp $
4
5    Variables and functions specific to the parallel RTS (i.e. GUM or GranSim)
6    ----------------------------------------------------------------------- */
7
8 #ifndef PARALLEL_RTS_H
9 #define PARALLEL_RTS_H
10
11 #if defined(GRAN) || defined(PAR)
12
13 //@menu
14 //* Packing routines::          
15 //* Spark handling routines::   
16 //* GC routines::               
17 //* Debugging routines::        
18 //* Generating .gr profiles::   
19 //* Common macros::             
20 //* Index::                     
21 //@end menu
22
23 #ifndef GRAN
24 // Dummy def for NO_PRI if not in GranSim
25 #define NO_PRI  0
26 #endif
27
28 //@node Packing routines, Spark handling routines
29 //@subsection Packing routines
30
31 #if defined(GRAN)
32 /* Statistics info */
33 extern nat tot_packets, tot_packet_size, tot_cuts, tot_thunks;
34 #endif
35
36 #if defined(GRAN)
37 /* Pack.c */
38 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, 
39                                nat *packBufferSize);
40 rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso, 
41                            nat *packBufferSize);
42 rtsPackBuffer *PackTSO(StgTSO *tso, nat *packBufferSize);
43 rtsPackBuffer *PackStkO(StgPtr stko, nat *packBufferSize);
44 void           PackFetchMe(StgClosure *closure);
45
46 /* Unpack.c */
47 StgClosure*    UnpackGraph(rtsPackBuffer* buffer);
48 void           InitPendingGABuffer(nat size); 
49
50 /* RBH.c */
51 StgClosure    *convertToRBH(StgClosure *closure);
52 void           convertFromRBH(StgClosure *closure);
53
54 /* General closure predicates */
55 /*
56     {Parallel.h}Daq ngoqvam vIroQpu'
57
58 StgInfoTable *get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, nat *vhs, char *info_hdr_ty);
59 rtsBool      IS_BLACK_HOLE(StgClosure* node);
60 StgClosure  *IS_INDIRECTION(StgClosure* node);
61 rtsBool      IS_THUNK(StgClosure* closure);
62 */
63
64 #elif defined(PAR)
65
66 /* Pack.c */
67 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, 
68                                nat *packBufferSize); 
69
70 rtsPackBuffer *PackTSO(StgTSO *tso, nat *packBufferSize);
71 rtsPackBuffer *PackStkO(StgPtr stko, nat *packBufferSize);
72 void           PackFetchMe(StgClosure *closure);
73
74 /* Unpack.c */
75 void           CommonUp(StgClosure *src, StgClosure *dst);
76 StgClosure    *UnpackGraph(rtsPackBuffer *buffer, globalAddr **gamap, 
77                            nat *nGAs);
78
79 /* RBH.c */
80 StgClosure    *convertToRBH(StgClosure *closure);
81 void           convertToFetchMe(StgRBH *rbh, globalAddr *ga);
82
83 /* General closure predicates */
84 /* 
85   {Parallel.h}Daq ngoqvam vIroQpu'
86
87 StgInfoTable *get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, nat *vhs, char *info_hdr_ty);
88 rtsBool      IS_BLACK_HOLE(StgClosure* node);
89 StgClosure  *IS_INDIRECTION(StgClosure* node);
90 rtsBool      IS_THUNK(StgClosure* closure);
91 */
92
93 #endif
94
95 /* this routine should be moved to a more general module; currently in Pack.c 
96 StgInfoTable* get_closure_info(StgClosure* node, 
97                                nat *size, nat *ptrs, nat *nonptrs, nat *vhs, 
98                                char *info_hdr_ty);
99 */
100 void doGlobalGC(void); 
101
102 //@node Spark handling routines, GC routines, Packing routines
103 //@subsection Spark handling routines
104
105 /* now in ../Sparks.c */
106
107 #if 0
108
109 #if defined(PAR)
110
111 rtsSpark  findLocalSpark(rtsBool forexport);
112 StgTSO*   activateSpark (rtsSpark spark); 
113 void      disposeSpark(rtsSpark spark);
114 rtsBool   add_to_spark_queue(StgClosure *closure, rtsBool required);
115 rtsBool   initSparkPools (void);
116
117 nat       spark_queue_len(nat pool);
118 void      markSparkQueue(void);
119 void      print_sparkq(void);
120
121 #elif defined(GRAN)
122
123 void      findLocalSpark (rtsEvent *event, 
124                           rtsBool *found_res, rtsSparkQ *spark_res);
125 rtsBool   activateSpark (rtsEvent *event, rtsSparkQ spark);
126 rtsSpark *newSpark (StgClosure *node, StgInt name, StgInt gran_info, 
127                     StgInt size_info, StgInt par_info, StgInt local);
128 void      disposeSpark(rtsSpark *spark);
129 void      disposeSparkQ(rtsSparkQ spark);
130 void      add_to_spark_queue(rtsSpark *spark);
131 void      print_spark(rtsSpark *spark);
132 nat       spark_queue_len(PEs proc);
133 rtsSpark *delete_from_sparkq (rtsSpark *spark, PEs p, rtsBool dispose_too);
134 void      markSparkQueue(void);
135 void      print_sparkq(PEs proc);
136 void      print_sparkq_stats(void);
137
138 #endif
139 #endif /* 0 */
140
141 //@node GC routines, Debugging routines, Spark handling routines
142 //@subsection GC routines
143
144 #if defined(PAR)
145 /* HLComms.c */
146 void      freeRemoteGA(int pe, globalAddr *ga);
147 void      sendFreeMessages(void);
148
149 /* Global.c */
150 void      markLocalGAs(rtsBool full);
151 void      RebuildGAtables(rtsBool full);
152 void      RebuildLAGAtable(void);
153 #endif
154
155 //@node Debugging routines, Generating .gr profiles, GC routines
156 //@subsection Debugging routines
157
158 #if defined(PAR)
159 void      printGA (globalAddr *ga);
160 void      printGALA (GALA *gala);
161 void      printLAGAtable(void);
162 #endif
163
164 //@node Generating .gr profiles, Common macros, Debugging routines
165 //@subsection Generating .gr profiles
166
167 #define STATS_FILENAME_MAXLEN   128
168
169 /* Where to write the log file */
170 //@cindex gr_file
171 //@cindex gr_filename
172 extern FILE *gr_file;
173 extern char gr_filename[STATS_FILENAME_MAXLEN];
174
175 //@cindex init_gr_simulation
176 //@cindex end_gr_simulation
177 void init_gr_simulation(int rts_argc, char *rts_argv[], 
178                         int prog_argc, char *prog_argv[]);
179 void end_gr_simulation(void);
180
181 //@node Common macros, Index, Generating .gr profiles
182 //@subsection Common macros
183
184 /* 
185    extracting specific info out of a closure; used in packing (GranSim, GUM)
186 */
187 //@cindex get_closure_info
188 static inline StgInfoTable*
189 get_closure_info(node, size, ptrs, nonptrs, vhs, info_hdr_ty)
190 StgClosure* node;
191 nat *size, *ptrs, *nonptrs, *vhs;
192 char *info_hdr_ty;
193 {
194   StgInfoTable *info;
195
196   info = get_itbl(node);
197   /* the switch shouldn't be necessary, really; just use default case */
198   switch (info->type) {
199   case RBH:
200     {
201       StgInfoTable *rip = REVERT_INFOPTR(info); // closure to revert to
202       *size = sizeW_fromITBL(rip);
203       *ptrs = (nat) (rip->layout.payload.ptrs);
204       *nonptrs = (nat) (rip->layout.payload.nptrs);
205       *vhs = (nat) 0; // unknown
206 #if 0 /* DEBUG */
207       info_hdr_type(node, info_hdr_ty);
208 #else
209       strcpy(info_hdr_ty, "UNKNOWN");
210 #endif
211       return rip;  // NB: we return the reverted info ptr for a RBH!!!!!!
212     }
213
214   default:
215     *size = sizeW_fromITBL(info);
216     *ptrs = (nat) (info->layout.payload.ptrs);
217     *nonptrs = (nat) (info->layout.payload.nptrs);
218     *vhs = (nat) 0; // unknown
219 #if 0 /* DEBUG */
220       info_hdr_type(node, info_hdr_ty);
221 #else
222       strcpy(info_hdr_ty, "UNKNOWN");
223 #endif
224     return info;
225   }
226
227
228 //@cindex IS_BLACK_HOLE
229 static inline rtsBool
230 IS_BLACK_HOLE(StgClosure* node)          
231
232   StgInfoTable *info;
233   switch (get_itbl(node)->type) {
234   case BLACKHOLE:
235   case BLACKHOLE_BQ:
236   case RBH:
237   case FETCH_ME:
238   case FETCH_ME_BQ:
239     return rtsTrue;
240   default:
241     return rtsFalse;
242   }
243 //return ((info->type == BLACKHOLE || info->type == RBH) ? rtsTrue : rtsFalse);
244 }
245
246 //@cindex IS_INDIRECTION
247 static inline StgClosure *
248 IS_INDIRECTION(StgClosure* node)          
249
250   StgInfoTable *info;
251   info = get_itbl(node);
252   switch (info->type) {
253     case IND:
254     case IND_OLDGEN:
255     case IND_PERM:
256     case IND_OLDGEN_PERM:
257     case IND_STATIC:
258       /* relies on indirectee being at same place for all these closure types */
259       return (((StgInd*)node) -> indirectee);
260     default:
261       return NULL;
262   }
263 }
264
265 //@cindex unwindInd
266 static inline StgClosure *
267 UNWIND_IND (StgClosure *closure)
268 {
269   StgClosure *next;
270
271   while ((next = IS_INDIRECTION((StgClosure *)closure)) != NULL) 
272     closure = next;
273
274   ASSERT(next==(StgClosure *)NULL);
275   return closure;
276 }
277
278 #endif /* defined(PAR) || defined(GRAN) */
279
280 #endif /* PARALLEL_RTS_H */
281
282 //@node Index,  , Common macros
283 //@subsection Index
284
285 //@index
286 //* IS_BLACK_HOLE::  @cindex\s-+IS_BLACK_HOLE
287 //* IS_INDIRECTION::  @cindex\s-+IS_INDIRECTION
288 //* end_gr_simulation::  @cindex\s-+end_gr_simulation
289 //* get_closure_info::  @cindex\s-+get_closure_info
290 //* gr_file::  @cindex\s-+gr_file
291 //* gr_filename::  @cindex\s-+gr_filename
292 //* init_gr_simulation::  @cindex\s-+init_gr_simulation
293 //* unwindInd::  @cindex\s-+unwindInd
294 //@end index