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