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