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