Document UniqSupply
[ghc-hetmet.git] / rts / parallel / ParallelRts.h
1 /* --------------------------------------------------------------------------
2    Time-stamp: <Tue Mar 06 2001 00:25:50 Stardate: [-30]6285.08 hwloidl>
3
4    Variables and functions specific to the parallel RTS (i.e. GUM or GranSim)
5    ----------------------------------------------------------------------- */
6
7 #ifndef PARALLEL_RTS_H
8 #define PARALLEL_RTS_H
9
10 #include "ParTicky.h"
11
12 /* HWL HACK: compile time sanity checks; shouldn't be necessary at all */
13 #if defined(PAR) && defined(GRAN)
14 # error "Both PAR and GRAN defined"
15 #endif
16
17 #if defined(DEBUG)
18 /* Paranoia debugging: we add an end-of-buffer marker to every pack buffer 
19                        (only when sanity checking RTS is enabled, of course) */
20 #define  DEBUG_HEADROOM        1
21 #define  END_OF_BUFFER_MARKER  0x1111bbbb
22 #define  GARBAGE_MARKER        0x1111eeee
23 #else
24 #define  DEBUG_HEADROOM        0
25 #endif /* DEBUG */
26
27 #if defined(GRAN) || defined(PAR)
28
29 #if defined(GRAN)
30
31 /* Statistics info */
32 extern nat tot_packets, tot_packet_size, tot_cuts, tot_thunks;
33
34 /* Pack.c */
35 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, 
36                                nat *packBufferSize, GlobalTaskId dest); 
37 rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso, 
38                            nat *packBufferSize);
39 rtsPackBuffer *PackTSO(StgTSO *tso, nat *packBufferSize);
40 rtsPackBuffer *PackStkO(StgPtr stko, nat *packBufferSize);
41 void           PackFetchMe(StgClosure *closure);
42
43 /* Unpack.c */
44 StgClosure*    UnpackGraph(rtsPackBuffer* buffer);
45 void           InitPendingGABuffer(nat size); 
46
47 /* RBH.c */
48 StgClosure    *convertToRBH(StgClosure *closure);
49 void           convertFromRBH(StgClosure *closure);
50
51 /* HLComms.c */
52 rtsFetchReturnCode blockFetch(StgTSO* tso, PEs proc, StgClosure* bh);
53 void               blockThread(StgTSO *tso);
54
55 #endif
56 #if defined(PAR)
57
58 /* Statistics info */
59
60 /* global structure for collecting statistics */
61 typedef struct GlobalParStats_ {
62   /* GALA and LAGA table info */
63   nat tot_mark_GA, tot_rebuild_GA, tot_free_GA,
64       res_mark_GA, res_rebuild_GA, res_free_GA,
65       cnt_mark_GA, cnt_rebuild_GA, cnt_free_GA,
66       res_size_GA, tot_size_GA, local_alloc_GA, tot_global, tot_local;
67
68   /* time spent managing the GAs */
69   double time_mark_GA, time_rebuild_GA;
70
71   /* spark queue stats */
72   nat res_sp, tot_sp, cnt_sp, emp_sp;
73   // nat tot_sq_len, tot_sq_probes, tot_sparks;
74   /* thread queue stats */
75   nat res_tp, tot_tp, cnt_tp, emp_tp;
76   //nat tot_add_threads, tot_tq_len, non_end_add_threads;
77
78   /* packet statistics */
79   nat tot_packets, tot_packet_size, tot_thunks,
80       res_packet_size, res_thunks,
81       rec_packets, rec_packet_size, rec_thunks,
82       rec_res_packet_size, rec_res_thunks;
83   /* time spent packing stuff */
84   double time_pack, time_unpack;
85
86   /* thread stats */
87   nat tot_threads_created;
88
89   /* spark stats */
90   //nat pruned_sparks, withered_sparks;
91   nat tot_sparks_created, tot_sparks_ignored, tot_sparks_marked,
92       res_sparks_created, res_sparks_ignored, res_sparks_marked; // , sparks_created_on_PE[MAX_PROC];
93   double time_sparks;
94
95   /* scheduling stats */
96   nat tot_yields, tot_stackover, tot_heapover;
97
98   /* message statistics */
99   nat tot_fish_mess, tot_fetch_mess, tot_resume_mess, tot_schedule_mess;
100   nat rec_fish_mess, rec_fetch_mess, rec_resume_mess, rec_schedule_mess;
101 #if defined(DIST)
102   nat tot_reval_mess;
103   nat rec_reval_mess;
104 #endif
105
106   /* blocking queue statistics
107   rtsTime tot_bq_processing_time;
108   nat tot_bq_len, tot_bq_len_local, tot_awbq, tot_FMBQs;
109   */
110
111   /* specialised info on arrays (for GPH/Maple mainly) */
112   nat tot_arrs, tot_arr_size;
113 } GlobalParStats;
114
115 extern GlobalParStats globalParStats;
116
117 void  globalParStat_exit(void);
118
119 /* Pack.c */
120 rtsBool        InitPackBuffer(void);
121 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, 
122                                nat *packBufferSize, GlobalTaskId dest); 
123
124 /* Unpack.c */
125 void           CommonUp(StgClosure *src, StgClosure *dst);
126 StgClosure    *UnpackGraph(rtsPackBuffer *buffer, globalAddr **gamap, 
127                            nat *nGAs);
128
129 /* RBH.c */
130 StgClosure    *convertToRBH(StgClosure *closure);
131 void           convertToFetchMe(StgRBH *rbh, globalAddr *ga);
132
133 /* HLComms.c */
134 void           blockFetch(StgBlockedFetch *bf, StgClosure *bh);
135 void           blockThread(StgTSO *tso);
136
137 /* Global.c */
138 void           GALAdeprecate(globalAddr *ga);
139
140 /* HLComms.c */
141 nat            pending_fetches_len(void);
142
143 /* ParInit.c */
144 void           initParallelSystem(void);
145 void           shutdownParallelSystem(StgInt n);
146 void           synchroniseSystem(void);
147 void           par_exit(I_);
148
149 #endif
150
151 /* this routine should be moved to a more general module; currently in Pack.c 
152 StgInfoTable* get_closure_info(StgClosure* node, 
153                                nat *size, nat *ptrs, nat *nonptrs, nat *vhs, 
154                                char *info_hdr_ty);
155 */
156 void doGlobalGC(void); 
157
158 //@node GC routines, Debugging routines, Spark handling routines
159 //@subsection GC routines
160
161 #if defined(PAR)
162 /* HLComms.c */
163 void      freeRemoteGA(int pe, globalAddr *ga);
164 void      sendFreeMessages(void);
165 void      markPendingFetches(rtsBool major_gc);
166
167 /* Global.c */
168 void      markLocalGAs(rtsBool full);
169 void      RebuildGAtables(rtsBool full);
170 void      RebuildLAGAtable(void);
171 #endif
172
173 //@node Debugging routines, Generating .gr profiles, GC routines
174 //@subsection Debugging routines
175
176 #if defined(PAR)
177 void      printGA (globalAddr *ga);
178 void      printGALA (GALA *gala);
179 void      printLAGAtable(void);
180
181 rtsBool   isOnLiveIndTable(globalAddr *ga);
182 rtsBool   isOnRemoteGATable(globalAddr *ga);
183 void      checkFreeGALAList(void);
184 void      checkFreeIndirectionsList(void);
185 #endif
186
187 //@node Generating .gr profiles, Index, Debugging routines
188 //@subsection Generating .gr profiles
189
190 #define STATS_FILENAME_MAXLEN   128
191
192 /* Where to write the log file */
193 //@cindex gr_file
194 //@cindex gr_filename
195 extern FILE *gr_file;
196 extern char gr_filename[STATS_FILENAME_MAXLEN];
197
198 //@cindex init_gr_stats
199 //@cindex init_gr_simulation
200 //@cindex end_gr_simulation
201 void            init_gr_stats (void);
202 void            init_gr_simulation(int rts_argc, char *rts_argv[], 
203                                    int prog_argc, char *prog_argv[]);
204 void            end_gr_simulation(void);
205
206 // TODO: move fcts in here (as static inline)
207 StgInfoTable*   get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, nat *vhs, char *info_hdr_ty);
208 rtsBool         IS_BLACK_HOLE(StgClosure* node);
209 StgClosure     *IS_INDIRECTION(StgClosure* node)          ;
210 StgClosure     *UNWIND_IND (StgClosure *closure);
211
212
213 #endif /* defined(PAR) || defined(GRAN) */
214
215 //@node Common macros, Index, Generating .gr profiles
216 //@subsection Common macros
217
218 #define LOOKS_LIKE_PTR(r)    \
219         (LOOKS_LIKE_STATIC_CLOSURE(r) ||  \
220          ((HEAP_ALLOCED(r) && Bdescr((P_)r)->free != (void *)-1)))
221
222 /* see Sanity.c for this kind of test; doing this in these basic fcts
223    is paranoid (nuke it after debugging!)
224 */
225
226 /* pathetic version of the check whether p can be a closure */
227 #define LOOKS_LIKE_COOL_CLOSURE(p)  1
228
229 //LOOKS_LIKE_GHC_INFO(get_itbl(p))
230
231     /* Is it a static closure (i.e. in the data segment)? */ \
232     /*
233 #define LOOKS_LIKE_COOL_CLOSURE(p)  \
234     ((LOOKS_LIKE_STATIC(p)) ?                                   \
235         closure_STATIC(p)                               \
236       : !closure_STATIC(p) && LOOKS_LIKE_PTR(p))
237     */
238
239 #endif /* PARALLEL_RTS_H */
240
241 //@node Index,  , Index
242 //@subsection Index
243
244 //@index
245 //* IS_BLACK_HOLE::  @cindex\s-+IS_BLACK_HOLE
246 //* IS_INDIRECTION::  @cindex\s-+IS_INDIRECTION
247 //* end_gr_simulation::  @cindex\s-+end_gr_simulation
248 //* get_closure_info::  @cindex\s-+get_closure_info
249 //* gr_file::  @cindex\s-+gr_file
250 //* gr_filename::  @cindex\s-+gr_filename
251 //* init_gr_simulation::  @cindex\s-+init_gr_simulation
252 //* unwindInd::  @cindex\s-+unwindInd
253 //@end index