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 $
5 Variables and functions specific to the parallel RTS (i.e. GUM or GranSim)
6 ----------------------------------------------------------------------- */
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"
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
25 #define DEBUG_HEADROOM 0
28 #if defined(GRAN) || defined(PAR)
33 extern nat tot_packets, tot_packet_size, tot_cuts, tot_thunks;
36 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso,
37 nat *packBufferSize, GlobalTaskId dest);
38 rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso,
40 rtsPackBuffer *PackTSO(StgTSO *tso, nat *packBufferSize);
41 rtsPackBuffer *PackStkO(StgPtr stko, nat *packBufferSize);
42 void PackFetchMe(StgClosure *closure);
45 StgClosure* UnpackGraph(rtsPackBuffer* buffer);
46 void InitPendingGABuffer(nat size);
49 StgClosure *convertToRBH(StgClosure *closure);
50 void convertFromRBH(StgClosure *closure);
53 rtsFetchReturnCode blockFetch(StgTSO* tso, PEs proc, StgClosure* bh);
54 void blockThread(StgTSO *tso);
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;
69 /* time spent managing the GAs */
70 double time_mark_GA, time_rebuild_GA;
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;
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;
88 nat tot_threads_created;
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];
96 /* scheduling stats */
97 nat tot_yields, tot_stackover, tot_heapover;
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;
107 /* blocking queue statistics
108 rtsTime tot_bq_processing_time;
109 nat tot_bq_len, tot_bq_len_local, tot_awbq, tot_FMBQs;
112 /* specialised info on arrays (for GPH/Maple mainly) */
113 nat tot_arrs, tot_arr_size;
116 extern GlobalParStats globalParStats;
118 void globalParStat_exit(void);
121 rtsBool InitPackBuffer(void);
122 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso,
123 nat *packBufferSize, GlobalTaskId dest);
126 void CommonUp(StgClosure *src, StgClosure *dst);
127 StgClosure *UnpackGraph(rtsPackBuffer *buffer, globalAddr **gamap,
131 StgClosure *convertToRBH(StgClosure *closure);
132 void convertToFetchMe(StgRBH *rbh, globalAddr *ga);
135 void blockFetch(StgBlockedFetch *bf, StgClosure *bh);
136 void blockThread(StgTSO *tso);
139 void GALAdeprecate(globalAddr *ga);
142 nat pending_fetches_len(void);
145 void initParallelSystem(void);
146 void shutdownParallelSystem(StgInt n);
147 void synchroniseSystem(void);
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,
157 void doGlobalGC(void);
159 //@node GC routines, Debugging routines, Spark handling routines
160 //@subsection GC routines
164 void freeRemoteGA(int pe, globalAddr *ga);
165 void sendFreeMessages(void);
166 void markPendingFetches(rtsBool major_gc);
169 void markLocalGAs(rtsBool full);
170 void RebuildGAtables(rtsBool full);
171 void RebuildLAGAtable(void);
174 //@node Debugging routines, Generating .gr profiles, GC routines
175 //@subsection Debugging routines
178 void printGA (globalAddr *ga);
179 void printGALA (GALA *gala);
180 void printLAGAtable(void);
182 rtsBool isOnLiveIndTable(globalAddr *ga);
183 rtsBool isOnRemoteGATable(globalAddr *ga);
184 void checkFreeGALAList(void);
185 void checkFreeIndirectionsList(void);
188 //@node Generating .gr profiles, Index, Debugging routines
189 //@subsection Generating .gr profiles
191 #define STATS_FILENAME_MAXLEN 128
193 /* Where to write the log file */
195 //@cindex gr_filename
196 extern FILE *gr_file;
197 extern char gr_filename[STATS_FILENAME_MAXLEN];
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);
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);
214 #endif /* defined(PAR) || defined(GRAN) */
216 //@node Common macros, Index, Generating .gr profiles
217 //@subsection Common macros
219 #define LOOKS_LIKE_PTR(r) \
220 (LOOKS_LIKE_STATIC_CLOSURE(r) || \
221 ((HEAP_ALLOCED(r) && Bdescr((P_)r)->free != (void *)-1)))
223 /* see Sanity.c for this kind of test; doing this in these basic fcts
224 is paranoid (nuke it after debugging!)
227 /* pathetic version of the check whether p can be a closure */
228 #define LOOKS_LIKE_COOL_CLOSURE(p) 1
230 //LOOKS_LIKE_GHC_INFO(get_itbl(p))
232 /* Is it a static closure (i.e. in the data segment)? */ \
234 #define LOOKS_LIKE_COOL_CLOSURE(p) \
235 ((LOOKS_LIKE_STATIC(p)) ? \
237 : !closure_STATIC(p) && LOOKS_LIKE_PTR(p))
240 #endif /* PARALLEL_RTS_H */
242 //@node Index, , 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