ParallelRts.h 7.5 KB
Newer Older
1
/* --------------------------------------------------------------------------
2
   Time-stamp: <Tue Mar 06 2001 00:25:50 Stardate: [-30]6285.08 hwloidl>
3 4 5 6 7 8 9

   Variables and functions specific to the parallel RTS (i.e. GUM or GranSim)
   ----------------------------------------------------------------------- */

#ifndef PARALLEL_RTS_H
#define PARALLEL_RTS_H

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "ParTicky.h"

/* HWL HACK: compile time sanity checks; shouldn't be necessary at all */
#if defined(PAR) && defined(GRAN)
# error "Both PAR and GRAN defined"
#endif

#if defined(DEBUG)
/* Paranoia debugging: we add an end-of-buffer marker to every pack buffer 
                       (only when sanity checking RTS is enabled, of course) */
#define  DEBUG_HEADROOM        1
#define  END_OF_BUFFER_MARKER  0x1111bbbb
#define  GARBAGE_MARKER        0x1111eeee
#else
#define  DEBUG_HEADROOM        0
#endif /* DEBUG */

27 28 29
#if defined(GRAN) || defined(PAR)

#if defined(GRAN)
30

31 32 33 34 35
/* Statistics info */
extern nat tot_packets, tot_packet_size, tot_cuts, tot_thunks;

/* Pack.c */
rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, 
36
			       nat *packBufferSize, GlobalTaskId dest); 
37 38 39 40 41 42 43 44 45 46 47 48 49 50
rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso, 
			   nat *packBufferSize);
rtsPackBuffer *PackTSO(StgTSO *tso, nat *packBufferSize);
rtsPackBuffer *PackStkO(StgPtr stko, nat *packBufferSize);
void           PackFetchMe(StgClosure *closure);

/* Unpack.c */
StgClosure*    UnpackGraph(rtsPackBuffer* buffer);
void           InitPendingGABuffer(nat size); 

/* RBH.c */
StgClosure    *convertToRBH(StgClosure *closure);
void           convertFromRBH(StgClosure *closure);

51 52
/* HLComms.c */
rtsFetchReturnCode blockFetch(StgTSO* tso, PEs proc, StgClosure* bh);
53
void               blockThread(StgTSO *tso);
54

55 56
#endif
#if defined(PAR)
57

58
/* Statistics info */
59

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/* global structure for collecting statistics */
typedef struct GlobalParStats_ {
  /* GALA and LAGA table info */
  nat tot_mark_GA, tot_rebuild_GA, tot_free_GA,
      res_mark_GA, res_rebuild_GA, res_free_GA,
      cnt_mark_GA, cnt_rebuild_GA, cnt_free_GA,
      res_size_GA, tot_size_GA, local_alloc_GA, tot_global, tot_local;

  /* time spent managing the GAs */
  double time_mark_GA, time_rebuild_GA;

  /* spark queue stats */
  nat res_sp, tot_sp, cnt_sp, emp_sp;
  // nat tot_sq_len, tot_sq_probes, tot_sparks;
  /* thread queue stats */
  nat res_tp, tot_tp, cnt_tp, emp_tp;
  //nat tot_add_threads, tot_tq_len, non_end_add_threads;

  /* packet statistics */
  nat tot_packets, tot_packet_size, tot_thunks,
      res_packet_size, res_thunks,
      rec_packets, rec_packet_size, rec_thunks,
      rec_res_packet_size, rec_res_thunks;
  /* time spent packing stuff */
  double time_pack, time_unpack;

  /* thread stats */
  nat tot_threads_created;

  /* spark stats */
  //nat pruned_sparks, withered_sparks;
  nat tot_sparks_created, tot_sparks_ignored, tot_sparks_marked,
      res_sparks_created, res_sparks_ignored, res_sparks_marked; // , sparks_created_on_PE[MAX_PROC];
  double time_sparks;

  /* scheduling stats */
  nat tot_yields, tot_stackover, tot_heapover;

  /* message statistics */
  nat tot_fish_mess, tot_fetch_mess, tot_resume_mess, tot_schedule_mess;
  nat rec_fish_mess, rec_fetch_mess, rec_resume_mess, rec_schedule_mess;
#if defined(DIST)
  nat tot_reval_mess;
  nat rec_reval_mess;
104
#endif
105 106 107 108 109 110 111 112 113 114 115 116 117

  /* blocking queue statistics
  rtsTime tot_bq_processing_time;
  nat tot_bq_len, tot_bq_len_local, tot_awbq, tot_FMBQs;
  */

  /* specialised info on arrays (for GPH/Maple mainly) */
  nat tot_arrs, tot_arr_size;
} GlobalParStats;

extern GlobalParStats globalParStats;

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 125 126 127 128 129 130 131 132

/* Unpack.c */
void           CommonUp(StgClosure *src, StgClosure *dst);
StgClosure    *UnpackGraph(rtsPackBuffer *buffer, globalAddr **gamap, 
			   nat *nGAs);

