1 /* -----------------------------------------------------------------------------
3 * (c) The AQUA Project, Glasgow University, 1994-1997
4 * (c) The GHC Team, 1998-2006
6 * Functions for parsing the argument list.
8 * ---------------------------------------------------------------------------*/
10 #include "PosixSource.h"
14 #include "BlockAlloc.h"
15 #include "Profiling.h"
28 * Split argument lists
30 int prog_argc = 0; /* an "int" so as to match normal "argc" */
31 char **prog_argv = NULL;
32 char *prog_name = NULL; /* 'basename' of prog_argv[0] */
33 int rts_argc = 0; /* ditto */
34 char *rts_argv[MAX_RTS_ARGS];
37 * constants, used later
44 static char *gran_debug_opts_strs[] = {
45 "DEBUG (-bDe, -bD1): event_trace; printing event trace.\n",
46 "DEBUG (-bDE, -bD2): event_stats; printing event statistics.\n",
47 "DEBUG (-bDb, -bD4): bq; check blocking queues\n",
48 "DEBUG (-bDG, -bD8): pack; routines for (un-)packing graph structures.\n",
49 "DEBUG (-bDq, -bD16): checkSparkQ; check consistency of the spark queues.\n",
50 "DEBUG (-bDf, -bD32): thunkStealing; print forwarding of fetches.\n",
51 "DEBUG (-bDr, -bD64): randomSteal; stealing sparks/threads from random PEs.\n",
52 "DEBUG (-bDF, -bD128): findWork; searching spark-pools (local & remote), thread queues for work.\n",
53 "DEBUG (-bDu, -bD256): unused; currently unused flag.\n",
54 "DEBUG (-bDS, -bD512): pri; priority sparking or scheduling.\n",
55 "DEBUG (-bD:, -bD1024): checkLight; check GranSim-Light setup.\n",
56 "DEBUG (-bDo, -bD2048): sortedQ; check whether spark/thread queues are sorted.\n",
57 "DEBUG (-bDz, -bD4096): blockOnFetch; check for blocked on fetch.\n",
58 "DEBUG (-bDP, -bD8192): packBuffer; routines handling pack buffer (GranSim internal!).\n",
59 "DEBUG (-bDt, -bD16384): blockOnFetch_sanity; check for TSO asleep on fetch.\n",
62 /* one character codes for the available debug options */
63 static char gran_debug_opts_flags[] = {
64 'e', 'E', 'b', 'G', 'q', 'f', 'r', 'F', 'u', 'S', ':', 'o', 'z', 'P', 't'
69 static char *par_debug_opts_strs[] = {
70 "DEBUG (-qDv, -qD1): verbose; be generally verbose with parallel related stuff.\n",
71 "DEBUG (-qDq, -qD2): bq; print blocking queues.\n",
72 "DEBUG (-qDs, -qD4): schedule; scheduling of parallel threads.\n",
73 "DEBUG (-qDe, -qD8): free; free messages.\n",
74 "DEBUG (-qDr, -qD16): resume; resume messages.\n",
75 "DEBUG (-qDw, -qD32): weight; print weights and distrib GC stuff.\n",
76 "DEBUG (-qDF, -qD64): fetch; fetch messages.\n",
77 // "DEBUG (-qDa, -qD128): ack; ack messages.\n",
78 "DEBUG (-qDf, -qD128): fish; fish messages.\n",
79 //"DEBUG (-qDo, -qD512): forward; forwarding messages to other PEs.\n",
80 "DEBUG (-qDl, -qD256): tables; print internal LAGA etc tables.\n",
81 "DEBUG (-qDo, -qD512): packet; packets and graph structures when packing.\n",
82 "DEBUG (-qDp, -qD1024): pack; packing and unpacking graphs.\n",
83 "DEBUG (-qDz, -qD2048): paranoia; ridiculously detailed output (excellent for filling a partition).\n"
86 /* one character codes for the available debug options */
87 static char par_debug_opts_flags[] = {
88 'v', 'q', 's', 'e', 'r', 'w', 'F', 'f', 'l', 'o', 'p', 'z'
93 /* -----------------------------------------------------------------------------
95 -------------------------------------------------------------------------- */
97 static int /* return NULL on error */
100 int argc, char *argv[],
101 int rts_argc, char *rts_argv[],
102 const char *FILENAME_FMT,
105 static I_ decode(const char *s);
106 static void bad_option(const char *s);
109 static void enable_GranSimLight(void);
110 static void process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
111 static void set_GranSim_debug_options(nat n);
112 static void help_GranSim_debug_options(nat n);
114 static void process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
115 static void set_par_debug_options(nat n);
116 static void help_par_debug_options(nat n);
119 /* -----------------------------------------------------------------------------
120 * Command-line option parsing routines.
121 * ---------------------------------------------------------------------------*/
123 void initRtsFlagsDefaults(void)
125 RtsFlags.GcFlags.statsFile = NULL;
126 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
128 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
129 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
131 RtsFlags.GcFlags.minAllocAreaSize = (512 * 1024) / BLOCK_SIZE;
132 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
133 RtsFlags.GcFlags.maxHeapSize = 0; /* off by default */
134 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
135 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
136 RtsFlags.GcFlags.oldGenFactor = 2;
138 /* A hack currently needed for GUM -- HWL */
139 RtsFlags.GcFlags.generations = 1;
140 RtsFlags.GcFlags.steps = 2;
141 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
143 RtsFlags.GcFlags.generations = 2;
144 RtsFlags.GcFlags.steps = 2;
145 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
147 RtsFlags.GcFlags.compact = rtsFalse;
148 RtsFlags.GcFlags.compactThreshold = 30.0;
149 #ifdef RTS_GTK_FRONTPANEL
150 RtsFlags.GcFlags.frontpanel = rtsFalse;
152 RtsFlags.GcFlags.idleGCDelayTime = 300; /* millisecs */
155 RtsFlags.DebugFlags.scheduler = rtsFalse;
156 RtsFlags.DebugFlags.interpreter = rtsFalse;
157 RtsFlags.DebugFlags.weak = rtsFalse;
158 RtsFlags.DebugFlags.gccafs = rtsFalse;
159 RtsFlags.DebugFlags.gc = rtsFalse;
160 RtsFlags.DebugFlags.block_alloc = rtsFalse;
161 RtsFlags.DebugFlags.sanity = rtsFalse;
162 RtsFlags.DebugFlags.stable = rtsFalse;
163 RtsFlags.DebugFlags.stm = rtsFalse;
164 RtsFlags.DebugFlags.prof = rtsFalse;
165 RtsFlags.DebugFlags.gran = rtsFalse;
166 RtsFlags.DebugFlags.par = rtsFalse;
167 RtsFlags.DebugFlags.linker = rtsFalse;
168 RtsFlags.DebugFlags.squeeze = rtsFalse;
171 #if defined(PROFILING) || defined(PAR)
172 RtsFlags.CcFlags.doCostCentres = 0;
173 #endif /* PROFILING or PAR */
176 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
177 RtsFlags.ProfFlags.profileInterval = 100;
178 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
179 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
180 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
181 RtsFlags.ProfFlags.modSelector = NULL;
182 RtsFlags.ProfFlags.descrSelector = NULL;
183 RtsFlags.ProfFlags.typeSelector = NULL;
184 RtsFlags.ProfFlags.ccSelector = NULL;
185 RtsFlags.ProfFlags.ccsSelector = NULL;
186 RtsFlags.ProfFlags.retainerSelector = NULL;
187 RtsFlags.ProfFlags.bioSelector = NULL;
190 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
193 RtsFlags.MiscFlags.tickInterval = 50; /* In milliseconds */
194 RtsFlags.ConcFlags.ctxtSwitchTime = 50; /* In milliseconds */
197 RtsFlags.ParFlags.nNodes = 1;
198 RtsFlags.ParFlags.migrate = rtsTrue;
199 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
203 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
204 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
205 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
206 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
207 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
208 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
209 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
211 RtsFlags.ParFlags.outputDisabled = rtsFalse;
213 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
215 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
217 RtsFlags.ParFlags.packBufferSize = 1024;
218 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
219 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
220 RtsFlags.ParFlags.maxThreads = 1024;
221 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
222 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
225 #if defined(PAR) || defined(THREADED_RTS)
226 RtsFlags.ParFlags.maxLocalSparks = 4096;
227 #endif /* PAR || THREADED_RTS */
230 /* ToDo: check defaults for GranSim and GUM */
231 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
232 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
234 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
235 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
236 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
237 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
238 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
239 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
240 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
241 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
243 RtsFlags.GranFlags.packBufferSize = 1024;
244 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
246 RtsFlags.GranFlags.proc = MAX_PROC;
247 RtsFlags.GranFlags.Fishing = rtsFalse;
248 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
249 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
250 RtsFlags.GranFlags.Light = rtsFalse;
252 RtsFlags.GranFlags.Costs.latency = LATENCY;
253 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
254 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
255 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
256 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
257 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
258 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
259 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
261 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
262 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
263 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
264 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
265 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
267 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
268 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
269 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
270 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
271 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
273 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
275 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
276 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
278 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
279 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
280 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
281 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
282 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
283 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
284 RtsFlags.GranFlags.FetchStrategy = 2;
285 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
286 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
287 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
288 RtsFlags.GranFlags.SparkPriority = 0;
289 RtsFlags.GranFlags.SparkPriority2 = 0;
290 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
291 RtsFlags.GranFlags.InversePriorities = rtsFalse;
292 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
293 RtsFlags.GranFlags.ThunksToPack = 0;
294 RtsFlags.GranFlags.RandomSteal = rtsTrue;
298 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
299 RtsFlags.TickyFlags.tickyFile = NULL;
302 RtsFlags.TraceFlags.timestamp = rtsFalse;
303 RtsFlags.TraceFlags.sched = rtsFalse;
309 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
311 " +RTS Indicates run time system options follow",
312 " -RTS Indicates program arguments follow",
313 " --RTS Indicates that ALL subsequent arguments will be given to the",
314 " program (including any of these RTS flags)",
316 "The following run time system options are available:",
318 " -? Prints this message and exits; the program is not executed",
320 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
321 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
323 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
324 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
325 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
326 " -m<n> Minimum % of heap which must be available (default 3%)",
327 " -G<n> Number of generations (default: 2)",
328 " -T<n> Number of steps in younger generations (default: 2)",
329 " -c<n> Auto-enable compaction of the oldest generation when live data is",
330 " at least <n>% of the maximum heap size set with -M (default: 30%)",
331 " -c Enable compaction for all major collections",
332 #if defined(THREADED_RTS)
333 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
336 " -t<file> One-line GC statistics (default file: <program>.stat)",
337 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
338 " -S<file> Detailed GC statistics",
339 #ifdef RTS_GTK_FRONTPANEL
340 " -f Display front panel (requires X11 & GTK+)",
344 " -Z Don't squeeze out update frames on stack overflow",
345 " -B Sound the bell at the start of each garbage collection",
346 #if defined(PROFILING) || defined(PAR)
348 " -px Time/allocation profile (XML) (output file <program>.prof)",
349 " -p Time/allocation profile (output file <program>.prof)",
350 " -P More detailed Time/Allocation profile",
351 " -Pa Give information about *all* cost centres",
353 # if defined(PROFILING)
355 " -hx Heap residency profile (XML) (output file <program>.prof)",
356 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
357 " break-down: c = cost centre stack (default)",
359 " d = closure description",
360 " y = type description",
362 " b = biography (LAG,DRAG,VOID,USE)",
363 " A subset of closures may be selected thusly:",
364 " -hc<cc>,... specific cost centre(s) (top of stack only)",
365 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
366 " -hm<mod>... all cost centres from the specified modules(s)",
367 " -hd<des>,... closures with specified closure descriptions",
368 " -hy<typ>... closures with specified type descriptions",
369 " -hr<cc>... closures with specified retainers",
370 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
372 " -R<size> Set the maximum retainer set size (default: 8)",
374 " -i<sec> Time between heap samples (seconds, default: 0.1)",
376 " -xt Include threads (TSOs) in a heap profile",
378 " -xc Show current cost centre stack on raising an exception",
380 #endif /* PROFILING or PAR */
381 #if !defined(PROFILING) && defined(DEBUG)
383 " -h<break-down> Debugging Heap residency profile",
384 " (output file <program>.hp)",
385 " break-down: L = closure label (default)",
386 " T = closure type (constructor, thunk etc.)",
389 #if defined(TICKY_TICKY)
390 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
394 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
395 /* NB: the -N<n> is implemented by the driver!! */
397 " -C<secs> Context-switch interval in seconds",
398 " (0 or no argument means switch as often as possible)",
399 " the default is .02 sec; resolution is .02 sec",
401 " -vs Trace scheduler events (see also -Ds with -debug)",
402 " -vt Time-stamp trace messages",
405 " -Ds DEBUG: scheduler",
406 " -Di DEBUG: interpreter",
408 " -DG DEBUG: gccafs",
411 " -DS DEBUG: sanity",
412 " -Dt DEBUG: stable",
416 " -Dl DEBUG: linker",
418 " -Dz DEBUG: stack squezing",
421 #if defined(THREADED_RTS) && !defined(NOSMP)
422 " -N<n> Use <n> OS threads (default: 1)",
423 " -qm Don't automatically migrate threads between CPUs",
424 " -qw Migrate a thread to the current CPU when it is woken up",
426 #if defined(THREADED_RTS) || defined(PAR)
427 " -e<size> Size of spark pools (default 100)",
430 " -t<num> Set maximum number of advisory threads per PE (default 32)",
431 " -qP Enable activity profile (output files in ~/<program>*.gr)",
432 " -qQ<size> Set pack-buffer size (default: 1024)",
433 " -qd Turn on PVM-ish debugging",
434 " -qO Disable output for performance measurement",
436 #if defined(THREADED_RTS) || defined(PAR)
437 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
440 " -d Turn on PVM-ish debugging",
441 " -O Disable output for performance measurement",
443 #if defined(GRAN) /* ToDo: fill in decent Docu here */
444 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
447 "RTS options may also be specified using the GHCRTS environment variable.",
449 "Other RTS options may be available for programs compiled a different way.",
450 "The GHC User's Guide has full details.",
455 STATIC_INLINE rtsBool
456 strequal(const char *a, const char * b)
458 return(strcmp(a, b) == 0);
462 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
468 while (isspace(*c1)) { c1++; };
470 while (!isspace(*c2) && *c2 != '\0') { c2++; };
472 if (c1 == c2) { break; }
474 if (*rts_argc < MAX_RTS_ARGS-1) {
475 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
476 strncpy(s, c1, c2-c1);
478 rts_argv[(*rts_argc)++] = s;
480 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
484 } while (*c1 != '\0');
488 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
490 rtsBool error = rtsFalse;
501 // process arguments from the ghc_rts_opts global variable first.
502 // (arguments from the GHCRTS environment variable and the command
503 // line override these).
505 if (ghc_rts_opts != NULL) {
506 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
510 // process arguments from the GHCRTS environment variable next
511 // (arguments from the command line override these).
513 char *ghc_rts = getenv("GHCRTS");
515 if (ghc_rts != NULL) {
516 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
520 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
521 // argv[0] must be PGM argument -- leave in argv
523 for (mode = PGM; arg < total_arg; arg++) {
524 // The '--RTS' argument disables all future +RTS ... -RTS processing.
525 if (strequal("--RTS", argv[arg])) {
529 // The '--' argument is passed through to the program, but
530 // disables all further +RTS ... -RTS processing.
531 else if (strequal("--", argv[arg])) {
534 else if (strequal("+RTS", argv[arg])) {
537 else if (strequal("-RTS", argv[arg])) {
540 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
541 rts_argv[(*rts_argc)++] = argv[arg];
543 else if (mode == PGM) {
544 argv[(*argc)++] = argv[arg];
547 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
550 // process remaining program arguments
551 for (; arg < total_arg; arg++) {
552 argv[(*argc)++] = argv[arg];
554 argv[*argc] = (char *) 0;
555 rts_argv[*rts_argc] = (char *) 0;
557 // Process RTS (rts_argv) part: mainly to determine statsfile
558 for (arg = 0; arg < *rts_argc; arg++) {
559 if (rts_argv[arg][0] != '-') {
561 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
565 switch(rts_argv[arg][1]) {
567 /* process: general args, then PROFILING-only ones,
568 then CONCURRENT-only, PARallel-only, GRAN-only,
569 TICKY-only (same order as defined in RtsFlags.lh);
570 within those groups, mostly in case-insensitive
572 Final group is x*, which allows for more options.
576 # define TICKY_BUILD_ONLY(x) x
578 # define TICKY_BUILD_ONLY(x) \
579 errorBelch("not built for: ticky-ticky stats"); \
583 #if defined(PROFILING)
584 # define COST_CENTRE_USING_BUILD_ONLY(x) x
586 # define COST_CENTRE_USING_BUILD_ONLY(x) \
587 errorBelch("not built for: -prof or -parallel"); \
592 # define PROFILING_BUILD_ONLY(x) x
594 # define PROFILING_BUILD_ONLY(x) \
595 errorBelch("not built for: -prof"); \
600 # define PAR_BUILD_ONLY(x) x
602 # define PAR_BUILD_ONLY(x) \
603 errorBelch("not built for: -parallel"); \
608 # define THREADED_BUILD_ONLY(x) x
610 # define THREADED_BUILD_ONLY(x) \
611 errorBelch("not built for: -smp"); \
615 #if defined(THREADED_RTS) || defined(PAR)
616 # define PAR_OR_THREADED_BUILD_ONLY(x) x
618 # define PAR_OR_THREADED_BUILD_ONLY(x) \
619 errorBelch("not built for: -parallel or -smp"); \
624 # define GRAN_BUILD_ONLY(x) x
626 # define GRAN_BUILD_ONLY(x) \
627 errorBelch("not built for: -gransim"); \
631 /* =========== GENERAL ========================== */
637 RtsFlags.GcFlags.minAllocAreaSize
638 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
639 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
640 bad_option(rts_argv[arg]);
645 RtsFlags.GcFlags.ringBell = rtsTrue;
649 if (rts_argv[arg][2] != '\0') {
650 RtsFlags.GcFlags.compactThreshold =
651 atof(rts_argv[arg]+2);
653 RtsFlags.GcFlags.compact = rtsTrue;
658 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
660 if (RtsFlags.GcFlags.oldGenFactor < 0)
661 bad_option( rts_argv[arg] );
669 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
672 RtsFlags.DebugFlags.scheduler = rtsTrue;
675 RtsFlags.DebugFlags.interpreter = rtsTrue;
678 RtsFlags.DebugFlags.weak = rtsTrue;
681 RtsFlags.DebugFlags.gccafs = rtsTrue;
684 RtsFlags.DebugFlags.gc = rtsTrue;
687 RtsFlags.DebugFlags.block_alloc = rtsTrue;
690 RtsFlags.DebugFlags.sanity = rtsTrue;
693 RtsFlags.DebugFlags.stable = rtsTrue;
696 RtsFlags.DebugFlags.prof = rtsTrue;
699 RtsFlags.DebugFlags.gran = rtsTrue;
702 RtsFlags.DebugFlags.par = rtsTrue;
705 RtsFlags.DebugFlags.linker = rtsTrue;
708 RtsFlags.DebugFlags.apply = rtsTrue;
711 RtsFlags.DebugFlags.stm = rtsTrue;
714 RtsFlags.DebugFlags.squeeze = rtsTrue;
717 bad_option( rts_argv[arg] );
725 RtsFlags.GcFlags.maxStkSize =
726 decode(rts_argv[arg]+2) / sizeof(W_);
728 if (RtsFlags.GcFlags.maxStkSize == 0)
729 bad_option( rts_argv[arg] );
733 RtsFlags.GcFlags.initialStkSize =
734 decode(rts_argv[arg]+2) / sizeof(W_);
736 if (RtsFlags.GcFlags.initialStkSize == 0)
737 bad_option( rts_argv[arg] );
741 RtsFlags.GcFlags.maxHeapSize =
742 decode(rts_argv[arg]+2) / BLOCK_SIZE;
743 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
745 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
746 bad_option(rts_argv[arg]);
751 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
753 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
754 RtsFlags.GcFlags.pcFreeHeap > 100)
755 bad_option( rts_argv[arg] );
759 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
760 if (RtsFlags.GcFlags.generations < 1) {
761 bad_option(rts_argv[arg]);
766 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
767 if (RtsFlags.GcFlags.steps < 1) {
768 bad_option(rts_argv[arg]);
773 RtsFlags.GcFlags.heapSizeSuggestion =
774 decode(rts_argv[arg]+2) / BLOCK_SIZE;
776 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
777 bad_option(rts_argv[arg]);
781 #ifdef RTS_GTK_FRONTPANEL
783 RtsFlags.GcFlags.frontpanel = rtsTrue;
787 case 'I': /* idle GC delay */
788 if (rts_argv[arg][2] == '\0') {
793 /* Convert to millisecs */
794 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
795 RtsFlags.GcFlags.idleGCDelayTime = cst;
800 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
804 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
808 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
813 /* Opening all those files would almost certainly fail... */
814 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
815 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
819 r = open_stats_file(arg, *argc, argv,
820 *rts_argc, rts_argv, STAT_FILENAME_FMT,
821 &RtsFlags.GcFlags.statsFile);
822 if (r == -1) { error = rtsTrue; }
828 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
831 /* =========== PROFILING ========================== */
833 case 'P': /* detailed cost centre profiling (time/alloc) */
834 case 'p': /* cost centre profiling (time/alloc) */
835 COST_CENTRE_USING_BUILD_ONLY(
836 switch (rts_argv[arg][2]) {
838 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
841 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
844 if (rts_argv[arg][1] == 'P') {
845 RtsFlags.CcFlags.doCostCentres =
846 COST_CENTRES_VERBOSE;
848 RtsFlags.CcFlags.doCostCentres =
849 COST_CENTRES_SUMMARY;
856 PROFILING_BUILD_ONLY(
857 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
860 case 'h': /* serial heap profile */
861 #if !defined(PROFILING) && defined(DEBUG)
862 switch (rts_argv[arg][2]) {
865 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
868 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
871 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
875 PROFILING_BUILD_ONLY(
876 switch (rts_argv[arg][2]) {
890 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
892 char *left = strchr(rts_argv[arg], '{');
893 char *right = strrchr(rts_argv[arg], '}');
895 // curly braces are optional, for
900 left = rts_argv[arg] + 3;
903 right = rts_argv[arg] + strlen(rts_argv[arg]);
907 switch (rts_argv[arg][2]) {
908 case 'c': // cost centre label select
909 RtsFlags.ProfFlags.ccSelector = left;
912 RtsFlags.ProfFlags.ccsSelector = left;
915 case 'm': // cost centre module select
916 RtsFlags.ProfFlags.modSelector = left;
919 case 'd': // closure descr select
920 RtsFlags.ProfFlags.descrSelector = left;
923 case 'y': // closure type select
924 RtsFlags.ProfFlags.typeSelector = left;
927 case 'r': // retainer select
928 RtsFlags.ProfFlags.retainerSelector = left;
931 case 'b': // biography select
932 RtsFlags.ProfFlags.bioSelector = left;
939 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
940 errorBelch("multiple heap profile options");
945 switch (rts_argv[arg][2]) {
949 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
953 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
957 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
961 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
965 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
969 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
975 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
979 #endif /* PROFILING */
982 #if defined(PROFILING)
983 case 'i': /* heap sample interval */
984 if (rts_argv[arg][2] == '\0') {
989 /* Convert to milliseconds */
990 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
991 RtsFlags.ProfFlags.profileInterval = cst;
996 /* =========== CONCURRENT ========================= */
997 case 'C': /* context switch interval */
998 if (rts_argv[arg][2] == '\0')
999 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1003 /* Convert to milliseconds */
1004 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1005 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1009 case 'V': /* master tick interval */
1010 if (rts_argv[arg][2] == '\0') {
1011 // turns off ticks completely
1012 RtsFlags.MiscFlags.tickInterval = 0;
1016 /* Convert to milliseconds */
1017 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1018 RtsFlags.MiscFlags.tickInterval = cst;
1022 #if defined(THREADED_RTS) && !defined(NOSMP)
1024 THREADED_BUILD_ONLY(
1025 if (rts_argv[arg][2] != '\0') {
1026 RtsFlags.ParFlags.nNodes
1027 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1028 if (RtsFlags.ParFlags.nNodes <= 0) {
1029 errorBelch("bad value for -N");
1036 switch (rts_argv[arg][2]) {
1038 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1042 RtsFlags.ParFlags.migrate = rtsFalse;
1045 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1048 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1054 /* =========== PARALLEL =========================== */
1056 PAR_OR_THREADED_BUILD_ONLY(
1057 if (rts_argv[arg][2] != '\0') {
1058 RtsFlags.ParFlags.maxLocalSparks
1059 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1060 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1061 errorBelch("bad value for -e");
1070 process_par_option(arg, rts_argc, rts_argv, &error);
1074 /* =========== GRAN =============================== */
1078 process_gran_option(arg, rts_argc, rts_argv, &error);
1081 /* =========== TICKY ============================== */
1083 case 'r': /* Basic profiling stats */
1086 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1090 r = open_stats_file(arg, *argc, argv,
1091 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1092 &RtsFlags.TickyFlags.tickyFile);
1093 if (r == -1) { error = rtsTrue; }
1097 /* =========== TRACING ---------=================== */
1100 switch(rts_argv[arg][2]) {
1102 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1106 RtsFlags.TraceFlags.timestamp = rtsTrue;
1109 RtsFlags.TraceFlags.sched = rtsTrue;
1112 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1118 /* =========== EXTENDED OPTIONS =================== */
1120 case 'x': /* Extend the argument space */
1121 switch(rts_argv[arg][2]) {
1123 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1127 case 'c': /* Debugging tool: show current cost centre on an exception */
1128 PROFILING_BUILD_ONLY(
1129 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1133 case 't': /* Include memory used by TSOs in a heap profile */
1134 PROFILING_BUILD_ONLY(
1135 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1139 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1142 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1146 break; /* defensive programming */
1148 /* =========== OH DEAR ============================ */
1150 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1157 // Determine what tick interval we should use for the RTS timer
1158 // by taking the shortest of the various intervals that we need to
1160 if (RtsFlags.MiscFlags.tickInterval <= 0) {
1161 RtsFlags.MiscFlags.tickInterval = 50;
1164 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1165 RtsFlags.MiscFlags.tickInterval =
1166 stg_min(RtsFlags.ConcFlags.ctxtSwitchTime,
1167 RtsFlags.MiscFlags.tickInterval);
1170 if (RtsFlags.GcFlags.idleGCDelayTime > 0) {
1171 RtsFlags.MiscFlags.tickInterval =
1172 stg_min(RtsFlags.GcFlags.idleGCDelayTime,
1173 RtsFlags.MiscFlags.tickInterval);
1177 if (RtsFlags.ProfFlags.profileInterval > 0) {
1178 RtsFlags.MiscFlags.tickInterval =
1179 stg_min(RtsFlags.ProfFlags.profileInterval,
1180 RtsFlags.MiscFlags.tickInterval);
1184 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1185 RtsFlags.ConcFlags.ctxtSwitchTicks =
1186 RtsFlags.ConcFlags.ctxtSwitchTime /
1187 RtsFlags.MiscFlags.tickInterval;
1189 RtsFlags.ConcFlags.ctxtSwitchTicks = 0;
1193 RtsFlags.ProfFlags.profileIntervalTicks =
1194 RtsFlags.ProfFlags.profileInterval / RtsFlags.MiscFlags.tickInterval;
1201 for (p = usage_text; *p; p++)
1202 errorBelch("%s", *p);
1203 stg_exit(EXIT_FAILURE);
1210 enable_GranSimLight(void) {
1212 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1213 RtsFlags.GranFlags.Light=rtsTrue;
1214 RtsFlags.GranFlags.Costs.latency =
1215 RtsFlags.GranFlags.Costs.fetchtime =
1216 RtsFlags.GranFlags.Costs.additional_latency =
1217 RtsFlags.GranFlags.Costs.gunblocktime =
1218 RtsFlags.GranFlags.Costs.lunblocktime =
1219 RtsFlags.GranFlags.Costs.threadcreatetime =
1220 RtsFlags.GranFlags.Costs.threadqueuetime =
1221 RtsFlags.GranFlags.Costs.threadscheduletime =
1222 RtsFlags.GranFlags.Costs.threaddescheduletime =
1223 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1225 RtsFlags.GranFlags.Costs.mpacktime =
1226 RtsFlags.GranFlags.Costs.munpacktime = 0;
1228 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1229 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1230 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1231 /* FetchStrategy is irrelevant in GrAnSim-Light */
1233 /* GrAnSim Light often creates an abundance of parallel threads,
1234 each with its own stack etc. Therefore, it's in general a good
1235 idea to use small stack chunks (use the -o<size> option to
1238 // RtsFlags.ConcFlags.stkChunkSize = 100;
1240 RtsFlags.GranFlags.proc = 1;
1244 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1246 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1249 /* or a ridiculously idealised simulator */
1250 if(strcmp((rts_argv[arg]+2),"oring")==0) {
1251 RtsFlags.GranFlags.Costs.latency =
1252 RtsFlags.GranFlags.Costs.fetchtime =
1253 RtsFlags.GranFlags.Costs.additional_latency =
1254 RtsFlags.GranFlags.Costs.gunblocktime =
1255 RtsFlags.GranFlags.Costs.lunblocktime =
1256 RtsFlags.GranFlags.Costs.threadcreatetime =
1257 RtsFlags.GranFlags.Costs.threadqueuetime =
1258 RtsFlags.GranFlags.Costs.threadscheduletime =
1259 RtsFlags.GranFlags.Costs.threaddescheduletime =
1260 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1262 RtsFlags.GranFlags.Costs.mpacktime =
1263 RtsFlags.GranFlags.Costs.munpacktime = 0;
1265 RtsFlags.GranFlags.Costs.arith_cost =
1266 RtsFlags.GranFlags.Costs.float_cost =
1267 RtsFlags.GranFlags.Costs.load_cost =
1268 RtsFlags.GranFlags.Costs.store_cost =
1269 RtsFlags.GranFlags.Costs.branch_cost = 0;
1271 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1273 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1274 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1275 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1276 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1280 /* or a somewhat idealised simulator */
1281 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1282 RtsFlags.GranFlags.Costs.latency =
1283 RtsFlags.GranFlags.Costs.fetchtime =
1284 RtsFlags.GranFlags.Costs.additional_latency =
1285 RtsFlags.GranFlags.Costs.gunblocktime =
1286 RtsFlags.GranFlags.Costs.lunblocktime =
1287 RtsFlags.GranFlags.Costs.threadcreatetime =
1288 RtsFlags.GranFlags.Costs.threadqueuetime =
1289 RtsFlags.GranFlags.Costs.threadscheduletime =
1290 RtsFlags.GranFlags.Costs.threaddescheduletime =
1291 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1293 RtsFlags.GranFlags.Costs.mpacktime =
1294 RtsFlags.GranFlags.Costs.munpacktime = 0;
1296 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1298 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1299 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1300 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1301 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1302 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1303 # if defined(GRAN_CHECK) && defined(GRAN)
1304 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1309 /* Communication and task creation cost parameters */
1310 switch(rts_argv[arg][2]) {
1312 IgnoreYields = rtsTrue; // HWL HACK
1316 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1320 if (rts_argv[arg][3] != '\0')
1322 RtsFlags.GranFlags.Costs.gunblocktime =
1323 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1324 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1327 RtsFlags.GranFlags.Costs.latency = LATENCY;
1331 if (rts_argv[arg][3] != '\0')
1332 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1334 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1338 if (rts_argv[arg][3] != '\0')
1339 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1341 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1345 if (rts_argv[arg][3] != '\0')
1346 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1348 RtsFlags.GranFlags.Costs.mtidytime = 0;
1352 if (rts_argv[arg][3] != '\0')
1353 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1355 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1359 if (rts_argv[arg][3] != '\0')
1360 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1362 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1366 if (rts_argv[arg][3] != '\0')
1367 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1369 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1373 if (rts_argv[arg][3] != '\0')
1374 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1376 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1379 /* Thread-related metrics */
1381 if (rts_argv[arg][3] != '\0')
1382 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1384 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1388 if (rts_argv[arg][3] != '\0')
1389 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1391 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1395 if (rts_argv[arg][3] != '\0')
1396 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1398 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1400 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1401 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1405 if (rts_argv[arg][3] != '\0')
1406 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1408 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1410 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1411 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1414 /* Instruction Cost Metrics */
1416 if (rts_argv[arg][3] != '\0')
1417 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1419 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1423 if (rts_argv[arg][3] != '\0')
1424 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1426 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1430 if (rts_argv[arg][3] != '\0')
1431 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1433 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1437 if (rts_argv[arg][3] != '\0')
1438 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1440 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1444 if (rts_argv[arg][3] != '\0')
1445 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1447 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1451 if (rts_argv[arg][3] != '\0')
1452 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1454 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1458 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1459 if (rts_argv[arg][3] != '\0')
1460 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1462 RtsFlags.GranFlags.FetchStrategy = 2;
1463 if (RtsFlags.GranFlags.FetchStrategy == 0)
1464 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1467 case 'K': /* sort overhead (per elem in spark list) */
1468 if (rts_argv[arg][3] != '\0')
1469 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1471 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1472 debugBelch("Overhead for pri spark: %d (per elem).\n",
1473 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1476 case 'O': /* sort overhead (per elem in spark list) */
1477 if (rts_argv[arg][3] != '\0')
1478 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1480 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1481 debugBelch("Overhead for pri sched: %d (per elem).\n",
1482 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1485 /* General Parameters */
1487 if (rts_argv[arg][3] != '\0')
1489 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1490 if (RtsFlags.GranFlags.proc==0) {
1491 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1492 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1493 RtsFlags.GranFlags.proc < 1)
1495 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1501 RtsFlags.GranFlags.proc = MAX_PROC;
1505 RtsFlags.GranFlags.Fishing = rtsTrue;
1506 if (rts_argv[arg][3] != '\0')
1507 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1509 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1513 if (rts_argv[arg][3] != '\0')
1514 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1516 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1520 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1521 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1525 debugBelch("Bulk fetching enabled.\n");
1526 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1530 debugBelch("Thread migration enabled.\n");
1531 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1535 debugBelch("Fair Scheduling enabled.\n");
1536 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1540 debugBelch("Priority Scheduling enabled.\n");
1541 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1545 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1546 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1550 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1554 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1558 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1562 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1566 /* format is -bP<c> where <c> is one char describing kind of profile */
1567 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1568 switch(rts_argv[arg][3]) {
1569 case '\0': break; // nothing special, just an ordinary profile
1570 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1572 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1574 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1576 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1578 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1580 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1582 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1587 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1591 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1594 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1595 if (rts_argv[arg][3] != '\0') {
1598 arg0 = rts_argv[arg]+3;
1599 if ((tmp = strstr(arg0,","))==NULL) {
1600 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1601 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1604 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1605 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1606 debugBelch("SparkPriority: %u.\n",
1607 RtsFlags.GranFlags.SparkPriority);
1608 debugBelch("SparkPriority2:%u.\n",
1609 RtsFlags.GranFlags.SparkPriority2);
1610 if (RtsFlags.GranFlags.SparkPriority2 <
1611 RtsFlags.GranFlags.SparkPriority) {
1612 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1613 RtsFlags.GranFlags.SparkPriority2,
1614 RtsFlags.GranFlags.SparkPriority);
1618 /* plain pri spark is now invoked with -bX
1619 RtsFlags.GranFlags.DoPrioritySparking = 1;
1620 debugBelch("PrioritySparking.\n");
1626 if (rts_argv[arg][3] != '\0') {
1627 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1629 RtsFlags.GranFlags.ThunksToPack = 1;
1631 debugBelch("Thunks To Pack in one packet: %u.\n",
1632 RtsFlags.GranFlags.ThunksToPack);
1636 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1637 debugBelch("Deterministic mode (no random stealing)\n");
1640 /* The following class of options contains eXperimental */
1641 /* features in connection with exploiting granularity */
1642 /* information. I.e. if -bY is chosen these options */
1643 /* tell the RTS what to do with the supplied info --HWL */
1646 if (rts_argv[arg][3] != '\0') {
1647 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1649 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1651 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1652 RtsFlags.GranFlags.packBufferSize_internal);
1656 switch(rts_argv[arg][3]) {
1659 RtsFlags.GranFlags.DoPrioritySparking = 1;
1660 debugBelch("Priority Sparking with Normal Priorities.\n");
1661 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1662 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1663 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1667 RtsFlags.GranFlags.DoPrioritySparking = 1;
1668 debugBelch("Priority Sparking with Inverse Priorities.\n");
1669 RtsFlags.GranFlags.InversePriorities++;
1673 RtsFlags.GranFlags.DoPrioritySparking = 1;
1674 debugBelch("Priority Sparking with Random Priorities.\n");
1675 RtsFlags.GranFlags.RandomPriorities++;
1679 RtsFlags.GranFlags.DoPrioritySparking = 1;
1680 debugBelch("Priority Sparking with No Priorities.\n");
1681 RtsFlags.GranFlags.IgnorePriorities++;
1685 bad_option( rts_argv[arg] );
1691 switch(rts_argv[arg][3]) {
1694 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1695 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1699 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1703 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1707 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1711 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1712 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1716 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1720 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1724 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1728 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1732 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1736 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1740 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1744 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1745 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1749 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1753 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1757 bad_option( rts_argv[arg] );
1762 # if defined(GRAN_CHECK) && defined(GRAN)
1764 switch(rts_argv[arg][3]) {
1765 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1766 if (rts_argv[arg][4] != '\0') {
1767 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1768 debugBelch("Pack buffer size: %d\n",
1769 RtsFlags.GranFlags.packBufferSize);
1771 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1777 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1778 /* hack warning: interpret the flags as a binary number */
1779 nat n = decode(rts_argv[arg]+3);
1780 set_GranSim_debug_options(n);
1783 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1784 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1787 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1788 debugBelch("Valid GranSim debug options are:\n");
1789 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1790 bad_option( rts_argv[arg] );
1791 } else { // flag found; now set it
1792 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1798 case 'e': /* event trace; also -bD1 */
1799 debugBelch("DEBUG: event_trace; printing event trace.\n");
1800 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1801 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1804 case 'E': /* event statistics; also -bD2 */
1805 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1806 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1807 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1810 case 'f': /* thunkStealing; also -bD4 */
1811 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1812 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1813 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1816 case 'z': /* blockOnFetch; also -bD8 */
1817 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1818 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1819 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1822 case 't': /* blockOnFetch_sanity; also -bD16 */
1823 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1824 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1825 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1828 case 'S': /* priSpark; also -bD32 */
1829 debugBelch("DEBUG: priSpark; priority sparking.\n");
1830 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1833 case 's': /* priSched; also -bD64 */
1834 debugBelch("DEBUG: priSched; priority scheduling.\n");
1835 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1838 case 'F': /* findWork; also -bD128 */
1839 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1840 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1843 case 'g': /* globalBlock; also -bD256 */
1844 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1845 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1848 case 'G': /* pack; also -bD512 */
1849 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1850 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1853 case 'P': /* packBuffer; also -bD1024 */
1854 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1855 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1858 case 'o': /* sortedQ; also -bD2048 */
1859 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1860 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1863 case 'r': /* randomSteal; also -bD4096 */
1864 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
1865 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
1868 case 'q': /* checkSparkQ; also -bD8192 */
1869 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
1870 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
1873 case ':': /* checkLight; also -bD16384 */
1874 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
1875 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
1878 case 'b': /* bq; also -bD32768 */
1879 debugBelch("DEBUG: bq; check blocking queues\n");
1880 RtsFlags.GranFlags.Debug.bq = rtsTrue;
1883 case 'd': /* all options turned on */
1884 debugBelch("DEBUG: all options turned on.\n");
1885 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1886 /* RtsFlags.GranFlags.Debug |= 0x40; */
1890 /* RtsFlags.GranFlags.Debug = 1; */
1896 # endif /* GRAN_CHECK */
1898 bad_option( rts_argv[arg] );
1904 Interpret n as a binary number masking GranSim debug options and set the
1905 correxponding option. See gran_debug_opts_strs for explanations of the flags.
1908 set_GranSim_debug_options(nat n) {
1911 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1913 errorBelch(gran_debug_opts_strs[i]);
1915 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
1916 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
1917 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
1918 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
1919 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
1920 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
1921 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
1922 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
1923 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
1924 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
1925 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
1926 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
1927 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
1928 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
1929 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
1930 default: barf("set_GranSim_debug_options: only %d debug options expected");
1936 Print one line explanation for each of the GranSim debug options specified
1940 help_GranSim_debug_options(nat n) {
1943 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1945 debugBelch(gran_debug_opts_strs[i]);
1951 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1954 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
1955 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
1959 /* Communication and task creation cost parameters */
1960 switch(rts_argv[arg][2]) {
1961 case 'e': /* -qe<n> ... allow <n> local sparks */
1962 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
1963 RtsFlags.ParFlags.maxLocalSparks
1964 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1966 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1967 errorBelch("setupRtsFlags: bad value for -e\n");
1971 IF_PAR_DEBUG(verbose,
1972 errorBelch("-qe<n>: max %d local sparks",
1973 RtsFlags.ParFlags.maxLocalSparks));
1977 if (rts_argv[arg][3] != '\0') {
1978 RtsFlags.ParFlags.maxThreads
1979 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1981 errorBelch("missing size for -qt\n");
1984 IF_PAR_DEBUG(verbose,
1985 errorBelch("-qt<n>: max %d threads",
1986 RtsFlags.ParFlags.maxThreads));
1990 if (rts_argv[arg][3] != '\0')
1991 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
1993 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
1995 IF_PAR_DEBUG(verbose,
1996 errorBelch("-qf<n>: max %d fishes sent out at one time",
1997 RtsFlags.ParFlags.maxFishes));
2001 if (rts_argv[arg][3] != '\0') {
2002 RtsFlags.ParFlags.fishDelay
2003 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2005 errorBelch("missing fish delay time for -qF\n");
2008 IF_PAR_DEBUG(verbose,
2009 errorBelch("-qF<n>: fish delay time %d us",
2010 RtsFlags.ParFlags.fishDelay));
2014 RtsFlags.ParFlags.outputDisabled = rtsTrue;
2015 IF_PAR_DEBUG(verbose,
2016 errorBelch("-qO: output disabled"));
2019 case 'g': /* -qg<n> ... globalisation scheme */
2020 if (rts_argv[arg][3] != '\0') {
2021 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
2023 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
2026 IF_PAR_DEBUG(verbose,
2027 debugBelch("-qg<n>: globalisation scheme set to %d",
2028 RtsFlags.ParFlags.globalising));
2031 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
2032 if (rts_argv[arg][3] != '\0') {
2033 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
2035 errorBelch("missing number of thunks per packet (for -qh)\n");
2038 IF_PAR_DEBUG(verbose,
2039 debugBelch("-qh<n>: thunks per packet set to %d",
2040 RtsFlags.ParFlags.thunksToPack));
2043 case 'P': /* -qP for writing a log file */
2044 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2045 /* same encoding as in GranSim after -bP */
2046 switch(rts_argv[arg][3]) {
2047 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2048 break; // nothing special, just an ordinary profile
2049 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2050 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2052 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2054 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2056 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2058 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2061 # if defined(PAR_TICKY)
2062 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2064 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2065 stg_exit(EXIT_FAILURE);
2068 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2070 IF_PAR_DEBUG(verbose,
2071 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2072 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2075 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2076 if (rts_argv[arg][3] != '\0') {
2077 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2079 errorBelch("missing size of PackBuffer (for -qQ)\n");
2082 IF_PAR_DEBUG(verbose,
2083 debugBelch("-qQ<n>: pack buffer size set to %d",
2084 RtsFlags.ParFlags.packBufferSize));
2088 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2089 IF_PAR_DEBUG(verbose,
2090 debugBelch("-qR: fair-ish scheduling"));
2095 if (rts_argv[arg][3] != '\0') {
2096 RtsFlags.ParFlags.wait
2097 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2099 RtsFlags.ParFlags.wait = 1000;
2101 IF_PAR_DEBUG(verbose,
2102 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2103 RtsFlags.ParFlags.wait));
2106 case 'D': /* -qD ... all the debugging options */
2107 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2108 /* hack warning: interpret the flags as a binary number */
2109 nat n = decode(rts_argv[arg]+3);
2110 set_par_debug_options(n);
2113 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2114 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2117 if (i==MAX_PAR_DEBUG_OPTION+1) {
2118 errorBelch("Valid GUM debug options are:\n");
2119 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2120 bad_option( rts_argv[arg] );
2121 } else { // flag found; now set it
2122 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2128 errorBelch("Unknown option -q%c (%d opts in total)",
2129 rts_argv[arg][2], *rts_argc);
2135 Interpret n as a binary number masking Par debug options and set the
2136 correxponding option. See par_debug_opts_strs for explanations of the flags.
2139 set_par_debug_options(nat n) {
2142 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2144 debugBelch(par_debug_opts_strs[i]);
2146 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2147 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2148 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2149 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2150 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2151 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2152 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2153 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2154 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2155 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2156 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2157 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2158 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2159 default: barf("set_par_debug_options: only %d debug options expected",
2160 MAX_PAR_DEBUG_OPTION);
2166 Print one line explanation for each of the GranSim debug options specified
2170 help_par_debug_options(nat n) {
2173 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2175 debugBelch(par_debug_opts_strs[i]);
2181 stats_fprintf(FILE *f, char *s, ...)
2193 static int /* return -1 on error */
2196 int argc, char *argv[],
2197 int rts_argc, char *rts_argv[],
2198 const char *FILENAME_FMT,
2203 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2204 f = NULL; /* NULL means use debugBelch */
2206 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2207 f = fopen(rts_argv[arg]+2,"w");
2209 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2210 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2211 f = fopen(stats_filename,"w");
2214 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2221 /* Write argv and rtsv into start of stats file */
2223 for(count = 0; count < argc; count++) {
2224 stats_fprintf(f, "%s ", argv[count]);
2226 stats_fprintf(f, "+RTS ");
2227 for(count = 0; count < rts_argc; count++)
2228 stats_fprintf(f, "%s ", rts_argv[count]);
2229 stats_fprintf(f, "\n");
2237 decode(const char *s)
2248 if (c == 'g' || c == 'G')
2249 m *= 1000*1000*1000; /* UNchecked! */
2250 else if (c == 'm' || c == 'M')
2251 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2252 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2253 m *= 1000; /* a direct-mapped cache. */
2254 else if (c == 'w' || c == 'W')
2261 bad_option(const char *s)
2263 errorBelch("bad RTS option: %s", s);
2264 stg_exit(EXIT_FAILURE);
2267 /* -----------------------------------------------------------------------------
2268 Getting/Setting the program's arguments.
2270 These are used by System.Environment, and parts of the RTS.
2271 -------------------------------------------------------------------------- */
2274 setProgName(char *argv[])
2276 /* Remove directory from argv[0] -- default files in current directory */
2277 #if !defined(mingw32_HOST_OS)
2279 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2280 prog_name = last_slash+1;
2282 prog_name = argv[0];
2285 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2286 while ( last_slash > argv[0] ) {
2287 if ( *last_slash == '/' || *last_slash == '\\' ) {
2288 prog_name = last_slash+1;
2293 prog_name = argv[0];
2298 getProgArgv(int *argc, char **argv[])
2300 if (argc) { *argc = prog_argc; }
2301 if (argv) { *argv = prog_argv; }
2305 setProgArgv(int argc, char *argv[])
2307 /* Usually this is done by startupHaskell, so we don't need to call this.
2308 However, sometimes Hugs wants to change the arguments which Haskell
2309 getArgs >>= ... will be fed. So you can do that by calling here
2310 _after_ calling startupHaskell.
2314 setProgName(prog_argv);