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