/* RBH.c */
StgClosure    *convertToRBH(StgClosure *closure);
void           convertToFetchMe(StgRBH *rbh, globalAddr *ga);

133 134 135 136 137 138 139
/* HLComms.c */
void           blockFetch(StgBlockedFetch *bf, StgClosure *bh);
void           blockThread(StgTSO *tso);

/* Global.c */
void           GALAdeprecate(globalAddr *ga);

140 141
/* HLComms.c */
nat            pending_fetches_len(void);
142

143 144 145 146 147
/* ParInit.c */
void 	       initParallelSystem(void);
void 	       shutdownParallelSystem(StgInt n);
void 	       synchroniseSystem(void);
void 	       par_exit(I_);
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

#endif

/* this routine should be moved to a more general module; currently in Pack.c 
StgInfoTable* get_closure_info(StgClosure* node, 
			       nat *size, nat *ptrs, nat *nonptrs, nat *vhs, 
			       char *info_hdr_ty);
*/
void doGlobalGC(void); 

//@node GC routines, Debugging routines, Spark handling routines
//@subsection GC routines

#if defined(PAR)
/* HLComms.c */
void      freeRemoteGA(int pe, globalAddr *ga);
void      sendFreeMessages(void);
165
void      markPendingFetches(rtsBool major_gc);
166 167 168 169 170 171 172 173 174 175 176 177 178 179

/* Global.c */
void      markLocalGAs(rtsBool full);
void      RebuildGAtables(rtsBool full);
void      RebuildLAGAtable(void);
#endif

//@node Debugging routines, Generating .gr profiles, GC routines
//@subsection Debugging routines

#if defined(PAR)
void      printGA (globalAddr *ga);
void      printGALA (GALA *gala);
void      printLAGAtable(void);
180 181 182 183 184

rtsBool   isOnLiveIndTable(globalAddr *ga);
rtsBool   isOnRemoteGATable(globalAddr *ga);
void      checkFreeGALAList(void);
void      checkFreeIndirectionsList(void);
185 186
#endif

187
//@node Generating .gr profiles, Index, Debugging routines
188 189 190 191 192 193 194 195 196 197
//@subsection Generating .gr profiles

#define STATS_FILENAME_MAXLEN	128

/* Where to write the log file */
//@cindex gr_file
//@cindex gr_filename
extern FILE *gr_file;
extern char gr_filename[STATS_FILENAME_MAXLEN];

198
//@cindex init_gr_stats
199 200
//@cindex init_gr_simulation
//@cindex end_gr_simulation
201 202 203 204
void 	  	init_gr_stats (void);
void 	  	init_gr_simulation(int rts_argc, char *rts_argv[], 
 	 			   int prog_argc, char *prog_argv[]);
void 	  	end_gr_simulation(void);
205

206
// TODO: move fcts in here (as static inline)
207 208 209 210
StgInfoTable*   get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, nat *vhs, char *info_hdr_ty);
rtsBool         IS_BLACK_HOLE(StgClosure* node);
StgClosure     *IS_INDIRECTION(StgClosure* node)          ;
StgClosure     *UNWIND_IND (StgClosure *closure);
211 212 213 214


#endif /* defined(PAR) || defined(GRAN) */

215 216 217
//@node Common macros, Index, Generating .gr profiles
//@subsection Common macros

218 219 220 221 222 223
#define LOOKS_LIKE_PTR(r)    \
        (LOOKS_LIKE_STATIC_CLOSURE(r) ||  \
         ((HEAP_ALLOCED(r) && Bdescr((P_)r)->free != (void *)-1)))

/* see Sanity.c for this kind of test; doing this in these basic fcts
   is paranoid (nuke it after debugging!)
224 225
*/

226 227 228 229 230 231 232 233 234 235 236 237
/* pathetic version of the check whether p can be a closure */
#define LOOKS_LIKE_COOL_CLOSURE(p)  1

//LOOKS_LIKE_GHC_INFO(get_itbl(p))

    /* Is it a static closure (i.e. in the data segment)? */ \
    /*
#define LOOKS_LIKE_COOL_CLOSURE(p)  \
    ((LOOKS_LIKE_STATIC(p)) ?                                   \
	closure_STATIC(p)                               \
      : !closure_STATIC(p) && LOOKS_LIKE_PTR(p))
    */
238 239 240

#endif /* PARALLEL_RTS_H */

241
//@node Index,  , Index
242 243 244 245 246 247 248 249 250 251 252 253
//@subsection Index

//@index
//* IS_BLACK_HOLE::  @cindex\s-+IS_BLACK_HOLE
//* IS_INDIRECTION::  @cindex\s-+IS_INDIRECTION
//* end_gr_simulation::  @cindex\s-+end_gr_simulation
//* get_closure_info::  @cindex\s-+get_closure_info
//* gr_file::  @cindex\s-+gr_file
//* gr_filename::  @cindex\s-+gr_filename
//* init_gr_simulation::  @cindex\s-+init_gr_simulation
//* unwindInd::  @cindex\s-+unwindInd
//@end index