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 RtsFlags.DebugFlags.scheduler = rtsFalse;
155 RtsFlags.DebugFlags.interpreter = rtsFalse;
156 RtsFlags.DebugFlags.weak = rtsFalse;
157 RtsFlags.DebugFlags.gccafs = rtsFalse;
158 RtsFlags.DebugFlags.gc = rtsFalse;
159 RtsFlags.DebugFlags.block_alloc = rtsFalse;
160 RtsFlags.DebugFlags.sanity = rtsFalse;
161 RtsFlags.DebugFlags.stable = rtsFalse;
162 RtsFlags.DebugFlags.stm = rtsFalse;
163 RtsFlags.DebugFlags.prof = rtsFalse;
164 RtsFlags.DebugFlags.gran = rtsFalse;
165 RtsFlags.DebugFlags.par = rtsFalse;
166 RtsFlags.DebugFlags.linker = rtsFalse;
167 RtsFlags.DebugFlags.squeeze = rtsFalse;
168 RtsFlags.DebugFlags.hpc = rtsFalse;
171 #if defined(PROFILING) || defined(PAR)
172 RtsFlags.CcFlags.doCostCentres = 0;
173 #endif /* PROFILING or PAR */
175 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
176 RtsFlags.ProfFlags.profileInterval = 100;
179 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
180 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
181 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
182 RtsFlags.ProfFlags.ccsLength = 25;
183 RtsFlags.ProfFlags.modSelector = NULL;
184 RtsFlags.ProfFlags.descrSelector = NULL;
185 RtsFlags.ProfFlags.typeSelector = NULL;
186 RtsFlags.ProfFlags.ccSelector = NULL;
187 RtsFlags.ProfFlags.ccsSelector = NULL;
188 RtsFlags.ProfFlags.retainerSelector = NULL;
189 RtsFlags.ProfFlags.bioSelector = NULL;
192 RtsFlags.MiscFlags.tickInterval = 50; /* In milliseconds */
193 RtsFlags.ConcFlags.ctxtSwitchTime = 50; /* In milliseconds */
195 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
198 RtsFlags.ParFlags.nNodes = 1;
199 RtsFlags.ParFlags.migrate = rtsTrue;
200 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
204 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
205 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
206 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
207 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
208 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
209 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
210 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
212 RtsFlags.ParFlags.outputDisabled = rtsFalse;
214 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
216 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
218 RtsFlags.ParFlags.packBufferSize = 1024;
219 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
220 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
221 RtsFlags.ParFlags.maxThreads = 1024;
222 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
223 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
226 #if defined(PAR) || defined(THREADED_RTS)
227 RtsFlags.ParFlags.maxLocalSparks = 4096;
228 #endif /* PAR || THREADED_RTS */
231 /* ToDo: check defaults for GranSim and GUM */
232 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
233 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
235 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
236 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
237 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
238 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
239 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
240 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
241 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
242 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
244 RtsFlags.GranFlags.packBufferSize = 1024;
245 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
247 RtsFlags.GranFlags.proc = MAX_PROC;
248 RtsFlags.GranFlags.Fishing = rtsFalse;
249 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
250 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
251 RtsFlags.GranFlags.Light = rtsFalse;
253 RtsFlags.GranFlags.Costs.latency = LATENCY;
254 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
255 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
256 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
257 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
258 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
259 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
260 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
262 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
263 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
264 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
265 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
266 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
268 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
269 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
270 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
271 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
272 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
274 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
276 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
277 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
279 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
280 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
281 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
282 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
283 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
284 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
285 RtsFlags.GranFlags.FetchStrategy = 2;
286 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
287 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
288 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
289 RtsFlags.GranFlags.SparkPriority = 0;
290 RtsFlags.GranFlags.SparkPriority2 = 0;
291 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
292 RtsFlags.GranFlags.InversePriorities = rtsFalse;
293 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
294 RtsFlags.GranFlags.ThunksToPack = 0;
295 RtsFlags.GranFlags.RandomSteal = rtsTrue;
299 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
300 RtsFlags.TickyFlags.tickyFile = NULL;
303 RtsFlags.TraceFlags.timestamp = rtsFalse;
304 RtsFlags.TraceFlags.sched = rtsFalse;
307 /* By default no special measurements taken */
308 RtsFlags.PapiFlags.eventType = 0;
315 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
317 " +RTS Indicates run time system options follow",
318 " -RTS Indicates program arguments follow",
319 " --RTS Indicates that ALL subsequent arguments will be given to the",
320 " program (including any of these RTS flags)",
322 "The following run time system options are available:",
324 " -? Prints this message and exits; the program is not executed",
326 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
327 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
329 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
330 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
331 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
332 " -m<n> Minimum % of heap which must be available (default 3%)",
333 " -G<n> Number of generations (default: 2)",
334 " -T<n> Number of steps in younger generations (default: 2)",
335 " -c<n> Auto-enable compaction of the oldest generation when live data is",
336 " at least <n>% of the maximum heap size set with -M (default: 30%)",
337 " -c Enable compaction for all major collections",
338 #if defined(THREADED_RTS)
339 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
342 " -t<file> One-line GC statistics (default file: <program>.stat)",
343 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
344 " -S<file> Detailed GC statistics",
345 #ifdef RTS_GTK_FRONTPANEL
346 " -f Display front panel (requires X11 & GTK+)",
350 " -Z Don't squeeze out update frames on stack overflow",
351 " -B Sound the bell at the start of each garbage collection",
352 #if defined(PROFILING) || defined(PAR)
354 " -px Time/allocation profile (XML) (output file <program>.prof)",
355 " -p Time/allocation profile (output file <program>.prof)",
356 " -P More detailed Time/Allocation profile",
357 " -Pa Give information about *all* cost centres",
359 # if defined(PROFILING)
361 " -hx Heap residency profile (XML) (output file <program>.prof)",
362 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
363 " break-down: c = cost centre stack (default)",
365 " d = closure description",
366 " y = type description",
368 " b = biography (LAG,DRAG,VOID,USE)",
369 " A subset of closures may be selected thusly:",
370 " -hc<cc>,... specific cost centre(s) (top of stack only)",
371 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
372 " -hm<mod>... all cost centres from the specified modules(s)",
373 " -hd<des>,... closures with specified closure descriptions",
374 " -hy<typ>... closures with specified type descriptions",
375 " -hr<cc>... closures with specified retainers",
376 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
378 " -R<size> Set the maximum retainer set size (default: 8)",
380 " -L<chars> Maximum length of a cost-centre stack in a heap profile",
383 " -xt Include threads (TSOs) in a heap profile",
385 " -xc Show current cost centre stack on raising an exception",
388 #endif /* PROFILING or PAR */
389 #if !defined(PROFILING)
391 " -hT Heap residency profile (output file <program>.hp)",
393 " -i<sec> Time between heap samples (seconds, default: 0.1)",
395 #if defined(TICKY_TICKY)
396 " -r<file> Produce ticky-ticky statistics (with -rstderr for stderr)",
400 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
401 /* NB: the -N<n> is implemented by the driver!! */
403 " -C<secs> Context-switch interval in seconds.",
404 " 0 or no argument means switch as often as possible.",
405 " Default: 0.02 sec; resolution is set by -V below.",
406 " -V<secs> Master tick interval in seconds.",
407 " This sets the resolution for -C and the profile timer -i.",
408 " Default: 0.02 sec.",
410 " -vs Trace scheduler events (see also -Ds with -debug)",
411 " -vt Time-stamp trace messages",
414 " -Ds DEBUG: scheduler",
415 " -Di DEBUG: interpreter",
417 " -DG DEBUG: gccafs",
420 " -DS DEBUG: sanity",
421 " -Dt DEBUG: stable",
425 " -Dl DEBUG: linker",
427 " -Dz DEBUG: stack squezing",
428 " -Dc DEBUG: program coverage",
431 #if defined(THREADED_RTS) && !defined(NOSMP)
432 " -N<n> Use <n> OS threads (default: 1)",
433 " -qm Don't automatically migrate threads between CPUs",
434 " -qw Migrate a thread to the current CPU when it is woken up",
436 " --install-signal-handlers=<yes|no>",
437 " Install signal handlers (default: yes)",
438 #if defined(THREADED_RTS) || defined(PAR)
439 " -e<size> Size of spark pools (default 100)",
442 " -t<num> Set maximum number of advisory threads per PE (default 32)",
443 " -qP Enable activity profile (output files in ~/<program>*.gr)",
444 " -qQ<size> Set pack-buffer size (default: 1024)",
445 " -qd Turn on PVM-ish debugging",
446 " -qO Disable output for performance measurement",
448 #if defined(THREADED_RTS) || defined(PAR)
449 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
452 " -d Turn on PVM-ish debugging",
453 " -O Disable output for performance measurement",
455 #if defined(GRAN) /* ToDo: fill in decent Docu here */
456 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
458 #if defined(USE_PAPI)
459 " -aX CPU performance counter measurements using PAPI",
460 " (use with the -s<file> option). X is one of:",
463 " 1 - level 1 cache misses",
464 " 2 - level 2 cache misses",
465 " b - branch mispredictions",
466 " s - stalled cycles",
467 " e - cache miss and branch misprediction events",
470 "RTS options may also be specified using the GHCRTS environment variable.",
472 "Other RTS options may be available for programs compiled a different way.",
473 "The GHC User's Guide has full details.",
478 STATIC_INLINE rtsBool
479 strequal(const char *a, const char * b)
481 return(strcmp(a, b) == 0);
485 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
491 while (isspace(*c1)) { c1++; };
493 while (!isspace(*c2) && *c2 != '\0') { c2++; };
495 if (c1 == c2) { break; }
497 if (*rts_argc < MAX_RTS_ARGS-1) {
498 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
499 strncpy(s, c1, c2-c1);
501 rts_argv[(*rts_argc)++] = s;
503 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
507 } while (*c1 != '\0');
511 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
513 rtsBool error = rtsFalse;
524 // process arguments from the ghc_rts_opts global variable first.
525 // (arguments from the GHCRTS environment variable and the command
526 // line override these).
528 if (ghc_rts_opts != NULL) {
529 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
533 // process arguments from the GHCRTS environment variable next
534 // (arguments from the command line override these).
536 char *ghc_rts = getenv("GHCRTS");
538 if (ghc_rts != NULL) {
539 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
543 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
544 // argv[0] must be PGM argument -- leave in argv
546 for (mode = PGM; arg < total_arg; arg++) {
547 // The '--RTS' argument disables all future +RTS ... -RTS processing.
548 if (strequal("--RTS", argv[arg])) {
552 // The '--' argument is passed through to the program, but
553 // disables all further +RTS ... -RTS processing.
554 else if (strequal("--", argv[arg])) {
557 else if (strequal("+RTS", argv[arg])) {
560 else if (strequal("-RTS", argv[arg])) {
563 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
564 rts_argv[(*rts_argc)++] = argv[arg];
566 else if (mode == PGM) {
567 argv[(*argc)++] = argv[arg];
570 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
573 // process remaining program arguments
574 for (; arg < total_arg; arg++) {
575 argv[(*argc)++] = argv[arg];
577 argv[*argc] = (char *) 0;
578 rts_argv[*rts_argc] = (char *) 0;
580 // Process RTS (rts_argv) part: mainly to determine statsfile
581 for (arg = 0; arg < *rts_argc; arg++) {
582 if (rts_argv[arg][0] != '-') {
584 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
588 switch(rts_argv[arg][1]) {
590 /* process: general args, then PROFILING-only ones,
591 then CONCURRENT-only, PARallel-only, GRAN-only,
592 TICKY-only (same order as defined in RtsFlags.lh);
593 within those groups, mostly in case-insensitive
595 Final group is x*, which allows for more options.
599 # define TICKY_BUILD_ONLY(x) x
601 # define TICKY_BUILD_ONLY(x) \
602 errorBelch("not built for: ticky-ticky stats"); \
606 #if defined(PROFILING)
607 # define COST_CENTRE_USING_BUILD_ONLY(x) x
609 # define COST_CENTRE_USING_BUILD_ONLY(x) \
610 errorBelch("not built for: -prof or -parallel"); \
615 # define PROFILING_BUILD_ONLY(x) x
617 # define PROFILING_BUILD_ONLY(x) \
618 errorBelch("not built for: -prof"); \
623 # define PAR_BUILD_ONLY(x) x
625 # define PAR_BUILD_ONLY(x) \
626 errorBelch("not built for: -parallel"); \
631 # define THREADED_BUILD_ONLY(x) x
633 # define THREADED_BUILD_ONLY(x) \
634 errorBelch("not built for: -smp"); \
638 #if defined(THREADED_RTS) || defined(PAR)
639 # define PAR_OR_THREADED_BUILD_ONLY(x) x
641 # define PAR_OR_THREADED_BUILD_ONLY(x) \
642 errorBelch("not built for: -parallel or -smp"); \
647 # define GRAN_BUILD_ONLY(x) x
649 # define GRAN_BUILD_ONLY(x) \
650 errorBelch("not built for: -gransim"); \
654 /* =========== GENERAL ========================== */
659 /* This isn't going to allow us to keep related options
660 together as we add more --* flags. We really need a
661 proper options parser. */
663 if (strequal("install-signal-handlers=yes",
664 &rts_argv[arg][2])) {
665 RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
667 else if (strequal("install-signal-handlers=no",
668 &rts_argv[arg][2])) {
669 RtsFlags.MiscFlags.install_signal_handlers = rtsFalse;
672 errorBelch("unknown RTS option: %s",rts_argv[arg]);
677 RtsFlags.GcFlags.minAllocAreaSize
678 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
679 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
680 bad_option(rts_argv[arg]);
686 switch(rts_argv[arg][2]) {
688 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L1;
691 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L2;
694 RtsFlags.PapiFlags.eventType = PAPI_FLAG_BRANCH;
697 RtsFlags.PapiFlags.eventType = PAPI_FLAG_STALLS;
700 RtsFlags.PapiFlags.eventType = PAPI_FLAG_CB_EVENTS;
703 bad_option( rts_argv[arg] );
709 RtsFlags.GcFlags.ringBell = rtsTrue;
713 if (rts_argv[arg][2] != '\0') {
714 RtsFlags.GcFlags.compactThreshold =
715 atof(rts_argv[arg]+2);
717 RtsFlags.GcFlags.compact = rtsTrue;
722 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
724 if (RtsFlags.GcFlags.oldGenFactor < 0)
725 bad_option( rts_argv[arg] );
733 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
736 RtsFlags.DebugFlags.scheduler = rtsTrue;
739 RtsFlags.DebugFlags.interpreter = rtsTrue;
742 RtsFlags.DebugFlags.weak = rtsTrue;
745 RtsFlags.DebugFlags.gccafs = rtsTrue;
748 RtsFlags.DebugFlags.gc = rtsTrue;
751 RtsFlags.DebugFlags.block_alloc = rtsTrue;
754 RtsFlags.DebugFlags.sanity = rtsTrue;
757 RtsFlags.DebugFlags.stable = rtsTrue;
760 RtsFlags.DebugFlags.prof = rtsTrue;
763 RtsFlags.DebugFlags.gran = rtsTrue;
766 RtsFlags.DebugFlags.par = rtsTrue;
769 RtsFlags.DebugFlags.linker = rtsTrue;
772 RtsFlags.DebugFlags.apply = rtsTrue;
775 RtsFlags.DebugFlags.stm = rtsTrue;
778 RtsFlags.DebugFlags.squeeze = rtsTrue;
781 RtsFlags.DebugFlags.hpc = rtsTrue;
784 bad_option( rts_argv[arg] );
792 RtsFlags.GcFlags.maxStkSize =
793 decode(rts_argv[arg]+2) / sizeof(W_);
795 if (RtsFlags.GcFlags.maxStkSize == 0)
796 bad_option( rts_argv[arg] );
800 RtsFlags.GcFlags.initialStkSize =
801 decode(rts_argv[arg]+2) / sizeof(W_);
803 if (RtsFlags.GcFlags.initialStkSize == 0)
804 bad_option( rts_argv[arg] );
808 RtsFlags.GcFlags.maxHeapSize =
809 decode(rts_argv[arg]+2) / BLOCK_SIZE;
810 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
812 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
813 bad_option(rts_argv[arg]);
818 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
820 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
821 RtsFlags.GcFlags.pcFreeHeap > 100)
822 bad_option( rts_argv[arg] );
826 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
827 if (RtsFlags.GcFlags.generations < 1) {
828 bad_option(rts_argv[arg]);
833 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
834 if (RtsFlags.GcFlags.steps < 1) {
835 bad_option(rts_argv[arg]);
840 RtsFlags.GcFlags.heapSizeSuggestion =
841 decode(rts_argv[arg]+2) / BLOCK_SIZE;
843 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
844 bad_option(rts_argv[arg]);
848 #ifdef RTS_GTK_FRONTPANEL
850 RtsFlags.GcFlags.frontpanel = rtsTrue;
854 case 'I': /* idle GC delay */
855 if (rts_argv[arg][2] == '\0') {
860 /* Convert to millisecs */
861 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
862 RtsFlags.GcFlags.idleGCDelayTime = cst;
867 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
871 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
875 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
880 /* Opening all those files would almost certainly fail... */
881 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
882 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
886 r = open_stats_file(arg, *argc, argv,
887 *rts_argc, rts_argv, STAT_FILENAME_FMT,
888 &RtsFlags.GcFlags.statsFile);
889 if (r == -1) { error = rtsTrue; }
895 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
898 /* =========== PROFILING ========================== */
900 case 'P': /* detailed cost centre profiling (time/alloc) */
901 case 'p': /* cost centre profiling (time/alloc) */
902 COST_CENTRE_USING_BUILD_ONLY(
903 switch (rts_argv[arg][2]) {
905 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
908 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
911 if (rts_argv[arg][1] == 'P') {
912 RtsFlags.CcFlags.doCostCentres =
913 COST_CENTRES_VERBOSE;
915 RtsFlags.CcFlags.doCostCentres =
916 COST_CENTRES_SUMMARY;
923 PROFILING_BUILD_ONLY(
924 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
927 PROFILING_BUILD_ONLY(
928 RtsFlags.ProfFlags.ccsLength = atof(rts_argv[arg]+2);
929 if(RtsFlags.ProfFlags.ccsLength <= 0) {
930 bad_option(rts_argv[arg]);
933 case 'h': /* serial heap profile */
934 #if !defined(PROFILING)
935 switch (rts_argv[arg][2]) {
938 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
941 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
945 PROFILING_BUILD_ONLY(
946 switch (rts_argv[arg][2]) {
960 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
962 char *left = strchr(rts_argv[arg], '{');
963 char *right = strrchr(rts_argv[arg], '}');
965 // curly braces are optional, for
970 left = rts_argv[arg] + 3;
973 right = rts_argv[arg] + strlen(rts_argv[arg]);
977 switch (rts_argv[arg][2]) {
978 case 'c': // cost centre label select
979 RtsFlags.ProfFlags.ccSelector = left;
982 RtsFlags.ProfFlags.ccsSelector = left;
985 case 'm': // cost centre module select
986 RtsFlags.ProfFlags.modSelector = left;
989 case 'd': // closure descr select
990 RtsFlags.ProfFlags.descrSelector = left;
993 case 'y': // closure type select
994 RtsFlags.ProfFlags.typeSelector = left;
997 case 'r': // retainer select
998 RtsFlags.ProfFlags.retainerSelector = left;
1001 case 'b': // biography select
1002 RtsFlags.ProfFlags.bioSelector = left;
1009 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
1010 errorBelch("multiple heap profile options");
1015 switch (rts_argv[arg][2]) {
1019 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
1023 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
1027 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
1031 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
1035 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
1039 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
1045 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
1049 #endif /* PROFILING */
1052 case 'i': /* heap sample interval */
1053 if (rts_argv[arg][2] == '\0') {
1058 /* Convert to milliseconds */
1059 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1060 RtsFlags.ProfFlags.profileInterval = cst;
1064 /* =========== CONCURRENT ========================= */
1065 case 'C': /* context switch interval */
1066 if (rts_argv[arg][2] == '\0')
1067 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1071 /* Convert to milliseconds */
1072 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1073 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1077 case 'V': /* master tick interval */
1078 if (rts_argv[arg][2] == '\0') {
1079 // turns off ticks completely
1080 RtsFlags.MiscFlags.tickInterval = 0;
1084 /* Convert to milliseconds */
1085 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1086 RtsFlags.MiscFlags.tickInterval = cst;
1090 #if defined(THREADED_RTS) && !defined(NOSMP)
1092 THREADED_BUILD_ONLY(
1093 if (rts_argv[arg][2] != '\0') {
1094 RtsFlags.ParFlags.nNodes
1095 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1096 if (RtsFlags.ParFlags.nNodes <= 0) {
1097 errorBelch("bad value for -N");
1104 switch (rts_argv[arg][2]) {
1106 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1110 RtsFlags.ParFlags.migrate = rtsFalse;
1113 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1116 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1122 /* =========== PARALLEL =========================== */
1124 PAR_OR_THREADED_BUILD_ONLY(
1125 if (rts_argv[arg][2] != '\0') {
1126 RtsFlags.ParFlags.maxLocalSparks
1127 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1128 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1129 errorBelch("bad value for -e");
1138 process_par_option(arg, rts_argc, rts_argv, &error);
1142 /* =========== GRAN =============================== */
1146 process_gran_option(arg, rts_argc, rts_argv, &error);
1149 /* =========== TICKY ============================== */
1151 case 'r': /* Basic profiling stats */
1154 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1158 r = open_stats_file(arg, *argc, argv,
1159 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1160 &RtsFlags.TickyFlags.tickyFile);
1161 if (r == -1) { error = rtsTrue; }
1165 /* =========== TRACING ---------=================== */
1168 switch(rts_argv[arg][2]) {
1170 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1174 RtsFlags.TraceFlags.timestamp = rtsTrue;
1177 RtsFlags.TraceFlags.sched = rtsTrue;
1180 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1186 /* =========== EXTENDED OPTIONS =================== */
1188 case 'x': /* Extend the argument space */
1189 switch(rts_argv[arg][2]) {
1191 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1195 case 'c': /* Debugging tool: show current cost centre on an exception */
1196 PROFILING_BUILD_ONLY(
1197 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1201 case 't': /* Include memory used by TSOs in a heap profile */
1202 PROFILING_BUILD_ONLY(
1203 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1207 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1210 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1214 break; /* defensive programming */
1216 /* =========== OH DEAR ============================ */
1218 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1225 // Determine what tick interval we should use for the RTS timer
1226 // by taking the shortest of the various intervals that we need to
1228 if (RtsFlags.MiscFlags.tickInterval <= 0) {
1229 RtsFlags.MiscFlags.tickInterval = 50;
1232 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1233 RtsFlags.MiscFlags.tickInterval =
1234 stg_min(RtsFlags.ConcFlags.ctxtSwitchTime,
1235 RtsFlags.MiscFlags.tickInterval);
1238 if (RtsFlags.GcFlags.idleGCDelayTime > 0) {
1239 RtsFlags.MiscFlags.tickInterval =
1240 stg_min(RtsFlags.GcFlags.idleGCDelayTime,
1241 RtsFlags.MiscFlags.tickInterval);
1244 if (RtsFlags.ProfFlags.profileInterval > 0) {
1245 RtsFlags.MiscFlags.tickInterval =
1246 stg_min(RtsFlags.ProfFlags.profileInterval,
1247 RtsFlags.MiscFlags.tickInterval);
1250 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1251 RtsFlags.ConcFlags.ctxtSwitchTicks =
1252 RtsFlags.ConcFlags.ctxtSwitchTime /
1253 RtsFlags.MiscFlags.tickInterval;
1255 RtsFlags.ConcFlags.ctxtSwitchTicks = 0;
1258 RtsFlags.ProfFlags.profileIntervalTicks =
1259 RtsFlags.ProfFlags.profileInterval / RtsFlags.MiscFlags.tickInterval;
1265 for (p = usage_text; *p; p++)
1266 errorBelch("%s", *p);
1267 stg_exit(EXIT_FAILURE);
1274 enable_GranSimLight(void) {
1276 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1277 RtsFlags.GranFlags.Light=rtsTrue;
1278 RtsFlags.GranFlags.Costs.latency =
1279 RtsFlags.GranFlags.Costs.fetchtime =
1280 RtsFlags.GranFlags.Costs.additional_latency =
1281 RtsFlags.GranFlags.Costs.gunblocktime =
1282 RtsFlags.GranFlags.Costs.lunblocktime =
1283 RtsFlags.GranFlags.Costs.threadcreatetime =
1284 RtsFlags.GranFlags.Costs.threadqueuetime =
1285 RtsFlags.GranFlags.Costs.threadscheduletime =
1286 RtsFlags.GranFlags.Costs.threaddescheduletime =
1287 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1289 RtsFlags.GranFlags.Costs.mpacktime =
1290 RtsFlags.GranFlags.Costs.munpacktime = 0;
1292 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1293 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1294 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1295 /* FetchStrategy is irrelevant in GrAnSim-Light */
1297 /* GrAnSim Light often creates an abundance of parallel threads,
1298 each with its own stack etc. Therefore, it's in general a good
1299 idea to use small stack chunks (use the -o<size> option to
1302 // RtsFlags.ConcFlags.stkChunkSize = 100;
1304 RtsFlags.GranFlags.proc = 1;
1308 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1310 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1313 /* or a ridiculously idealised simulator */
1314 if(strcmp((rts_argv[arg]+2),"oring")==0) {
1315 RtsFlags.GranFlags.Costs.latency =
1316 RtsFlags.GranFlags.Costs.fetchtime =
1317 RtsFlags.GranFlags.Costs.additional_latency =
1318 RtsFlags.GranFlags.Costs.gunblocktime =
1319 RtsFlags.GranFlags.Costs.lunblocktime =
1320 RtsFlags.GranFlags.Costs.threadcreatetime =
1321 RtsFlags.GranFlags.Costs.threadqueuetime =
1322 RtsFlags.GranFlags.Costs.threadscheduletime =
1323 RtsFlags.GranFlags.Costs.threaddescheduletime =
1324 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1326 RtsFlags.GranFlags.Costs.mpacktime =
1327 RtsFlags.GranFlags.Costs.munpacktime = 0;
1329 RtsFlags.GranFlags.Costs.arith_cost =
1330 RtsFlags.GranFlags.Costs.float_cost =
1331 RtsFlags.GranFlags.Costs.load_cost =
1332 RtsFlags.GranFlags.Costs.store_cost =
1333 RtsFlags.GranFlags.Costs.branch_cost = 0;
1335 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1337 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1338 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1339 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1340 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1344 /* or a somewhat idealised simulator */
1345 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1346 RtsFlags.GranFlags.Costs.latency =
1347 RtsFlags.GranFlags.Costs.fetchtime =
1348 RtsFlags.GranFlags.Costs.additional_latency =
1349 RtsFlags.GranFlags.Costs.gunblocktime =
1350 RtsFlags.GranFlags.Costs.lunblocktime =
1351 RtsFlags.GranFlags.Costs.threadcreatetime =
1352 RtsFlags.GranFlags.Costs.threadqueuetime =
1353 RtsFlags.GranFlags.Costs.threadscheduletime =
1354 RtsFlags.GranFlags.Costs.threaddescheduletime =
1355 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1357 RtsFlags.GranFlags.Costs.mpacktime =
1358 RtsFlags.GranFlags.Costs.munpacktime = 0;
1360 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1362 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1363 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1364 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1365 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1366 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1367 # if defined(GRAN_CHECK) && defined(GRAN)
1368 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1373 /* Communication and task creation cost parameters */
1374 switch(rts_argv[arg][2]) {
1376 IgnoreYields = rtsTrue; // HWL HACK
1380 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1384 if (rts_argv[arg][3] != '\0')
1386 RtsFlags.GranFlags.Costs.gunblocktime =
1387 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1388 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1391 RtsFlags.GranFlags.Costs.latency = LATENCY;
1395 if (rts_argv[arg][3] != '\0')
1396 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1398 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1402 if (rts_argv[arg][3] != '\0')
1403 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1405 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1409 if (rts_argv[arg][3] != '\0')
1410 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1412 RtsFlags.GranFlags.Costs.mtidytime = 0;
1416 if (rts_argv[arg][3] != '\0')
1417 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1419 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1423 if (rts_argv[arg][3] != '\0')
1424 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1426 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1430 if (rts_argv[arg][3] != '\0')
1431 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1433 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1437 if (rts_argv[arg][3] != '\0')
1438 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1440 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1443 /* Thread-related metrics */
1445 if (rts_argv[arg][3] != '\0')
1446 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1448 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1452 if (rts_argv[arg][3] != '\0')
1453 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1455 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1459 if (rts_argv[arg][3] != '\0')
1460 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1462 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1464 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1465 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1469 if (rts_argv[arg][3] != '\0')
1470 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1472 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1474 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1475 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1478 /* Instruction Cost Metrics */
1480 if (rts_argv[arg][3] != '\0')
1481 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1483 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1487 if (rts_argv[arg][3] != '\0')
1488 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1490 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1494 if (rts_argv[arg][3] != '\0')
1495 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1497 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1501 if (rts_argv[arg][3] != '\0')
1502 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1504 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1508 if (rts_argv[arg][3] != '\0')
1509 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1511 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1515 if (rts_argv[arg][3] != '\0')
1516 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1518 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1522 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1523 if (rts_argv[arg][3] != '\0')
1524 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1526 RtsFlags.GranFlags.FetchStrategy = 2;
1527 if (RtsFlags.GranFlags.FetchStrategy == 0)
1528 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1531 case 'K': /* sort overhead (per elem in spark list) */
1532 if (rts_argv[arg][3] != '\0')
1533 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1535 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1536 debugBelch("Overhead for pri spark: %d (per elem).\n",
1537 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1540 case 'O': /* sort overhead (per elem in spark list) */
1541 if (rts_argv[arg][3] != '\0')
1542 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1544 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1545 debugBelch("Overhead for pri sched: %d (per elem).\n",
1546 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1549 /* General Parameters */
1551 if (rts_argv[arg][3] != '\0')
1553 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1554 if (RtsFlags.GranFlags.proc==0) {
1555 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1556 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1557 RtsFlags.GranFlags.proc < 1)
1559 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1565 RtsFlags.GranFlags.proc = MAX_PROC;
1569 RtsFlags.GranFlags.Fishing = rtsTrue;
1570 if (rts_argv[arg][3] != '\0')
1571 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1573 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1577 if (rts_argv[arg][3] != '\0')
1578 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1580 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1584 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1585 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1589 debugBelch("Bulk fetching enabled.\n");
1590 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1594 debugBelch("Thread migration enabled.\n");
1595 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1599 debugBelch("Fair Scheduling enabled.\n");
1600 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1604 debugBelch("Priority Scheduling enabled.\n");
1605 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1609 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1610 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1614 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1618 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1622 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1626 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1630 /* format is -bP<c> where <c> is one char describing kind of profile */
1631 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1632 switch(rts_argv[arg][3]) {
1633 case '\0': break; // nothing special, just an ordinary profile
1634 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1636 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1638 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1640 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1642 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1644 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1646 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1651 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1655 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1658 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1659 if (rts_argv[arg][3] != '\0') {
1662 arg0 = rts_argv[arg]+3;
1663 if ((tmp = strstr(arg0,","))==NULL) {
1664 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1665 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1668 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1669 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1670 debugBelch("SparkPriority: %u.\n",
1671 RtsFlags.GranFlags.SparkPriority);
1672 debugBelch("SparkPriority2:%u.\n",
1673 RtsFlags.GranFlags.SparkPriority2);
1674 if (RtsFlags.GranFlags.SparkPriority2 <
1675 RtsFlags.GranFlags.SparkPriority) {
1676 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1677 RtsFlags.GranFlags.SparkPriority2,
1678 RtsFlags.GranFlags.SparkPriority);
1682 /* plain pri spark is now invoked with -bX
1683 RtsFlags.GranFlags.DoPrioritySparking = 1;
1684 debugBelch("PrioritySparking.\n");
1690 if (rts_argv[arg][3] != '\0') {
1691 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1693 RtsFlags.GranFlags.ThunksToPack = 1;
1695 debugBelch("Thunks To Pack in one packet: %u.\n",
1696 RtsFlags.GranFlags.ThunksToPack);
1700 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1701 debugBelch("Deterministic mode (no random stealing)\n");
1704 /* The following class of options contains eXperimental */
1705 /* features in connection with exploiting granularity */
1706 /* information. I.e. if -bY is chosen these options */
1707 /* tell the RTS what to do with the supplied info --HWL */
1710 if (rts_argv[arg][3] != '\0') {
1711 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1713 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1715 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1716 RtsFlags.GranFlags.packBufferSize_internal);
1720 switch(rts_argv[arg][3]) {
1723 RtsFlags.GranFlags.DoPrioritySparking = 1;
1724 debugBelch("Priority Sparking with Normal Priorities.\n");
1725 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1726 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1727 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1731 RtsFlags.GranFlags.DoPrioritySparking = 1;
1732 debugBelch("Priority Sparking with Inverse Priorities.\n");
1733 RtsFlags.GranFlags.InversePriorities++;
1737 RtsFlags.GranFlags.DoPrioritySparking = 1;
1738 debugBelch("Priority Sparking with Random Priorities.\n");
1739 RtsFlags.GranFlags.RandomPriorities++;
1743 RtsFlags.GranFlags.DoPrioritySparking = 1;
1744 debugBelch("Priority Sparking with No Priorities.\n");
1745 RtsFlags.GranFlags.IgnorePriorities++;
1749 bad_option( rts_argv[arg] );
1755 switch(rts_argv[arg][3]) {
1758 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1759 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1763 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1767 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1771 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1775 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1776 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1780 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1784 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1788 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1792 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1796 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1800 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1804 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1808 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1809 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1813 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1817 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1821 bad_option( rts_argv[arg] );
1826 # if defined(GRAN_CHECK) && defined(GRAN)
1828 switch(rts_argv[arg][3]) {
1829 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1830 if (rts_argv[arg][4] != '\0') {
1831 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1832 debugBelch("Pack buffer size: %d\n",
1833 RtsFlags.GranFlags.packBufferSize);
1835 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1841 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1842 /* hack warning: interpret the flags as a binary number */
1843 nat n = decode(rts_argv[arg]+3);
1844 set_GranSim_debug_options(n);
1847 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1848 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1851 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1852 debugBelch("Valid GranSim debug options are:\n");
1853 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1854 bad_option( rts_argv[arg] );
1855 } else { // flag found; now set it
1856 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1862 case 'e': /* event trace; also -bD1 */
1863 debugBelch("DEBUG: event_trace; printing event trace.\n");
1864 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1865 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1868 case 'E': /* event statistics; also -bD2 */
1869 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1870 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1871 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1874 case 'f': /* thunkStealing; also -bD4 */
1875 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1876 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1877 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1880 case 'z': /* blockOnFetch; also -bD8 */
1881 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1882 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1883 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1886 case 't': /* blockOnFetch_sanity; also -bD16 */
1887 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1888 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1889 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1892 case 'S': /* priSpark; also -bD32 */
1893 debugBelch("DEBUG: priSpark; priority sparking.\n");
1894 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1897 case 's': /* priSched; also -bD64 */
1898 debugBelch("DEBUG: priSched; priority scheduling.\n");
1899 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1902 case 'F': /* findWork; also -bD128 */
1903 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1904 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1907 case 'g': /* globalBlock; also -bD256 */
1908 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1909 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1912 case 'G': /* pack; also -bD512 */
1913 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1914 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1917 case 'P': /* packBuffer; also -bD1024 */
1918 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1919 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1922 case 'o': /* sortedQ; also -bD2048 */
1923 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1924 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1927 case 'r': /* randomSteal; also -bD4096 */
1928 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
1929 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
1932 case 'q': /* checkSparkQ; also -bD8192 */
1933 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
1934 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
1937 case ':': /* checkLight; also -bD16384 */
1938 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
1939 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
1942 case 'b': /* bq; also -bD32768 */
1943 debugBelch("DEBUG: bq; check blocking queues\n");
1944 RtsFlags.GranFlags.Debug.bq = rtsTrue;
1947 case 'd': /* all options turned on */
1948 debugBelch("DEBUG: all options turned on.\n");
1949 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1950 /* RtsFlags.GranFlags.Debug |= 0x40; */
1954 /* RtsFlags.GranFlags.Debug = 1; */
1960 # endif /* GRAN_CHECK */
1962 bad_option( rts_argv[arg] );
1968 Interpret n as a binary number masking GranSim debug options and set the
1969 correxponding option. See gran_debug_opts_strs for explanations of the flags.
1972 set_GranSim_debug_options(nat n) {
1975 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1977 errorBelch(gran_debug_opts_strs[i]);
1979 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
1980 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
1981 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
1982 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
1983 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
1984 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
1985 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
1986 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
1987 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
1988 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
1989 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
1990 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
1991 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
1992 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
1993 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
1994 default: barf("set_GranSim_debug_options: only %d debug options expected");
2000 Print one line explanation for each of the GranSim debug options specified
2004 help_GranSim_debug_options(nat n) {
2007 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
2009 debugBelch(gran_debug_opts_strs[i]);
2015 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
2018 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
2019 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
2023 /* Communication and task creation cost parameters */
2024 switch(rts_argv[arg][2]) {
2025 case 'e': /* -qe<n> ... allow <n> local sparks */
2026 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
2027 RtsFlags.ParFlags.maxLocalSparks
2028 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2030 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
2031 errorBelch("setupRtsFlags: bad value for -e\n");
2035 IF_PAR_DEBUG(verbose,
2036 errorBelch("-qe<n>: max %d local sparks",
2037 RtsFlags.ParFlags.maxLocalSparks));
2041 if (rts_argv[arg][3] != '\0') {
2042 RtsFlags.ParFlags.maxThreads
2043 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2045 errorBelch("missing size for -qt\n");
2048 IF_PAR_DEBUG(verbose,
2049 errorBelch("-qt<n>: max %d threads",
2050 RtsFlags.ParFlags.maxThreads));
2054 if (rts_argv[arg][3] != '\0')
2055 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
2057 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
2059 IF_PAR_DEBUG(verbose,
2060 errorBelch("-qf<n>: max %d fishes sent out at one time",
2061 RtsFlags.ParFlags.maxFishes));
2065 if (rts_argv[arg][3] != '\0') {
2066 RtsFlags.ParFlags.fishDelay
2067 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2069 errorBelch("missing fish delay time for -qF\n");
2072 IF_PAR_DEBUG(verbose,
2073 errorBelch("-qF<n>: fish delay time %d us",
2074 RtsFlags.ParFlags.fishDelay));
2078 RtsFlags.ParFlags.outputDisabled = rtsTrue;
2079 IF_PAR_DEBUG(verbose,
2080 errorBelch("-qO: output disabled"));
2083 case 'g': /* -qg<n> ... globalisation scheme */
2084 if (rts_argv[arg][3] != '\0') {
2085 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
2087 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
2090 IF_PAR_DEBUG(verbose,
2091 debugBelch("-qg<n>: globalisation scheme set to %d",
2092 RtsFlags.ParFlags.globalising));
2095 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
2096 if (rts_argv[arg][3] != '\0') {
2097 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
2099 errorBelch("missing number of thunks per packet (for -qh)\n");
2102 IF_PAR_DEBUG(verbose,
2103 debugBelch("-qh<n>: thunks per packet set to %d",
2104 RtsFlags.ParFlags.thunksToPack));
2107 case 'P': /* -qP for writing a log file */
2108 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2109 /* same encoding as in GranSim after -bP */
2110 switch(rts_argv[arg][3]) {
2111 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2112 break; // nothing special, just an ordinary profile
2113 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2114 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2116 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2118 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2120 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2122 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2125 # if defined(PAR_TICKY)
2126 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2128 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2129 stg_exit(EXIT_FAILURE);
2132 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2134 IF_PAR_DEBUG(verbose,
2135 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2136 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2139 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2140 if (rts_argv[arg][3] != '\0') {
2141 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2143 errorBelch("missing size of PackBuffer (for -qQ)\n");
2146 IF_PAR_DEBUG(verbose,
2147 debugBelch("-qQ<n>: pack buffer size set to %d",
2148 RtsFlags.ParFlags.packBufferSize));
2152 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2153 IF_PAR_DEBUG(verbose,
2154 debugBelch("-qR: fair-ish scheduling"));
2159 if (rts_argv[arg][3] != '\0') {
2160 RtsFlags.ParFlags.wait
2161 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2163 RtsFlags.ParFlags.wait = 1000;
2165 IF_PAR_DEBUG(verbose,
2166 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2167 RtsFlags.ParFlags.wait));
2170 case 'D': /* -qD ... all the debugging options */
2171 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2172 /* hack warning: interpret the flags as a binary number */
2173 nat n = decode(rts_argv[arg]+3);
2174 set_par_debug_options(n);
2177 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2178 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2181 if (i==MAX_PAR_DEBUG_OPTION+1) {
2182 errorBelch("Valid GUM debug options are:\n");
2183 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2184 bad_option( rts_argv[arg] );
2185 } else { // flag found; now set it
2186 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2192 errorBelch("Unknown option -q%c (%d opts in total)",
2193 rts_argv[arg][2], *rts_argc);
2199 Interpret n as a binary number masking Par debug options and set the
2200 correxponding option. See par_debug_opts_strs for explanations of the flags.
2203 set_par_debug_options(nat n) {
2206 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2208 debugBelch(par_debug_opts_strs[i]);
2210 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2211 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2212 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2213 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2214 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2215 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2216 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2217 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2218 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2219 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2220 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2221 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2222 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2223 default: barf("set_par_debug_options: only %d debug options expected",
2224 MAX_PAR_DEBUG_OPTION);
2230 Print one line explanation for each of the GranSim debug options specified
2234 help_par_debug_options(nat n) {
2237 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2239 debugBelch(par_debug_opts_strs[i]);
2245 stats_fprintf(FILE *f, char *s, ...)
2257 static int /* return -1 on error */
2260 int argc, char *argv[],
2261 int rts_argc, char *rts_argv[],
2262 const char *FILENAME_FMT,
2267 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2268 f = NULL; /* NULL means use debugBelch */
2270 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2271 f = fopen(rts_argv[arg]+2,"w");
2273 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2274 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2275 f = fopen(stats_filename,"w");
2278 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2285 /* Write argv and rtsv into start of stats file */
2287 for(count = 0; count < argc; count++) {
2288 stats_fprintf(f, "%s ", argv[count]);
2290 stats_fprintf(f, "+RTS ");
2291 for(count = 0; count < rts_argc; count++)
2292 stats_fprintf(f, "%s ", rts_argv[count]);
2293 stats_fprintf(f, "\n");
2301 decode(const char *s)
2312 if (c == 'g' || c == 'G')
2313 m *= 1000*1000*1000; /* UNchecked! */
2314 else if (c == 'm' || c == 'M')
2315 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2316 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2317 m *= 1000; /* a direct-mapped cache. */
2318 else if (c == 'w' || c == 'W')
2325 bad_option(const char *s)
2327 errorBelch("bad RTS option: %s", s);
2328 stg_exit(EXIT_FAILURE);
2331 /* -----------------------------------------------------------------------------
2332 Getting/Setting the program's arguments.
2334 These are used by System.Environment, and parts of the RTS.
2335 -------------------------------------------------------------------------- */
2338 setProgName(char *argv[])
2340 /* Remove directory from argv[0] -- default files in current directory */
2341 #if !defined(mingw32_HOST_OS)
2343 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2344 prog_name = last_slash+1;
2346 prog_name = argv[0];
2349 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2350 while ( last_slash > argv[0] ) {
2351 if ( *last_slash == '/' || *last_slash == '\\' ) {
2352 prog_name = last_slash+1;
2357 prog_name = argv[0];
2362 getProgArgv(int *argc, char **argv[])
2364 if (argc) { *argc = prog_argc; }
2365 if (argv) { *argv = prog_argv; }
2369 setProgArgv(int argc, char *argv[])
2371 /* Usually this is done by startupHaskell, so we don't need to call this.
2372 However, sometimes Hugs wants to change the arguments which Haskell
2373 getArgs >>= ... will be fed. So you can do that by calling here
2374 _after_ calling startupHaskell.
2378 setProgName(prog_argv);