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 char *prog_name = NULL; /* 'basename' of prog_argv[0] */
32 int rts_argc = 0; /* ditto */
33 char *rts_argv[MAX_RTS_ARGS];
36 * constants, used later
43 static char *gran_debug_opts_strs[] = {
44 "DEBUG (-bDe, -bD1): event_trace; printing event trace.\n",
45 "DEBUG (-bDE, -bD2): event_stats; printing event statistics.\n",
46 "DEBUG (-bDb, -bD4): bq; check blocking queues\n",
47 "DEBUG (-bDG, -bD8): pack; routines for (un-)packing graph structures.\n",
48 "DEBUG (-bDq, -bD16): checkSparkQ; check consistency of the spark queues.\n",
49 "DEBUG (-bDf, -bD32): thunkStealing; print forwarding of fetches.\n",
50 "DEBUG (-bDr, -bD64): randomSteal; stealing sparks/threads from random PEs.\n",
51 "DEBUG (-bDF, -bD128): findWork; searching spark-pools (local & remote), thread queues for work.\n",
52 "DEBUG (-bDu, -bD256): unused; currently unused flag.\n",
53 "DEBUG (-bDS, -bD512): pri; priority sparking or scheduling.\n",
54 "DEBUG (-bD:, -bD1024): checkLight; check GranSim-Light setup.\n",
55 "DEBUG (-bDo, -bD2048): sortedQ; check whether spark/thread queues are sorted.\n",
56 "DEBUG (-bDz, -bD4096): blockOnFetch; check for blocked on fetch.\n",
57 "DEBUG (-bDP, -bD8192): packBuffer; routines handling pack buffer (GranSim internal!).\n",
58 "DEBUG (-bDt, -bD16384): blockOnFetch_sanity; check for TSO asleep on fetch.\n",
61 /* one character codes for the available debug options */
62 static char gran_debug_opts_flags[] = {
63 'e', 'E', 'b', 'G', 'q', 'f', 'r', 'F', 'u', 'S', ':', 'o', 'z', 'P', 't'
68 static char *par_debug_opts_strs[] = {
69 "DEBUG (-qDv, -qD1): verbose; be generally verbose with parallel related stuff.\n",
70 "DEBUG (-qDq, -qD2): bq; print blocking queues.\n",
71 "DEBUG (-qDs, -qD4): schedule; scheduling of parallel threads.\n",
72 "DEBUG (-qDe, -qD8): free; free messages.\n",
73 "DEBUG (-qDr, -qD16): resume; resume messages.\n",
74 "DEBUG (-qDw, -qD32): weight; print weights and distrib GC stuff.\n",
75 "DEBUG (-qDF, -qD64): fetch; fetch messages.\n",
76 // "DEBUG (-qDa, -qD128): ack; ack messages.\n",
77 "DEBUG (-qDf, -qD128): fish; fish messages.\n",
78 //"DEBUG (-qDo, -qD512): forward; forwarding messages to other PEs.\n",
79 "DEBUG (-qDl, -qD256): tables; print internal LAGA etc tables.\n",
80 "DEBUG (-qDo, -qD512): packet; packets and graph structures when packing.\n",
81 "DEBUG (-qDp, -qD1024): pack; packing and unpacking graphs.\n",
82 "DEBUG (-qDz, -qD2048): paranoia; ridiculously detailed output (excellent for filling a partition).\n"
85 /* one character codes for the available debug options */
86 static char par_debug_opts_flags[] = {
87 'v', 'q', 's', 'e', 'r', 'w', 'F', 'f', 'l', 'o', 'p', 'z'
92 /* -----------------------------------------------------------------------------
94 -------------------------------------------------------------------------- */
96 static int /* return NULL on error */
99 int argc, char *argv[],
100 int rts_argc, char *rts_argv[],
101 const char *FILENAME_FMT,
104 static I_ decode(const char *s);
105 static void bad_option(const char *s);
108 static void enable_GranSimLight(void);
109 static void process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
110 static void set_GranSim_debug_options(nat n);
111 static void help_GranSim_debug_options(nat n);
113 static void process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
114 static void set_par_debug_options(nat n);
115 static void help_par_debug_options(nat n);
118 /* -----------------------------------------------------------------------------
119 * Command-line option parsing routines.
120 * ---------------------------------------------------------------------------*/
122 void initRtsFlagsDefaults(void)
124 RtsFlags.GcFlags.statsFile = NULL;
125 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
127 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
128 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
130 RtsFlags.GcFlags.minAllocAreaSize = (512 * 1024) / BLOCK_SIZE;
131 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
132 RtsFlags.GcFlags.maxHeapSize = 0; /* off by default */
133 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
134 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
135 RtsFlags.GcFlags.oldGenFactor = 2;
137 /* A hack currently needed for GUM -- HWL */
138 RtsFlags.GcFlags.generations = 1;
139 RtsFlags.GcFlags.steps = 2;
140 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
142 RtsFlags.GcFlags.generations = 2;
143 RtsFlags.GcFlags.steps = 2;
144 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
146 RtsFlags.GcFlags.compact = rtsFalse;
147 RtsFlags.GcFlags.compactThreshold = 30.0;
148 #ifdef RTS_GTK_FRONTPANEL
149 RtsFlags.GcFlags.frontpanel = rtsFalse;
151 RtsFlags.GcFlags.idleGCDelayTime = 300; /* millisecs */
154 /* ToDo: Perhaps by adjusting this value we can make linking without
155 * -static work (i.e., not generate a core-dumping executable)? */
156 # if SIZEOF_VOID_P == 8
157 RtsFlags.GcFlags.heapBase = 0x180000000L;
159 # error I have no idea where to begin the heap on a non-64-bit osf3 machine.
162 RtsFlags.GcFlags.heapBase = 0; /* means don't care */
166 RtsFlags.DebugFlags.scheduler = rtsFalse;
167 RtsFlags.DebugFlags.interpreter = rtsFalse;
168 RtsFlags.DebugFlags.weak = rtsFalse;
169 RtsFlags.DebugFlags.gccafs = rtsFalse;
170 RtsFlags.DebugFlags.gc = rtsFalse;
171 RtsFlags.DebugFlags.block_alloc = rtsFalse;
172 RtsFlags.DebugFlags.sanity = rtsFalse;
173 RtsFlags.DebugFlags.stable = rtsFalse;
174 RtsFlags.DebugFlags.stm = rtsFalse;
175 RtsFlags.DebugFlags.prof = rtsFalse;
176 RtsFlags.DebugFlags.gran = rtsFalse;
177 RtsFlags.DebugFlags.par = rtsFalse;
178 RtsFlags.DebugFlags.linker = rtsFalse;
179 RtsFlags.DebugFlags.squeeze = rtsFalse;
180 RtsFlags.DebugFlags.hpc = rtsFalse;
183 #if defined(PROFILING) || defined(PAR)
184 RtsFlags.CcFlags.doCostCentres = 0;
185 #endif /* PROFILING or PAR */
187 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
188 RtsFlags.ProfFlags.profileInterval = 100;
191 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
192 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
193 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
194 RtsFlags.ProfFlags.ccsLength = 25;
195 RtsFlags.ProfFlags.modSelector = NULL;
196 RtsFlags.ProfFlags.descrSelector = NULL;
197 RtsFlags.ProfFlags.typeSelector = NULL;
198 RtsFlags.ProfFlags.ccSelector = NULL;
199 RtsFlags.ProfFlags.ccsSelector = NULL;
200 RtsFlags.ProfFlags.retainerSelector = NULL;
201 RtsFlags.ProfFlags.bioSelector = NULL;
204 RtsFlags.MiscFlags.tickInterval = 50; /* In milliseconds */
205 RtsFlags.ConcFlags.ctxtSwitchTime = 50; /* In milliseconds */
207 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
210 RtsFlags.ParFlags.nNodes = 1;
211 RtsFlags.ParFlags.migrate = rtsTrue;
212 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
216 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
217 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
218 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
219 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
220 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
221 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
222 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
224 RtsFlags.ParFlags.outputDisabled = rtsFalse;
226 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
228 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
230 RtsFlags.ParFlags.packBufferSize = 1024;
231 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
232 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
233 RtsFlags.ParFlags.maxThreads = 1024;
234 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
235 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
238 #if defined(PAR) || defined(THREADED_RTS)
239 RtsFlags.ParFlags.maxLocalSparks = 4096;
240 #endif /* PAR || THREADED_RTS */
243 /* ToDo: check defaults for GranSim and GUM */
244 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
245 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
247 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
248 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
249 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
250 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
251 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
252 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
253 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
254 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
256 RtsFlags.GranFlags.packBufferSize = 1024;
257 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
259 RtsFlags.GranFlags.proc = MAX_PROC;
260 RtsFlags.GranFlags.Fishing = rtsFalse;
261 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
262 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
263 RtsFlags.GranFlags.Light = rtsFalse;
265 RtsFlags.GranFlags.Costs.latency = LATENCY;
266 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
267 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
268 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
269 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
270 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
271 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
272 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
274 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
275 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
276 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
277 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
278 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
280 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
281 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
282 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
283 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
284 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
286 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
288 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
289 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
291 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
292 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
293 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
294 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
295 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
296 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
297 RtsFlags.GranFlags.FetchStrategy = 2;
298 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
299 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
300 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
301 RtsFlags.GranFlags.SparkPriority = 0;
302 RtsFlags.GranFlags.SparkPriority2 = 0;
303 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
304 RtsFlags.GranFlags.InversePriorities = rtsFalse;
305 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
306 RtsFlags.GranFlags.ThunksToPack = 0;
307 RtsFlags.GranFlags.RandomSteal = rtsTrue;
311 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
312 RtsFlags.TickyFlags.tickyFile = NULL;
315 RtsFlags.TraceFlags.timestamp = rtsFalse;
316 RtsFlags.TraceFlags.sched = rtsFalse;
319 /* By default no special measurements taken */
320 RtsFlags.PapiFlags.eventType = 0;
327 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
329 " +RTS Indicates run time system options follow",
330 " -RTS Indicates program arguments follow",
331 " --RTS Indicates that ALL subsequent arguments will be given to the",
332 " program (including any of these RTS flags)",
334 "The following run time system options are available:",
336 " -? Prints this message and exits; the program is not executed",
338 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
339 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
341 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
342 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
343 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
344 " -m<n> Minimum % of heap which must be available (default 3%)",
345 " -G<n> Number of generations (default: 2)",
346 " -T<n> Number of steps in younger generations (default: 2)",
347 " -c<n> Auto-enable compaction of the oldest generation when live data is",
348 " at least <n>% of the maximum heap size set with -M (default: 30%)",
349 " -c Enable compaction for all major collections",
350 #if defined(THREADED_RTS)
351 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
354 " -t<file> One-line GC statistics (default file: <program>.stat)",
355 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
356 " -S<file> Detailed GC statistics",
357 #ifdef RTS_GTK_FRONTPANEL
358 " -f Display front panel (requires X11 & GTK+)",
362 " -Z Don't squeeze out update frames on stack overflow",
363 " -B Sound the bell at the start of each garbage collection",
364 #if defined(PROFILING) || defined(PAR)
366 " -px Time/allocation profile (XML) (output file <program>.prof)",
367 " -p Time/allocation profile (output file <program>.prof)",
368 " -P More detailed Time/Allocation profile",
369 " -Pa Give information about *all* cost centres",
371 # if defined(PROFILING)
373 " -hx Heap residency profile (XML) (output file <program>.prof)",
374 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
375 " break-down: c = cost centre stack (default)",
377 " d = closure description",
378 " y = type description",
380 " b = biography (LAG,DRAG,VOID,USE)",
381 " A subset of closures may be selected thusly:",
382 " -hc<cc>,... specific cost centre(s) (top of stack only)",
383 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
384 " -hm<mod>... all cost centres from the specified modules(s)",
385 " -hd<des>,... closures with specified closure descriptions",
386 " -hy<typ>... closures with specified type descriptions",
387 " -hr<cc>... closures with specified retainers",
388 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
390 " -R<size> Set the maximum retainer set size (default: 8)",
392 " -L<chars> Maximum length of a cost-centre stack in a heap profile",
395 " -xt Include threads (TSOs) in a heap profile",
397 " -xc Show current cost centre stack on raising an exception",
400 #endif /* PROFILING or PAR */
401 #if !defined(PROFILING)
403 " -hT Heap residency profile (output file <program>.hp)",
405 " -i<sec> Time between heap samples (seconds, default: 0.1)",
407 #if defined(TICKY_TICKY)
408 " -r<file> Produce ticky-ticky statistics (with -rstderr for stderr)",
412 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
413 /* NB: the -N<n> is implemented by the driver!! */
415 " -C<secs> Context-switch interval in seconds.",
416 " 0 or no argument means switch as often as possible.",
417 " Default: 0.02 sec; resolution is set by -V below.",
418 " -V<secs> Master tick interval in seconds (0 == disable timer).",
419 " This sets the resolution for -C and the profile timer -i.",
420 " Default: 0.02 sec.",
422 " -vs Trace scheduler events (see also -Ds with -debug)",
423 " -vt Time-stamp trace messages",
426 " -Ds DEBUG: scheduler",
427 " -Di DEBUG: interpreter",
429 " -DG DEBUG: gccafs",
432 " -DS DEBUG: sanity",
433 " -Dt DEBUG: stable",
437 " -Dl DEBUG: linker",
439 " -Dz DEBUG: stack squezing",
440 " -Dc DEBUG: program coverage",
443 #if defined(THREADED_RTS) && !defined(NOSMP)
444 " -N<n> Use <n> OS threads (default: 1)",
445 " -qm Don't automatically migrate threads between CPUs",
446 " -qw Migrate a thread to the current CPU when it is woken up",
448 " --install-signal-handlers=<yes|no>",
449 " Install signal handlers (default: yes)",
450 #if defined(THREADED_RTS) || defined(PAR)
451 " -e<size> Size of spark pools (default 100)",
454 " -t<num> Set maximum number of advisory threads per PE (default 32)",
455 " -qP Enable activity profile (output files in ~/<program>*.gr)",
456 " -qQ<size> Set pack-buffer size (default: 1024)",
457 " -qd Turn on PVM-ish debugging",
458 " -qO Disable output for performance measurement",
460 #if defined(THREADED_RTS) || defined(PAR)
461 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
464 " -d Turn on PVM-ish debugging",
465 " -O Disable output for performance measurement",
467 #if defined(GRAN) /* ToDo: fill in decent Docu here */
468 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
470 #if defined(USE_PAPI)
471 " -aX CPU performance counter measurements using PAPI",
472 " (use with the -s<file> option). X is one of:",
475 " 1 - level 1 cache misses",
476 " 2 - level 2 cache misses",
477 " b - branch mispredictions",
478 " s - stalled cycles",
479 " e - cache miss and branch misprediction events",
482 "RTS options may also be specified using the GHCRTS environment variable.",
484 "Other RTS options may be available for programs compiled a different way.",
485 "The GHC User's Guide has full details.",
490 STATIC_INLINE rtsBool
491 strequal(const char *a, const char * b)
493 return(strcmp(a, b) == 0);
497 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
503 while (isspace(*c1)) { c1++; };
505 while (!isspace(*c2) && *c2 != '\0') { c2++; };
507 if (c1 == c2) { break; }
509 if (*rts_argc < MAX_RTS_ARGS-1) {
510 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
511 strncpy(s, c1, c2-c1);
513 rts_argv[(*rts_argc)++] = s;
515 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
519 } while (*c1 != '\0');
523 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
525 rtsBool error = rtsFalse;
536 // process arguments from the ghc_rts_opts global variable first.
537 // (arguments from the GHCRTS environment variable and the command
538 // line override these).
540 if (ghc_rts_opts != NULL) {
541 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
545 // process arguments from the GHCRTS environment variable next
546 // (arguments from the command line override these).
548 char *ghc_rts = getenv("GHCRTS");
550 if (ghc_rts != NULL) {
551 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
555 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
556 // argv[0] must be PGM argument -- leave in argv
558 for (mode = PGM; arg < total_arg; arg++) {
559 // The '--RTS' argument disables all future +RTS ... -RTS processing.
560 if (strequal("--RTS", argv[arg])) {
564 // The '--' argument is passed through to the program, but
565 // disables all further +RTS ... -RTS processing.
566 else if (strequal("--", argv[arg])) {
569 else if (strequal("+RTS", argv[arg])) {
572 else if (strequal("-RTS", argv[arg])) {
575 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
576 rts_argv[(*rts_argc)++] = argv[arg];
578 else if (mode == PGM) {
579 argv[(*argc)++] = argv[arg];
582 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
585 // process remaining program arguments
586 for (; arg < total_arg; arg++) {
587 argv[(*argc)++] = argv[arg];
589 argv[*argc] = (char *) 0;
590 rts_argv[*rts_argc] = (char *) 0;
592 // Process RTS (rts_argv) part: mainly to determine statsfile
593 for (arg = 0; arg < *rts_argc; arg++) {
594 if (rts_argv[arg][0] != '-') {
596 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
600 switch(rts_argv[arg][1]) {
602 /* process: general args, then PROFILING-only ones,
603 then CONCURRENT-only, PARallel-only, GRAN-only,
604 TICKY-only (same order as defined in RtsFlags.lh);
605 within those groups, mostly in case-insensitive
607 Final group is x*, which allows for more options.
611 # define TICKY_BUILD_ONLY(x) x
613 # define TICKY_BUILD_ONLY(x) \
614 errorBelch("not built for: ticky-ticky stats"); \
618 #if defined(PROFILING)
619 # define COST_CENTRE_USING_BUILD_ONLY(x) x
621 # define COST_CENTRE_USING_BUILD_ONLY(x) \
622 errorBelch("not built for: -prof or -parallel"); \
627 # define PROFILING_BUILD_ONLY(x) x
629 # define PROFILING_BUILD_ONLY(x) \
630 errorBelch("not built for: -prof"); \
635 # define PAR_BUILD_ONLY(x) x
637 # define PAR_BUILD_ONLY(x) \
638 errorBelch("not built for: -parallel"); \
643 # define THREADED_BUILD_ONLY(x) x
645 # define THREADED_BUILD_ONLY(x) \
646 errorBelch("not built for: -smp"); \
650 #if defined(THREADED_RTS) || defined(PAR)
651 # define PAR_OR_THREADED_BUILD_ONLY(x) x
653 # define PAR_OR_THREADED_BUILD_ONLY(x) \
654 errorBelch("not built for: -parallel or -smp"); \
659 # define GRAN_BUILD_ONLY(x) x
661 # define GRAN_BUILD_ONLY(x) \
662 errorBelch("not built for: -gransim"); \
666 /* =========== GENERAL ========================== */
671 /* This isn't going to allow us to keep related options
672 together as we add more --* flags. We really need a
673 proper options parser. */
675 if (strequal("install-signal-handlers=yes",
676 &rts_argv[arg][2])) {
677 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
679 else if (strequal("install-signal-handlers=no",
680 &rts_argv[arg][2])) {
681 RtsFlags.MiscFlags.install_signal_handlers = rtsFalse;
684 errorBelch("unknown RTS option: %s",rts_argv[arg]);
689 RtsFlags.GcFlags.minAllocAreaSize
690 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
691 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
692 bad_option(rts_argv[arg]);
698 switch(rts_argv[arg][2]) {
700 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L1;
703 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L2;
706 RtsFlags.PapiFlags.eventType = PAPI_FLAG_BRANCH;
709 RtsFlags.PapiFlags.eventType = PAPI_FLAG_STALLS;
712 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CB_EVENTS;
715 bad_option( rts_argv[arg] );
721 RtsFlags.GcFlags.ringBell = rtsTrue;
725 if (rts_argv[arg][2] != '\0') {
726 RtsFlags.GcFlags.compactThreshold =
727 atof(rts_argv[arg]+2);
729 RtsFlags.GcFlags.compact = rtsTrue;
734 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
736 if (RtsFlags.GcFlags.oldGenFactor < 0)
737 bad_option( rts_argv[arg] );
745 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
748 RtsFlags.DebugFlags.scheduler = rtsTrue;
751 RtsFlags.DebugFlags.interpreter = rtsTrue;
754 RtsFlags.DebugFlags.weak = rtsTrue;
757 RtsFlags.DebugFlags.gccafs = rtsTrue;
760 RtsFlags.DebugFlags.gc = rtsTrue;
763 RtsFlags.DebugFlags.block_alloc = rtsTrue;
766 RtsFlags.DebugFlags.sanity = rtsTrue;
769 RtsFlags.DebugFlags.stable = rtsTrue;
772 RtsFlags.DebugFlags.prof = rtsTrue;
775 RtsFlags.DebugFlags.gran = rtsTrue;
778 RtsFlags.DebugFlags.par = rtsTrue;
781 RtsFlags.DebugFlags.linker = rtsTrue;
784 RtsFlags.DebugFlags.apply = rtsTrue;
787 RtsFlags.DebugFlags.stm = rtsTrue;
790 RtsFlags.DebugFlags.squeeze = rtsTrue;
793 RtsFlags.DebugFlags.hpc = rtsTrue;
796 bad_option( rts_argv[arg] );
804 RtsFlags.GcFlags.maxStkSize =
805 decode(rts_argv[arg]+2) / sizeof(W_);
807 if (RtsFlags.GcFlags.maxStkSize == 0)
808 bad_option( rts_argv[arg] );
812 RtsFlags.GcFlags.initialStkSize =
813 decode(rts_argv[arg]+2) / sizeof(W_);
815 if (RtsFlags.GcFlags.initialStkSize == 0)
816 bad_option( rts_argv[arg] );
820 RtsFlags.GcFlags.maxHeapSize =
821 decode(rts_argv[arg]+2) / BLOCK_SIZE;
822 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
824 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
825 bad_option(rts_argv[arg]);
830 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
832 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
833 RtsFlags.GcFlags.pcFreeHeap > 100)
834 bad_option( rts_argv[arg] );
838 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
839 if (RtsFlags.GcFlags.generations < 1) {
840 bad_option(rts_argv[arg]);
845 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
846 if (RtsFlags.GcFlags.steps < 1) {
847 bad_option(rts_argv[arg]);
852 RtsFlags.GcFlags.heapSizeSuggestion =
853 decode(rts_argv[arg]+2) / BLOCK_SIZE;
855 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
856 bad_option(rts_argv[arg]);
860 #ifdef RTS_GTK_FRONTPANEL
862 RtsFlags.GcFlags.frontpanel = rtsTrue;
866 case 'I': /* idle GC delay */
867 if (rts_argv[arg][2] == '\0') {
872 /* Convert to millisecs */
873 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
874 RtsFlags.GcFlags.idleGCDelayTime = cst;
879 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
883 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
887 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
892 /* Opening all those files would almost certainly fail... */
893 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
894 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
898 r = open_stats_file(arg, *argc, argv,
899 *rts_argc, rts_argv, STAT_FILENAME_FMT,
900 &RtsFlags.GcFlags.statsFile);
901 if (r == -1) { error = rtsTrue; }
907 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
910 /* =========== PROFILING ========================== */
912 case 'P': /* detailed cost centre profiling (time/alloc) */
913 case 'p': /* cost centre profiling (time/alloc) */
914 COST_CENTRE_USING_BUILD_ONLY(
915 switch (rts_argv[arg][2]) {
917 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
920 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
923 if (rts_argv[arg][1] == 'P') {
924 RtsFlags.CcFlags.doCostCentres =
925 COST_CENTRES_VERBOSE;
927 RtsFlags.CcFlags.doCostCentres =
928 COST_CENTRES_SUMMARY;
935 PROFILING_BUILD_ONLY(
936 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
939 PROFILING_BUILD_ONLY(
940 RtsFlags.ProfFlags.ccsLength = atof(rts_argv[arg]+2);
941 if(RtsFlags.ProfFlags.ccsLength <= 0) {
942 bad_option(rts_argv[arg]);
945 case 'h': /* serial heap profile */
946 #if !defined(PROFILING)
947 switch (rts_argv[arg][2]) {
950 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
953 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
957 PROFILING_BUILD_ONLY(
958 switch (rts_argv[arg][2]) {
972 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
974 char *left = strchr(rts_argv[arg], '{');
975 char *right = strrchr(rts_argv[arg], '}');
977 // curly braces are optional, for
982 left = rts_argv[arg] + 3;
985 right = rts_argv[arg] + strlen(rts_argv[arg]);
989 switch (rts_argv[arg][2]) {
990 case 'c': // cost centre label select
991 RtsFlags.ProfFlags.ccSelector = left;
994 RtsFlags.ProfFlags.ccsSelector = left;
997 case 'm': // cost centre module select
998 RtsFlags.ProfFlags.modSelector = left;
1001 case 'd': // closure descr select
1002 RtsFlags.ProfFlags.descrSelector = left;
1005 case 'y': // closure type select
1006 RtsFlags.ProfFlags.typeSelector = left;
1009 case 'r': // retainer select
1010 RtsFlags.ProfFlags.retainerSelector = left;
1013 case 'b': // biography select
1014 RtsFlags.ProfFlags.bioSelector = left;
1021 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
1022 errorBelch("multiple heap profile options");
1027 switch (rts_argv[arg][2]) {
1031 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
1035 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
1039 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
1043 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
1047 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
1051 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
1057 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
1061 #endif /* PROFILING */
1064 case 'i': /* heap sample interval */
1065 if (rts_argv[arg][2] == '\0') {
1070 /* Convert to milliseconds */
1071 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1072 RtsFlags.ProfFlags.profileInterval = cst;
1076 /* =========== CONCURRENT ========================= */
1077 case 'C': /* context switch interval */
1078 if (rts_argv[arg][2] == '\0')
1079 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1083 /* Convert to milliseconds */
1084 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1085 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1089 case 'V': /* master tick interval */
1090 if (rts_argv[arg][2] == '\0') {
1091 // turns off ticks completely
1092 RtsFlags.MiscFlags.tickInterval = 0;
1096 /* Convert to milliseconds */
1097 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1098 RtsFlags.MiscFlags.tickInterval = cst;
1102 #if defined(THREADED_RTS) && !defined(NOSMP)
1104 THREADED_BUILD_ONLY(
1105 if (rts_argv[arg][2] != '\0') {
1106 RtsFlags.ParFlags.nNodes
1107 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1108 if (RtsFlags.ParFlags.nNodes <= 0) {
1109 errorBelch("bad value for -N");
1116 switch (rts_argv[arg][2]) {
1118 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1122 RtsFlags.ParFlags.migrate = rtsFalse;
1125 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1128 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1134 /* =========== PARALLEL =========================== */
1136 PAR_OR_THREADED_BUILD_ONLY(
1137 if (rts_argv[arg][2] != '\0') {
1138 RtsFlags.ParFlags.maxLocalSparks
1139 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1140 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1141 errorBelch("bad value for -e");
1150 process_par_option(arg, rts_argc, rts_argv, &error);
1154 /* =========== GRAN =============================== */
1158 process_gran_option(arg, rts_argc, rts_argv, &error);
1161 /* =========== TICKY ============================== */
1163 case 'r': /* Basic profiling stats */
1166 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1170 r = open_stats_file(arg, *argc, argv,
1171 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1172 &RtsFlags.TickyFlags.tickyFile);
1173 if (r == -1) { error = rtsTrue; }
1177 /* =========== TRACING ---------=================== */
1180 switch(rts_argv[arg][2]) {
1182 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1186 RtsFlags.TraceFlags.timestamp = rtsTrue;
1189 RtsFlags.TraceFlags.sched = rtsTrue;
1192 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1198 /* =========== EXTENDED OPTIONS =================== */
1200 case 'x': /* Extend the argument space */
1201 switch(rts_argv[arg][2]) {
1203 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1207 case 'b': /* heapBase in hex; undocumented */
1208 if (rts_argv[arg][3] != '\0') {
1209 RtsFlags.GcFlags.heapBase
1210 = strtol(rts_argv[arg]+3, (char **) NULL, 16);
1212 errorBelch("-xb: requires argument");
1217 case 'c': /* Debugging tool: show current cost centre on an exception */
1218 PROFILING_BUILD_ONLY(
1219 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1223 case 't': /* Include memory used by TSOs in a heap profile */
1224 PROFILING_BUILD_ONLY(
1225 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1229 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1232 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1236 break; /* defensive programming */
1238 /* =========== OH DEAR ============================ */
1240 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1247 if (RtsFlags.MiscFlags.tickInterval < 0) {
1248 RtsFlags.MiscFlags.tickInterval = 50;
1251 // If the master timer is disabled, turn off the other timers.
1252 if (RtsFlags.MiscFlags.tickInterval == 0) {
1253 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1254 RtsFlags.GcFlags.idleGCDelayTime = 0;
1255 RtsFlags.ProfFlags.profileInterval = 0;
1258 // Determine what tick interval we should use for the RTS timer
1259 // by taking the shortest of the various intervals that we need to
1261 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1262 RtsFlags.MiscFlags.tickInterval =
1263 stg_min(RtsFlags.ConcFlags.ctxtSwitchTime,
1264 RtsFlags.MiscFlags.tickInterval);
1267 if (RtsFlags.GcFlags.idleGCDelayTime > 0) {
1268 RtsFlags.MiscFlags.tickInterval =
1269 stg_min(RtsFlags.GcFlags.idleGCDelayTime,
1270 RtsFlags.MiscFlags.tickInterval);
1273 if (RtsFlags.ProfFlags.profileInterval > 0) {
1274 RtsFlags.MiscFlags.tickInterval =
1275 stg_min(RtsFlags.ProfFlags.profileInterval,
1276 RtsFlags.MiscFlags.tickInterval);
1279 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1280 RtsFlags.ConcFlags.ctxtSwitchTicks =
1281 RtsFlags.ConcFlags.ctxtSwitchTime /
1282 RtsFlags.MiscFlags.tickInterval;
1284 RtsFlags.ConcFlags.ctxtSwitchTicks = 0;
1287 if (RtsFlags.ProfFlags.profileInterval > 0) {
1288 RtsFlags.ProfFlags.profileIntervalTicks =
1289 RtsFlags.ProfFlags.profileInterval /
1290 RtsFlags.MiscFlags.tickInterval;
1292 RtsFlags.ProfFlags.profileIntervalTicks = 0;
1299 for (p = usage_text; *p; p++)
1300 errorBelch("%s", *p);
1301 stg_exit(EXIT_FAILURE);
1308 enable_GranSimLight(void) {
1310 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1311 RtsFlags.GranFlags.Light=rtsTrue;
1312 RtsFlags.GranFlags.Costs.latency =
1313 RtsFlags.GranFlags.Costs.fetchtime =
1314 RtsFlags.GranFlags.Costs.additional_latency =
1315 RtsFlags.GranFlags.Costs.gunblocktime =
1316 RtsFlags.GranFlags.Costs.lunblocktime =
1317 RtsFlags.GranFlags.Costs.threadcreatetime =
1318 RtsFlags.GranFlags.Costs.threadqueuetime =
1319 RtsFlags.GranFlags.Costs.threadscheduletime =
1320 RtsFlags.GranFlags.Costs.threaddescheduletime =
1321 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1323 RtsFlags.GranFlags.Costs.mpacktime =
1324 RtsFlags.GranFlags.Costs.munpacktime = 0;
1326 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1327 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1328 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1329 /* FetchStrategy is irrelevant in GrAnSim-Light */
1331 /* GrAnSim Light often creates an abundance of parallel threads,
1332 each with its own stack etc. Therefore, it's in general a good
1333 idea to use small stack chunks (use the -o<size> option to
1336 // RtsFlags.ConcFlags.stkChunkSize = 100;
1338 RtsFlags.GranFlags.proc = 1;
1342 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1344 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1347 /* or a ridiculously idealised simulator */
1348 if(strcmp((rts_argv[arg]+2),"oring")==0) {
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.Costs.arith_cost =
1364 RtsFlags.GranFlags.Costs.float_cost =
1365 RtsFlags.GranFlags.Costs.load_cost =
1366 RtsFlags.GranFlags.Costs.store_cost =
1367 RtsFlags.GranFlags.Costs.branch_cost = 0;
1369 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1371 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1372 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1373 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1374 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1378 /* or a somewhat idealised simulator */
1379 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1380 RtsFlags.GranFlags.Costs.latency =
1381 RtsFlags.GranFlags.Costs.fetchtime =
1382 RtsFlags.GranFlags.Costs.additional_latency =
1383 RtsFlags.GranFlags.Costs.gunblocktime =
1384 RtsFlags.GranFlags.Costs.lunblocktime =
1385 RtsFlags.GranFlags.Costs.threadcreatetime =
1386 RtsFlags.GranFlags.Costs.threadqueuetime =
1387 RtsFlags.GranFlags.Costs.threadscheduletime =
1388 RtsFlags.GranFlags.Costs.threaddescheduletime =
1389 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1391 RtsFlags.GranFlags.Costs.mpacktime =
1392 RtsFlags.GranFlags.Costs.munpacktime = 0;
1394 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1396 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1397 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1398 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1399 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1400 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1401 # if defined(GRAN_CHECK) && defined(GRAN)
1402 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1407 /* Communication and task creation cost parameters */
1408 switch(rts_argv[arg][2]) {
1410 IgnoreYields = rtsTrue; // HWL HACK
1414 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1418 if (rts_argv[arg][3] != '\0')
1420 RtsFlags.GranFlags.Costs.gunblocktime =
1421 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1422 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1425 RtsFlags.GranFlags.Costs.latency = LATENCY;
1429 if (rts_argv[arg][3] != '\0')
1430 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1432 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1436 if (rts_argv[arg][3] != '\0')
1437 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1439 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1443 if (rts_argv[arg][3] != '\0')
1444 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1446 RtsFlags.GranFlags.Costs.mtidytime = 0;
1450 if (rts_argv[arg][3] != '\0')
1451 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1453 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1457 if (rts_argv[arg][3] != '\0')
1458 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1460 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1464 if (rts_argv[arg][3] != '\0')
1465 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1467 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1471 if (rts_argv[arg][3] != '\0')
1472 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1474 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1477 /* Thread-related metrics */
1479 if (rts_argv[arg][3] != '\0')
1480 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1482 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1486 if (rts_argv[arg][3] != '\0')
1487 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1489 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1493 if (rts_argv[arg][3] != '\0')
1494 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1496 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1498 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1499 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1503 if (rts_argv[arg][3] != '\0')
1504 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1506 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1508 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1509 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1512 /* Instruction Cost Metrics */
1514 if (rts_argv[arg][3] != '\0')
1515 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1517 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1521 if (rts_argv[arg][3] != '\0')
1522 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1524 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1528 if (rts_argv[arg][3] != '\0')
1529 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1531 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1535 if (rts_argv[arg][3] != '\0')
1536 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1538 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1542 if (rts_argv[arg][3] != '\0')
1543 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1545 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1549 if (rts_argv[arg][3] != '\0')
1550 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1552 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1556 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1557 if (rts_argv[arg][3] != '\0')
1558 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1560 RtsFlags.GranFlags.FetchStrategy = 2;
1561 if (RtsFlags.GranFlags.FetchStrategy == 0)
1562 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1565 case 'K': /* sort overhead (per elem in spark list) */
1566 if (rts_argv[arg][3] != '\0')
1567 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1569 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1570 debugBelch("Overhead for pri spark: %d (per elem).\n",
1571 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1574 case 'O': /* sort overhead (per elem in spark list) */
1575 if (rts_argv[arg][3] != '\0')
1576 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1578 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1579 debugBelch("Overhead for pri sched: %d (per elem).\n",
1580 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1583 /* General Parameters */
1585 if (rts_argv[arg][3] != '\0')
1587 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1588 if (RtsFlags.GranFlags.proc==0) {
1589 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1590 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1591 RtsFlags.GranFlags.proc < 1)
1593 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1599 RtsFlags.GranFlags.proc = MAX_PROC;
1603 RtsFlags.GranFlags.Fishing = rtsTrue;
1604 if (rts_argv[arg][3] != '\0')
1605 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1607 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1611 if (rts_argv[arg][3] != '\0')
1612 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1614 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1618 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1619 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1623 debugBelch("Bulk fetching enabled.\n");
1624 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1628 debugBelch("Thread migration enabled.\n");
1629 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1633 debugBelch("Fair Scheduling enabled.\n");
1634 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1638 debugBelch("Priority Scheduling enabled.\n");
1639 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1643 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1644 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1648 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1652 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1656 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1660 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1664 /* format is -bP<c> where <c> is one char describing kind of profile */
1665 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1666 switch(rts_argv[arg][3]) {
1667 case '\0': break; // nothing special, just an ordinary profile
1668 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1670 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1672 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1674 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1676 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1678 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1680 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1685 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1689 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1692 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1693 if (rts_argv[arg][3] != '\0') {
1696 arg0 = rts_argv[arg]+3;
1697 if ((tmp = strstr(arg0,","))==NULL) {
1698 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1699 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1702 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1703 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1704 debugBelch("SparkPriority: %u.\n",
1705 RtsFlags.GranFlags.SparkPriority);
1706 debugBelch("SparkPriority2:%u.\n",
1707 RtsFlags.GranFlags.SparkPriority2);
1708 if (RtsFlags.GranFlags.SparkPriority2 <
1709 RtsFlags.GranFlags.SparkPriority) {
1710 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1711 RtsFlags.GranFlags.SparkPriority2,
1712 RtsFlags.GranFlags.SparkPriority);
1716 /* plain pri spark is now invoked with -bX
1717 RtsFlags.GranFlags.DoPrioritySparking = 1;
1718 debugBelch("PrioritySparking.\n");
1724 if (rts_argv[arg][3] != '\0') {
1725 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1727 RtsFlags.GranFlags.ThunksToPack = 1;
1729 debugBelch("Thunks To Pack in one packet: %u.\n",
1730 RtsFlags.GranFlags.ThunksToPack);
1734 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1735 debugBelch("Deterministic mode (no random stealing)\n");
1738 /* The following class of options contains eXperimental */
1739 /* features in connection with exploiting granularity */
1740 /* information. I.e. if -bY is chosen these options */
1741 /* tell the RTS what to do with the supplied info --HWL */
1744 if (rts_argv[arg][3] != '\0') {
1745 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1747 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1749 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1750 RtsFlags.GranFlags.packBufferSize_internal);
1754 switch(rts_argv[arg][3]) {
1757 RtsFlags.GranFlags.DoPrioritySparking = 1;
1758 debugBelch("Priority Sparking with Normal Priorities.\n");
1759 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1760 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1761 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1765 RtsFlags.GranFlags.DoPrioritySparking = 1;
1766 debugBelch("Priority Sparking with Inverse Priorities.\n");
1767 RtsFlags.GranFlags.InversePriorities++;
1771 RtsFlags.GranFlags.DoPrioritySparking = 1;
1772 debugBelch("Priority Sparking with Random Priorities.\n");
1773 RtsFlags.GranFlags.RandomPriorities++;
1777 RtsFlags.GranFlags.DoPrioritySparking = 1;
1778 debugBelch("Priority Sparking with No Priorities.\n");
1779 RtsFlags.GranFlags.IgnorePriorities++;
1783 bad_option( rts_argv[arg] );
1789 switch(rts_argv[arg][3]) {
1792 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1793 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1797 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1801 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1805 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1809 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1810 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1814 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1818 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1822 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1826 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1830 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1834 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1838 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1842 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1843 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1847 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1851 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1855 bad_option( rts_argv[arg] );
1860 # if defined(GRAN_CHECK) && defined(GRAN)
1862 switch(rts_argv[arg][3]) {
1863 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1864 if (rts_argv[arg][4] != '\0') {
1865 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1866 debugBelch("Pack buffer size: %d\n",
1867 RtsFlags.GranFlags.packBufferSize);
1869 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1875 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1876 /* hack warning: interpret the flags as a binary number */
1877 nat n = decode(rts_argv[arg]+3);
1878 set_GranSim_debug_options(n);
1881 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1882 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1885 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1886 debugBelch("Valid GranSim debug options are:\n");
1887 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1888 bad_option( rts_argv[arg] );
1889 } else { // flag found; now set it
1890 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1896 case 'e': /* event trace; also -bD1 */
1897 debugBelch("DEBUG: event_trace; printing event trace.\n");
1898 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1899 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1902 case 'E': /* event statistics; also -bD2 */
1903 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1904 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1905 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1908 case 'f': /* thunkStealing; also -bD4 */
1909 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1910 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1911 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1914 case 'z': /* blockOnFetch; also -bD8 */
1915 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1916 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1917 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1920 case 't': /* blockOnFetch_sanity; also -bD16 */
1921 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1922 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1923 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1926 case 'S': /* priSpark; also -bD32 */
1927 debugBelch("DEBUG: priSpark; priority sparking.\n");
1928 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1931 case 's': /* priSched; also -bD64 */
1932 debugBelch("DEBUG: priSched; priority scheduling.\n");
1933 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1936 case 'F': /* findWork; also -bD128 */
1937 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1938 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1941 case 'g': /* globalBlock; also -bD256 */
1942 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1943 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1946 case 'G': /* pack; also -bD512 */
1947 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1948 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1951 case 'P': /* packBuffer; also -bD1024 */
1952 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1953 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1956 case 'o': /* sortedQ; also -bD2048 */
1957 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1958 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1961 case 'r': /* randomSteal; also -bD4096 */
1962 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
1963 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
1966 case 'q': /* checkSparkQ; also -bD8192 */
1967 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
1968 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
1971 case ':': /* checkLight; also -bD16384 */
1972 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
1973 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
1976 case 'b': /* bq; also -bD32768 */
1977 debugBelch("DEBUG: bq; check blocking queues\n");
1978 RtsFlags.GranFlags.Debug.bq = rtsTrue;
1981 case 'd': /* all options turned on */
1982 debugBelch("DEBUG: all options turned on.\n");
1983 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1984 /* RtsFlags.GranFlags.Debug |= 0x40; */
1988 /* RtsFlags.GranFlags.Debug = 1; */
1994 # endif /* GRAN_CHECK */
1996 bad_option( rts_argv[arg] );
2002 Interpret n as a binary number masking GranSim debug options and set the
2003 correxponding option. See gran_debug_opts_strs for explanations of the flags.
2006 set_GranSim_debug_options(nat n) {
2009 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
2011 errorBelch(gran_debug_opts_strs[i]);
2013 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
2014 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
2015 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
2016 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
2017 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
2018 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
2019 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
2020 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
2021 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
2022 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
2023 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
2024 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
2025 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
2026 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
2027 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
2028 default: barf("set_GranSim_debug_options: only %d debug options expected");
2034 Print one line explanation for each of the GranSim debug options specified
2038 help_GranSim_debug_options(nat n) {
2041 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
2043 debugBelch(gran_debug_opts_strs[i]);
2049 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
2052 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
2053 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
2057 /* Communication and task creation cost parameters */
2058 switch(rts_argv[arg][2]) {
2059 case 'e': /* -qe<n> ... allow <n> local sparks */
2060 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
2061 RtsFlags.ParFlags.maxLocalSparks
2062 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2064 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
2065 errorBelch("setupRtsFlags: bad value for -e\n");
2069 IF_PAR_DEBUG(verbose,
2070 errorBelch("-qe<n>: max %d local sparks",
2071 RtsFlags.ParFlags.maxLocalSparks));
2075 if (rts_argv[arg][3] != '\0') {
2076 RtsFlags.ParFlags.maxThreads
2077 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2079 errorBelch("missing size for -qt\n");
2082 IF_PAR_DEBUG(verbose,
2083 errorBelch("-qt<n>: max %d threads",
2084 RtsFlags.ParFlags.maxThreads));
2088 if (rts_argv[arg][3] != '\0')
2089 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
2091 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
2093 IF_PAR_DEBUG(verbose,
2094 errorBelch("-qf<n>: max %d fishes sent out at one time",
2095 RtsFlags.ParFlags.maxFishes));
2099 if (rts_argv[arg][3] != '\0') {
2100 RtsFlags.ParFlags.fishDelay
2101 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2103 errorBelch("missing fish delay time for -qF\n");
2106 IF_PAR_DEBUG(verbose,
2107 errorBelch("-qF<n>: fish delay time %d us",
2108 RtsFlags.ParFlags.fishDelay));
2112 RtsFlags.ParFlags.outputDisabled = rtsTrue;
2113 IF_PAR_DEBUG(verbose,
2114 errorBelch("-qO: output disabled"));
2117 case 'g': /* -qg<n> ... globalisation scheme */
2118 if (rts_argv[arg][3] != '\0') {
2119 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
2121 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
2124 IF_PAR_DEBUG(verbose,
2125 debugBelch("-qg<n>: globalisation scheme set to %d",
2126 RtsFlags.ParFlags.globalising));
2129 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
2130 if (rts_argv[arg][3] != '\0') {
2131 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
2133 errorBelch("missing number of thunks per packet (for -qh)\n");
2136 IF_PAR_DEBUG(verbose,
2137 debugBelch("-qh<n>: thunks per packet set to %d",
2138 RtsFlags.ParFlags.thunksToPack));
2141 case 'P': /* -qP for writing a log file */
2142 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2143 /* same encoding as in GranSim after -bP */
2144 switch(rts_argv[arg][3]) {
2145 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2146 break; // nothing special, just an ordinary profile
2147 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2148 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2150 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2152 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2154 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2156 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2159 # if defined(PAR_TICKY)
2160 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2162 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2163 stg_exit(EXIT_FAILURE);
2166 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2168 IF_PAR_DEBUG(verbose,
2169 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2170 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2173 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2174 if (rts_argv[arg][3] != '\0') {
2175 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2177 errorBelch("missing size of PackBuffer (for -qQ)\n");
2180 IF_PAR_DEBUG(verbose,
2181 debugBelch("-qQ<n>: pack buffer size set to %d",
2182 RtsFlags.ParFlags.packBufferSize));
2186 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2187 IF_PAR_DEBUG(verbose,
2188 debugBelch("-qR: fair-ish scheduling"));
2193 if (rts_argv[arg][3] != '\0') {
2194 RtsFlags.ParFlags.wait
2195 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2197 RtsFlags.ParFlags.wait = 1000;
2199 IF_PAR_DEBUG(verbose,
2200 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2201 RtsFlags.ParFlags.wait));
2204 case 'D': /* -qD ... all the debugging options */
2205 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2206 /* hack warning: interpret the flags as a binary number */
2207 nat n = decode(rts_argv[arg]+3);
2208 set_par_debug_options(n);
2211 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2212 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2215 if (i==MAX_PAR_DEBUG_OPTION+1) {
2216 errorBelch("Valid GUM debug options are:\n");
2217 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2218 bad_option( rts_argv[arg] );
2219 } else { // flag found; now set it
2220 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2226 errorBelch("Unknown option -q%c (%d opts in total)",
2227 rts_argv[arg][2], *rts_argc);
2233 Interpret n as a binary number masking Par debug options and set the
2234 correxponding option. See par_debug_opts_strs for explanations of the flags.
2237 set_par_debug_options(nat n) {
2240 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2242 debugBelch(par_debug_opts_strs[i]);
2244 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2245 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2246 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2247 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2248 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2249 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2250 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2251 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2252 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2253 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2254 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2255 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2256 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2257 default: barf("set_par_debug_options: only %d debug options expected",
2258 MAX_PAR_DEBUG_OPTION);
2264 Print one line explanation for each of the GranSim debug options specified
2268 help_par_debug_options(nat n) {
2271 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2273 debugBelch(par_debug_opts_strs[i]);
2279 stats_fprintf(FILE *f, char *s, ...)
2291 static int /* return -1 on error */
2294 int argc, char *argv[],
2295 int rts_argc, char *rts_argv[],
2296 const char *FILENAME_FMT,
2301 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2302 f = NULL; /* NULL means use debugBelch */
2304 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2305 f = fopen(rts_argv[arg]+2,"w");
2307 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2308 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2309 f = fopen(stats_filename,"w");
2312 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2319 /* Write argv and rtsv into start of stats file */
2321 for(count = 0; count < argc; count++) {
2322 stats_fprintf(f, "%s ", argv[count]);
2324 stats_fprintf(f, "+RTS ");
2325 for(count = 0; count < rts_argc; count++)
2326 stats_fprintf(f, "%s ", rts_argv[count]);
2327 stats_fprintf(f, "\n");
2335 decode(const char *s)
2346 if (c == 'g' || c == 'G')
2347 m *= 1000*1000*1000; /* UNchecked! */
2348 else if (c == 'm' || c == 'M')
2349 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2350 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2351 m *= 1000; /* a direct-mapped cache. */
2352 else if (c == 'w' || c == 'W')
2359 bad_option(const char *s)
2361 errorBelch("bad RTS option: %s", s);
2362 stg_exit(EXIT_FAILURE);
2365 /* -----------------------------------------------------------------------------
2366 Getting/Setting the program's arguments.
2368 These are used by System.Environment, and parts of the RTS.
2369 -------------------------------------------------------------------------- */
2372 setProgName(char *argv[])
2374 /* Remove directory from argv[0] -- default files in current directory */
2375 #if !defined(mingw32_HOST_OS)
2377 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2378 prog_name = last_slash+1;
2380 prog_name = argv[0];
2383 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2384 while ( last_slash > argv[0] ) {
2385 if ( *last_slash == '/' || *last_slash == '\\' ) {
2386 prog_name = last_slash+1;
2391 prog_name = argv[0];
2396 getProgArgv(int *argc, char **argv[])
2398 if (argc) { *argc = prog_argc; }
2399 if (argv) { *argv = prog_argv; }
2403 setProgArgv(int argc, char *argv[])
2405 /* Usually this is done by startupHaskell, so we don't need to call this.
2406 However, sometimes Hugs wants to change the arguments which Haskell
2407 getArgs >>= ... will be fed. So you can do that by calling here
2408 _after_ calling startupHaskell.
2412 setProgName(prog_argv);