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