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