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