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 "Profiling.h"
27 * Split argument lists
29 int prog_argc = 0; /* an "int" so as to match normal "argc" */
30 char **prog_argv = NULL;
31 int full_prog_argc = 0; /* an "int" so as to match normal "argc" */
32 char **full_prog_argv = NULL;
33 char *prog_name = NULL; /* 'basename' of prog_argv[0] */
34 int rts_argc = 0; /* ditto */
35 char *rts_argv[MAX_RTS_ARGS];
38 * constants, used later
45 static char *gran_debug_opts_strs[] = {
46 "DEBUG (-bDe, -bD1): event_trace; printing event trace.\n",
47 "DEBUG (-bDE, -bD2): event_stats; printing event statistics.\n",
48 "DEBUG (-bDb, -bD4): bq; check blocking queues\n",
49 "DEBUG (-bDG, -bD8): pack; routines for (un-)packing graph structures.\n",
50 "DEBUG (-bDq, -bD16): checkSparkQ; check consistency of the spark queues.\n",
51 "DEBUG (-bDf, -bD32): thunkStealing; print forwarding of fetches.\n",
52 "DEBUG (-bDr, -bD64): randomSteal; stealing sparks/threads from random PEs.\n",
53 "DEBUG (-bDF, -bD128): findWork; searching spark-pools (local & remote), thread queues for work.\n",
54 "DEBUG (-bDu, -bD256): unused; currently unused flag.\n",
55 "DEBUG (-bDS, -bD512): pri; priority sparking or scheduling.\n",
56 "DEBUG (-bD:, -bD1024): checkLight; check GranSim-Light setup.\n",
57 "DEBUG (-bDo, -bD2048): sortedQ; check whether spark/thread queues are sorted.\n",
58 "DEBUG (-bDz, -bD4096): blockOnFetch; check for blocked on fetch.\n",
59 "DEBUG (-bDP, -bD8192): packBuffer; routines handling pack buffer (GranSim internal!).\n",
60 "DEBUG (-bDt, -bD16384): blockOnFetch_sanity; check for TSO asleep on fetch.\n",
63 /* one character codes for the available debug options */
64 static char gran_debug_opts_flags[] = {
65 'e', 'E', 'b', 'G', 'q', 'f', 'r', 'F', 'u', 'S', ':', 'o', 'z', 'P', 't'
70 static char *par_debug_opts_strs[] = {
71 "DEBUG (-qDv, -qD1): verbose; be generally verbose with parallel related stuff.\n",
72 "DEBUG (-qDq, -qD2): bq; print blocking queues.\n",
73 "DEBUG (-qDs, -qD4): schedule; scheduling of parallel threads.\n",
74 "DEBUG (-qDe, -qD8): free; free messages.\n",
75 "DEBUG (-qDr, -qD16): resume; resume messages.\n",
76 "DEBUG (-qDw, -qD32): weight; print weights and distrib GC stuff.\n",
77 "DEBUG (-qDF, -qD64): fetch; fetch messages.\n",
78 // "DEBUG (-qDa, -qD128): ack; ack messages.\n",
79 "DEBUG (-qDf, -qD128): fish; fish messages.\n",
80 //"DEBUG (-qDo, -qD512): forward; forwarding messages to other PEs.\n",
81 "DEBUG (-qDl, -qD256): tables; print internal LAGA etc tables.\n",
82 "DEBUG (-qDo, -qD512): packet; packets and graph structures when packing.\n",
83 "DEBUG (-qDp, -qD1024): pack; packing and unpacking graphs.\n",
84 "DEBUG (-qDz, -qD2048): paranoia; ridiculously detailed output (excellent for filling a partition).\n"
87 /* one character codes for the available debug options */
88 static char par_debug_opts_flags[] = {
89 'v', 'q', 's', 'e', 'r', 'w', 'F', 'f', 'l', 'o', 'p', 'z'
94 /* -----------------------------------------------------------------------------
96 -------------------------------------------------------------------------- */
98 static int /* return NULL on error */
101 int argc, char *argv[],
102 int rts_argc, char *rts_argv[],
103 const char *FILENAME_FMT,
106 static I_ decode(const char *s);
107 static void bad_option(const char *s);
110 static void enable_GranSimLight(void);
111 static void process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
112 static void set_GranSim_debug_options(nat n);
113 static void help_GranSim_debug_options(nat n);
115 static void process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
116 static void set_par_debug_options(nat n);
117 static void help_par_debug_options(nat n);
120 /* -----------------------------------------------------------------------------
121 * Command-line option parsing routines.
122 * ---------------------------------------------------------------------------*/
124 void initRtsFlagsDefaults(void)
126 RtsFlags.GcFlags.statsFile = NULL;
127 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
129 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
130 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
132 RtsFlags.GcFlags.minAllocAreaSize = (512 * 1024) / BLOCK_SIZE;
133 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
134 RtsFlags.GcFlags.maxHeapSize = 0; /* off by default */
135 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
136 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
137 RtsFlags.GcFlags.oldGenFactor = 2;
139 /* A hack currently needed for GUM -- HWL */
140 RtsFlags.GcFlags.generations = 1;
141 RtsFlags.GcFlags.steps = 2;
142 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
144 RtsFlags.GcFlags.generations = 2;
145 RtsFlags.GcFlags.steps = 2;
146 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
148 RtsFlags.GcFlags.compact = rtsFalse;
149 RtsFlags.GcFlags.compactThreshold = 30.0;
150 #ifdef RTS_GTK_FRONTPANEL
151 RtsFlags.GcFlags.frontpanel = rtsFalse;
153 RtsFlags.GcFlags.idleGCDelayTime = 300; /* millisecs */
156 /* ToDo: Perhaps by adjusting this value we can make linking without
157 * -static work (i.e., not generate a core-dumping executable)? */
158 # if SIZEOF_VOID_P == 8
159 RtsFlags.GcFlags.heapBase = 0x180000000L;
161 # error I have no idea where to begin the heap on a non-64-bit osf3 machine.
164 RtsFlags.GcFlags.heapBase = 0; /* means don't care */
168 RtsFlags.DebugFlags.scheduler = rtsFalse;
169 RtsFlags.DebugFlags.interpreter = rtsFalse;
170 RtsFlags.DebugFlags.weak = rtsFalse;
171 RtsFlags.DebugFlags.gccafs = rtsFalse;
172 RtsFlags.DebugFlags.gc = rtsFalse;
173 RtsFlags.DebugFlags.block_alloc = rtsFalse;
174 RtsFlags.DebugFlags.sanity = rtsFalse;
175 RtsFlags.DebugFlags.stable = rtsFalse;
176 RtsFlags.DebugFlags.stm = rtsFalse;
177 RtsFlags.DebugFlags.prof = rtsFalse;
178 RtsFlags.DebugFlags.gran = rtsFalse;
179 RtsFlags.DebugFlags.par = rtsFalse;
180 RtsFlags.DebugFlags.linker = rtsFalse;
181 RtsFlags.DebugFlags.squeeze = rtsFalse;
182 RtsFlags.DebugFlags.hpc = rtsFalse;
185 #if defined(PROFILING) || defined(PAR)
186 RtsFlags.CcFlags.doCostCentres = 0;
187 #endif /* PROFILING or PAR */
189 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
190 RtsFlags.ProfFlags.profileInterval = 100;
193 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
194 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
195 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
196 RtsFlags.ProfFlags.ccsLength = 25;
197 RtsFlags.ProfFlags.modSelector = NULL;
198 RtsFlags.ProfFlags.descrSelector = NULL;
199 RtsFlags.ProfFlags.typeSelector = NULL;
200 RtsFlags.ProfFlags.ccSelector = NULL;
201 RtsFlags.ProfFlags.ccsSelector = NULL;
202 RtsFlags.ProfFlags.retainerSelector = NULL;
203 RtsFlags.ProfFlags.bioSelector = NULL;
206 RtsFlags.MiscFlags.tickInterval = 20; /* In milliseconds */
207 RtsFlags.ConcFlags.ctxtSwitchTime = 20; /* In milliseconds */
209 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
212 RtsFlags.ParFlags.nNodes = 1;
213 RtsFlags.ParFlags.migrate = rtsTrue;
214 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
215 RtsFlags.ParFlags.gcThreads = 1;
219 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
220 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
221 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
222 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
223 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
224 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
225 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
227 RtsFlags.ParFlags.outputDisabled = rtsFalse;
229 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
231 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
233 RtsFlags.ParFlags.packBufferSize = 1024;
234 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
235 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
236 RtsFlags.ParFlags.maxThreads = 1024;
237 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
238 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
241 #if defined(PAR) || defined(THREADED_RTS)
242 RtsFlags.ParFlags.maxLocalSparks = 4096;
243 #endif /* PAR || THREADED_RTS */
246 /* ToDo: check defaults for GranSim and GUM */
247 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
248 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
250 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
251 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
252 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
253 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
254 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
255 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
256 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
257 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
259 RtsFlags.GranFlags.packBufferSize = 1024;
260 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
262 RtsFlags.GranFlags.proc = MAX_PROC;
263 RtsFlags.GranFlags.Fishing = rtsFalse;
264 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
265 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
266 RtsFlags.GranFlags.Light = rtsFalse;
268 RtsFlags.GranFlags.Costs.latency = LATENCY;
269 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
270 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
271 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
272 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
273 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
274 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
275 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
277 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
278 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
279 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
280 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
281 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
283 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
284 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
285 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
286 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
287 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
289 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
291 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
292 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
294 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
295 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
296 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
297 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
298 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
299 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
300 RtsFlags.GranFlags.FetchStrategy = 2;
301 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
302 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
303 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
304 RtsFlags.GranFlags.SparkPriority = 0;
305 RtsFlags.GranFlags.SparkPriority2 = 0;
306 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
307 RtsFlags.GranFlags.InversePriorities = rtsFalse;
308 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
309 RtsFlags.GranFlags.ThunksToPack = 0;
310 RtsFlags.GranFlags.RandomSteal = rtsTrue;
314 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
315 RtsFlags.TickyFlags.tickyFile = NULL;
318 RtsFlags.TraceFlags.timestamp = rtsFalse;
319 RtsFlags.TraceFlags.sched = rtsFalse;
322 /* By default no special measurements taken */
323 RtsFlags.PapiFlags.eventType = 0;
324 RtsFlags.PapiFlags.numUserEvents = 0;
331 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
333 " +RTS Indicates run time system options follow",
334 " -RTS Indicates program arguments follow",
335 " --RTS Indicates that ALL subsequent arguments will be given to the",
336 " program (including any of these RTS flags)",
338 "The following run time system options are available:",
340 " -? Prints this message and exits; the program is not executed",
341 " --info Print information about the RTS used by this program",
343 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
344 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
346 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
347 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
348 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
349 " -m<n> Minimum % of heap which must be available (default 3%)",
350 " -G<n> Number of generations (default: 2)",
351 " -T<n> Number of steps in younger generations (default: 2)",
352 " -c<n> Auto-enable compaction of the oldest generation when live data is",
353 " at least <n>% of the maximum heap size set with -M (default: 30%)",
354 " -c Enable compaction for all major collections",
355 #if defined(THREADED_RTS)
356 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
359 " -t<file> One-line GC statistics (default file: <program>.stat)",
360 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
361 " -S<file> Detailed GC statistics",
362 #ifdef RTS_GTK_FRONTPANEL
363 " -f Display front panel (requires X11 & GTK+)",
367 " -Z Don't squeeze out update frames on stack overflow",
368 " -B Sound the bell at the start of each garbage collection",
369 #if defined(PROFILING) || defined(PAR)
371 " -px Time/allocation profile (XML) (output file <program>.prof)",
372 " -p Time/allocation profile (output file <program>.prof)",
373 " -P More detailed Time/Allocation profile",
374 " -Pa Give information about *all* cost centres",
376 # if defined(PROFILING)
378 " -hx Heap residency profile (XML) (output file <program>.prof)",
379 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
380 " break-down: c = cost centre stack (default)",
382 " d = closure description",
383 " y = type description",
385 " b = biography (LAG,DRAG,VOID,USE)",
386 " A subset of closures may be selected thusly:",
387 " -hc<cc>,... specific cost centre(s) (top of stack only)",
388 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
389 " -hm<mod>... all cost centres from the specified modules(s)",
390 " -hd<des>,... closures with specified closure descriptions",
391 " -hy<typ>... closures with specified type descriptions",
392 " -hr<cc>... closures with specified retainers",
393 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
395 " -R<size> Set the maximum retainer set size (default: 8)",
397 " -L<chars> Maximum length of a cost-centre stack in a heap profile",
400 " -xt Include threads (TSOs) in a heap profile",
402 " -xc Show current cost centre stack on raising an exception",
405 #endif /* PROFILING or PAR */
406 #if !defined(PROFILING)
408 " -hT Heap residency profile (output file <program>.hp)",
410 " -i<sec> Time between heap samples (seconds, default: 0.1)",
412 #if defined(TICKY_TICKY)
413 " -r<file> Produce ticky-ticky statistics (with -rstderr for stderr)",
417 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
418 /* NB: the -N<n> is implemented by the driver!! */
420 " -C<secs> Context-switch interval in seconds.",
421 " 0 or no argument means switch as often as possible.",
422 " Default: 0.02 sec; resolution is set by -V below.",
423 " -V<secs> Master tick interval in seconds (0 == disable timer).",
424 " This sets the resolution for -C and the profile timer -i.",
425 " Default: 0.02 sec.",
427 " -vs Trace scheduler events (see also -Ds with -debug)",
428 " -vt Time-stamp trace messages",
431 " -Ds DEBUG: scheduler",
432 " -Di DEBUG: interpreter",
434 " -DG DEBUG: gccafs",
437 " -DS DEBUG: sanity",
438 " -Dt DEBUG: stable",
442 " -Dl DEBUG: linker",
444 " -Dz DEBUG: stack squezing",
445 " -Dc DEBUG: program coverage",
448 #if defined(THREADED_RTS) && !defined(NOSMP)
449 " -N<n> Use <n> OS threads (default: 1)",
450 " -g<n> Use <n> OS threads for GC (default: 1)",
451 " -qm Don't automatically migrate threads between CPUs",
452 " -qw Migrate a thread to the current CPU when it is woken up",
454 " --install-signal-handlers=<yes|no>",
455 " Install signal handlers (default: yes)",
456 #if defined(THREADED_RTS) || defined(PAR)
457 " -e<size> Size of spark pools (default 100)",
460 " -t<num> Set maximum number of advisory threads per PE (default 32)",
461 " -qP Enable activity profile (output files in ~/<program>*.gr)",
462 " -qQ<size> Set pack-buffer size (default: 1024)",
463 " -qd Turn on PVM-ish debugging",
464 " -qO Disable output for performance measurement",
466 #if defined(THREADED_RTS) || defined(PAR)
467 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
470 " -d Turn on PVM-ish debugging",
471 " -O Disable output for performance measurement",
473 #if defined(GRAN) /* ToDo: fill in decent Docu here */
474 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
476 #if defined(USE_PAPI)
477 " -aX CPU performance counter measurements using PAPI",
478 " (use with the -s<file> option). X is one of:",
481 " 1 - level 1 cache misses",
482 " 2 - level 2 cache misses",
483 " b - branch mispredictions",
484 " s - stalled cycles",
485 " e - cache miss and branch misprediction events",
488 "RTS options may also be specified using the GHCRTS environment variable.",
490 "Other RTS options may be available for programs compiled a different way.",
491 "The GHC User's Guide has full details.",
496 STATIC_INLINE rtsBool
497 strequal(const char *a, const char * b)
499 return(strcmp(a, b) == 0);
503 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
509 while (isspace(*c1)) { c1++; };
511 while (!isspace(*c2) && *c2 != '\0') { c2++; };
513 if (c1 == c2) { break; }
515 if (*rts_argc < MAX_RTS_ARGS-1) {
516 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
517 strncpy(s, c1, c2-c1);
519 rts_argv[(*rts_argc)++] = s;
521 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
525 } while (*c1 != '\0');
529 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
531 rtsBool error = rtsFalse;
542 // process arguments from the ghc_rts_opts global variable first.
543 // (arguments from the GHCRTS environment variable and the command
544 // line override these).
546 if (ghc_rts_opts != NULL) {
547 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
551 // process arguments from the GHCRTS environment variable next
552 // (arguments from the command line override these).
554 char *ghc_rts = getenv("GHCRTS");
556 if (ghc_rts != NULL) {
557 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
561 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
562 // argv[0] must be PGM argument -- leave in argv
564 for (mode = PGM; arg < total_arg; arg++) {
565 // The '--RTS' argument disables all future +RTS ... -RTS processing.
566 if (strequal("--RTS", argv[arg])) {
570 // The '--' argument is passed through to the program, but
571 // disables all further +RTS ... -RTS processing.
572 else if (strequal("--", argv[arg])) {
575 else if (strequal("+RTS", argv[arg])) {
578 else if (strequal("-RTS", argv[arg])) {
581 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
582 rts_argv[(*rts_argc)++] = argv[arg];
584 else if (mode == PGM) {
585 argv[(*argc)++] = argv[arg];
588 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
591 // process remaining program arguments
592 for (; arg < total_arg; arg++) {
593 argv[(*argc)++] = argv[arg];
595 argv[*argc] = (char *) 0;
596 rts_argv[*rts_argc] = (char *) 0;
598 // Process RTS (rts_argv) part: mainly to determine statsfile
599 for (arg = 0; arg < *rts_argc; arg++) {
600 if (rts_argv[arg][0] != '-') {
602 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
606 switch(rts_argv[arg][1]) {
608 /* process: general args, then PROFILING-only ones,
609 then CONCURRENT-only, PARallel-only, GRAN-only,
610 TICKY-only (same order as defined in RtsFlags.lh);
611 within those groups, mostly in case-insensitive
613 Final group is x*, which allows for more options.
617 # define TICKY_BUILD_ONLY(x) x
619 # define TICKY_BUILD_ONLY(x) \
620 errorBelch("not built for: ticky-ticky stats"); \
624 #if defined(PROFILING)
625 # define COST_CENTRE_USING_BUILD_ONLY(x) x
627 # define COST_CENTRE_USING_BUILD_ONLY(x) \
628 errorBelch("not built for: -prof or -parallel"); \
633 # define PROFILING_BUILD_ONLY(x) x
635 # define PROFILING_BUILD_ONLY(x) \
636 errorBelch("not built for: -prof"); \
641 # define PAR_BUILD_ONLY(x) x
643 # define PAR_BUILD_ONLY(x) \
644 errorBelch("not built for: -parallel"); \
649 # define THREADED_BUILD_ONLY(x) x
651 # define THREADED_BUILD_ONLY(x) \
652 errorBelch("not built for: -smp"); \
656 #if defined(THREADED_RTS) || defined(PAR)
657 # define PAR_OR_THREADED_BUILD_ONLY(x) x
659 # define PAR_OR_THREADED_BUILD_ONLY(x) \
660 errorBelch("not built for: -parallel or -smp"); \
665 # define GRAN_BUILD_ONLY(x) x
667 # define GRAN_BUILD_ONLY(x) \
668 errorBelch("not built for: -gransim"); \
672 /* =========== GENERAL ========================== */
677 /* This isn't going to allow us to keep related options
678 together as we add more --* flags. We really need a
679 proper options parser. */
681 if (strequal("install-signal-handlers=yes",
682 &rts_argv[arg][2])) {
683 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
685 else if (strequal("install-signal-handlers=no",
686 &rts_argv[arg][2])) {
687 RtsFlags.MiscFlags.install_signal_handlers = rtsFalse;
689 else if (strequal("info",
690 &rts_argv[arg][2])) {
695 errorBelch("unknown RTS option: %s",rts_argv[arg]);
700 RtsFlags.GcFlags.minAllocAreaSize
701 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
702 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
703 bad_option(rts_argv[arg]);
709 switch(rts_argv[arg][2]) {
711 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L1;
714 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L2;
717 RtsFlags.PapiFlags.eventType = PAPI_FLAG_BRANCH;
720 RtsFlags.PapiFlags.eventType = PAPI_FLAG_STALLS;
723 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CB_EVENTS;
726 if (RtsFlags.PapiFlags.numUserEvents >= MAX_PAPI_USER_EVENTS) {
727 errorBelch("maximum number of PAPI events reached");
728 stg_exit(EXIT_FAILURE);
730 RtsFlags.PapiFlags.eventType = PAPI_USER_EVENTS;
731 RtsFlags.PapiFlags.userEvents[RtsFlags.PapiFlags.numUserEvents++] = rts_argv[arg] + 3;
734 bad_option( rts_argv[arg] );
740 RtsFlags.GcFlags.ringBell = rtsTrue;
744 if (rts_argv[arg][2] != '\0') {
745 RtsFlags.GcFlags.compactThreshold =
746 atof(rts_argv[arg]+2);
748 RtsFlags.GcFlags.compact = rtsTrue;
753 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
755 if (RtsFlags.GcFlags.oldGenFactor < 0)
756 bad_option( rts_argv[arg] );
764 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
767 RtsFlags.DebugFlags.scheduler = rtsTrue;
770 RtsFlags.DebugFlags.interpreter = rtsTrue;
773 RtsFlags.DebugFlags.weak = rtsTrue;
776 RtsFlags.DebugFlags.gccafs = rtsTrue;
779 RtsFlags.DebugFlags.gc = rtsTrue;
782 RtsFlags.DebugFlags.block_alloc = rtsTrue;
785 RtsFlags.DebugFlags.sanity = rtsTrue;
788 RtsFlags.DebugFlags.stable = rtsTrue;
791 RtsFlags.DebugFlags.prof = rtsTrue;
794 RtsFlags.DebugFlags.gran = rtsTrue;
797 RtsFlags.DebugFlags.par = rtsTrue;
800 RtsFlags.DebugFlags.linker = rtsTrue;
803 RtsFlags.DebugFlags.apply = rtsTrue;
806 RtsFlags.DebugFlags.stm = rtsTrue;
809 RtsFlags.DebugFlags.squeeze = rtsTrue;
812 RtsFlags.DebugFlags.hpc = rtsTrue;
815 bad_option( rts_argv[arg] );
823 RtsFlags.GcFlags.maxStkSize =
824 decode(rts_argv[arg]+2) / sizeof(W_);
826 if (RtsFlags.GcFlags.maxStkSize == 0)
827 bad_option( rts_argv[arg] );
831 RtsFlags.GcFlags.initialStkSize =
832 decode(rts_argv[arg]+2) / sizeof(W_);
834 if (RtsFlags.GcFlags.initialStkSize == 0)
835 bad_option( rts_argv[arg] );
839 RtsFlags.GcFlags.maxHeapSize =
840 decode(rts_argv[arg]+2) / BLOCK_SIZE;
841 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
843 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
844 bad_option(rts_argv[arg]);
849 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
851 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
852 RtsFlags.GcFlags.pcFreeHeap > 100)
853 bad_option( rts_argv[arg] );
857 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
858 if (RtsFlags.GcFlags.generations < 1) {
859 bad_option(rts_argv[arg]);
864 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
865 if (RtsFlags.GcFlags.steps < 1) {
866 bad_option(rts_argv[arg]);
871 RtsFlags.GcFlags.heapSizeSuggestion =
872 decode(rts_argv[arg]+2) / BLOCK_SIZE;
874 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
875 bad_option(rts_argv[arg]);
879 #ifdef RTS_GTK_FRONTPANEL
881 RtsFlags.GcFlags.frontpanel = rtsTrue;
885 case 'I': /* idle GC delay */
886 if (rts_argv[arg][2] == '\0') {
891 /* Convert to millisecs */
892 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
893 RtsFlags.GcFlags.idleGCDelayTime = cst;
898 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
902 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
906 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
911 /* Opening all those files would almost certainly fail... */
912 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
913 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
917 r = open_stats_file(arg, *argc, argv,
918 *rts_argc, rts_argv, STAT_FILENAME_FMT,
919 &RtsFlags.GcFlags.statsFile);
920 if (r == -1) { error = rtsTrue; }
926 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
929 /* =========== PROFILING ========================== */
931 case 'P': /* detailed cost centre profiling (time/alloc) */
932 case 'p': /* cost centre profiling (time/alloc) */
933 COST_CENTRE_USING_BUILD_ONLY(
934 switch (rts_argv[arg][2]) {
936 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
939 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
942 if (rts_argv[arg][1] == 'P') {
943 RtsFlags.CcFlags.doCostCentres =
944 COST_CENTRES_VERBOSE;
946 RtsFlags.CcFlags.doCostCentres =
947 COST_CENTRES_SUMMARY;
954 PROFILING_BUILD_ONLY(
955 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
958 PROFILING_BUILD_ONLY(
959 RtsFlags.ProfFlags.ccsLength = atof(rts_argv[arg]+2);
960 if(RtsFlags.ProfFlags.ccsLength <= 0) {
961 bad_option(rts_argv[arg]);
964 case 'h': /* serial heap profile */
965 #if !defined(PROFILING)
966 switch (rts_argv[arg][2]) {
969 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
972 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
976 PROFILING_BUILD_ONLY(
977 switch (rts_argv[arg][2]) {
991 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
993 char *left = strchr(rts_argv[arg], '{');
994 char *right = strrchr(rts_argv[arg], '}');
996 // curly braces are optional, for
1001 left = rts_argv[arg] + 3;
1004 right = rts_argv[arg] + strlen(rts_argv[arg]);
1008 switch (rts_argv[arg][2]) {
1009 case 'c': // cost centre label select
1010 RtsFlags.ProfFlags.ccSelector = left;
1013 RtsFlags.ProfFlags.ccsSelector = left;
1016 case 'm': // cost centre module select
1017 RtsFlags.ProfFlags.modSelector = left;
1020 case 'd': // closure descr select
1021 RtsFlags.ProfFlags.descrSelector = left;
1024 case 'y': // closure type select
1025 RtsFlags.ProfFlags.typeSelector = left;
1028 case 'r': // retainer select
1029 RtsFlags.ProfFlags.retainerSelector = left;
1032 case 'b': // biography select
1033 RtsFlags.ProfFlags.bioSelector = left;
1040 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
1041 errorBelch("multiple heap profile options");
1046 switch (rts_argv[arg][2]) {
1050 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
1054 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
1058 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
1062 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
1066 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
1070 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
1076 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
1080 #endif /* PROFILING */
1083 case 'i': /* heap sample interval */
1084 if (rts_argv[arg][2] == '\0') {
1089 /* Convert to milliseconds */
1090 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1091 RtsFlags.ProfFlags.profileInterval = cst;
1095 /* =========== CONCURRENT ========================= */
1096 case 'C': /* context switch interval */
1097 if (rts_argv[arg][2] == '\0')
1098 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1102 /* Convert to milliseconds */
1103 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1104 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1108 case 'V': /* master tick interval */
1109 if (rts_argv[arg][2] == '\0') {
1110 // turns off ticks completely
1111 RtsFlags.MiscFlags.tickInterval = 0;
1115 /* Convert to milliseconds */
1116 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1117 RtsFlags.MiscFlags.tickInterval = cst;
1121 #if defined(THREADED_RTS) && !defined(NOSMP)
1123 THREADED_BUILD_ONLY(
1124 if (rts_argv[arg][2] != '\0') {
1125 RtsFlags.ParFlags.nNodes
1126 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1127 if (RtsFlags.ParFlags.nNodes <= 0) {
1128 errorBelch("bad value for -N");
1135 THREADED_BUILD_ONLY(
1136 if (rts_argv[arg][2] != '\0') {
1137 RtsFlags.ParFlags.gcThreads
1138 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1139 if (RtsFlags.ParFlags.nNodes <= 0) {
1140 errorBelch("bad value for -g");
1143 #if defined(PROFILING)
1144 if (RtsFlags.ParFlags.nNodes > 1) {
1145 errorBelch("bad option %s: only -N1 is supported with profiling", rts_argv[arg]);
1153 switch (rts_argv[arg][2]) {
1155 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1159 RtsFlags.ParFlags.migrate = rtsFalse;
1162 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1165 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1171 /* =========== PARALLEL =========================== */
1173 PAR_OR_THREADED_BUILD_ONLY(
1174 if (rts_argv[arg][2] != '\0') {
1175 RtsFlags.ParFlags.maxLocalSparks
1176 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1177 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1178 errorBelch("bad value for -e");
1187 process_par_option(arg, rts_argc, rts_argv, &error);
1191 /* =========== GRAN =============================== */
1195 process_gran_option(arg, rts_argc, rts_argv, &error);
1198 /* =========== TICKY ============================== */
1200 case 'r': /* Basic profiling stats */
1203 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1207 r = open_stats_file(arg, *argc, argv,
1208 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1209 &RtsFlags.TickyFlags.tickyFile);
1210 if (r == -1) { error = rtsTrue; }
1214 /* =========== TRACING ---------=================== */
1217 switch(rts_argv[arg][2]) {
1219 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1223 RtsFlags.TraceFlags.timestamp = rtsTrue;
1226 RtsFlags.TraceFlags.sched = rtsTrue;
1229 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1235 /* =========== EXTENDED OPTIONS =================== */
1237 case 'x': /* Extend the argument space */
1238 switch(rts_argv[arg][2]) {
1240 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1244 case 'b': /* heapBase in hex; undocumented */
1245 if (rts_argv[arg][3] != '\0') {
1246 RtsFlags.GcFlags.heapBase
1247 = strtol(rts_argv[arg]+3, (char **) NULL, 16);
1249 errorBelch("-xb: requires argument");
1254 case 'c': /* Debugging tool: show current cost centre on an exception */
1255 PROFILING_BUILD_ONLY(
1256 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1260 case 't': /* Include memory used by TSOs in a heap profile */
1261 PROFILING_BUILD_ONLY(
1262 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1266 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1269 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1273 break; /* defensive programming */
1275 /* =========== OH DEAR ============================ */
1277 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1284 if (RtsFlags.MiscFlags.tickInterval < 0) {
1285 RtsFlags.MiscFlags.tickInterval = 50;
1288 // If the master timer is disabled, turn off the other timers.
1289 if (RtsFlags.MiscFlags.tickInterval == 0) {
1290 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1291 RtsFlags.GcFlags.idleGCDelayTime = 0;
1292 RtsFlags.ProfFlags.profileInterval = 0;
1295 // Determine what tick interval we should use for the RTS timer
1296 // by taking the shortest of the various intervals that we need to
1298 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1299 RtsFlags.MiscFlags.tickInterval =
1300 stg_min(RtsFlags.ConcFlags.ctxtSwitchTime,
1301 RtsFlags.MiscFlags.tickInterval);
1304 if (RtsFlags.GcFlags.idleGCDelayTime > 0) {
1305 RtsFlags.MiscFlags.tickInterval =
1306 stg_min(RtsFlags.GcFlags.idleGCDelayTime,
1307 RtsFlags.MiscFlags.tickInterval);
1310 if (RtsFlags.ProfFlags.profileInterval > 0) {
1311 RtsFlags.MiscFlags.tickInterval =
1312 stg_min(RtsFlags.ProfFlags.profileInterval,
1313 RtsFlags.MiscFlags.tickInterval);
1316 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1317 RtsFlags.ConcFlags.ctxtSwitchTicks =
1318 RtsFlags.ConcFlags.ctxtSwitchTime /
1319 RtsFlags.MiscFlags.tickInterval;
1321 RtsFlags.ConcFlags.ctxtSwitchTicks = 0;
1324 if (RtsFlags.ProfFlags.profileInterval > 0) {
1325 RtsFlags.ProfFlags.profileIntervalTicks =
1326 RtsFlags.ProfFlags.profileInterval /
1327 RtsFlags.MiscFlags.tickInterval;
1329 RtsFlags.ProfFlags.profileIntervalTicks = 0;
1336 for (p = usage_text; *p; p++)
1337 errorBelch("%s", *p);
1338 stg_exit(EXIT_FAILURE);
1345 enable_GranSimLight(void) {
1347 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1348 RtsFlags.GranFlags.Light=rtsTrue;
1349 RtsFlags.GranFlags.Costs.latency =
1350 RtsFlags.GranFlags.Costs.fetchtime =
1351 RtsFlags.GranFlags.Costs.additional_latency =
1352 RtsFlags.GranFlags.Costs.gunblocktime =
1353 RtsFlags.GranFlags.Costs.lunblocktime =
1354 RtsFlags.GranFlags.Costs.threadcreatetime =
1355 RtsFlags.GranFlags.Costs.threadqueuetime =
1356 RtsFlags.GranFlags.Costs.threadscheduletime =
1357 RtsFlags.GranFlags.Costs.threaddescheduletime =
1358 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1360 RtsFlags.GranFlags.Costs.mpacktime =
1361 RtsFlags.GranFlags.Costs.munpacktime = 0;
1363 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1364 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1365 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1366 /* FetchStrategy is irrelevant in GrAnSim-Light */
1368 /* GrAnSim Light often creates an abundance of parallel threads,
1369 each with its own stack etc. Therefore, it's in general a good
1370 idea to use small stack chunks (use the -o<size> option to
1373 // RtsFlags.ConcFlags.stkChunkSize = 100;
1375 RtsFlags.GranFlags.proc = 1;
1379 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1381 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1384 /* or a ridiculously idealised simulator */
1385 if(strcmp((rts_argv[arg]+2),"oring")==0) {
1386 RtsFlags.GranFlags.Costs.latency =
1387 RtsFlags.GranFlags.Costs.fetchtime =
1388 RtsFlags.GranFlags.Costs.additional_latency =
1389 RtsFlags.GranFlags.Costs.gunblocktime =
1390 RtsFlags.GranFlags.Costs.lunblocktime =
1391 RtsFlags.GranFlags.Costs.threadcreatetime =
1392 RtsFlags.GranFlags.Costs.threadqueuetime =
1393 RtsFlags.GranFlags.Costs.threadscheduletime =
1394 RtsFlags.GranFlags.Costs.threaddescheduletime =
1395 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1397 RtsFlags.GranFlags.Costs.mpacktime =
1398 RtsFlags.GranFlags.Costs.munpacktime = 0;
1400 RtsFlags.GranFlags.Costs.arith_cost =
1401 RtsFlags.GranFlags.Costs.float_cost =
1402 RtsFlags.GranFlags.Costs.load_cost =
1403 RtsFlags.GranFlags.Costs.store_cost =
1404 RtsFlags.GranFlags.Costs.branch_cost = 0;
1406 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1408 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1409 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1410 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1411 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1415 /* or a somewhat idealised simulator */
1416 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1417 RtsFlags.GranFlags.Costs.latency =
1418 RtsFlags.GranFlags.Costs.fetchtime =
1419 RtsFlags.GranFlags.Costs.additional_latency =
1420 RtsFlags.GranFlags.Costs.gunblocktime =
1421 RtsFlags.GranFlags.Costs.lunblocktime =
1422 RtsFlags.GranFlags.Costs.threadcreatetime =
1423 RtsFlags.GranFlags.Costs.threadqueuetime =
1424 RtsFlags.GranFlags.Costs.threadscheduletime =
1425 RtsFlags.GranFlags.Costs.threaddescheduletime =
1426 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1428 RtsFlags.GranFlags.Costs.mpacktime =
1429 RtsFlags.GranFlags.Costs.munpacktime = 0;
1431 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1433 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1434 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1435 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1436 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1437 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1438 # if defined(GRAN_CHECK) && defined(GRAN)
1439 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1444 /* Communication and task creation cost parameters */
1445 switch(rts_argv[arg][2]) {
1447 IgnoreYields = rtsTrue; // HWL HACK
1451 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1455 if (rts_argv[arg][3] != '\0')
1457 RtsFlags.GranFlags.Costs.gunblocktime =
1458 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1459 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1462 RtsFlags.GranFlags.Costs.latency = LATENCY;
1466 if (rts_argv[arg][3] != '\0')
1467 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1469 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1473 if (rts_argv[arg][3] != '\0')
1474 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1476 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1480 if (rts_argv[arg][3] != '\0')
1481 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1483 RtsFlags.GranFlags.Costs.mtidytime = 0;
1487 if (rts_argv[arg][3] != '\0')
1488 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1490 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1494 if (rts_argv[arg][3] != '\0')
1495 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1497 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1501 if (rts_argv[arg][3] != '\0')
1502 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1504 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1508 if (rts_argv[arg][3] != '\0')
1509 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1511 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1514 /* Thread-related metrics */
1516 if (rts_argv[arg][3] != '\0')
1517 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1519 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1523 if (rts_argv[arg][3] != '\0')
1524 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1526 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1530 if (rts_argv[arg][3] != '\0')
1531 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1533 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1535 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1536 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1540 if (rts_argv[arg][3] != '\0')
1541 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1543 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1545 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1546 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1549 /* Instruction Cost Metrics */
1551 if (rts_argv[arg][3] != '\0')
1552 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1554 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1558 if (rts_argv[arg][3] != '\0')
1559 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1561 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1565 if (rts_argv[arg][3] != '\0')
1566 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1568 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1572 if (rts_argv[arg][3] != '\0')
1573 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1575 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1579 if (rts_argv[arg][3] != '\0')
1580 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1582 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1586 if (rts_argv[arg][3] != '\0')
1587 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1589 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1593 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1594 if (rts_argv[arg][3] != '\0')
1595 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1597 RtsFlags.GranFlags.FetchStrategy = 2;
1598 if (RtsFlags.GranFlags.FetchStrategy == 0)
1599 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1602 case 'K': /* sort overhead (per elem in spark list) */
1603 if (rts_argv[arg][3] != '\0')
1604 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1606 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1607 debugBelch("Overhead for pri spark: %d (per elem).\n",
1608 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1611 case 'O': /* sort overhead (per elem in spark list) */
1612 if (rts_argv[arg][3] != '\0')
1613 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1615 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1616 debugBelch("Overhead for pri sched: %d (per elem).\n",
1617 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1620 /* General Parameters */
1622 if (rts_argv[arg][3] != '\0')
1624 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1625 if (RtsFlags.GranFlags.proc==0) {
1626 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1627 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1628 RtsFlags.GranFlags.proc < 1)
1630 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1636 RtsFlags.GranFlags.proc = MAX_PROC;
1640 RtsFlags.GranFlags.Fishing = rtsTrue;
1641 if (rts_argv[arg][3] != '\0')
1642 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1644 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1648 if (rts_argv[arg][3] != '\0')
1649 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1651 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1655 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1656 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1660 debugBelch("Bulk fetching enabled.\n");
1661 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1665 debugBelch("Thread migration enabled.\n");
1666 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1670 debugBelch("Fair Scheduling enabled.\n");
1671 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1675 debugBelch("Priority Scheduling enabled.\n");
1676 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1680 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1681 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1685 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1689 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1693 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1697 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1701 /* format is -bP<c> where <c> is one char describing kind of profile */
1702 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1703 switch(rts_argv[arg][3]) {
1704 case '\0': break; // nothing special, just an ordinary profile
1705 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1707 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1709 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1711 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1713 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1715 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1717 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1722 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1726 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1729 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1730 if (rts_argv[arg][3] != '\0') {
1733 arg0 = rts_argv[arg]+3;
1734 if ((tmp = strstr(arg0,","))==NULL) {
1735 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1736 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1739 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1740 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1741 debugBelch("SparkPriority: %u.\n",
1742 RtsFlags.GranFlags.SparkPriority);
1743 debugBelch("SparkPriority2:%u.\n",
1744 RtsFlags.GranFlags.SparkPriority2);
1745 if (RtsFlags.GranFlags.SparkPriority2 <
1746 RtsFlags.GranFlags.SparkPriority) {
1747 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1748 RtsFlags.GranFlags.SparkPriority2,
1749 RtsFlags.GranFlags.SparkPriority);
1753 /* plain pri spark is now invoked with -bX
1754 RtsFlags.GranFlags.DoPrioritySparking = 1;
1755 debugBelch("PrioritySparking.\n");
1761 if (rts_argv[arg][3] != '\0') {
1762 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1764 RtsFlags.GranFlags.ThunksToPack = 1;
1766 debugBelch("Thunks To Pack in one packet: %u.\n",
1767 RtsFlags.GranFlags.ThunksToPack);
1771 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1772 debugBelch("Deterministic mode (no random stealing)\n");
1775 /* The following class of options contains eXperimental */
1776 /* features in connection with exploiting granularity */
1777 /* information. I.e. if -bY is chosen these options */
1778 /* tell the RTS what to do with the supplied info --HWL */
1781 if (rts_argv[arg][3] != '\0') {
1782 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1784 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1786 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1787 RtsFlags.GranFlags.packBufferSize_internal);
1791 switch(rts_argv[arg][3]) {
1794 RtsFlags.GranFlags.DoPrioritySparking = 1;
1795 debugBelch("Priority Sparking with Normal Priorities.\n");
1796 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1797 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1798 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1802 RtsFlags.GranFlags.DoPrioritySparking = 1;
1803 debugBelch("Priority Sparking with Inverse Priorities.\n");
1804 RtsFlags.GranFlags.InversePriorities++;
1808 RtsFlags.GranFlags.DoPrioritySparking = 1;
1809 debugBelch("Priority Sparking with Random Priorities.\n");
1810 RtsFlags.GranFlags.RandomPriorities++;
1814 RtsFlags.GranFlags.DoPrioritySparking = 1;
1815 debugBelch("Priority Sparking with No Priorities.\n");
1816 RtsFlags.GranFlags.IgnorePriorities++;
1820 bad_option( rts_argv[arg] );
1826 switch(rts_argv[arg][3]) {
1829 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1830 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1834 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1838 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1842 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1846 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1847 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1851 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1855 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1859 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1863 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1867 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1871 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1875 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1879 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1880 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1884 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1888 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1892 bad_option( rts_argv[arg] );
1897 # if defined(GRAN_CHECK) && defined(GRAN)
1899 switch(rts_argv[arg][3]) {
1900 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1901 if (rts_argv[arg][4] != '\0') {
1902 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1903 debugBelch("Pack buffer size: %d\n",
1904 RtsFlags.GranFlags.packBufferSize);
1906 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1912 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1913 /* hack warning: interpret the flags as a binary number */
1914 nat n = decode(rts_argv[arg]+3);
1915 set_GranSim_debug_options(n);
1918 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1919 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1922 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1923 debugBelch("Valid GranSim debug options are:\n");
1924 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1925 bad_option( rts_argv[arg] );
1926 } else { // flag found; now set it
1927 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1933 case 'e': /* event trace; also -bD1 */
1934 debugBelch("DEBUG: event_trace; printing event trace.\n");
1935 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1936 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1939 case 'E': /* event statistics; also -bD2 */
1940 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1941 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1942 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1945 case 'f': /* thunkStealing; also -bD4 */
1946 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1947 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1948 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1951 case 'z': /* blockOnFetch; also -bD8 */
1952 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1953 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1954 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1957 case 't': /* blockOnFetch_sanity; also -bD16 */
1958 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1959 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1960 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1963 case 'S': /* priSpark; also -bD32 */
1964 debugBelch("DEBUG: priSpark; priority sparking.\n");
1965 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1968 case 's': /* priSched; also -bD64 */
1969 debugBelch("DEBUG: priSched; priority scheduling.\n");
1970 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1973 case 'F': /* findWork; also -bD128 */
1974 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1975 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1978 case 'g': /* globalBlock; also -bD256 */
1979 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1980 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1983 case 'G': /* pack; also -bD512 */
1984 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1985 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1988 case 'P': /* packBuffer; also -bD1024 */
1989 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1990 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1993 case 'o': /* sortedQ; also -bD2048 */
1994 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1995 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1998 case 'r': /* randomSteal; also -bD4096 */
1999 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
2000 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
2003 case 'q': /* checkSparkQ; also -bD8192 */
2004 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
2005 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
2008 case ':': /* checkLight; also -bD16384 */
2009 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
2010 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
2013 case 'b': /* bq; also -bD32768 */
2014 debugBelch("DEBUG: bq; check blocking queues\n");
2015 RtsFlags.GranFlags.Debug.bq = rtsTrue;
2018 case 'd': /* all options turned on */
2019 debugBelch("DEBUG: all options turned on.\n");
2020 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
2021 /* RtsFlags.GranFlags.Debug |= 0x40; */
2025 /* RtsFlags.GranFlags.Debug = 1; */
2031 # endif /* GRAN_CHECK */
2033 bad_option( rts_argv[arg] );
2039 Interpret n as a binary number masking GranSim debug options and set the
2040 correxponding option. See gran_debug_opts_strs for explanations of the flags.
2043 set_GranSim_debug_options(nat n) {
2046 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
2048 errorBelch(gran_debug_opts_strs[i]);
2050 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
2051 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
2052 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
2053 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
2054 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
2055 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
2056 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
2057 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
2058 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
2059 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
2060 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
2061 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
2062 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
2063 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
2064 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
2065 default: barf("set_GranSim_debug_options: only %d debug options expected");
2071 Print one line explanation for each of the GranSim debug options specified
2075 help_GranSim_debug_options(nat n) {
2078 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
2080 debugBelch(gran_debug_opts_strs[i]);
2086 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
2089 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
2090 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
2094 /* Communication and task creation cost parameters */
2095 switch(rts_argv[arg][2]) {
2096 case 'e': /* -qe<n> ... allow <n> local sparks */
2097 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
2098 RtsFlags.ParFlags.maxLocalSparks
2099 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2101 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
2102 errorBelch("setupRtsFlags: bad value for -e\n");
2106 IF_PAR_DEBUG(verbose,
2107 errorBelch("-qe<n>: max %d local sparks",
2108 RtsFlags.ParFlags.maxLocalSparks));
2112 if (rts_argv[arg][3] != '\0') {
2113 RtsFlags.ParFlags.maxThreads
2114 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2116 errorBelch("missing size for -qt\n");
2119 IF_PAR_DEBUG(verbose,
2120 errorBelch("-qt<n>: max %d threads",
2121 RtsFlags.ParFlags.maxThreads));
2125 if (rts_argv[arg][3] != '\0')
2126 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
2128 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
2130 IF_PAR_DEBUG(verbose,
2131 errorBelch("-qf<n>: max %d fishes sent out at one time",
2132 RtsFlags.ParFlags.maxFishes));
2136 if (rts_argv[arg][3] != '\0') {
2137 RtsFlags.ParFlags.fishDelay
2138 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2140 errorBelch("missing fish delay time for -qF\n");
2143 IF_PAR_DEBUG(verbose,
2144 errorBelch("-qF<n>: fish delay time %d us",
2145 RtsFlags.ParFlags.fishDelay));
2149 RtsFlags.ParFlags.outputDisabled = rtsTrue;
2150 IF_PAR_DEBUG(verbose,
2151 errorBelch("-qO: output disabled"));
2154 case 'g': /* -qg<n> ... globalisation scheme */
2155 if (rts_argv[arg][3] != '\0') {
2156 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
2158 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
2161 IF_PAR_DEBUG(verbose,
2162 debugBelch("-qg<n>: globalisation scheme set to %d",
2163 RtsFlags.ParFlags.globalising));
2166 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
2167 if (rts_argv[arg][3] != '\0') {
2168 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
2170 errorBelch("missing number of thunks per packet (for -qh)\n");
2173 IF_PAR_DEBUG(verbose,
2174 debugBelch("-qh<n>: thunks per packet set to %d",
2175 RtsFlags.ParFlags.thunksToPack));
2178 case 'P': /* -qP for writing a log file */
2179 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2180 /* same encoding as in GranSim after -bP */
2181 switch(rts_argv[arg][3]) {
2182 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2183 break; // nothing special, just an ordinary profile
2184 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2185 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2187 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2189 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2191 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2193 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2196 # if defined(PAR_TICKY)
2197 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2199 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2200 stg_exit(EXIT_FAILURE);
2203 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2205 IF_PAR_DEBUG(verbose,
2206 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2207 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2210 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2211 if (rts_argv[arg][3] != '\0') {
2212 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2214 errorBelch("missing size of PackBuffer (for -qQ)\n");
2217 IF_PAR_DEBUG(verbose,
2218 debugBelch("-qQ<n>: pack buffer size set to %d",
2219 RtsFlags.ParFlags.packBufferSize));
2223 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2224 IF_PAR_DEBUG(verbose,
2225 debugBelch("-qR: fair-ish scheduling"));
2230 if (rts_argv[arg][3] != '\0') {
2231 RtsFlags.ParFlags.wait
2232 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2234 RtsFlags.ParFlags.wait = 1000;
2236 IF_PAR_DEBUG(verbose,
2237 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2238 RtsFlags.ParFlags.wait));
2241 case 'D': /* -qD ... all the debugging options */
2242 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2243 /* hack warning: interpret the flags as a binary number */
2244 nat n = decode(rts_argv[arg]+3);
2245 set_par_debug_options(n);
2248 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2249 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2252 if (i==MAX_PAR_DEBUG_OPTION+1) {
2253 errorBelch("Valid GUM debug options are:\n");
2254 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2255 bad_option( rts_argv[arg] );
2256 } else { // flag found; now set it
2257 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2263 errorBelch("Unknown option -q%c (%d opts in total)",
2264 rts_argv[arg][2], *rts_argc);
2270 Interpret n as a binary number masking Par debug options and set the
2271 correxponding option. See par_debug_opts_strs for explanations of the flags.
2274 set_par_debug_options(nat n) {
2277 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2279 debugBelch(par_debug_opts_strs[i]);
2281 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2282 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2283 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2284 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2285 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2286 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2287 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2288 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2289 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2290 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2291 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2292 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2293 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2294 default: barf("set_par_debug_options: only %d debug options expected",
2295 MAX_PAR_DEBUG_OPTION);
2301 Print one line explanation for each of the GranSim debug options specified
2305 help_par_debug_options(nat n) {
2308 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2310 debugBelch(par_debug_opts_strs[i]);
2316 stats_fprintf(FILE *f, char *s, ...)
2328 static int /* return -1 on error */
2331 int argc, char *argv[],
2332 int rts_argc, char *rts_argv[],
2333 const char *FILENAME_FMT,
2338 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2339 f = NULL; /* NULL means use debugBelch */
2341 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2342 f = fopen(rts_argv[arg]+2,"w");
2344 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2345 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2346 f = fopen(stats_filename,"w");
2349 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2356 /* Write argv and rtsv into start of stats file */
2358 for(count = 0; count < argc; count++) {
2359 stats_fprintf(f, "%s ", argv[count]);
2361 stats_fprintf(f, "+RTS ");
2362 for(count = 0; count < rts_argc; count++)
2363 stats_fprintf(f, "%s ", rts_argv[count]);
2364 stats_fprintf(f, "\n");
2372 decode(const char *s)
2383 if (c == 'g' || c == 'G')
2384 m *= 1000*1000*1000; /* UNchecked! */
2385 else if (c == 'm' || c == 'M')
2386 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2387 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2388 m *= 1000; /* a direct-mapped cache. */
2389 else if (c == 'w' || c == 'W')
2396 bad_option(const char *s)
2398 errorBelch("bad RTS option: %s", s);
2399 stg_exit(EXIT_FAILURE);
2402 /* -----------------------------------------------------------------------------
2403 Getting/Setting the program's arguments.
2405 These are used by System.Environment, and parts of the RTS.
2406 -------------------------------------------------------------------------- */
2409 setProgName(char *argv[])
2411 /* Remove directory from argv[0] -- default files in current directory */
2412 #if !defined(mingw32_HOST_OS)
2414 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2415 prog_name = last_slash+1;
2417 prog_name = argv[0];
2420 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2421 while ( last_slash > argv[0] ) {
2422 if ( *last_slash == '/' || *last_slash == '\\' ) {
2423 prog_name = last_slash+1;
2428 prog_name = argv[0];
2433 getProgArgv(int *argc, char **argv[])
2435 if (argc) { *argc = prog_argc; }
2436 if (argv) { *argv = prog_argv; }
2440 setProgArgv(int argc, char *argv[])
2442 /* Usually this is done by startupHaskell, so we don't need to call this.
2443 However, sometimes Hugs wants to change the arguments which Haskell
2444 getArgs >>= ... will be fed. So you can do that by calling here
2445 _after_ calling startupHaskell.
2449 setProgName(prog_argv);
2452 /* These functions record and recall the full arguments, including the
2453 +RTS ... -RTS options. The reason for adding them was so that the
2454 ghc-inplace program can pass /all/ the arguments on to the real ghc. */
2456 getFullProgArgv(int *argc, char **argv[])
2458 if (argc) { *argc = full_prog_argc; }
2459 if (argv) { *argv = full_prog_argv; }
2463 setFullProgArgv(int argc, char *argv[])
2466 full_prog_argc = argc;
2467 full_prog_argv = stgCallocBytes(argc + 1, sizeof (char *),
2468 "setFullProgArgv 1");
2469 for (i = 0; i < argc; i++) {
2470 full_prog_argv[i] = stgMallocBytes(strlen(argv[i]) + 1,
2471 "setFullProgArgv 2");
2472 strcpy(full_prog_argv[i], argv[i]);
2474 full_prog_argv[argc] = NULL;