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