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