5c72bbb3e21a8f785b5864861b668db71a6443bd
[ghc-hetmet.git] / includes / RtsFlags.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-1999
4  *
5  * Datatypes that holds the command-line flag settings.
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef RTSFLAGS_H
10 #define RTSFLAGS_H
11
12 #include <stdio.h>
13
14 /* For defaults, see the @initRtsFlagsDefaults@ routine. */
15
16 struct GC_FLAGS {
17     FILE   *statsFile;
18     nat     giveStats;
19 #define NO_GC_STATS      0
20 #define COLLECT_GC_STATS 1
21 #define ONELINE_GC_STATS 2
22 #define SUMMARY_GC_STATS 3
23 #define VERBOSE_GC_STATS 4
24
25     nat     maxStkSize;         /* in *words* */
26     nat     initialStkSize;     /* in *words* */
27
28     nat     maxHeapSize;        /* in *blocks* */
29     nat     minAllocAreaSize;   /* in *blocks* */
30     nat     minOldGenSize;      /* in *blocks* */
31     nat     heapSizeSuggestion; /* in *blocks* */
32     double  oldGenFactor;
33     double  pcFreeHeap;
34
35     nat     generations;
36     nat     steps;
37     rtsBool squeezeUpdFrames;
38
39     rtsBool compact;            /* True <=> "compact all the time" */
40     double  compactThreshold;
41
42     rtsBool sweep;              /* use "mostly mark-sweep" instead of copying
43                                  * for the oldest generation */
44     rtsBool ringBell;
45     rtsBool frontpanel;
46
47     int idleGCDelayTime;        /* in milliseconds */
48
49     StgWord heapBase;           /* address to ask the OS for memory */
50 };
51
52 struct DEBUG_FLAGS {  
53     /* flags to control debugging output & extra checking in various subsystems */
54     rtsBool scheduler;      /* 's' */
55     rtsBool interpreter;    /* 'i' */
56     rtsBool weak;           /* 'w' */
57     rtsBool gccafs;         /* 'G' */
58     rtsBool gc;             /* 'g' */
59     rtsBool block_alloc;    /* 'b' */
60     rtsBool sanity;         /* 'S'   warning: might be expensive! */
61     rtsBool stable;         /* 't' */
62     rtsBool prof;           /* 'p' */
63     rtsBool gran;           /* 'r' */
64     rtsBool par;            /* 'P' */
65     rtsBool linker;         /* 'l'   the object linker */
66     rtsBool apply;          /* 'a' */
67     rtsBool stm;            /* 'm' */
68     rtsBool squeeze;        /* 'z'  stack squeezing & lazy blackholing */
69     rtsBool hpc;            /* 'c' coverage */
70 };
71
72 struct COST_CENTRE_FLAGS {
73     unsigned int            doCostCentres;
74 # define COST_CENTRES_SUMMARY   1
75 # define COST_CENTRES_VERBOSE   2 /* incl. serial time profile */
76 # define COST_CENTRES_ALL       3
77 # define COST_CENTRES_XML       4
78
79     int     profilerTicks;   /* derived */
80     int     msecsPerTick;    /* derived */
81 };
82
83 struct PROFILING_FLAGS {
84     unsigned int        doHeapProfile;
85 # define NO_HEAP_PROFILING      0       /* N.B. Used as indexes into arrays */
86 # define HEAP_BY_CCS            1
87 # define HEAP_BY_MOD            2
88 # define HEAP_BY_DESCR          4
89 # define HEAP_BY_TYPE           5
90 # define HEAP_BY_RETAINER       6
91 # define HEAP_BY_LDV            7
92
93 # define HEAP_BY_CLOSURE_TYPE   8
94
95     nat                 profileInterval;      /* delta between samples (in ms) */
96     nat                 profileIntervalTicks; /* delta between samples (in 'ticks') */
97     rtsBool             includeTSOs;
98
99
100     rtsBool             showCCSOnException;
101
102     nat                 maxRetainerSetSize;
103
104     nat                 ccsLength;
105
106     char*               modSelector;
107     char*               descrSelector;
108     char*               typeSelector;
109     char*               ccSelector;
110     char*               ccsSelector;
111     char*               retainerSelector;
112     char*               bioSelector;
113
114 };
115
116 struct CONCURRENT_FLAGS {
117     int ctxtSwitchTime;         /* in milliseconds */
118     int ctxtSwitchTicks;        /* derived */
119 };
120
121 struct MISC_FLAGS {
122     int tickInterval;     /* in milliseconds */
123     rtsBool install_signal_handlers;
124     rtsBool machineReadable;
125     StgWord linkerMemBase;       /* address to ask the OS for memory
126                                   * for the linker, NULL ==> off */
127 };
128
129 #ifdef PAR
130 /* currently the same as GRAN_STATS_FLAGS */
131 struct PAR_STATS_FLAGS {
132   rtsBool Full;       /* Full .gr profile (rtsTrue) or only END events? */
133   rtsBool Suppressed; /* No .gr profile at all */
134   rtsBool Binary;     /* Binary profile? (not yet implemented) */
135   rtsBool Sparks;     /* Info on sparks in profile? */
136   rtsBool Heap;       /* Info on heap allocs in profile? */ 
137   rtsBool NewLogfile; /* Use new log-file format? (not yet implemented) */
138   rtsBool Global;     /* Global statistics? (printed on shutdown; no log file) */
139 };
140
141 struct PAR_DEBUG_FLAGS {  
142   /* flags to control debugging output in various subsystems */
143   rtsBool verbose    : 1; /*    1 */
144   rtsBool bq         : 1; /*    2 */
145   rtsBool schedule   : 1; /*    4 */
146   rtsBool free       : 1; /*    8 */
147   rtsBool resume     : 1; /*   16 */
148   rtsBool weight     : 1; /*   32 */
149   rtsBool fetch      : 1; /*   64 */
150   rtsBool fish       : 1; /*  128 */
151   rtsBool tables     : 1; /*  256 */
152   rtsBool packet     : 1; /*  512 */
153   rtsBool pack       : 1; /* 1024 */
154   rtsBool paranoia   : 1; /* 2048 */
155 };
156
157 #define MAX_PAR_DEBUG_OPTION     11
158 #define PAR_DEBUG_MASK(n)        ((nat)(ldexp(1,n)))
159 #define MAX_PAR_DEBUG_MASK       ((nat)(ldexp(1,(MAX_PAR_DEBUG_OPTION+1))-1))
160
161 struct PAR_FLAGS {
162   struct PAR_STATS_FLAGS ParStats;  /* profile and stats output */
163   struct PAR_DEBUG_FLAGS Debug;         /* debugging options */
164   rtsBool  outputDisabled;        /* Disable output for performance purposes */
165   rtsBool  doFairScheduling;      /* Fair-ish scheduling (round robin; no time-slices) */
166   nat      packBufferSize;
167   nat      thunksToPack;          /* number of thunks in packet + 1 */ 
168   nat      globalising;           /* globalisation scheme */
169   nat      maxLocalSparks;        /* spark pool size */
170   nat      maxThreads;            /* thread pool size */
171   nat      maxFishes;             /* max number of active fishes */
172   rtsTime  fishDelay;             /* delay before sending a new fish */
173   long   wait;
174 };
175 #endif /* PAR */
176
177 #ifdef THREADED_RTS
178 struct PAR_FLAGS {
179   nat            nNodes;         /* number of threads to run simultaneously */
180   rtsBool        migrate;        /* migrate threads between capabilities */
181   rtsBool        wakeupMigrate;  /* migrate a thread on wakeup */
182   unsigned int   maxLocalSparks;
183   rtsBool        parGcEnabled;   /* enable parallel GC */
184   rtsBool        parGcGen;       /* do parallel GC in this generation
185                                   * and higher only */
186   rtsBool        parGcLoadBalancing; /* do load-balancing in parallel GC */
187 };
188 #endif /* THREADED_RTS */
189
190 #ifdef GRAN
191 struct GRAN_STATS_FLAGS {
192   rtsBool Full;       /* Full .gr profile (rtsTrue) or only END events? */
193   rtsBool Suppressed; /* No .gr profile at all */
194   rtsBool Binary;     /* Binary profile? (not yet implemented) */
195   rtsBool Sparks;     /* Info on sparks in profile? */
196   rtsBool Heap;       /* Info on heap allocs in profile? */ 
197   rtsBool NewLogfile; /* Use new log-file format? (not yet implemented) */
198   rtsBool Global;     /* Global statistics? (printed on shutdown; no log file) */
199 };
200
201 struct GRAN_COST_FLAGS {
202   /* Communication Cost Variables -- set in main program */
203   nat latency;              /* Latency for single packet */
204   nat additional_latency;   /* Latency for additional packets */
205   nat fetchtime;            
206   nat lunblocktime;         /* Time for local unblock */
207   nat gunblocktime;         /* Time for global unblock */
208   nat mpacktime;            /* Cost of creating a packet */     
209   nat munpacktime;          /* Cost of receiving a packet */    
210   nat mtidytime;            /* Cost of cleaning up after send */
211   
212   nat threadcreatetime;     /* Thread creation costs */
213   nat threadqueuetime;      /* Cost of adding a thread to the running/runnable queue */
214   nat threaddescheduletime; /* Cost of descheduling a thread */
215   nat threadscheduletime;   /* Cost of scheduling a thread */
216   nat threadcontextswitchtime;  /* Cost of context switch  */
217   
218   /* Instruction Costs */
219   nat arith_cost;        /* arithmetic instructions (+,i,< etc) */
220   nat branch_cost;       /* branch instructions */ 
221   nat load_cost;         /* load into register */
222   nat store_cost;        /* store into memory */
223   nat float_cost;        /* floating point operations */
224   
225   nat heapalloc_cost;    /* heap allocation costs */
226   
227   /* Overhead for granularity control mechanisms */
228   /* overhead per elem of spark queue */
229   nat pri_spark_overhead;
230   /* overhead per elem of thread queue */
231   nat pri_sched_overhead;
232 };
233
234 struct GRAN_DEBUG_FLAGS {  
235   /* flags to control debugging output in various subsystems */
236   rtsBool event_trace    : 1; /*    1 */
237   rtsBool event_stats    : 1; /*    2 */
238   rtsBool bq             : 1; /*    4 */
239   rtsBool pack           : 1; /*    8 */
240   rtsBool checkSparkQ    : 1; /*   16 */
241   rtsBool thunkStealing  : 1; /*   32 */
242   rtsBool randomSteal    : 1; /*   64 */
243   rtsBool findWork       : 1; /*  128 */
244   rtsBool unused         : 1; /*  256 */
245   rtsBool pri            : 1; /*  512 */
246   rtsBool checkLight     : 1; /* 1024 */
247   rtsBool sortedQ        : 1; /* 2048 */
248   rtsBool blockOnFetch   : 1; /* 4096 */
249   rtsBool packBuffer     : 1; /* 8192 */
250   rtsBool blockOnFetch_sanity : 1; /*  16384 */
251 };
252
253 #define MAX_GRAN_DEBUG_OPTION     14
254 #define GRAN_DEBUG_MASK(n)        ((nat)(ldexp(1,n)))
255 #define MAX_GRAN_DEBUG_MASK       ((nat)(ldexp(1,(MAX_GRAN_DEBUG_OPTION+1))-1))
256
257 struct GRAN_FLAGS {
258   struct GRAN_STATS_FLAGS GranSimStats;  /* profile and stats output */
259   struct GRAN_COST_FLAGS Costs;          /* cost metric for simulation */
260   struct GRAN_DEBUG_FLAGS Debug;         /* debugging options */
261
262   nat  maxThreads;              /* ToDo: share with THREADED_RTS and GUM */
263   /* rtsBool labelling; */
264   nat  packBufferSize;
265   nat  packBufferSize_internal;
266
267   PEs proc;                     /* number of processors */
268   rtsBool Fishing;              /* Simulate GUM style fishing mechanism? */
269   nat maxFishes;                /* max number of spark or thread steals */
270   rtsTime time_slice;           /* max time slice of one reduction thread */
271
272     /* GrAnSim-Light: This version puts no bound on the number of
273          processors but in exchange doesn't model communication costs
274          (all communication is 0 cost). Mainly intended to show maximal
275          degree of parallelism in the program (*not* to simulate the
276          execution on a real machine). */
277    
278     rtsBool Light;
279
280     rtsBool DoFairSchedule ;        /* fair scheduling alg? default: unfair */
281     rtsBool DoAsyncFetch;           /* async. communication? */
282     rtsBool DoStealThreadsFirst;    /* prefer threads over sparks when stealing */
283   rtsBool DoAlwaysCreateThreads;  /* eager thread creation */
284   rtsBool DoBulkFetching;         /* bulk fetching */
285   rtsBool DoThreadMigration;      /* allow to move threads */
286   nat     FetchStrategy;         /* what to do when waiting for data */
287   rtsBool PreferSparksOfLocalNodes; /* prefer local over global sparks */
288   rtsBool DoPrioritySparking;     /* sparks sorted by priorities */
289   rtsBool DoPriorityScheduling;   /* threads sorted by priorities */
290   nat     SparkPriority;         /* threshold for cut-off mechanism */
291   nat     SparkPriority2;
292   rtsBool RandomPriorities;
293   rtsBool InversePriorities;
294   rtsBool IgnorePriorities;
295   nat     ThunksToPack;      /* number of thunks in packet + 1 */ 
296   rtsBool RandomSteal;        /* steal spark/thread from random proc */
297   rtsBool NoForward;        /* no forwarding of fetch messages */
298
299   /* unsigned int           debug; */
300   /*  rtsBool event_trace; */
301   /*  rtsBool event_trace_all; */
302 };
303 #endif /* GRAN */
304
305 struct TICKY_FLAGS {
306     rtsBool showTickyStats;
307     FILE   *tickyFile;
308 };
309
310 struct TRACE_FLAGS {
311     rtsBool sched;              /* trace scheduler events for profiling */
312     rtsBool gc;                 /* trace GC events */
313     rtsBool timestamp;          /* add timestamps to traces */
314 };
315
316 #ifdef USE_PAPI
317 #define MAX_PAPI_USER_EVENTS 8
318
319 struct PAPI_FLAGS {
320     nat     eventType;          /* The type of events to count */
321     nat     numUserEvents;
322     char *  userEvents[MAX_PAPI_USER_EVENTS];
323 };
324
325 #define PAPI_FLAG_CACHE_L1 1
326 #define PAPI_FLAG_CACHE_L2 2
327 #define PAPI_FLAG_BRANCH 3
328 #define PAPI_FLAG_STALLS 4
329 #define PAPI_FLAG_CB_EVENTS 5
330 #define PAPI_USER_EVENTS 6
331
332 #endif
333
334 /* Put them together: */
335
336 typedef struct _RTS_FLAGS {
337     /* The first portion of RTS_FLAGS is invariant. */
338     struct GC_FLAGS          GcFlags;
339     struct CONCURRENT_FLAGS  ConcFlags;
340     struct MISC_FLAGS        MiscFlags;
341     struct DEBUG_FLAGS       DebugFlags;
342     struct COST_CENTRE_FLAGS CcFlags;
343     struct PROFILING_FLAGS   ProfFlags;
344     struct TICKY_FLAGS       TickyFlags;
345     struct TRACE_FLAGS       TraceFlags;
346
347 #if defined(THREADED_RTS) || defined(PAR)
348     struct PAR_FLAGS    ParFlags;
349 #endif
350 #ifdef GRAN
351     struct GRAN_FLAGS   GranFlags;
352 #endif
353 #ifdef USE_PAPI
354     struct PAPI_FLAGS   PapiFlags;
355 #endif
356 } RTS_FLAGS;
357
358 #ifdef COMPILING_RTS_MAIN
359 extern DLLIMPORT RTS_FLAGS RtsFlags;
360 #elif IN_STG_CODE
361 /* Hack because the C code generator can't generate '&label'. */
362 extern RTS_FLAGS RtsFlags[];
363 #else
364 extern RTS_FLAGS RtsFlags;
365 #endif
366
367 /* Routines that operate-on/to-do-with RTS flags: */
368
369 extern void initRtsFlagsDefaults(void);
370 extern void setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[]);
371 extern void setProgName(char *argv[]);
372
373
374 /*
375  * The printf formats are here, so we are less likely to make
376  * overly-long filenames (with disastrous results).  No more than 128
377  * chars, please!  
378  */
379
380 #define STATS_FILENAME_MAXLEN   128
381
382 #define GR_FILENAME_FMT         "%0.124s.gr"
383 #define GR_FILENAME_FMT_GUM     "%0.120s.%03d.%s"
384 #define HP_FILENAME_FMT         "%0.124s.hp"
385 #define LIFE_FILENAME_FMT       "%0.122s.life"
386 #define PROF_FILENAME_FMT       "%0.122s.prof"
387 #define PROF_FILENAME_FMT_GUM   "%0.118s.%03d.prof"
388 #define QP_FILENAME_FMT         "%0.124s.qp"
389 #define STAT_FILENAME_FMT       "%0.122s.stat"
390 #define TICKY_FILENAME_FMT      "%0.121s.ticky"
391 #define TIME_FILENAME_FMT       "%0.122s.time"
392 #define TIME_FILENAME_FMT_GUM   "%0.118s.%03d.time"
393
394 /* an "int" so as to match normal "argc" */
395 /* Now defined in Stg.h (lib/std/cbits need these too.)
396 extern int     prog_argc;
397 extern char  **prog_argv;
398 */
399 extern int     rts_argc;  /* ditto */
400 extern char   *rts_argv[];
401
402 #endif  /* RTSFLAGS_H */