6040201c737d259befd66e570495944b5314a035
[ghc.git] / includes / rts / Flags.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2009
4 *
5 * Datatypes that holds the command-line flag settings.
6 *
7 * Do not #include this file directly: #include "Rts.h" instead.
8 *
9 * To understand the structure of the RTS headers, see the wiki:
10 * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
11 *
12 * ---------------------------------------------------------------------------*/
13
14 #pragma once
15
16 #include <stdio.h>
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include "stg/Types.h"
20 #include "Time.h"
21
22 /* For defaults, see the @initRtsFlagsDefaults@ routine. */
23
24 /* Note [Synchronization of flags and base APIs]
25 *
26 * We provide accessors to RTS flags in base. (GHC.RTS module)
27 * The API should be updated whenever RTS flags are modified.
28 */
29
30 /* See Note [Synchronization of flags and base APIs] */
31 typedef struct _GC_FLAGS {
32 FILE *statsFile;
33 uint32_t giveStats;
34 #define NO_GC_STATS 0
35 #define COLLECT_GC_STATS 1
36 #define ONELINE_GC_STATS 2
37 #define SUMMARY_GC_STATS 3
38 #define VERBOSE_GC_STATS 4
39
40 uint32_t maxStkSize; /* in *words* */
41 uint32_t initialStkSize; /* in *words* */
42 uint32_t stkChunkSize; /* in *words* */
43 uint32_t stkChunkBufferSize; /* in *words* */
44
45 uint32_t maxHeapSize; /* in *blocks* */
46 uint32_t minAllocAreaSize; /* in *blocks* */
47 uint32_t largeAllocLim; /* in *blocks* */
48 uint32_t nurseryChunkSize; /* in *blocks* */
49 uint32_t minOldGenSize; /* in *blocks* */
50 uint32_t heapSizeSuggestion; /* in *blocks* */
51 bool heapSizeSuggestionAuto;
52 double oldGenFactor;
53 double pcFreeHeap;
54
55 uint32_t generations;
56 bool squeezeUpdFrames;
57
58 bool compact; /* True <=> "compact all the time" */
59 double compactThreshold;
60
61 bool sweep; /* use "mostly mark-sweep" instead of copying
62 * for the oldest generation */
63 bool ringBell;
64
65 Time idleGCDelayTime; /* units: TIME_RESOLUTION */
66 bool doIdleGC;
67
68 StgWord heapBase; /* address to ask the OS for memory */
69
70 StgWord allocLimitGrace; /* units: *blocks*
71 * After an AllocationLimitExceeded
72 * exception has been raised, how much
73 * extra space is given to the thread
74 * to handle the exception before we
75 * raise it again.
76 */
77 StgWord heapLimitGrace; /* units: *blocks*
78 * After a HeapOverflow exception has
79 * been raised, how much extra space is
80 * given to the thread to handle the
81 * exception before we raise it again.
82 */
83
84 bool numa; /* Use NUMA */
85 StgWord numaMask;
86 } GC_FLAGS;
87
88 /* See Note [Synchronization of flags and base APIs] */
89 typedef struct _DEBUG_FLAGS {
90 /* flags to control debugging output & extra checking in various subsystems */
91 bool scheduler; /* 's' */
92 bool interpreter; /* 'i' */
93 bool weak; /* 'w' */
94 bool gccafs; /* 'G' */
95 bool gc; /* 'g' */
96 bool block_alloc; /* 'b' */
97 bool sanity; /* 'S' warning: might be expensive! */
98 bool stable; /* 't' */
99 bool prof; /* 'p' */
100 bool linker; /* 'l' the object linker */
101 bool apply; /* 'a' */
102 bool stm; /* 'm' */
103 bool squeeze; /* 'z' stack squeezing & lazy blackholing */
104 bool hpc; /* 'c' coverage */
105 bool sparks; /* 'r' */
106 bool numa; /* '--debug-numa' */
107 bool compact; /* 'C' */
108 } DEBUG_FLAGS;
109
110 /* See Note [Synchronization of flags and base APIs] */
111 typedef struct _COST_CENTRE_FLAGS {
112 uint32_t doCostCentres;
113 # define COST_CENTRES_NONE 0
114 # define COST_CENTRES_SUMMARY 1
115 # define COST_CENTRES_VERBOSE 2 /* incl. serial time profile */
116 # define COST_CENTRES_ALL 3
117 # define COST_CENTRES_JSON 4
118
119 int profilerTicks; /* derived */
120 int msecsPerTick; /* derived */
121 char const *outputFileNameStem;
122 } COST_CENTRE_FLAGS;
123
124 /* See Note [Synchronization of flags and base APIs] */
125 typedef struct _PROFILING_FLAGS {
126 uint32_t doHeapProfile;
127 # define NO_HEAP_PROFILING 0 /* N.B. Used as indexes into arrays */
128 # define HEAP_BY_CCS 1
129 # define HEAP_BY_MOD 2
130 # define HEAP_BY_DESCR 4
131 # define HEAP_BY_TYPE 5
132 # define HEAP_BY_RETAINER 6
133 # define HEAP_BY_LDV 7
134
135 # define HEAP_BY_CLOSURE_TYPE 8
136
137 Time heapProfileInterval; /* time between samples */
138 uint32_t heapProfileIntervalTicks; /* ticks between samples (derived) */
139 bool includeTSOs;
140
141
142 bool showCCSOnException;
143
144 uint32_t maxRetainerSetSize;
145
146 uint32_t ccsLength;
147
148 const char* modSelector;
149 const char* descrSelector;
150 const char* typeSelector;
151 const char* ccSelector;
152 const char* ccsSelector;
153 const char* retainerSelector;
154 const char* bioSelector;
155
156 } PROFILING_FLAGS;
157
158 #define TRACE_NONE 0
159 #define TRACE_EVENTLOG 1
160 #define TRACE_STDERR 2
161
162 /* See Note [Synchronization of flags and base APIs] */
163 typedef struct _TRACE_FLAGS {
164 int tracing;
165 bool timestamp; /* show timestamp in stderr output */
166 bool scheduler; /* trace scheduler events */
167 bool gc; /* trace GC events */
168 bool sparks_sampled; /* trace spark events by a sampled method */
169 bool sparks_full; /* trace spark events 100% accurately */
170 bool user; /* trace user events (emitted from Haskell code) */
171 } TRACE_FLAGS;
172
173 /* See Note [Synchronization of flags and base APIs] */
174 typedef struct _CONCURRENT_FLAGS {
175 Time ctxtSwitchTime; /* units: TIME_RESOLUTION */
176 int ctxtSwitchTicks; /* derived */
177 } CONCURRENT_FLAGS;
178
179 /*
180 * The tickInterval is the time interval between "ticks", ie.
181 * timer signals (see Timer.{c,h}). It is the frequency at
182 * which we sample CCCS for profiling.
183 *
184 * It is changed by the +RTS -V<secs> flag.
185 */
186 #define DEFAULT_TICK_INTERVAL USToTime(10000)
187
188 /* See Note [Synchronization of flags and base APIs] */
189 typedef struct _MISC_FLAGS {
190 Time tickInterval; /* units: TIME_RESOLUTION */
191 bool install_signal_handlers;
192 bool machineReadable;
193 StgWord linkerMemBase; /* address to ask the OS for memory
194 * for the linker, NULL ==> off */
195 } MISC_FLAGS;
196
197 /* See Note [Synchronization of flags and base APIs] */
198 typedef struct _PAR_FLAGS {
199 uint32_t nCapabilities; /* number of threads to run simultaneously */
200 bool migrate; /* migrate threads between capabilities */
201 uint32_t maxLocalSparks;
202 bool parGcEnabled; /* enable parallel GC */
203 uint32_t parGcGen; /* do parallel GC in this generation
204 * and higher only */
205 bool parGcLoadBalancingEnabled;
206 /* enable load-balancing in the
207 * parallel GC */
208 uint32_t parGcLoadBalancingGen;
209 /* do load-balancing in this
210 * generation and higher only */
211
212 uint32_t parGcNoSyncWithIdle;
213 /* if a Capability has been idle for
214 * this many GCs, do not try to wake
215 * it up when doing a
216 * non-load-balancing parallel GC.
217 * (zero disables) */
218
219 uint32_t parGcThreads;
220 /* Use this many threads for parallel
221 * GC (default: use all nNodes). */
222
223 bool setAffinity; /* force thread affinity with CPUs */
224 } PAR_FLAGS;
225
226 /* See Note [Synchronization of flags and base APIs] */
227 typedef struct _TICKY_FLAGS {
228 bool showTickyStats;
229 FILE *tickyFile;
230 } TICKY_FLAGS;
231
232 /* Put them together: */
233
234 /* See Note [Synchronization of flags and base APIs] */
235 typedef struct _RTS_FLAGS {
236 /* The first portion of RTS_FLAGS is invariant. */
237 GC_FLAGS GcFlags;
238 CONCURRENT_FLAGS ConcFlags;
239 MISC_FLAGS MiscFlags;
240 DEBUG_FLAGS DebugFlags;
241 COST_CENTRE_FLAGS CcFlags;
242 PROFILING_FLAGS ProfFlags;
243 TRACE_FLAGS TraceFlags;
244 TICKY_FLAGS TickyFlags;
245 PAR_FLAGS ParFlags;
246 } RTS_FLAGS;
247
248 #if defined(COMPILING_RTS_MAIN)
249 extern DLLIMPORT RTS_FLAGS RtsFlags;
250 #elif IN_STG_CODE
251 /* Hack because the C code generator can't generate '&label'. */
252 extern RTS_FLAGS RtsFlags[];
253 #else
254 extern RTS_FLAGS RtsFlags;
255 #endif
256
257 /*
258 * The printf formats are here, so we are less likely to make
259 * overly-long filenames (with disastrous results). No more than 128
260 * chars, please!
261 */
262
263 #define STATS_FILENAME_MAXLEN 128
264
265 #define GR_FILENAME_FMT "%0.124s.gr"
266 #define HP_FILENAME_FMT "%0.124s.hp"
267 #define LIFE_FILENAME_FMT "%0.122s.life"
268 #define PROF_FILENAME_FMT "%0.122s.prof"
269 #define PROF_FILENAME_FMT_GUM "%0.118s.%03d.prof"
270 #define QP_FILENAME_FMT "%0.124s.qp"
271 #define STAT_FILENAME_FMT "%0.122s.stat"
272 #define TICKY_FILENAME_FMT "%0.121s.ticky"
273 #define TIME_FILENAME_FMT "%0.122s.time"
274 #define TIME_FILENAME_FMT_GUM "%0.118s.%03d.time"
275
276 /* an "int" so as to match normal "argc" */
277 /* Now defined in Stg.h (lib/std/cbits need these too.)
278 extern int prog_argc;
279 extern char **prog_argv;
280 */
281 extern int rts_argc; /* ditto */
282 extern char **rts_argv;