2 /* -----------------------------------------------------------------------------
4 * (c) The AQUA Project, Glasgow University, 1994-1997
5 * (c) The GHC Team, 1998-1999
7 * Functions for parsing the argument list.
9 * ---------------------------------------------------------------------------*/
14 //* Static function decls::
15 //* Command-line option parsing routines::
16 //* GranSim specific options::
21 //@node Includes, Constants
22 //@subsection Includes
24 #include "PosixSource.h"
28 #include "BlockAlloc.h"
29 #include "Timer.h" /* CS_MIN_MILLISECS */
30 #include "Profiling.h"
43 * Split argument lists
45 int prog_argc = 0; /* an "int" so as to match normal "argc" */
46 char **prog_argv = NULL;
47 char *prog_name = NULL; /* 'basename' of prog_argv[0] */
48 int rts_argc = 0; /* ditto */
49 char *rts_argv[MAX_RTS_ARGS];
51 //@node Constants, Static function decls, Includes
52 //@subsection Constants
55 * constants, used later
62 static char *gran_debug_opts_strs[] = {
63 "DEBUG (-bDe, -bD1): event_trace; printing event trace.\n",
64 "DEBUG (-bDE, -bD2): event_stats; printing event statistics.\n",
65 "DEBUG (-bDb, -bD4): bq; check blocking queues\n",
66 "DEBUG (-bDG, -bD8): pack; routines for (un-)packing graph structures.\n",
67 "DEBUG (-bDq, -bD16): checkSparkQ; check consistency of the spark queues.\n",
68 "DEBUG (-bDf, -bD32): thunkStealing; print forwarding of fetches.\n",
69 "DEBUG (-bDr, -bD64): randomSteal; stealing sparks/threads from random PEs.\n",
70 "DEBUG (-bDF, -bD128): findWork; searching spark-pools (local & remote), thread queues for work.\n",
71 "DEBUG (-bDu, -bD256): unused; currently unused flag.\n",
72 "DEBUG (-bDS, -bD512): pri; priority sparking or scheduling.\n",
73 "DEBUG (-bD:, -bD1024): checkLight; check GranSim-Light setup.\n",
74 "DEBUG (-bDo, -bD2048): sortedQ; check whether spark/thread queues are sorted.\n",
75 "DEBUG (-bDz, -bD4096): blockOnFetch; check for blocked on fetch.\n",
76 "DEBUG (-bDP, -bD8192): packBuffer; routines handling pack buffer (GranSim internal!).\n",
77 "DEBUG (-bDt, -bD16384): blockOnFetch_sanity; check for TSO asleep on fetch.\n",
80 /* one character codes for the available debug options */
81 static char gran_debug_opts_flags[] = {
82 'e', 'E', 'b', 'G', 'q', 'f', 'r', 'F', 'u', 'S', ':', 'o', 'z', 'P', 't'
87 static char *par_debug_opts_strs[] = {
88 "DEBUG (-qDv, -qD1): verbose; be generally verbose with parallel related stuff.\n",
89 "DEBUG (-qDq, -qD2): bq; print blocking queues.\n",
90 "DEBUG (-qDs, -qD4): schedule; scheduling of parallel threads.\n",
91 "DEBUG (-qDe, -qD8): free; free messages.\n",
92 "DEBUG (-qDr, -qD16): resume; resume messages.\n",
93 "DEBUG (-qDw, -qD32): weight; print weights and distrib GC stuff.\n",
94 "DEBUG (-qDF, -qD64): fetch; fetch messages.\n",
95 // "DEBUG (-qDa, -qD128): ack; ack messages.\n",
96 "DEBUG (-qDf, -qD128): fish; fish messages.\n",
97 //"DEBUG (-qDo, -qD512): forward; forwarding messages to other PEs.\n",
98 "DEBUG (-qDl, -qD256): tables; print internal LAGA etc tables.\n",
99 "DEBUG (-qDo, -qD512): packet; packets and graph structures when packing.\n",
100 "DEBUG (-qDp, -qD1024): pack; packing and unpacking graphs.\n",
101 "DEBUG (-qDz, -qD2048): paranoia; ridiculously detailed output (excellent for filling a partition).\n"
104 /* one character codes for the available debug options */
105 static char par_debug_opts_flags[] = {
106 'v', 'q', 's', 'e', 'r', 'w', 'F', 'f', 'l', 'o', 'p', 'z'
111 //@node Static function decls, Command-line option parsing routines, Constants
112 //@subsection Static function decls
114 /* -----------------------------------------------------------------------------
115 Static function decls
116 -------------------------------------------------------------------------- */
118 static int /* return NULL on error */
121 int argc, char *argv[],
122 int rts_argc, char *rts_argv[],
123 const char *FILENAME_FMT,
126 static I_ decode(const char *s);
127 static void bad_option(const char *s);
130 static void enable_GranSimLight(void);
131 static void process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
132 static void set_GranSim_debug_options(nat n);
133 static void help_GranSim_debug_options(nat n);
135 static void process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error);
136 static void set_par_debug_options(nat n);
137 static void help_par_debug_options(nat n);
140 //@node Command-line option parsing routines, GranSim specific options, Static function decls
141 //@subsection Command-line option parsing routines
143 /* -----------------------------------------------------------------------------
144 * Command-line option parsing routines.
145 * ---------------------------------------------------------------------------*/
147 void initRtsFlagsDefaults(void)
149 RtsFlags.GcFlags.statsFile = NULL;
150 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
152 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
153 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
155 RtsFlags.GcFlags.minAllocAreaSize = (512 * 1024) / BLOCK_SIZE;
156 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
157 RtsFlags.GcFlags.maxHeapSize = 0; /* off by default */
158 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
159 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
160 RtsFlags.GcFlags.oldGenFactor = 2;
162 /* A hack currently needed for GUM -- HWL */
163 RtsFlags.GcFlags.generations = 1;
164 RtsFlags.GcFlags.steps = 2;
165 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
167 RtsFlags.GcFlags.generations = 2;
168 RtsFlags.GcFlags.steps = 2;
169 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
171 RtsFlags.GcFlags.compact = rtsFalse;
172 RtsFlags.GcFlags.compactThreshold = 30.0;
173 #ifdef RTS_GTK_FRONTPANEL
174 RtsFlags.GcFlags.frontpanel = rtsFalse;
176 RtsFlags.GcFlags.idleGCDelayTicks = 300 / TICK_MILLISECS; /* ticks */
179 RtsFlags.DebugFlags.scheduler = rtsFalse;
180 RtsFlags.DebugFlags.interpreter = rtsFalse;
181 RtsFlags.DebugFlags.codegen = rtsFalse;
182 RtsFlags.DebugFlags.weak = rtsFalse;
183 RtsFlags.DebugFlags.gccafs = rtsFalse;
184 RtsFlags.DebugFlags.gc = rtsFalse;
185 RtsFlags.DebugFlags.block_alloc = rtsFalse;
186 RtsFlags.DebugFlags.sanity = rtsFalse;
187 RtsFlags.DebugFlags.stable = rtsFalse;
188 RtsFlags.DebugFlags.stm = rtsFalse;
189 RtsFlags.DebugFlags.prof = rtsFalse;
190 RtsFlags.DebugFlags.gran = rtsFalse;
191 RtsFlags.DebugFlags.par = rtsFalse;
192 RtsFlags.DebugFlags.linker = rtsFalse;
193 RtsFlags.DebugFlags.squeeze = rtsFalse;
196 #if defined(PROFILING) || defined(PAR)
197 RtsFlags.CcFlags.doCostCentres = 0;
198 #endif /* PROFILING or PAR */
201 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
202 RtsFlags.ProfFlags.profileInterval = 100;
203 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
204 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
205 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
206 RtsFlags.ProfFlags.modSelector = NULL;
207 RtsFlags.ProfFlags.descrSelector = NULL;
208 RtsFlags.ProfFlags.typeSelector = NULL;
209 RtsFlags.ProfFlags.ccSelector = NULL;
210 RtsFlags.ProfFlags.ccsSelector = NULL;
211 RtsFlags.ProfFlags.retainerSelector = NULL;
212 RtsFlags.ProfFlags.bioSelector = NULL;
215 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
218 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
221 RtsFlags.ParFlags.nNodes = 1;
222 RtsFlags.ParFlags.migrate = rtsTrue;
223 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
227 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
228 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
229 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
230 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
231 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
232 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
233 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
235 RtsFlags.ParFlags.outputDisabled = rtsFalse;
237 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
239 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
241 RtsFlags.ParFlags.packBufferSize = 1024;
242 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
243 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
244 RtsFlags.ParFlags.maxThreads = 1024;
245 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
246 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
249 #if defined(PAR) || defined(THREADED_RTS)
250 RtsFlags.ParFlags.maxLocalSparks = 4096;
251 #endif /* PAR || THREADED_RTS */
254 /* ToDo: check defaults for GranSim and GUM */
255 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
256 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
258 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
259 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
260 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
261 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
262 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
263 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
264 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
265 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
267 RtsFlags.GranFlags.packBufferSize = 1024;
268 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
270 RtsFlags.GranFlags.proc = MAX_PROC;
271 RtsFlags.GranFlags.Fishing = rtsFalse;
272 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
273 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
274 RtsFlags.GranFlags.Light = rtsFalse;
276 RtsFlags.GranFlags.Costs.latency = LATENCY;
277 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
278 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
279 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
280 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
281 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
282 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
283 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
285 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
286 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
287 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
288 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
289 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
291 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
292 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
293 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
294 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
295 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
297 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
299 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
300 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
302 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
303 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
304 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
305 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
306 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
307 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
308 RtsFlags.GranFlags.FetchStrategy = 2;
309 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
310 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
311 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
312 RtsFlags.GranFlags.SparkPriority = 0;
313 RtsFlags.GranFlags.SparkPriority2 = 0;
314 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
315 RtsFlags.GranFlags.InversePriorities = rtsFalse;
316 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
317 RtsFlags.GranFlags.ThunksToPack = 0;
318 RtsFlags.GranFlags.RandomSteal = rtsTrue;
322 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
323 RtsFlags.TickyFlags.tickyFile = NULL;
330 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
332 " +RTS Indicates run time system options follow",
333 " -RTS Indicates program arguments follow",
334 " --RTS Indicates that ALL subsequent arguments will be given to the",
335 " program (including any of these RTS flags)",
337 "The following run time system options are available:",
339 " -? Prints this message and exits; the program is not executed",
341 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
342 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
344 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
345 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
346 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
347 " -m<n> Minimum % of heap which must be available (default 3%)",
348 " -G<n> Number of generations (default: 2)",
349 " -T<n> Number of steps in younger generations (default: 2)",
350 " -c<n> Auto-enable compaction of the oldest generation when live data is",
351 " at least <n>% of the maximum heap size set with -M (default: 30%)",
352 " -c Enable compaction for all major collections",
353 #if defined(THREADED_RTS)
354 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
357 " -t<file> One-line GC statistics (default file: <program>.stat)",
358 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
359 " -S<file> Detailed GC statistics",
360 #ifdef RTS_GTK_FRONTPANEL
361 " -f Display front panel (requires X11 & GTK+)",
365 " -Z Don't squeeze out update frames on stack overflow",
366 " -B Sound the bell at the start of each garbage collection",
367 #if defined(PROFILING) || defined(PAR)
369 " -px Time/allocation profile (XML) (output file <program>.prof)",
370 " -p Time/allocation profile (output file <program>.prof)",
371 " -P More detailed Time/Allocation profile",
372 " -Pa Give information about *all* cost centres",
374 # if defined(PROFILING)
376 " -hx Heap residency profile (XML) (output file <program>.prof)",
377 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
378 " break-down: c = cost centre stack (default)",
380 " d = closure description",
381 " y = type description",
383 " b = biography (LAG,DRAG,VOID,USE)",
384 " A subset of closures may be selected thusly:",
385 " -hc<cc>,... specific cost centre(s) (top of stack only)",
386 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
387 " -hm<mod>... all cost centres from the specified modules(s)",
388 " -hd<des>,... closures with specified closure descriptions",
389 " -hy<typ>... closures with specified type descriptions",
390 " -hr<cc>... closures with specified retainers",
391 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
393 " -R<size> Set the maximum retainer set size (default: 8)",
395 " -i<sec> Time between heap samples (seconds, default: 0.1)",
397 " -xt Include threads (TSOs) in a heap profile",
399 " -xc Show current cost centre stack on raising an exception",
401 #endif /* PROFILING or PAR */
402 #if !defined(PROFILING) && defined(DEBUG)
404 " -h<break-down> Debugging Heap residency profile",
405 " (output file <program>.hp)",
406 " break-down: L = closure label (default)",
407 " T = closure type (constructor, thunk etc.)",
410 #if defined(TICKY_TICKY)
411 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
415 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
416 /* NB: the -N<n> is implemented by the driver!! */
418 " -C<secs> Context-switch interval in seconds",
419 " (0 or no argument means switch as often as possible)",
420 " the default is .02 sec; resolution is .02 sec",
423 " -Ds DEBUG: scheduler",
424 " -Di DEBUG: interpreter",
425 " -Dc DEBUG: codegen",
427 " -DG DEBUG: gccafs",
430 " -DS DEBUG: sanity",
431 " -Dt DEBUG: stable",
435 " -Dl DEBUG: linker",
437 " -Dz DEBUG: stack squezing",
440 #if defined(THREADED_RTS)
441 " -N<n> Use <n> OS threads (default: 1)",
442 " -qm Don't automatically migrate threads between CPUs",
443 " -qw Migrate a thread to the current CPU when it is woken up",
445 #if defined(THREADED_RTS) || defined(PAR)
446 " -e<size> Size of spark pools (default 100)",
449 " -t<num> Set maximum number of advisory threads per PE (default 32)",
450 " -qP Enable activity profile (output files in ~/<program>*.gr)",
451 " -qQ<size> Set pack-buffer size (default: 1024)",
452 " -qd Turn on PVM-ish debugging",
453 " -qO Disable output for performance measurement",
455 #if defined(THREADED_RTS) || defined(PAR)
456 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
459 " -d Turn on PVM-ish debugging",
460 " -O Disable output for performance measurement",
462 #if defined(GRAN) /* ToDo: fill in decent Docu here */
463 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
466 "RTS options may also be specified using the GHCRTS environment variable.",
468 "Other RTS options may be available for programs compiled a different way.",
469 "The GHC User's Guide has full details.",
474 STATIC_INLINE rtsBool
475 strequal(const char *a, const char * b)
477 return(strcmp(a, b) == 0);
481 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
487 while (isspace(*c1)) { c1++; };
489 while (!isspace(*c2) && *c2 != '\0') { c2++; };
491 if (c1 == c2) { break; }
493 if (*rts_argc < MAX_RTS_ARGS-1) {
494 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
495 strncpy(s, c1, c2-c1);
497 rts_argv[(*rts_argc)++] = s;
499 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
503 } while (*c1 != '\0');
507 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
509 rtsBool error = rtsFalse;
520 // process arguments from the ghc_rts_opts global variable first.
521 // (arguments from the GHCRTS environment variable and the command
522 // line override these).
524 if (ghc_rts_opts != NULL) {
525 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
529 // process arguments from the GHCRTS environment variable next
530 // (arguments from the command line override these).
532 char *ghc_rts = getenv("GHCRTS");
534 if (ghc_rts != NULL) {
535 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
539 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
540 // argv[0] must be PGM argument -- leave in argv
542 for (mode = PGM; arg < total_arg; arg++) {
543 // The '--RTS' argument disables all future +RTS ... -RTS processing.
544 if (strequal("--RTS", argv[arg])) {
548 // The '--' argument is passed through to the program, but
549 // disables all further +RTS ... -RTS processing.
550 else if (strequal("--", argv[arg])) {
553 else if (strequal("+RTS", argv[arg])) {
556 else if (strequal("-RTS", argv[arg])) {
559 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
560 rts_argv[(*rts_argc)++] = argv[arg];
562 else if (mode == PGM) {
563 argv[(*argc)++] = argv[arg];
566 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
569 // process remaining program arguments
570 for (; arg < total_arg; arg++) {
571 argv[(*argc)++] = argv[arg];
573 argv[*argc] = (char *) 0;
574 rts_argv[*rts_argc] = (char *) 0;
576 // Process RTS (rts_argv) part: mainly to determine statsfile
577 for (arg = 0; arg < *rts_argc; arg++) {
578 if (rts_argv[arg][0] != '-') {
580 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
584 switch(rts_argv[arg][1]) {
586 /* process: general args, then PROFILING-only ones,
587 then CONCURRENT-only, PARallel-only, GRAN-only,
588 TICKY-only (same order as defined in RtsFlags.lh);
589 within those groups, mostly in case-insensitive
591 Final group is x*, which allows for more options.
595 # define TICKY_BUILD_ONLY(x) x
597 # define TICKY_BUILD_ONLY(x) \
598 errorBelch("not built for: ticky-ticky stats"); \
602 #if defined(PROFILING)
603 # define COST_CENTRE_USING_BUILD_ONLY(x) x
605 # define COST_CENTRE_USING_BUILD_ONLY(x) \
606 errorBelch("not built for: -prof or -parallel"); \
611 # define PROFILING_BUILD_ONLY(x) x
613 # define PROFILING_BUILD_ONLY(x) \
614 errorBelch("not built for: -prof"); \
619 # define PAR_BUILD_ONLY(x) x
621 # define PAR_BUILD_ONLY(x) \
622 errorBelch("not built for: -parallel"); \
627 # define THREADED_BUILD_ONLY(x) x
629 # define THREADED_BUILD_ONLY(x) \
630 errorBelch("not built for: -smp"); \
634 #if defined(THREADED_RTS) || defined(PAR)
635 # define PAR_OR_THREADED_BUILD_ONLY(x) x
637 # define PAR_OR_THREADED_BUILD_ONLY(x) \
638 errorBelch("not built for: -parallel or -smp"); \
643 # define GRAN_BUILD_ONLY(x) x
645 # define GRAN_BUILD_ONLY(x) \
646 errorBelch("not built for: -gransim"); \
650 /* =========== GENERAL ========================== */
656 RtsFlags.GcFlags.minAllocAreaSize
657 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
658 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
659 bad_option(rts_argv[arg]);
664 RtsFlags.GcFlags.ringBell = rtsTrue;
668 if (rts_argv[arg][2] != '\0') {
669 RtsFlags.GcFlags.compactThreshold =
670 atof(rts_argv[arg]+2);
672 RtsFlags.GcFlags.compact = rtsTrue;
677 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
679 if (RtsFlags.GcFlags.oldGenFactor < 0)
680 bad_option( rts_argv[arg] );
688 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
691 RtsFlags.DebugFlags.scheduler = rtsTrue;
694 RtsFlags.DebugFlags.interpreter = rtsTrue;
697 RtsFlags.DebugFlags.codegen = rtsTrue;
700 RtsFlags.DebugFlags.weak = rtsTrue;
703 RtsFlags.DebugFlags.gccafs = rtsTrue;
706 RtsFlags.DebugFlags.gc = rtsTrue;
709 RtsFlags.DebugFlags.block_alloc = rtsTrue;
712 RtsFlags.DebugFlags.sanity = rtsTrue;
715 RtsFlags.DebugFlags.stable = rtsTrue;
718 RtsFlags.DebugFlags.prof = rtsTrue;
721 RtsFlags.DebugFlags.gran = rtsTrue;
724 RtsFlags.DebugFlags.par = rtsTrue;
727 RtsFlags.DebugFlags.linker = rtsTrue;
730 RtsFlags.DebugFlags.apply = rtsTrue;
733 RtsFlags.DebugFlags.stm = rtsTrue;
736 RtsFlags.DebugFlags.squeeze = rtsTrue;
739 bad_option( rts_argv[arg] );
747 RtsFlags.GcFlags.maxStkSize =
748 decode(rts_argv[arg]+2) / sizeof(W_);
750 if (RtsFlags.GcFlags.maxStkSize == 0)
751 bad_option( rts_argv[arg] );
755 RtsFlags.GcFlags.initialStkSize =
756 decode(rts_argv[arg]+2) / sizeof(W_);
758 if (RtsFlags.GcFlags.initialStkSize == 0)
759 bad_option( rts_argv[arg] );
763 RtsFlags.GcFlags.maxHeapSize =
764 decode(rts_argv[arg]+2) / BLOCK_SIZE;
765 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
767 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
768 bad_option(rts_argv[arg]);
773 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
775 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
776 RtsFlags.GcFlags.pcFreeHeap > 100)
777 bad_option( rts_argv[arg] );
781 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
782 if (RtsFlags.GcFlags.generations < 1) {
783 bad_option(rts_argv[arg]);
788 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
789 if (RtsFlags.GcFlags.steps < 1) {
790 bad_option(rts_argv[arg]);
795 RtsFlags.GcFlags.heapSizeSuggestion =
796 decode(rts_argv[arg]+2) / BLOCK_SIZE;
798 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
799 bad_option(rts_argv[arg]);
803 #ifdef RTS_GTK_FRONTPANEL
805 RtsFlags.GcFlags.frontpanel = rtsTrue;
809 case 'I': /* idle GC delay */
810 if (rts_argv[arg][2] == '\0') {
815 /* Convert to ticks */
816 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
817 if (cst > 0 && cst < TICK_MILLISECS) {
818 cst = TICK_MILLISECS;
820 cst = cst / TICK_MILLISECS;
822 RtsFlags.GcFlags.idleGCDelayTicks = cst;
827 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
831 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
835 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
840 /* Opening all those files would almost certainly fail... */
841 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
842 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
846 r = open_stats_file(arg, *argc, argv,
847 *rts_argc, rts_argv, STAT_FILENAME_FMT,
848 &RtsFlags.GcFlags.statsFile);
849 if (r == -1) { error = rtsTrue; }
855 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
858 /* =========== PROFILING ========================== */
860 case 'P': /* detailed cost centre profiling (time/alloc) */
861 case 'p': /* cost centre profiling (time/alloc) */
862 COST_CENTRE_USING_BUILD_ONLY(
863 switch (rts_argv[arg][2]) {
865 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
868 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
871 if (rts_argv[arg][1] == 'P') {
872 RtsFlags.CcFlags.doCostCentres =
873 COST_CENTRES_VERBOSE;
875 RtsFlags.CcFlags.doCostCentres =
876 COST_CENTRES_SUMMARY;
883 PROFILING_BUILD_ONLY(
884 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
887 case 'h': /* serial heap profile */
888 #if !defined(PROFILING) && defined(DEBUG)
889 switch (rts_argv[arg][2]) {
892 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
895 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
898 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
902 PROFILING_BUILD_ONLY(
903 switch (rts_argv[arg][2]) {
917 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
919 char *left = strchr(rts_argv[arg], '{');
920 char *right = strrchr(rts_argv[arg], '}');
922 // curly braces are optional, for
927 left = rts_argv[arg] + 3;
930 right = rts_argv[arg] + strlen(rts_argv[arg]);
934 switch (rts_argv[arg][2]) {
935 case 'c': // cost centre label select
936 RtsFlags.ProfFlags.ccSelector = left;
939 RtsFlags.ProfFlags.ccsSelector = left;
942 case 'm': // cost centre module select
943 RtsFlags.ProfFlags.modSelector = left;
946 case 'd': // closure descr select
947 RtsFlags.ProfFlags.descrSelector = left;
950 case 'y': // closure type select
951 RtsFlags.ProfFlags.typeSelector = left;
954 case 'r': // retainer select
955 RtsFlags.ProfFlags.retainerSelector = left;
958 case 'b': // biography select
959 RtsFlags.ProfFlags.bioSelector = left;
966 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
967 errorBelch("multiple heap profile options");
972 switch (rts_argv[arg][2]) {
976 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
980 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
984 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
988 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
992 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
996 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
1002 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
1006 #endif /* PROFILING */
1009 #if defined(PROFILING)
1010 case 'i': /* heap sample interval */
1011 if (rts_argv[arg][2] == '\0') {
1016 /* Convert to milliseconds */
1017 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1018 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
1019 if (cst != 0 && cst < CS_MIN_MILLISECS)
1020 cst = CS_MIN_MILLISECS;
1022 RtsFlags.ProfFlags.profileInterval = cst;
1027 /* =========== CONCURRENT ========================= */
1028 case 'C': /* context switch interval */
1029 if (rts_argv[arg][2] == '\0')
1030 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1034 /* Convert to milliseconds */
1035 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1036 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
1037 if (cst != 0 && cst < CS_MIN_MILLISECS)
1038 cst = CS_MIN_MILLISECS;
1040 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1046 THREADED_BUILD_ONLY(
1047 if (rts_argv[arg][2] != '\0') {
1048 RtsFlags.ParFlags.nNodes
1049 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1050 if (RtsFlags.ParFlags.nNodes <= 0) {
1051 errorBelch("bad value for -N");
1058 switch (rts_argv[arg][2]) {
1060 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1064 RtsFlags.ParFlags.migrate = rtsFalse;
1067 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1070 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1076 /* =========== PARALLEL =========================== */
1078 PAR_OR_THREADED_BUILD_ONLY(
1079 if (rts_argv[arg][2] != '\0') {
1080 RtsFlags.ParFlags.maxLocalSparks
1081 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1082 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1083 errorBelch("bad value for -e");
1092 process_par_option(arg, rts_argc, rts_argv, &error);
1096 /* =========== GRAN =============================== */
1100 process_gran_option(arg, rts_argc, rts_argv, &error);
1103 /* =========== TICKY ============================== */
1105 case 'r': /* Basic profiling stats */
1108 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1112 r = open_stats_file(arg, *argc, argv,
1113 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1114 &RtsFlags.TickyFlags.tickyFile);
1115 if (r == -1) { error = rtsTrue; }
1119 /* =========== EXTENDED OPTIONS =================== */
1121 case 'x': /* Extend the argument space */
1122 switch(rts_argv[arg][2]) {
1124 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1128 case 'c': /* Debugging tool: show current cost centre on an exception */
1129 PROFILING_BUILD_ONLY(
1130 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1134 case 't': /* Include memory used by TSOs in a heap profile */
1135 PROFILING_BUILD_ONLY(
1136 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1140 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1143 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1147 break; /* defensive programming */
1149 /* =========== OH DEAR ============================ */
1151 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1161 for (p = usage_text; *p; p++)
1162 errorBelch("%s", *p);
1163 stg_exit(EXIT_FAILURE);
1169 //@node GranSim specific options, Aux fcts, Command-line option parsing routines
1170 //@subsection GranSim specific options
1173 enable_GranSimLight(void) {
1175 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1176 RtsFlags.GranFlags.Light=rtsTrue;
1177 RtsFlags.GranFlags.Costs.latency =
1178 RtsFlags.GranFlags.Costs.fetchtime =
1179 RtsFlags.GranFlags.Costs.additional_latency =
1180 RtsFlags.GranFlags.Costs.gunblocktime =
1181 RtsFlags.GranFlags.Costs.lunblocktime =
1182 RtsFlags.GranFlags.Costs.threadcreatetime =
1183 RtsFlags.GranFlags.Costs.threadqueuetime =
1184 RtsFlags.GranFlags.Costs.threadscheduletime =
1185 RtsFlags.GranFlags.Costs.threaddescheduletime =
1186 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1188 RtsFlags.GranFlags.Costs.mpacktime =
1189 RtsFlags.GranFlags.Costs.munpacktime = 0;
1191 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1192 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1193 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1194 /* FetchStrategy is irrelevant in GrAnSim-Light */
1196 /* GrAnSim Light often creates an abundance of parallel threads,
1197 each with its own stack etc. Therefore, it's in general a good
1198 idea to use small stack chunks (use the -o<size> option to
1201 // RtsFlags.ConcFlags.stkChunkSize = 100;
1203 RtsFlags.GranFlags.proc = 1;
1207 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1209 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1212 /* or a ridiculously idealised simulator */
1213 if(strcmp((rts_argv[arg]+2),"oring")==0) {
1214 RtsFlags.GranFlags.Costs.latency =
1215 RtsFlags.GranFlags.Costs.fetchtime =
1216 RtsFlags.GranFlags.Costs.additional_latency =
1217 RtsFlags.GranFlags.Costs.gunblocktime =
1218 RtsFlags.GranFlags.Costs.lunblocktime =
1219 RtsFlags.GranFlags.Costs.threadcreatetime =
1220 RtsFlags.GranFlags.Costs.threadqueuetime =
1221 RtsFlags.GranFlags.Costs.threadscheduletime =
1222 RtsFlags.GranFlags.Costs.threaddescheduletime =
1223 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1225 RtsFlags.GranFlags.Costs.mpacktime =
1226 RtsFlags.GranFlags.Costs.munpacktime = 0;
1228 RtsFlags.GranFlags.Costs.arith_cost =
1229 RtsFlags.GranFlags.Costs.float_cost =
1230 RtsFlags.GranFlags.Costs.load_cost =
1231 RtsFlags.GranFlags.Costs.store_cost =
1232 RtsFlags.GranFlags.Costs.branch_cost = 0;
1234 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1236 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1237 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1238 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1239 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1243 /* or a somewhat idealised simulator */
1244 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1245 RtsFlags.GranFlags.Costs.latency =
1246 RtsFlags.GranFlags.Costs.fetchtime =
1247 RtsFlags.GranFlags.Costs.additional_latency =
1248 RtsFlags.GranFlags.Costs.gunblocktime =
1249 RtsFlags.GranFlags.Costs.lunblocktime =
1250 RtsFlags.GranFlags.Costs.threadcreatetime =
1251 RtsFlags.GranFlags.Costs.threadqueuetime =
1252 RtsFlags.GranFlags.Costs.threadscheduletime =
1253 RtsFlags.GranFlags.Costs.threaddescheduletime =
1254 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1256 RtsFlags.GranFlags.Costs.mpacktime =
1257 RtsFlags.GranFlags.Costs.munpacktime = 0;
1259 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1261 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1262 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1263 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1264 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1265 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1266 # if defined(GRAN_CHECK) && defined(GRAN)
1267 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1272 /* Communication and task creation cost parameters */
1273 switch(rts_argv[arg][2]) {
1275 IgnoreYields = rtsTrue; // HWL HACK
1279 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1283 if (rts_argv[arg][3] != '\0')
1285 RtsFlags.GranFlags.Costs.gunblocktime =
1286 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1287 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1290 RtsFlags.GranFlags.Costs.latency = LATENCY;
1294 if (rts_argv[arg][3] != '\0')
1295 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1297 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1301 if (rts_argv[arg][3] != '\0')
1302 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1304 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1308 if (rts_argv[arg][3] != '\0')
1309 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1311 RtsFlags.GranFlags.Costs.mtidytime = 0;
1315 if (rts_argv[arg][3] != '\0')
1316 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1318 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1322 if (rts_argv[arg][3] != '\0')
1323 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1325 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1329 if (rts_argv[arg][3] != '\0')
1330 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1332 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1336 if (rts_argv[arg][3] != '\0')
1337 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1339 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1342 /* Thread-related metrics */
1344 if (rts_argv[arg][3] != '\0')
1345 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1347 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1351 if (rts_argv[arg][3] != '\0')
1352 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1354 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1358 if (rts_argv[arg][3] != '\0')
1359 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1361 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1363 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1364 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1368 if (rts_argv[arg][3] != '\0')
1369 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1371 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1373 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1374 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1377 /* Instruction Cost Metrics */
1379 if (rts_argv[arg][3] != '\0')
1380 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1382 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1386 if (rts_argv[arg][3] != '\0')
1387 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1389 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1393 if (rts_argv[arg][3] != '\0')
1394 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1396 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1400 if (rts_argv[arg][3] != '\0')
1401 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1403 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1407 if (rts_argv[arg][3] != '\0')
1408 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1410 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1414 if (rts_argv[arg][3] != '\0')
1415 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1417 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1421 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1422 if (rts_argv[arg][3] != '\0')
1423 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1425 RtsFlags.GranFlags.FetchStrategy = 2;
1426 if (RtsFlags.GranFlags.FetchStrategy == 0)
1427 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1430 case 'K': /* sort overhead (per elem in spark list) */
1431 if (rts_argv[arg][3] != '\0')
1432 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1434 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1435 debugBelch("Overhead for pri spark: %d (per elem).\n",
1436 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1439 case 'O': /* sort overhead (per elem in spark list) */
1440 if (rts_argv[arg][3] != '\0')
1441 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1443 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1444 debugBelch("Overhead for pri sched: %d (per elem).\n",
1445 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1448 /* General Parameters */
1450 if (rts_argv[arg][3] != '\0')
1452 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1453 if (RtsFlags.GranFlags.proc==0) {
1454 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1455 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1456 RtsFlags.GranFlags.proc < 1)
1458 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1464 RtsFlags.GranFlags.proc = MAX_PROC;
1468 RtsFlags.GranFlags.Fishing = rtsTrue;
1469 if (rts_argv[arg][3] != '\0')
1470 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1472 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1476 if (rts_argv[arg][3] != '\0')
1477 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1479 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1483 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1484 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1488 debugBelch("Bulk fetching enabled.\n");
1489 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1493 debugBelch("Thread migration enabled.\n");
1494 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1498 debugBelch("Fair Scheduling enabled.\n");
1499 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1503 debugBelch("Priority Scheduling enabled.\n");
1504 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1508 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1509 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1513 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1517 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1521 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1525 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1529 /* format is -bP<c> where <c> is one char describing kind of profile */
1530 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1531 switch(rts_argv[arg][3]) {
1532 case '\0': break; // nothing special, just an ordinary profile
1533 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1535 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1537 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1539 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1541 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1543 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1545 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1550 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1554 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1557 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1558 if (rts_argv[arg][3] != '\0') {
1561 arg0 = rts_argv[arg]+3;
1562 if ((tmp = strstr(arg0,","))==NULL) {
1563 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1564 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1567 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1568 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1569 debugBelch("SparkPriority: %u.\n",
1570 RtsFlags.GranFlags.SparkPriority);
1571 debugBelch("SparkPriority2:%u.\n",
1572 RtsFlags.GranFlags.SparkPriority2);
1573 if (RtsFlags.GranFlags.SparkPriority2 <
1574 RtsFlags.GranFlags.SparkPriority) {
1575 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1576 RtsFlags.GranFlags.SparkPriority2,
1577 RtsFlags.GranFlags.SparkPriority);
1581 /* plain pri spark is now invoked with -bX
1582 RtsFlags.GranFlags.DoPrioritySparking = 1;
1583 debugBelch("PrioritySparking.\n");
1589 if (rts_argv[arg][3] != '\0') {
1590 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1592 RtsFlags.GranFlags.ThunksToPack = 1;
1594 debugBelch("Thunks To Pack in one packet: %u.\n",
1595 RtsFlags.GranFlags.ThunksToPack);
1599 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1600 debugBelch("Deterministic mode (no random stealing)\n");
1603 /* The following class of options contains eXperimental */
1604 /* features in connection with exploiting granularity */
1605 /* information. I.e. if -bY is chosen these options */
1606 /* tell the RTS what to do with the supplied info --HWL */
1609 if (rts_argv[arg][3] != '\0') {
1610 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1612 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1614 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1615 RtsFlags.GranFlags.packBufferSize_internal);
1619 switch(rts_argv[arg][3]) {
1622 RtsFlags.GranFlags.DoPrioritySparking = 1;
1623 debugBelch("Priority Sparking with Normal Priorities.\n");
1624 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1625 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1626 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1630 RtsFlags.GranFlags.DoPrioritySparking = 1;
1631 debugBelch("Priority Sparking with Inverse Priorities.\n");
1632 RtsFlags.GranFlags.InversePriorities++;
1636 RtsFlags.GranFlags.DoPrioritySparking = 1;
1637 debugBelch("Priority Sparking with Random Priorities.\n");
1638 RtsFlags.GranFlags.RandomPriorities++;
1642 RtsFlags.GranFlags.DoPrioritySparking = 1;
1643 debugBelch("Priority Sparking with No Priorities.\n");
1644 RtsFlags.GranFlags.IgnorePriorities++;
1648 bad_option( rts_argv[arg] );
1654 switch(rts_argv[arg][3]) {
1657 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1658 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1662 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1666 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1670 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1674 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1675 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1679 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1683 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1687 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1691 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1695 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1699 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1703 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1707 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1708 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1712 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1716 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1720 bad_option( rts_argv[arg] );
1725 # if defined(GRAN_CHECK) && defined(GRAN)
1727 switch(rts_argv[arg][3]) {
1728 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1729 if (rts_argv[arg][4] != '\0') {
1730 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1731 debugBelch("Pack buffer size: %d\n",
1732 RtsFlags.GranFlags.packBufferSize);
1734 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1740 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1741 /* hack warning: interpret the flags as a binary number */
1742 nat n = decode(rts_argv[arg]+3);
1743 set_GranSim_debug_options(n);
1746 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1747 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1750 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1751 debugBelch("Valid GranSim debug options are:\n");
1752 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1753 bad_option( rts_argv[arg] );
1754 } else { // flag found; now set it
1755 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1761 case 'e': /* event trace; also -bD1 */
1762 debugBelch("DEBUG: event_trace; printing event trace.\n");
1763 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1764 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1767 case 'E': /* event statistics; also -bD2 */
1768 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1769 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1770 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1773 case 'f': /* thunkStealing; also -bD4 */
1774 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1775 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1776 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1779 case 'z': /* blockOnFetch; also -bD8 */
1780 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1781 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1782 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1785 case 't': /* blockOnFetch_sanity; also -bD16 */
1786 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1787 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1788 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1791 case 'S': /* priSpark; also -bD32 */
1792 debugBelch("DEBUG: priSpark; priority sparking.\n");
1793 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1796 case 's': /* priSched; also -bD64 */
1797 debugBelch("DEBUG: priSched; priority scheduling.\n");
1798 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1801 case 'F': /* findWork; also -bD128 */
1802 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1803 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1806 case 'g': /* globalBlock; also -bD256 */
1807 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1808 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1811 case 'G': /* pack; also -bD512 */
1812 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1813 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1816 case 'P': /* packBuffer; also -bD1024 */
1817 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1818 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1821 case 'o': /* sortedQ; also -bD2048 */
1822 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1823 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1826 case 'r': /* randomSteal; also -bD4096 */
1827 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
1828 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
1831 case 'q': /* checkSparkQ; also -bD8192 */
1832 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
1833 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
1836 case ':': /* checkLight; also -bD16384 */
1837 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
1838 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
1841 case 'b': /* bq; also -bD32768 */
1842 debugBelch("DEBUG: bq; check blocking queues\n");
1843 RtsFlags.GranFlags.Debug.bq = rtsTrue;
1846 case 'd': /* all options turned on */
1847 debugBelch("DEBUG: all options turned on.\n");
1848 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1849 /* RtsFlags.GranFlags.Debug |= 0x40; */
1853 /* RtsFlags.GranFlags.Debug = 1; */
1859 # endif /* GRAN_CHECK */
1861 bad_option( rts_argv[arg] );
1867 Interpret n as a binary number masking GranSim debug options and set the
1868 correxponding option. See gran_debug_opts_strs for explanations of the flags.
1871 set_GranSim_debug_options(nat n) {
1874 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1876 errorBelch(gran_debug_opts_strs[i]);
1878 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
1879 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
1880 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
1881 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
1882 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
1883 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
1884 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
1885 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
1886 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
1887 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
1888 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
1889 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
1890 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
1891 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
1892 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
1893 default: barf("set_GranSim_debug_options: only %d debug options expected");
1899 Print one line explanation for each of the GranSim debug options specified
1903 help_GranSim_debug_options(nat n) {
1906 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1908 debugBelch(gran_debug_opts_strs[i]);
1914 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1917 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
1918 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
1922 /* Communication and task creation cost parameters */
1923 switch(rts_argv[arg][2]) {
1924 case 'e': /* -qe<n> ... allow <n> local sparks */
1925 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
1926 RtsFlags.ParFlags.maxLocalSparks
1927 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1929 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1930 errorBelch("setupRtsFlags: bad value for -e\n");
1934 IF_PAR_DEBUG(verbose,
1935 errorBelch("-qe<n>: max %d local sparks",
1936 RtsFlags.ParFlags.maxLocalSparks));
1940 if (rts_argv[arg][3] != '\0') {
1941 RtsFlags.ParFlags.maxThreads
1942 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1944 errorBelch("missing size for -qt\n");
1947 IF_PAR_DEBUG(verbose,
1948 errorBelch("-qt<n>: max %d threads",
1949 RtsFlags.ParFlags.maxThreads));
1953 if (rts_argv[arg][3] != '\0')
1954 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
1956 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
1958 IF_PAR_DEBUG(verbose,
1959 errorBelch("-qf<n>: max %d fishes sent out at one time",
1960 RtsFlags.ParFlags.maxFishes));
1964 if (rts_argv[arg][3] != '\0') {
1965 RtsFlags.ParFlags.fishDelay
1966 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1968 errorBelch("missing fish delay time for -qF\n");
1971 IF_PAR_DEBUG(verbose,
1972 errorBelch("-qF<n>: fish delay time %d us",
1973 RtsFlags.ParFlags.fishDelay));
1977 RtsFlags.ParFlags.outputDisabled = rtsTrue;
1978 IF_PAR_DEBUG(verbose,
1979 errorBelch("-qO: output disabled"));
1982 case 'g': /* -qg<n> ... globalisation scheme */
1983 if (rts_argv[arg][3] != '\0') {
1984 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
1986 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
1989 IF_PAR_DEBUG(verbose,
1990 debugBelch("-qg<n>: globalisation scheme set to %d",
1991 RtsFlags.ParFlags.globalising));
1994 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
1995 if (rts_argv[arg][3] != '\0') {
1996 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
1998 errorBelch("missing number of thunks per packet (for -qh)\n");
2001 IF_PAR_DEBUG(verbose,
2002 debugBelch("-qh<n>: thunks per packet set to %d",
2003 RtsFlags.ParFlags.thunksToPack));
2006 case 'P': /* -qP for writing a log file */
2007 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2008 /* same encoding as in GranSim after -bP */
2009 switch(rts_argv[arg][3]) {
2010 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2011 break; // nothing special, just an ordinary profile
2012 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2013 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2015 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2017 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2019 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2021 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2024 # if defined(PAR_TICKY)
2025 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2027 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2028 stg_exit(EXIT_FAILURE);
2031 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2033 IF_PAR_DEBUG(verbose,
2034 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2035 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2038 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2039 if (rts_argv[arg][3] != '\0') {
2040 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2042 errorBelch("missing size of PackBuffer (for -qQ)\n");
2045 IF_PAR_DEBUG(verbose,
2046 debugBelch("-qQ<n>: pack buffer size set to %d",
2047 RtsFlags.ParFlags.packBufferSize));
2051 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2052 IF_PAR_DEBUG(verbose,
2053 debugBelch("-qR: fair-ish scheduling"));
2058 if (rts_argv[arg][3] != '\0') {
2059 RtsFlags.ParFlags.wait
2060 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2062 RtsFlags.ParFlags.wait = 1000;
2064 IF_PAR_DEBUG(verbose,
2065 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2066 RtsFlags.ParFlags.wait));
2069 case 'D': /* -qD ... all the debugging options */
2070 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2071 /* hack warning: interpret the flags as a binary number */
2072 nat n = decode(rts_argv[arg]+3);
2073 set_par_debug_options(n);
2076 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2077 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2080 if (i==MAX_PAR_DEBUG_OPTION+1) {
2081 errorBelch("Valid GUM debug options are:\n");
2082 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2083 bad_option( rts_argv[arg] );
2084 } else { // flag found; now set it
2085 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2091 errorBelch("Unknown option -q%c (%d opts in total)",
2092 rts_argv[arg][2], *rts_argc);
2098 Interpret n as a binary number masking Par debug options and set the
2099 correxponding option. See par_debug_opts_strs for explanations of the flags.
2102 set_par_debug_options(nat n) {
2105 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2107 debugBelch(par_debug_opts_strs[i]);
2109 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2110 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2111 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2112 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2113 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2114 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2115 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2116 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2117 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2118 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2119 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2120 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2121 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2122 default: barf("set_par_debug_options: only %d debug options expected",
2123 MAX_PAR_DEBUG_OPTION);
2129 Print one line explanation for each of the GranSim debug options specified
2133 help_par_debug_options(nat n) {
2136 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2138 debugBelch(par_debug_opts_strs[i]);
2143 //@node Aux fcts, , GranSim specific options
2144 //@subsection Aux fcts
2147 stats_fprintf(FILE *f, char *s, ...)
2159 static int /* return -1 on error */
2162 int argc, char *argv[],
2163 int rts_argc, char *rts_argv[],
2164 const char *FILENAME_FMT,
2169 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2170 f = NULL; /* NULL means use debugBelch */
2172 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2173 f = fopen(rts_argv[arg]+2,"w");
2175 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2176 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2177 f = fopen(stats_filename,"w");
2180 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2187 /* Write argv and rtsv into start of stats file */
2189 for(count = 0; count < argc; count++) {
2190 stats_fprintf(f, "%s ", argv[count]);
2192 stats_fprintf(f, "+RTS ");
2193 for(count = 0; count < rts_argc; count++)
2194 stats_fprintf(f, "%s ", rts_argv[count]);
2195 stats_fprintf(f, "\n");
2203 decode(const char *s)
2214 if (c == 'g' || c == 'G')
2215 m *= 1000*1000*1000; /* UNchecked! */
2216 else if (c == 'm' || c == 'M')
2217 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2218 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2219 m *= 1000; /* a direct-mapped cache. */
2220 else if (c == 'w' || c == 'W')
2227 bad_option(const char *s)
2229 errorBelch("bad RTS option: %s", s);
2230 stg_exit(EXIT_FAILURE);
2233 /* -----------------------------------------------------------------------------
2234 Getting/Setting the program's arguments.
2236 These are used by System.Environment, and parts of the RTS.
2237 -------------------------------------------------------------------------- */
2240 setProgName(char *argv[])
2242 /* Remove directory from argv[0] -- default files in current directory */
2243 #if !defined(mingw32_HOST_OS)
2245 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2246 prog_name = last_slash+1;
2248 prog_name = argv[0];
2251 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2252 while ( last_slash > argv[0] ) {
2253 if ( *last_slash == '/' || *last_slash == '\\' ) {
2254 prog_name = last_slash+1;
2259 prog_name = argv[0];
2264 getProgArgv(int *argc, char **argv[])
2266 if (argc) { *argc = prog_argc; }
2267 if (argv) { *argv = prog_argv; }
2271 setProgArgv(int argc, char *argv[])
2273 /* Usually this is done by startupHaskell, so we don't need to call this.
2274 However, sometimes Hugs wants to change the arguments which Haskell
2275 getArgs >>= ... will be fed. So you can do that by calling here
2276 _after_ calling startupHaskell.
2280 setProgName(prog_argv);