61d0a9a99932dbce39965a212832b14723541346
[ghc-hetmet.git] / ghc / rts / RtsFlags.h
1 /* -----------------------------------------------------------------------------
2  * $Id: RtsFlags.h,v 1.25 2000/04/19 12:42:48 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Datatypes that holds the command-line flag settings.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef RTSFLAGS_H
11 #define RTSFLAGS_H
12
13 /* For defaults, see the @initRtsFlagsDefaults@ routine. */
14
15 struct GC_FLAGS {
16     FILE   *statsFile;
17     nat     giveStats;
18 #define NO_GC_STATS      0
19 #define SUMMARY_GC_STATS 1
20 #define VERBOSE_GC_STATS 2
21
22     nat     maxStkSize;         /* in *words* */
23     nat     initialStkSize;     /* in *words* */
24
25     nat     maxHeapSize;        /* in *blocks* */
26     nat     minAllocAreaSize;   /* in *blocks* */
27     nat     minOldGenSize;      /* in *blocks* */
28     nat     heapSizeSuggestion; /* in *blocks* */
29     double  oldGenFactor;
30     double  pcFreeHeap;
31
32     nat     generations;
33     nat     steps;
34
35     rtsBool ringBell;
36
37     rtsBool squeezeUpdFrames;
38 };
39
40 /* Hack: this struct uses bitfields so that we can use a binary arg
41  * with the -D flag.
42  * Remember to update the corresponding bit of RtsFlags.c if you
43  * change/extend this struct.
44  */
45 struct DEBUG_FLAGS {  
46   /* flags to control debugging output in various subsystems */
47   rtsBool scheduler   : 1; /*  1 */
48   rtsBool evaluator   : 1; /*  2 */
49   rtsBool codegen     : 1; /*  4 */
50   rtsBool weak        : 1; /*  8 */
51   rtsBool gccafs      : 1; /* 16 */
52   rtsBool gc          : 1; /* 32 */
53   rtsBool block_alloc : 1; /* 64 */
54
55   /* flags to control consistency checking (often very expensive!) */
56   rtsBool sanity      : 1; /* 128 */
57
58   rtsBool stable      : 1; /* 256 */
59   rtsBool prof        : 1; /* 512 */
60   rtsBool gran        : 1; /* 1024 */
61   rtsBool par         : 1; /* 2048 */
62 };
63
64 #define MAX_DEBUG_OPTION     11
65 #define DEBUG_MASK(n)        ((nat)(ldexp(1,n)))
66 #define MAX_DEBUG_MASK       ((nat)(ldexp(1,(MAX_DEBUG_OPTION+1))-1))
67
68 #if defined(PROFILING) || defined(PAR)
69     /* with PROFILING, full cost-centre stuff (also PROFILING_FLAGS);
70        with PAR, just the four fixed cost-centres.
71     */
72 struct COST_CENTRE_FLAGS {
73     unsigned int            doCostCentres;
74 # define COST_CENTRES_SUMMARY   1
75 # define COST_CENTRES_VERBOSE   2 /* incl. serial time profile */
76 # define COST_CENTRES_ALL       3
77 # define COST_CENTRES_XML       4
78
79     int     ctxtSwitchTicks; /* derived */
80     int     profilerTicks;   /* derived */
81     int     msecsPerTick;    /* derived */
82 };
83 #endif
84
85 #ifdef PROFILING
86 struct PROFILING_FLAGS {
87     unsigned int        doHeapProfile;
88
89 # define NO_HEAP_PROFILING      0       /* N.B. Used as indexes into arrays */
90 # define HEAP_BY_CCS            1
91 # define HEAP_BY_MOD            2
92 # define HEAP_BY_DESCR          4
93 # define HEAP_BY_TYPE           5
94 # define HEAP_BY_TIME           6
95
96     rtsBool             showCCSOnException;
97   
98 # define CCchar    'C'
99 # define MODchar   'M'
100 # define DESCRchar 'D'
101 # define TYPEchar  'Y'
102 # define TIMEchar  'T'
103 };
104 #elif defined(DEBUG)
105 # define NO_HEAP_PROFILING      0
106 # define HEAP_BY_INFOPTR        1
107 # define HEAP_BY_CLOSURE_TYPE   2
108 struct PROFILING_FLAGS {
109     unsigned int      doHeapProfile; /* heap profile using symbol table */
110 };
111 #endif /* DEBUG || PROFILING */
112
113 struct CONCURRENT_FLAGS {
114   int ctxtSwitchTime; /* in milliseconds */
115 };
116
117 #ifdef PAR
118 /* currently the same as GRAN_STATS_FLAGS */
119 struct PAR_STATS_FLAGS {
120   rtsBool Full;       /* Full .gr profile (rtsTrue) or only END events? */
121   // rtsBool Suppressed; /* No .gr profile at all */
122   rtsBool Binary;     /* Binary profile? (not yet implemented) */
123   rtsBool Sparks;     /* Info on sparks in profile? */
124   rtsBool Heap;       /* Info on heap allocs in profile? */ 
125   rtsBool NewLogfile; /* Use new log-file format? (not yet implemented) */
126   rtsBool Global;     /* Global statistics? (printed on shutdown; no log file) */
127 };
128
129 struct PAR_DEBUG_FLAGS {  
130   /* flags to control debugging output in various subsystems */
131   rtsBool verbose    : 1; /*    1 */
132   rtsBool trace      : 1; /*    2 */
133   rtsBool schedule   : 1; /*    4 */
134   rtsBool free       : 1; /*    8 */
135   rtsBool resume     : 1; /*   16 */
136   rtsBool weight     : 1; /*   32 */
137   rtsBool fetch      : 1; /*   64 */
138   rtsBool fish       : 1; /*  128 */
139   rtsBool tables     : 1; /*  256 */
140   rtsBool packet     : 1; /*  512 */
141   rtsBool pack       : 1; /* 1024 */
142 };
143
144 #define MAX_PAR_DEBUG_OPTION     10
145 #define PAR_DEBUG_MASK(n)        ((nat)(ldexp(1,n)))
146 #define MAX_PAR_DEBUG_MASK       ((nat)(ldexp(1,(MAX_PAR_DEBUG_OPTION+1))-1))
147
148 struct PAR_FLAGS {
149   struct PAR_STATS_FLAGS ParStats;  /* profile and stats output */
150   struct PAR_DEBUG_FLAGS Debug;         /* debugging options */
151   rtsBool  outputDisabled;        /* Disable output for performance purposes */
152   nat      packBufferSize;
153   nat      maxLocalSparks;        /* spark pool size */
154   nat      maxThreads;            /* thread pool size */
155   nat      maxFishes;             /* max number of active fishes */
156   rtsTime  fishDelay;             /* delay before sending a new fish */
157   long   wait;
158 };
159 #endif /* PAR */
160
161 #ifdef SMP
162 struct PAR_FLAGS {
163   nat            nNodes;         /* number of threads to run simultaneously */
164   unsigned int   maxLocalSparks;
165 };
166 #endif /* SMP */
167
168 #ifdef GRAN
169 struct GRAN_STATS_FLAGS {
170   rtsBool Full;       /* Full .gr profile (rtsTrue) or only END events? */
171   rtsBool Suppressed; /* No .gr profile at all */
172   rtsBool Binary;     /* Binary profile? (not yet implemented) */
173   rtsBool Sparks;     /* Info on sparks in profile? */
174   rtsBool Heap;       /* Info on heap allocs in profile? */ 
175   rtsBool NewLogfile; /* Use new log-file format? (not yet implemented) */
176   rtsBool Global;     /* Global statistics? (printed on shutdown; no log file) */
177 };
178
179 struct GRAN_COST_FLAGS {
180   /* Communication Cost Variables -- set in main program */
181   nat latency;              /* Latency for single packet */
182   nat additional_latency;   /* Latency for additional packets */
183   nat fetchtime;            
184   nat lunblocktime;         /* Time for local unblock */
185   nat gunblocktime;         /* Time for global unblock */
186   nat mpacktime;            /* Cost of creating a packet */     
187   nat munpacktime;          /* Cost of receiving a packet */    
188   nat mtidytime;            /* Cost of cleaning up after send */
189   
190   nat threadcreatetime;     /* Thread creation costs */
191   nat threadqueuetime;      /* Cost of adding a thread to the running/runnable queue */
192   nat threaddescheduletime; /* Cost of descheduling a thread */
193   nat threadscheduletime;   /* Cost of scheduling a thread */
194   nat threadcontextswitchtime;  /* Cost of context switch  */
195   
196   /* Instruction Costs */
197   nat arith_cost;        /* arithmetic instructions (+,i,< etc) */
198   nat branch_cost;       /* branch instructions */ 
199   nat load_cost;         /* load into register */
200   nat store_cost;        /* store into memory */
201   nat float_cost;        /* floating point operations */
202   
203   nat heapalloc_cost;    /* heap allocation costs */
204   
205   /* Overhead for granularity control mechanisms */
206   /* overhead per elem of spark queue */
207   nat pri_spark_overhead;
208   /* overhead per elem of thread queue */
209   nat pri_sched_overhead;
210 };
211
212 struct GRAN_DEBUG_FLAGS {  
213   /* flags to control debugging output in various subsystems */
214   rtsBool event_trace    : 1; /*    1 */
215   rtsBool event_stats    : 1; /*    2 */
216   rtsBool bq             : 1; /*    4 */
217   rtsBool pack           : 1; /*    8 */
218   rtsBool checkSparkQ    : 1; /*   16 */
219   rtsBool thunkStealing  : 1; /*   32 */
220   rtsBool randomSteal    : 1; /*   64 */
221   rtsBool findWork       : 1; /*  128 */
222   rtsBool unused         : 1; /*  256 */
223   rtsBool pri            : 1; /*  512 */
224   rtsBool checkLight     : 1; /* 1024 */
225   rtsBool sortedQ        : 1; /* 2048 */
226   rtsBool blockOnFetch   : 1; /* 4096 */
227   rtsBool packBuffer     : 1; /* 8192 */
228   rtsBool blockOnFetch_sanity : 1; /*  16384 */
229 };
230
231 #define MAX_GRAN_DEBUG_OPTION     14
232 #define GRAN_DEBUG_MASK(n)        ((nat)(ldexp(1,n)))
233 #define MAX_GRAN_DEBUG_MASK       ((nat)(ldexp(1,(MAX_GRAN_DEBUG_OPTION+1))-1))
234
235 struct GRAN_FLAGS {
236   struct GRAN_STATS_FLAGS GranSimStats;  /* profile and stats output */
237   struct GRAN_COST_FLAGS Costs;          /* cost metric for simulation */
238   struct GRAN_DEBUG_FLAGS Debug;         /* debugging options */
239
240   nat  maxThreads;              // ToDo: share with SMP and GUM
241   // rtsBool labelling;
242   nat  packBufferSize;
243   nat  packBufferSize_internal;
244
245   PEs proc;                     /* number of processors */
246   rtsBool Fishing;              /* Simulate GUM style fishing mechanism? */
247   nat maxFishes;                /* max number of spark or thread steals */
248   rtsTime time_slice;           /* max time slice of one reduction thread */
249
250     /* GrAnSim-Light: This version puts no bound on the number of
251          processors but in exchange doesn't model communication costs
252          (all communication is 0 cost). Mainly intended to show maximal
253          degree of parallelism in the program (*not* to simulate the
254          execution on a real machine). */
255    
256     rtsBool Light;
257
258     rtsBool DoFairSchedule ;        /* fair scheduling alg? default: unfair */
259     rtsBool DoAsyncFetch;           /* async. communication? */
260     rtsBool DoStealThreadsFirst;    /* prefer threads over sparks when stealing */
261   rtsBool DoAlwaysCreateThreads;  /* eager thread creation */
262   rtsBool DoBulkFetching;         /* bulk fetching */
263   rtsBool DoThreadMigration;      /* allow to move threads */
264   nat     FetchStrategy;         /* what to do when waiting for data */
265   rtsBool PreferSparksOfLocalNodes; /* prefer local over global sparks */
266   rtsBool DoPrioritySparking;     /* sparks sorted by priorities */
267   rtsBool DoPriorityScheduling;   /* threads sorted by priorities */
268   nat     SparkPriority;         /* threshold for cut-off mechanism */
269   nat     SparkPriority2;
270   rtsBool RandomPriorities;
271   rtsBool InversePriorities;
272   rtsBool IgnorePriorities;
273   nat     ThunksToPack;      /* number of thunks in packet + 1 */ 
274   rtsBool RandomSteal;        /* steal spark/thread from random proc */
275   rtsBool NoForward;        /* no forwarding of fetch messages */
276
277   // unsigned int           debug;
278   //  rtsBool event_trace;
279   //  rtsBool event_trace_all;
280 };
281 #endif /* GRAN */
282
283 #ifdef TICKY_TICKY
284 struct TICKY_FLAGS {
285     rtsBool showTickyStats;
286     FILE   *tickyFile;
287 };
288 #endif /* TICKY_TICKY */
289
290
291 /* Put them together: */
292
293 struct RTS_FLAGS {
294     struct GC_FLAGS     GcFlags;
295     struct DEBUG_FLAGS  DebugFlags;
296     struct CONCURRENT_FLAGS ConcFlags;
297
298 #if defined(PROFILING) || defined(PAR)
299     struct COST_CENTRE_FLAGS CcFlags;
300 #endif
301 #if defined(PROFILING) || defined(DEBUG)
302     struct PROFILING_FLAGS ProfFlags;
303 #endif
304 #if defined(SMP) || defined(PAR)
305     struct PAR_FLAGS    ParFlags;
306 #endif
307 #ifdef GRAN
308     struct GRAN_FLAGS   GranFlags;
309 #endif
310 #ifdef TICKY_TICKY
311     struct TICKY_FLAGS  TickyFlags;
312 #endif
313 };
314
315 #ifdef COMPILING_RTS_MAIN
316 extern DLLIMPORT struct RTS_FLAGS RtsFlags;
317 #else
318 extern struct RTS_FLAGS RtsFlags;
319 #endif
320
321 /* Routines that operate-on/to-do-with RTS flags: */
322
323 void initRtsFlagsDefaults(void);
324 void setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[]);
325
326 /*
327  * The printf formats are here, so we are less likely to make
328  * overly-long filenames (with disastrous results).  No more than 128
329  * chars, please!  
330  */
331
332 #define STATS_FILENAME_MAXLEN   128
333
334 #define GR_FILENAME_FMT         "%0.124s.gr"
335 #define GR_FILENAME_FMT_GUM     "%0.120s.%03d.%s"
336 #define HP_FILENAME_FMT         "%0.124s.hp"
337 #define LIFE_FILENAME_FMT       "%0.122s.life"
338 #define PROF_FILENAME_FMT       "%0.122s.prof"
339 #define PROF_FILENAME_FMT_GUM   "%0.118s.%03d.prof"
340 #define QP_FILENAME_FMT         "%0.124s.qp"
341 #define STAT_FILENAME_FMT       "%0.122s.stat"
342 #define TICKY_FILENAME_FMT      "%0.121s.ticky"
343 #define TIME_FILENAME_FMT       "%0.122s.time"
344 #define TIME_FILENAME_FMT_GUM   "%0.118s.%03d.time"
345
346 /* an "int" so as to match normal "argc" */
347 /* Now defined in Stg.h (lib/std/cbits need these too.)
348 extern int     prog_argc;
349 extern char  **prog_argv;
350 */
351 extern int     rts_argc;  /* ditto */
352 extern char   *rts_argv[];
353
354 #endif  /* RTSFLAGS_H */