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