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