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