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;
170 #if defined(PROFILING) || defined(PAR)
171 RtsFlags.CcFlags.doCostCentres = 0;
172 #endif /* PROFILING or PAR */
175 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
176 RtsFlags.ProfFlags.profileInterval = 100;
177 RtsFlags.ProfFlags.includeTSOs = rtsFalse;
178 RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
179 RtsFlags.ProfFlags.maxRetainerSetSize = 8;
180 RtsFlags.ProfFlags.modSelector = NULL;
181 RtsFlags.ProfFlags.descrSelector = NULL;
182 RtsFlags.ProfFlags.typeSelector = NULL;
183 RtsFlags.ProfFlags.ccSelector = NULL;
184 RtsFlags.ProfFlags.ccsSelector = NULL;
185 RtsFlags.ProfFlags.retainerSelector = NULL;
186 RtsFlags.ProfFlags.bioSelector = NULL;
189 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
192 RtsFlags.MiscFlags.tickInterval = 50; /* In milliseconds */
193 RtsFlags.ConcFlags.ctxtSwitchTime = 50; /* In milliseconds */
196 RtsFlags.ParFlags.nNodes = 1;
197 RtsFlags.ParFlags.migrate = rtsTrue;
198 RtsFlags.ParFlags.wakeupMigrate = rtsFalse;
202 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
203 RtsFlags.ParFlags.ParStats.Suppressed = rtsFalse;
204 RtsFlags.ParFlags.ParStats.Binary = rtsFalse;
205 RtsFlags.ParFlags.ParStats.Sparks = rtsFalse;
206 RtsFlags.ParFlags.ParStats.Heap = rtsFalse;
207 RtsFlags.ParFlags.ParStats.NewLogfile = rtsFalse;
208 RtsFlags.ParFlags.ParStats.Global = rtsFalse;
210 RtsFlags.ParFlags.outputDisabled = rtsFalse;
212 RtsFlags.ParFlags.doFairScheduling = rtsTrue; /* fair sched by def */
214 RtsFlags.ParFlags.doFairScheduling = rtsFalse; /* unfair sched by def */
216 RtsFlags.ParFlags.packBufferSize = 1024;
217 RtsFlags.ParFlags.thunksToPack = 1; /* 0 ... infinity; */
218 RtsFlags.ParFlags.globalising = 1; /* 0 ... everything */
219 RtsFlags.ParFlags.maxThreads = 1024;
220 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
221 RtsFlags.ParFlags.fishDelay = FISH_DELAY;
224 #if defined(PAR) || defined(THREADED_RTS)
225 RtsFlags.ParFlags.maxLocalSparks = 4096;
226 #endif /* PAR || THREADED_RTS */
229 /* ToDo: check defaults for GranSim and GUM */
230 RtsFlags.GcFlags.maxStkSize = (8 * 1024 * 1024) / sizeof(W_);
231 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
233 RtsFlags.GranFlags.maxThreads = 65536; // refers to mandatory threads
234 RtsFlags.GranFlags.GranSimStats.Full = rtsFalse;
235 RtsFlags.GranFlags.GranSimStats.Suppressed = rtsFalse;
236 RtsFlags.GranFlags.GranSimStats.Binary = rtsFalse;
237 RtsFlags.GranFlags.GranSimStats.Sparks = rtsFalse;
238 RtsFlags.GranFlags.GranSimStats.Heap = rtsFalse;
239 RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsFalse;
240 RtsFlags.GranFlags.GranSimStats.Global = rtsFalse;
242 RtsFlags.GranFlags.packBufferSize = 1024;
243 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
245 RtsFlags.GranFlags.proc = MAX_PROC;
246 RtsFlags.GranFlags.Fishing = rtsFalse;
247 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
248 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
249 RtsFlags.GranFlags.Light = rtsFalse;
251 RtsFlags.GranFlags.Costs.latency = LATENCY;
252 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
253 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
254 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
255 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
256 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
257 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
258 RtsFlags.GranFlags.Costs.mtidytime = MSGTIDYTIME;
260 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
261 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
262 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
263 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
264 RtsFlags.GranFlags.Costs.threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
266 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
267 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
268 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
269 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
270 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
272 RtsFlags.GranFlags.Costs.heapalloc_cost = HEAPALLOC_COST;
274 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
275 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
277 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
278 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
279 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
280 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
281 RtsFlags.GranFlags.DoBulkFetching = rtsFalse;
282 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
283 RtsFlags.GranFlags.FetchStrategy = 2;
284 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
285 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
286 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
287 RtsFlags.GranFlags.SparkPriority = 0;
288 RtsFlags.GranFlags.SparkPriority2 = 0;
289 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
290 RtsFlags.GranFlags.InversePriorities = rtsFalse;
291 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
292 RtsFlags.GranFlags.ThunksToPack = 0;
293 RtsFlags.GranFlags.RandomSteal = rtsTrue;
297 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
298 RtsFlags.TickyFlags.tickyFile = NULL;
301 RtsFlags.TraceFlags.timestamp = rtsFalse;
302 RtsFlags.TraceFlags.sched = rtsFalse;
308 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
310 " +RTS Indicates run time system options follow",
311 " -RTS Indicates program arguments follow",
312 " --RTS Indicates that ALL subsequent arguments will be given to the",
313 " program (including any of these RTS flags)",
315 "The following run time system options are available:",
317 " -? Prints this message and exits; the program is not executed",
319 " -K<size> Sets the maximum stack size (default 8M) Egs: -K32k -K512k",
320 " -k<size> Sets the initial thread stack size (default 1k) Egs: -k4k -k2m",
322 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
323 " -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
324 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
325 " -m<n> Minimum % of heap which must be available (default 3%)",
326 " -G<n> Number of generations (default: 2)",
327 " -T<n> Number of steps in younger generations (default: 2)",
328 " -c<n> Auto-enable compaction of the oldest generation when live data is",
329 " at least <n>% of the maximum heap size set with -M (default: 30%)",
330 " -c Enable compaction for all major collections",
331 #if defined(THREADED_RTS)
332 " -I<sec> Perform full GC after <sec> idle time (default: 0.3, 0 == off)",
335 " -t<file> One-line GC statistics (default file: <program>.stat)",
336 " -s<file> Summary GC statistics (with -Sstderr going to stderr)",
337 " -S<file> Detailed GC statistics",
338 #ifdef RTS_GTK_FRONTPANEL
339 " -f Display front panel (requires X11 & GTK+)",
343 " -Z Don't squeeze out update frames on stack overflow",
344 " -B Sound the bell at the start of each garbage collection",
345 #if defined(PROFILING) || defined(PAR)
347 " -px Time/allocation profile (XML) (output file <program>.prof)",
348 " -p Time/allocation profile (output file <program>.prof)",
349 " -P More detailed Time/Allocation profile",
350 " -Pa Give information about *all* cost centres",
352 # if defined(PROFILING)
354 " -hx Heap residency profile (XML) (output file <program>.prof)",
355 " -h<break-down> Heap residency profile (hp2ps) (output file <program>.hp)",
356 " break-down: c = cost centre stack (default)",
358 " d = closure description",
359 " y = type description",
361 " b = biography (LAG,DRAG,VOID,USE)",
362 " A subset of closures may be selected thusly:",
363 " -hc<cc>,... specific cost centre(s) (top of stack only)",
364 " -hC<cc>,... specific cost centre(s) (anywhere in stack)",
365 " -hm<mod>... all cost centres from the specified modules(s)",
366 " -hd<des>,... closures with specified closure descriptions",
367 " -hy<typ>... closures with specified type descriptions",
368 " -hr<cc>... closures with specified retainers",
369 " -hb<bio>... closures with specified biographies (lag,drag,void,use)",
371 " -R<size> Set the maximum retainer set size (default: 8)",
373 " -i<sec> Time between heap samples (seconds, default: 0.1)",
375 " -xt Include threads (TSOs) in a heap profile",
377 " -xc Show current cost centre stack on raising an exception",
379 #endif /* PROFILING or PAR */
380 #if !defined(PROFILING) && defined(DEBUG)
382 " -h<break-down> Debugging Heap residency profile",
383 " (output file <program>.hp)",
384 " break-down: L = closure label (default)",
385 " T = closure type (constructor, thunk etc.)",
388 #if defined(TICKY_TICKY)
389 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
393 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
394 /* NB: the -N<n> is implemented by the driver!! */
396 " -C<secs> Context-switch interval in seconds.",
397 " 0 or no argument means switch as often as possible.",
398 " Default: 0.02 sec; resolution is set by -V below.",
399 " -V<secs> Master tick interval in seconds.",
400 " This sets the resolution for -C and the profile timer -i.",
401 " Default: 0.02 sec.",
403 " -vs Trace scheduler events (see also -Ds with -debug)",
404 " -vt Time-stamp trace messages",
407 " -Ds DEBUG: scheduler",
408 " -Di DEBUG: interpreter",
410 " -DG DEBUG: gccafs",
413 " -DS DEBUG: sanity",
414 " -Dt DEBUG: stable",
418 " -Dl DEBUG: linker",
420 " -Dz DEBUG: stack squezing",
423 #if defined(THREADED_RTS) && !defined(NOSMP)
424 " -N<n> Use <n> OS threads (default: 1)",
425 " -qm Don't automatically migrate threads between CPUs",
426 " -qw Migrate a thread to the current CPU when it is woken up",
428 #if defined(THREADED_RTS) || defined(PAR)
429 " -e<size> Size of spark pools (default 100)",
432 " -t<num> Set maximum number of advisory threads per PE (default 32)",
433 " -qP Enable activity profile (output files in ~/<program>*.gr)",
434 " -qQ<size> Set pack-buffer size (default: 1024)",
435 " -qd Turn on PVM-ish debugging",
436 " -qO Disable output for performance measurement",
438 #if defined(THREADED_RTS) || defined(PAR)
439 " -e<n> Maximum number of outstanding local sparks (default: 4096)",
442 " -d Turn on PVM-ish debugging",
443 " -O Disable output for performance measurement",
445 #if defined(GRAN) /* ToDo: fill in decent Docu here */
446 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
449 "RTS options may also be specified using the GHCRTS environment variable.",
451 "Other RTS options may be available for programs compiled a different way.",
452 "The GHC User's Guide has full details.",
457 STATIC_INLINE rtsBool
458 strequal(const char *a, const char * b)
460 return(strcmp(a, b) == 0);
464 splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
470 while (isspace(*c1)) { c1++; };
472 while (!isspace(*c2) && *c2 != '\0') { c2++; };
474 if (c1 == c2) { break; }
476 if (*rts_argc < MAX_RTS_ARGS-1) {
477 s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
478 strncpy(s, c1, c2-c1);
480 rts_argv[(*rts_argc)++] = s;
482 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
486 } while (*c1 != '\0');
490 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
492 rtsBool error = rtsFalse;
503 // process arguments from the ghc_rts_opts global variable first.
504 // (arguments from the GHCRTS environment variable and the command
505 // line override these).
507 if (ghc_rts_opts != NULL) {
508 splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
512 // process arguments from the GHCRTS environment variable next
513 // (arguments from the command line override these).
515 char *ghc_rts = getenv("GHCRTS");
517 if (ghc_rts != NULL) {
518 splitRtsFlags(ghc_rts, rts_argc, rts_argv);
522 // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
523 // argv[0] must be PGM argument -- leave in argv
525 for (mode = PGM; arg < total_arg; arg++) {
526 // The '--RTS' argument disables all future +RTS ... -RTS processing.
527 if (strequal("--RTS", argv[arg])) {
531 // The '--' argument is passed through to the program, but
532 // disables all further +RTS ... -RTS processing.
533 else if (strequal("--", argv[arg])) {
536 else if (strequal("+RTS", argv[arg])) {
539 else if (strequal("-RTS", argv[arg])) {
542 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
543 rts_argv[(*rts_argc)++] = argv[arg];
545 else if (mode == PGM) {
546 argv[(*argc)++] = argv[arg];
549 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
552 // process remaining program arguments
553 for (; arg < total_arg; arg++) {
554 argv[(*argc)++] = argv[arg];
556 argv[*argc] = (char *) 0;
557 rts_argv[*rts_argc] = (char *) 0;
559 // Process RTS (rts_argv) part: mainly to determine statsfile
560 for (arg = 0; arg < *rts_argc; arg++) {
561 if (rts_argv[arg][0] != '-') {
563 errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
567 switch(rts_argv[arg][1]) {
569 /* process: general args, then PROFILING-only ones,
570 then CONCURRENT-only, PARallel-only, GRAN-only,
571 TICKY-only (same order as defined in RtsFlags.lh);
572 within those groups, mostly in case-insensitive
574 Final group is x*, which allows for more options.
578 # define TICKY_BUILD_ONLY(x) x
580 # define TICKY_BUILD_ONLY(x) \
581 errorBelch("not built for: ticky-ticky stats"); \
585 #if defined(PROFILING)
586 # define COST_CENTRE_USING_BUILD_ONLY(x) x
588 # define COST_CENTRE_USING_BUILD_ONLY(x) \
589 errorBelch("not built for: -prof or -parallel"); \
594 # define PROFILING_BUILD_ONLY(x) x
596 # define PROFILING_BUILD_ONLY(x) \
597 errorBelch("not built for: -prof"); \
602 # define PAR_BUILD_ONLY(x) x
604 # define PAR_BUILD_ONLY(x) \
605 errorBelch("not built for: -parallel"); \
610 # define THREADED_BUILD_ONLY(x) x
612 # define THREADED_BUILD_ONLY(x) \
613 errorBelch("not built for: -smp"); \
617 #if defined(THREADED_RTS) || defined(PAR)
618 # define PAR_OR_THREADED_BUILD_ONLY(x) x
620 # define PAR_OR_THREADED_BUILD_ONLY(x) \
621 errorBelch("not built for: -parallel or -smp"); \
626 # define GRAN_BUILD_ONLY(x) x
628 # define GRAN_BUILD_ONLY(x) \
629 errorBelch("not built for: -gransim"); \
633 /* =========== GENERAL ========================== */
639 RtsFlags.GcFlags.minAllocAreaSize
640 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
641 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
642 bad_option(rts_argv[arg]);
647 RtsFlags.GcFlags.ringBell = rtsTrue;
651 if (rts_argv[arg][2] != '\0') {
652 RtsFlags.GcFlags.compactThreshold =
653 atof(rts_argv[arg]+2);
655 RtsFlags.GcFlags.compact = rtsTrue;
660 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
662 if (RtsFlags.GcFlags.oldGenFactor < 0)
663 bad_option( rts_argv[arg] );
671 for (c = rts_argv[arg] + 2; *c != '\0'; c++) {
674 RtsFlags.DebugFlags.scheduler = rtsTrue;
677 RtsFlags.DebugFlags.interpreter = rtsTrue;
680 RtsFlags.DebugFlags.weak = rtsTrue;
683 RtsFlags.DebugFlags.gccafs = rtsTrue;
686 RtsFlags.DebugFlags.gc = rtsTrue;
689 RtsFlags.DebugFlags.block_alloc = rtsTrue;
692 RtsFlags.DebugFlags.sanity = rtsTrue;
695 RtsFlags.DebugFlags.stable = rtsTrue;
698 RtsFlags.DebugFlags.prof = rtsTrue;
701 RtsFlags.DebugFlags.gran = rtsTrue;
704 RtsFlags.DebugFlags.par = rtsTrue;
707 RtsFlags.DebugFlags.linker = rtsTrue;
710 RtsFlags.DebugFlags.apply = rtsTrue;
713 RtsFlags.DebugFlags.stm = rtsTrue;
716 RtsFlags.DebugFlags.squeeze = rtsTrue;
719 bad_option( rts_argv[arg] );
727 RtsFlags.GcFlags.maxStkSize =
728 decode(rts_argv[arg]+2) / sizeof(W_);
730 if (RtsFlags.GcFlags.maxStkSize == 0)
731 bad_option( rts_argv[arg] );
735 RtsFlags.GcFlags.initialStkSize =
736 decode(rts_argv[arg]+2) / sizeof(W_);
738 if (RtsFlags.GcFlags.initialStkSize == 0)
739 bad_option( rts_argv[arg] );
743 RtsFlags.GcFlags.maxHeapSize =
744 decode(rts_argv[arg]+2) / BLOCK_SIZE;
745 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
747 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
748 bad_option(rts_argv[arg]);
753 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
755 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
756 RtsFlags.GcFlags.pcFreeHeap > 100)
757 bad_option( rts_argv[arg] );
761 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
762 if (RtsFlags.GcFlags.generations < 1) {
763 bad_option(rts_argv[arg]);
768 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
769 if (RtsFlags.GcFlags.steps < 1) {
770 bad_option(rts_argv[arg]);
775 RtsFlags.GcFlags.heapSizeSuggestion =
776 decode(rts_argv[arg]+2) / BLOCK_SIZE;
778 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
779 bad_option(rts_argv[arg]);
783 #ifdef RTS_GTK_FRONTPANEL
785 RtsFlags.GcFlags.frontpanel = rtsTrue;
789 case 'I': /* idle GC delay */
790 if (rts_argv[arg][2] == '\0') {
795 /* Convert to millisecs */
796 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
797 RtsFlags.GcFlags.idleGCDelayTime = cst;
802 RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
806 RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
810 RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
815 /* Opening all those files would almost certainly fail... */
816 // RtsFlags.ParFlags.ParStats.Full = rtsTrue;
817 RtsFlags.GcFlags.statsFile = NULL; /* temporary; ToDo: rm */
821 r = open_stats_file(arg, *argc, argv,
822 *rts_argc, rts_argv, STAT_FILENAME_FMT,
823 &RtsFlags.GcFlags.statsFile);
824 if (r == -1) { error = rtsTrue; }
830 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
833 /* =========== PROFILING ========================== */
835 case 'P': /* detailed cost centre profiling (time/alloc) */
836 case 'p': /* cost centre profiling (time/alloc) */
837 COST_CENTRE_USING_BUILD_ONLY(
838 switch (rts_argv[arg][2]) {
840 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
843 RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
846 if (rts_argv[arg][1] == 'P') {
847 RtsFlags.CcFlags.doCostCentres =
848 COST_CENTRES_VERBOSE;
850 RtsFlags.CcFlags.doCostCentres =
851 COST_CENTRES_SUMMARY;
858 PROFILING_BUILD_ONLY(
859 RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
862 case 'h': /* serial heap profile */
863 #if !defined(PROFILING) && defined(DEBUG)
864 switch (rts_argv[arg][2]) {
867 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
870 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
873 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
877 PROFILING_BUILD_ONLY(
878 switch (rts_argv[arg][2]) {
892 if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') {
894 char *left = strchr(rts_argv[arg], '{');
895 char *right = strrchr(rts_argv[arg], '}');
897 // curly braces are optional, for
902 left = rts_argv[arg] + 3;
905 right = rts_argv[arg] + strlen(rts_argv[arg]);
909 switch (rts_argv[arg][2]) {
910 case 'c': // cost centre label select
911 RtsFlags.ProfFlags.ccSelector = left;
914 RtsFlags.ProfFlags.ccsSelector = left;
917 case 'm': // cost centre module select
918 RtsFlags.ProfFlags.modSelector = left;
921 case 'd': // closure descr select
922 RtsFlags.ProfFlags.descrSelector = left;
925 case 'y': // closure type select
926 RtsFlags.ProfFlags.typeSelector = left;
929 case 'r': // retainer select
930 RtsFlags.ProfFlags.retainerSelector = left;
933 case 'b': // biography select
934 RtsFlags.ProfFlags.bioSelector = left;
941 if (RtsFlags.ProfFlags.doHeapProfile != 0) {
942 errorBelch("multiple heap profile options");
947 switch (rts_argv[arg][2]) {
951 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS;
955 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
959 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
963 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
967 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER;
971 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV;
977 errorBelch("invalid heap profile option: %s",rts_argv[arg]);
981 #endif /* PROFILING */
984 #if defined(PROFILING)
985 case 'i': /* heap sample interval */
986 if (rts_argv[arg][2] == '\0') {
991 /* Convert to milliseconds */
992 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
993 RtsFlags.ProfFlags.profileInterval = cst;
998 /* =========== CONCURRENT ========================= */
999 case 'C': /* context switch interval */
1000 if (rts_argv[arg][2] == '\0')
1001 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
1005 /* Convert to milliseconds */
1006 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1007 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
1011 case 'V': /* master tick interval */
1012 if (rts_argv[arg][2] == '\0') {
1013 // turns off ticks completely
1014 RtsFlags.MiscFlags.tickInterval = 0;
1018 /* Convert to milliseconds */
1019 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
1020 RtsFlags.MiscFlags.tickInterval = cst;
1024 #if defined(THREADED_RTS) && !defined(NOSMP)
1026 THREADED_BUILD_ONLY(
1027 if (rts_argv[arg][2] != '\0') {
1028 RtsFlags.ParFlags.nNodes
1029 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1030 if (RtsFlags.ParFlags.nNodes <= 0) {
1031 errorBelch("bad value for -N");
1038 switch (rts_argv[arg][2]) {
1040 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1044 RtsFlags.ParFlags.migrate = rtsFalse;
1047 RtsFlags.ParFlags.wakeupMigrate = rtsTrue;
1050 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1056 /* =========== PARALLEL =========================== */
1058 PAR_OR_THREADED_BUILD_ONLY(
1059 if (rts_argv[arg][2] != '\0') {
1060 RtsFlags.ParFlags.maxLocalSparks
1061 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
1062 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1063 errorBelch("bad value for -e");
1072 process_par_option(arg, rts_argc, rts_argv, &error);
1076 /* =========== GRAN =============================== */
1080 process_gran_option(arg, rts_argc, rts_argv, &error);
1083 /* =========== TICKY ============================== */
1085 case 'r': /* Basic profiling stats */
1088 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
1092 r = open_stats_file(arg, *argc, argv,
1093 *rts_argc, rts_argv, TICKY_FILENAME_FMT,
1094 &RtsFlags.TickyFlags.tickyFile);
1095 if (r == -1) { error = rtsTrue; }
1099 /* =========== TRACING ---------=================== */
1102 switch(rts_argv[arg][2]) {
1104 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1108 RtsFlags.TraceFlags.timestamp = rtsTrue;
1111 RtsFlags.TraceFlags.sched = rtsTrue;
1114 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1120 /* =========== EXTENDED OPTIONS =================== */
1122 case 'x': /* Extend the argument space */
1123 switch(rts_argv[arg][2]) {
1125 errorBelch("incomplete RTS option: %s",rts_argv[arg]);
1129 case 'c': /* Debugging tool: show current cost centre on an exception */
1130 PROFILING_BUILD_ONLY(
1131 RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
1135 case 't': /* Include memory used by TSOs in a heap profile */
1136 PROFILING_BUILD_ONLY(
1137 RtsFlags.ProfFlags.includeTSOs = rtsTrue;
1141 /* The option prefix '-xx' is reserved for future extension. KSW 1999-11. */
1144 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1148 break; /* defensive programming */
1150 /* =========== OH DEAR ============================ */
1152 errorBelch("unknown RTS option: %s",rts_argv[arg]);
1159 // Determine what tick interval we should use for the RTS timer
1160 // by taking the shortest of the various intervals that we need to
1162 if (RtsFlags.MiscFlags.tickInterval <= 0) {
1163 RtsFlags.MiscFlags.tickInterval = 50;
1166 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1167 RtsFlags.MiscFlags.tickInterval =
1168 stg_min(RtsFlags.ConcFlags.ctxtSwitchTime,
1169 RtsFlags.MiscFlags.tickInterval);
1172 if (RtsFlags.GcFlags.idleGCDelayTime > 0) {
1173 RtsFlags.MiscFlags.tickInterval =
1174 stg_min(RtsFlags.GcFlags.idleGCDelayTime,
1175 RtsFlags.MiscFlags.tickInterval);
1179 if (RtsFlags.ProfFlags.profileInterval > 0) {
1180 RtsFlags.MiscFlags.tickInterval =
1181 stg_min(RtsFlags.ProfFlags.profileInterval,
1182 RtsFlags.MiscFlags.tickInterval);
1186 if (RtsFlags.ConcFlags.ctxtSwitchTime > 0) {
1187 RtsFlags.ConcFlags.ctxtSwitchTicks =
1188 RtsFlags.ConcFlags.ctxtSwitchTime /
1189 RtsFlags.MiscFlags.tickInterval;
1191 RtsFlags.ConcFlags.ctxtSwitchTicks = 0;
1195 RtsFlags.ProfFlags.profileIntervalTicks =
1196 RtsFlags.ProfFlags.profileInterval / RtsFlags.MiscFlags.tickInterval;
1203 for (p = usage_text; *p; p++)
1204 errorBelch("%s", *p);
1205 stg_exit(EXIT_FAILURE);
1212 enable_GranSimLight(void) {
1214 debugBelch("GrAnSim Light enabled (infinite number of processors; 0 communication costs)\n");
1215 RtsFlags.GranFlags.Light=rtsTrue;
1216 RtsFlags.GranFlags.Costs.latency =
1217 RtsFlags.GranFlags.Costs.fetchtime =
1218 RtsFlags.GranFlags.Costs.additional_latency =
1219 RtsFlags.GranFlags.Costs.gunblocktime =
1220 RtsFlags.GranFlags.Costs.lunblocktime =
1221 RtsFlags.GranFlags.Costs.threadcreatetime =
1222 RtsFlags.GranFlags.Costs.threadqueuetime =
1223 RtsFlags.GranFlags.Costs.threadscheduletime =
1224 RtsFlags.GranFlags.Costs.threaddescheduletime =
1225 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1227 RtsFlags.GranFlags.Costs.mpacktime =
1228 RtsFlags.GranFlags.Costs.munpacktime = 0;
1230 RtsFlags.GranFlags.DoFairSchedule = rtsTrue;
1231 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1232 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsTrue;
1233 /* FetchStrategy is irrelevant in GrAnSim-Light */
1235 /* GrAnSim Light often creates an abundance of parallel threads,
1236 each with its own stack etc. Therefore, it's in general a good
1237 idea to use small stack chunks (use the -o<size> option to
1240 // RtsFlags.ConcFlags.stkChunkSize = 100;
1242 RtsFlags.GranFlags.proc = 1;
1246 process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1248 if (rts_argv[arg][1] != 'b') /* All GranSim options start with -b */
1251 /* or a ridiculously idealised simulator */
1252 if(strcmp((rts_argv[arg]+2),"oring")==0) {
1253 RtsFlags.GranFlags.Costs.latency =
1254 RtsFlags.GranFlags.Costs.fetchtime =
1255 RtsFlags.GranFlags.Costs.additional_latency =
1256 RtsFlags.GranFlags.Costs.gunblocktime =
1257 RtsFlags.GranFlags.Costs.lunblocktime =
1258 RtsFlags.GranFlags.Costs.threadcreatetime =
1259 RtsFlags.GranFlags.Costs.threadqueuetime =
1260 RtsFlags.GranFlags.Costs.threadscheduletime =
1261 RtsFlags.GranFlags.Costs.threaddescheduletime =
1262 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1264 RtsFlags.GranFlags.Costs.mpacktime =
1265 RtsFlags.GranFlags.Costs.munpacktime = 0;
1267 RtsFlags.GranFlags.Costs.arith_cost =
1268 RtsFlags.GranFlags.Costs.float_cost =
1269 RtsFlags.GranFlags.Costs.load_cost =
1270 RtsFlags.GranFlags.Costs.store_cost =
1271 RtsFlags.GranFlags.Costs.branch_cost = 0;
1273 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1275 /* ++RtsFlags.GranFlags.DoFairSchedule; */
1276 RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; /* -bZ */
1277 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1278 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1282 /* or a somewhat idealised simulator */
1283 if(strcmp((rts_argv[arg]+2),"onzo")==0) {
1284 RtsFlags.GranFlags.Costs.latency =
1285 RtsFlags.GranFlags.Costs.fetchtime =
1286 RtsFlags.GranFlags.Costs.additional_latency =
1287 RtsFlags.GranFlags.Costs.gunblocktime =
1288 RtsFlags.GranFlags.Costs.lunblocktime =
1289 RtsFlags.GranFlags.Costs.threadcreatetime =
1290 RtsFlags.GranFlags.Costs.threadqueuetime =
1291 RtsFlags.GranFlags.Costs.threadscheduletime =
1292 RtsFlags.GranFlags.Costs.threaddescheduletime =
1293 RtsFlags.GranFlags.Costs.threadcontextswitchtime = 0;
1295 RtsFlags.GranFlags.Costs.mpacktime =
1296 RtsFlags.GranFlags.Costs.munpacktime = 0;
1298 RtsFlags.GranFlags.Costs.heapalloc_cost = 1;
1300 /* RtsFlags.GranFlags.DoFairSchedule = rtsTrue; */ /* -b-R */
1301 /* RtsFlags.GranFlags.DoStealThreadsFirst = rtsTrue; */ /* -b-T */
1302 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue; /* -bZ */
1303 RtsFlags.GranFlags.DoThreadMigration = rtsTrue; /* -bM */
1304 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue; /* -bP */
1305 # if defined(GRAN_CHECK) && defined(GRAN)
1306 RtsFlags.GranFlags.Debug.event_stats = rtsTrue; /* print event statistics */
1311 /* Communication and task creation cost parameters */
1312 switch(rts_argv[arg][2]) {
1314 IgnoreYields = rtsTrue; // HWL HACK
1318 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1322 if (rts_argv[arg][3] != '\0')
1324 RtsFlags.GranFlags.Costs.gunblocktime =
1325 RtsFlags.GranFlags.Costs.latency = decode(rts_argv[arg]+3);
1326 RtsFlags.GranFlags.Costs.fetchtime = 2*RtsFlags.GranFlags.Costs.latency;
1329 RtsFlags.GranFlags.Costs.latency = LATENCY;
1333 if (rts_argv[arg][3] != '\0')
1334 RtsFlags.GranFlags.Costs.additional_latency = decode(rts_argv[arg]+3);
1336 RtsFlags.GranFlags.Costs.additional_latency = ADDITIONAL_LATENCY;
1340 if (rts_argv[arg][3] != '\0')
1341 RtsFlags.GranFlags.Costs.mpacktime = decode(rts_argv[arg]+3);
1343 RtsFlags.GranFlags.Costs.mpacktime = MSGPACKTIME;
1347 if (rts_argv[arg][3] != '\0')
1348 RtsFlags.GranFlags.Costs.mtidytime = decode(rts_argv[arg]+3);
1350 RtsFlags.GranFlags.Costs.mtidytime = 0;
1354 if (rts_argv[arg][3] != '\0')
1355 RtsFlags.GranFlags.Costs.munpacktime = decode(rts_argv[arg]+3);
1357 RtsFlags.GranFlags.Costs.munpacktime = MSGUNPACKTIME;
1361 if (rts_argv[arg][3] != '\0')
1362 RtsFlags.GranFlags.Costs.fetchtime = decode(rts_argv[arg]+3);
1364 RtsFlags.GranFlags.Costs.fetchtime = FETCHTIME;
1368 if (rts_argv[arg][3] != '\0')
1369 RtsFlags.GranFlags.Costs.gunblocktime = decode(rts_argv[arg]+3);
1371 RtsFlags.GranFlags.Costs.gunblocktime = GLOBALUNBLOCKTIME;
1375 if (rts_argv[arg][3] != '\0')
1376 RtsFlags.GranFlags.Costs.lunblocktime = decode(rts_argv[arg]+3);
1378 RtsFlags.GranFlags.Costs.lunblocktime = LOCALUNBLOCKTIME;
1381 /* Thread-related metrics */
1383 if (rts_argv[arg][3] != '\0')
1384 RtsFlags.GranFlags.Costs.threadcreatetime = decode(rts_argv[arg]+3);
1386 RtsFlags.GranFlags.Costs.threadcreatetime = THREADCREATETIME;
1390 if (rts_argv[arg][3] != '\0')
1391 RtsFlags.GranFlags.Costs.threadqueuetime = decode(rts_argv[arg]+3);
1393 RtsFlags.GranFlags.Costs.threadqueuetime = THREADQUEUETIME;
1397 if (rts_argv[arg][3] != '\0')
1398 RtsFlags.GranFlags.Costs.threadscheduletime = decode(rts_argv[arg]+3);
1400 RtsFlags.GranFlags.Costs.threadscheduletime = THREADSCHEDULETIME;
1402 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1403 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1407 if (rts_argv[arg][3] != '\0')
1408 RtsFlags.GranFlags.Costs.threaddescheduletime = decode(rts_argv[arg]+3);
1410 RtsFlags.GranFlags.Costs.threaddescheduletime = THREADDESCHEDULETIME;
1412 RtsFlags.GranFlags.Costs.threadcontextswitchtime = RtsFlags.GranFlags.Costs.threadscheduletime
1413 + RtsFlags.GranFlags.Costs.threaddescheduletime;
1416 /* Instruction Cost Metrics */
1418 if (rts_argv[arg][3] != '\0')
1419 RtsFlags.GranFlags.Costs.arith_cost = decode(rts_argv[arg]+3);
1421 RtsFlags.GranFlags.Costs.arith_cost = ARITH_COST;
1425 if (rts_argv[arg][3] != '\0')
1426 RtsFlags.GranFlags.Costs.float_cost = decode(rts_argv[arg]+3);
1428 RtsFlags.GranFlags.Costs.float_cost = FLOAT_COST;
1432 if (rts_argv[arg][3] != '\0')
1433 RtsFlags.GranFlags.Costs.branch_cost = decode(rts_argv[arg]+3);
1435 RtsFlags.GranFlags.Costs.branch_cost = BRANCH_COST;
1439 if (rts_argv[arg][3] != '\0')
1440 RtsFlags.GranFlags.Costs.load_cost = decode(rts_argv[arg]+3);
1442 RtsFlags.GranFlags.Costs.load_cost = LOAD_COST;
1446 if (rts_argv[arg][3] != '\0')
1447 RtsFlags.GranFlags.Costs.store_cost = decode(rts_argv[arg]+3);
1449 RtsFlags.GranFlags.Costs.store_cost = STORE_COST;
1453 if (rts_argv[arg][3] != '\0')
1454 RtsFlags.GranFlags.Costs.heapalloc_cost = decode(rts_argv[arg]+3);
1456 RtsFlags.GranFlags.Costs.heapalloc_cost = 0;
1460 RtsFlags.GranFlags.DoAsyncFetch = rtsTrue;
1461 if (rts_argv[arg][3] != '\0')
1462 RtsFlags.GranFlags.FetchStrategy = decode(rts_argv[arg]+3);
1464 RtsFlags.GranFlags.FetchStrategy = 2;
1465 if (RtsFlags.GranFlags.FetchStrategy == 0)
1466 RtsFlags.GranFlags.DoAsyncFetch = rtsFalse;
1469 case 'K': /* sort overhead (per elem in spark list) */
1470 if (rts_argv[arg][3] != '\0')
1471 RtsFlags.GranFlags.Costs.pri_spark_overhead = decode(rts_argv[arg]+3);
1473 RtsFlags.GranFlags.Costs.pri_spark_overhead = PRI_SPARK_OVERHEAD;
1474 debugBelch("Overhead for pri spark: %d (per elem).\n",
1475 RtsFlags.GranFlags.Costs.pri_spark_overhead);
1478 case 'O': /* sort overhead (per elem in spark list) */
1479 if (rts_argv[arg][3] != '\0')
1480 RtsFlags.GranFlags.Costs.pri_sched_overhead = decode(rts_argv[arg]+3);
1482 RtsFlags.GranFlags.Costs.pri_sched_overhead = PRI_SCHED_OVERHEAD;
1483 debugBelch("Overhead for pri sched: %d (per elem).\n",
1484 RtsFlags.GranFlags.Costs.pri_sched_overhead);
1487 /* General Parameters */
1489 if (rts_argv[arg][3] != '\0')
1491 RtsFlags.GranFlags.proc = decode(rts_argv[arg]+3);
1492 if (RtsFlags.GranFlags.proc==0) {
1493 enable_GranSimLight(); /* set flags for GrAnSim-Light mode */
1494 } else if (RtsFlags.GranFlags.proc > MAX_PROC ||
1495 RtsFlags.GranFlags.proc < 1)
1497 debugBelch("setupRtsFlags: no more than %u processors allowed\n",
1503 RtsFlags.GranFlags.proc = MAX_PROC;
1507 RtsFlags.GranFlags.Fishing = rtsTrue;
1508 if (rts_argv[arg][3] != '\0')
1509 RtsFlags.GranFlags.maxFishes = decode(rts_argv[arg]+3);
1511 RtsFlags.GranFlags.maxFishes = MAX_FISHES;
1515 if (rts_argv[arg][3] != '\0')
1516 RtsFlags.GranFlags.time_slice = decode(rts_argv[arg]+3);
1518 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
1522 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsTrue;
1523 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1527 debugBelch("Bulk fetching enabled.\n");
1528 RtsFlags.GranFlags.DoBulkFetching=rtsTrue;
1532 debugBelch("Thread migration enabled.\n");
1533 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1537 debugBelch("Fair Scheduling enabled.\n");
1538 RtsFlags.GranFlags.DoFairSchedule=rtsTrue;
1542 debugBelch("Priority Scheduling enabled.\n");
1543 RtsFlags.GranFlags.DoPriorityScheduling=rtsTrue;
1547 RtsFlags.GranFlags.DoStealThreadsFirst=rtsTrue;
1548 RtsFlags.GranFlags.DoThreadMigration=rtsTrue;
1552 RtsFlags.GranFlags.DoAsyncFetch=rtsTrue;
1556 /* RtsFlags.GranFlags.SimplifiedFetch=rtsTrue; */
1560 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsTrue;
1564 RtsFlags.GranFlags.GranSimStats.Binary=rtsTrue;
1568 /* format is -bP<c> where <c> is one char describing kind of profile */
1569 RtsFlags.GranFlags.GranSimStats.Full = rtsTrue;
1570 switch(rts_argv[arg][3]) {
1571 case '\0': break; // nothing special, just an ordinary profile
1572 case '0': RtsFlags.GranFlags.GranSimStats.Suppressed = rtsTrue;
1574 case 'b': RtsFlags.GranFlags.GranSimStats.Binary = rtsTrue;
1576 case 's': RtsFlags.GranFlags.GranSimStats.Sparks = rtsTrue;
1578 case 'h': RtsFlags.GranFlags.GranSimStats.Heap = rtsTrue;
1580 case 'n': RtsFlags.GranFlags.GranSimStats.NewLogfile = rtsTrue;
1582 case 'g': RtsFlags.GranFlags.GranSimStats.Global = rtsTrue;
1584 default: barf("Unknown option -bP%c", rts_argv[arg][3]);
1589 RtsFlags.GranFlags.GranSimStats.Sparks=rtsTrue;
1593 RtsFlags.GranFlags.GranSimStats.Heap=rtsTrue;
1596 case 'Y': /* syntax: -bY<n>[,<n>] n ... pos int */
1597 if (rts_argv[arg][3] != '\0') {
1600 arg0 = rts_argv[arg]+3;
1601 if ((tmp = strstr(arg0,","))==NULL) {
1602 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1603 debugBelch("SparkPriority: %u.\n",RtsFlags.GranFlags.SparkPriority);
1606 RtsFlags.GranFlags.SparkPriority = decode(arg0);
1607 RtsFlags.GranFlags.SparkPriority2 = decode(tmp);
1608 debugBelch("SparkPriority: %u.\n",
1609 RtsFlags.GranFlags.SparkPriority);
1610 debugBelch("SparkPriority2:%u.\n",
1611 RtsFlags.GranFlags.SparkPriority2);
1612 if (RtsFlags.GranFlags.SparkPriority2 <
1613 RtsFlags.GranFlags.SparkPriority) {
1614 debugBelch("WARNING: 2nd pri < main pri (%u<%u); 2nd pri has no effect\n",
1615 RtsFlags.GranFlags.SparkPriority2,
1616 RtsFlags.GranFlags.SparkPriority);
1620 /* plain pri spark is now invoked with -bX
1621 RtsFlags.GranFlags.DoPrioritySparking = 1;
1622 debugBelch("PrioritySparking.\n");
1628 if (rts_argv[arg][3] != '\0') {
1629 RtsFlags.GranFlags.ThunksToPack = decode(rts_argv[arg]+3);
1631 RtsFlags.GranFlags.ThunksToPack = 1;
1633 debugBelch("Thunks To Pack in one packet: %u.\n",
1634 RtsFlags.GranFlags.ThunksToPack);
1638 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1639 debugBelch("Deterministic mode (no random stealing)\n");
1642 /* The following class of options contains eXperimental */
1643 /* features in connection with exploiting granularity */
1644 /* information. I.e. if -bY is chosen these options */
1645 /* tell the RTS what to do with the supplied info --HWL */
1648 if (rts_argv[arg][3] != '\0') {
1649 RtsFlags.GranFlags.packBufferSize_internal = decode(rts_argv[arg]+3);
1651 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
1653 debugBelch("Size of GranSim internal pack buffer: %u.\n",
1654 RtsFlags.GranFlags.packBufferSize_internal);
1658 switch(rts_argv[arg][3]) {
1661 RtsFlags.GranFlags.DoPrioritySparking = 1;
1662 debugBelch("Priority Sparking with Normal Priorities.\n");
1663 RtsFlags.GranFlags.InversePriorities = rtsFalse;
1664 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
1665 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
1669 RtsFlags.GranFlags.DoPrioritySparking = 1;
1670 debugBelch("Priority Sparking with Inverse Priorities.\n");
1671 RtsFlags.GranFlags.InversePriorities++;
1675 RtsFlags.GranFlags.DoPrioritySparking = 1;
1676 debugBelch("Priority Sparking with Random Priorities.\n");
1677 RtsFlags.GranFlags.RandomPriorities++;
1681 RtsFlags.GranFlags.DoPrioritySparking = 1;
1682 debugBelch("Priority Sparking with No Priorities.\n");
1683 RtsFlags.GranFlags.IgnorePriorities++;
1687 bad_option( rts_argv[arg] );
1693 switch(rts_argv[arg][3]) {
1696 RtsFlags.GranFlags.DoAlwaysCreateThreads=rtsFalse;
1697 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1701 RtsFlags.GranFlags.DoBulkFetching=rtsFalse;
1705 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1709 RtsFlags.GranFlags.DoFairSchedule=rtsFalse;
1713 RtsFlags.GranFlags.DoStealThreadsFirst=rtsFalse;
1714 RtsFlags.GranFlags.DoThreadMigration=rtsFalse;
1718 RtsFlags.GranFlags.DoAsyncFetch=rtsFalse;
1722 RtsFlags.GranFlags.PreferSparksOfLocalNodes=rtsFalse;
1726 RtsFlags.GranFlags.GranSimStats.Suppressed=rtsTrue;
1730 RtsFlags.GranFlags.GranSimStats.Sparks=rtsFalse;
1734 RtsFlags.GranFlags.GranSimStats.Heap=rtsFalse;
1738 RtsFlags.GranFlags.GranSimStats.Binary=rtsFalse;
1742 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1746 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
1747 RtsFlags.GranFlags.SparkPriority = rtsFalse;
1751 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
1755 RtsFlags.GranFlags.RandomSteal = rtsFalse;
1759 bad_option( rts_argv[arg] );
1764 # if defined(GRAN_CHECK) && defined(GRAN)
1766 switch(rts_argv[arg][3]) {
1767 case 'Q': /* Set pack buffer size (same as 'Q' in GUM) */
1768 if (rts_argv[arg][4] != '\0') {
1769 RtsFlags.GranFlags.packBufferSize = decode(rts_argv[arg]+4);
1770 debugBelch("Pack buffer size: %d\n",
1771 RtsFlags.GranFlags.packBufferSize);
1773 debugBelch("setupRtsFlags: missing size of PackBuffer (for -Q)\n");
1779 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
1780 /* hack warning: interpret the flags as a binary number */
1781 nat n = decode(rts_argv[arg]+3);
1782 set_GranSim_debug_options(n);
1785 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1786 if (rts_argv[arg][3] == gran_debug_opts_flags[i])
1789 if (i==MAX_GRAN_DEBUG_OPTION+1) {
1790 debugBelch("Valid GranSim debug options are:\n");
1791 help_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1792 bad_option( rts_argv[arg] );
1793 } else { // flag found; now set it
1794 set_GranSim_debug_options(GRAN_DEBUG_MASK(i)); // 2^i
1800 case 'e': /* event trace; also -bD1 */
1801 debugBelch("DEBUG: event_trace; printing event trace.\n");
1802 RtsFlags.GranFlags.Debug.event_trace = rtsTrue;
1803 /* RtsFlags.GranFlags.event_trace=rtsTrue; */
1806 case 'E': /* event statistics; also -bD2 */
1807 debugBelch("DEBUG: event_stats; printing event statistics.\n");
1808 RtsFlags.GranFlags.Debug.event_stats = rtsTrue;
1809 /* RtsFlags.GranFlags.Debug |= 0x20; print event statistics */
1812 case 'f': /* thunkStealing; also -bD4 */
1813 debugBelch("DEBUG: thunkStealing; printing forwarding of FETCHNODES.\n");
1814 RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue;
1815 /* RtsFlags.GranFlags.Debug |= 0x2; print fwd messages */
1818 case 'z': /* blockOnFetch; also -bD8 */
1819 debugBelch("DEBUG: blockOnFetch; check for blocked on fetch.\n");
1820 RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue;
1821 /* RtsFlags.GranFlags.Debug |= 0x4; debug non-reschedule-on-fetch */
1824 case 't': /* blockOnFetch_sanity; also -bD16 */
1825 debugBelch("DEBUG: blockOnFetch_sanity; check for TSO asleep on fetch.\n");
1826 RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue;
1827 /* RtsFlags.GranFlags.Debug |= 0x10; debug TSO asleep for fetch */
1830 case 'S': /* priSpark; also -bD32 */
1831 debugBelch("DEBUG: priSpark; priority sparking.\n");
1832 RtsFlags.GranFlags.Debug.priSpark = rtsTrue;
1835 case 's': /* priSched; also -bD64 */
1836 debugBelch("DEBUG: priSched; priority scheduling.\n");
1837 RtsFlags.GranFlags.Debug.priSched = rtsTrue;
1840 case 'F': /* findWork; also -bD128 */
1841 debugBelch("DEBUG: findWork; searching spark-pools (local & remote), thread queues for work.\n");
1842 RtsFlags.GranFlags.Debug.findWork = rtsTrue;
1845 case 'g': /* globalBlock; also -bD256 */
1846 debugBelch("DEBUG: globalBlock; blocking on remote closures (FETCHMEs etc in GUM).\n");
1847 RtsFlags.GranFlags.Debug.globalBlock = rtsTrue;
1850 case 'G': /* pack; also -bD512 */
1851 debugBelch("DEBUG: pack; routines for (un-)packing graph structures.\n");
1852 RtsFlags.GranFlags.Debug.pack = rtsTrue;
1855 case 'P': /* packBuffer; also -bD1024 */
1856 debugBelch("DEBUG: packBuffer; routines handling pack buffer (GranSim internal!).\n");
1857 RtsFlags.GranFlags.Debug.packBuffer = rtsTrue;
1860 case 'o': /* sortedQ; also -bD2048 */
1861 debugBelch("DEBUG: sortedQ; check whether spark/thread queues are sorted.\n");
1862 RtsFlags.GranFlags.Debug.sortedQ = rtsTrue;
1865 case 'r': /* randomSteal; also -bD4096 */
1866 debugBelch("DEBUG: randomSteal; stealing sparks/threads from random PEs.\n");
1867 RtsFlags.GranFlags.Debug.randomSteal = rtsTrue;
1870 case 'q': /* checkSparkQ; also -bD8192 */
1871 debugBelch("DEBUG: checkSparkQ; check consistency of the spark queues.\n");
1872 RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue;
1875 case ':': /* checkLight; also -bD16384 */
1876 debugBelch("DEBUG: checkLight; check GranSim-Light setup.\n");
1877 RtsFlags.GranFlags.Debug.checkLight = rtsTrue;
1880 case 'b': /* bq; also -bD32768 */
1881 debugBelch("DEBUG: bq; check blocking queues\n");
1882 RtsFlags.GranFlags.Debug.bq = rtsTrue;
1885 case 'd': /* all options turned on */
1886 debugBelch("DEBUG: all options turned on.\n");
1887 set_GranSim_debug_options(MAX_GRAN_DEBUG_MASK);
1888 /* RtsFlags.GranFlags.Debug |= 0x40; */
1892 /* RtsFlags.GranFlags.Debug = 1; */
1898 # endif /* GRAN_CHECK */
1900 bad_option( rts_argv[arg] );
1906 Interpret n as a binary number masking GranSim debug options and set the
1907 correxponding option. See gran_debug_opts_strs for explanations of the flags.
1910 set_GranSim_debug_options(nat n) {
1913 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1915 errorBelch(gran_debug_opts_strs[i]);
1917 case 0: RtsFlags.GranFlags.Debug.event_trace = rtsTrue; break;
1918 case 1: RtsFlags.GranFlags.Debug.event_stats = rtsTrue; break;
1919 case 2: RtsFlags.GranFlags.Debug.bq = rtsTrue; break;
1920 case 3: RtsFlags.GranFlags.Debug.pack = rtsTrue; break;
1921 case 4: RtsFlags.GranFlags.Debug.checkSparkQ = rtsTrue; break;
1922 case 5: RtsFlags.GranFlags.Debug.thunkStealing = rtsTrue; break;
1923 case 6: RtsFlags.GranFlags.Debug.randomSteal = rtsTrue; break;
1924 case 7: RtsFlags.GranFlags.Debug.findWork = rtsTrue; break;
1925 case 8: RtsFlags.GranFlags.Debug.unused = rtsTrue; break;
1926 case 9: RtsFlags.GranFlags.Debug.pri = rtsTrue; break;
1927 case 10: RtsFlags.GranFlags.Debug.checkLight = rtsTrue; break;
1928 case 11: RtsFlags.GranFlags.Debug.sortedQ = rtsTrue; break;
1929 case 12: RtsFlags.GranFlags.Debug.blockOnFetch = rtsTrue; break;
1930 case 13: RtsFlags.GranFlags.Debug.packBuffer = rtsTrue; break;
1931 case 14: RtsFlags.GranFlags.Debug.blockOnFetch_sanity = rtsTrue; break;
1932 default: barf("set_GranSim_debug_options: only %d debug options expected");
1938 Print one line explanation for each of the GranSim debug options specified
1942 help_GranSim_debug_options(nat n) {
1945 for (i=0; i<=MAX_GRAN_DEBUG_OPTION; i++)
1947 debugBelch(gran_debug_opts_strs[i]);
1953 process_par_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
1956 if (rts_argv[arg][1] != 'q') { /* All GUM options start with -q */
1957 errorBelch("Warning: GUM option does not start with -q: %s", rts_argv[arg]);
1961 /* Communication and task creation cost parameters */
1962 switch(rts_argv[arg][2]) {
1963 case 'e': /* -qe<n> ... allow <n> local sparks */
1964 if (rts_argv[arg][3] != '\0') { /* otherwise, stick w/ the default */
1965 RtsFlags.ParFlags.maxLocalSparks
1966 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1968 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
1969 errorBelch("setupRtsFlags: bad value for -e\n");
1973 IF_PAR_DEBUG(verbose,
1974 errorBelch("-qe<n>: max %d local sparks",
1975 RtsFlags.ParFlags.maxLocalSparks));
1979 if (rts_argv[arg][3] != '\0') {
1980 RtsFlags.ParFlags.maxThreads
1981 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
1983 errorBelch("missing size for -qt\n");
1986 IF_PAR_DEBUG(verbose,
1987 errorBelch("-qt<n>: max %d threads",
1988 RtsFlags.ParFlags.maxThreads));
1992 if (rts_argv[arg][3] != '\0')
1993 RtsFlags.ParFlags.maxFishes = decode(rts_argv[arg]+3);
1995 RtsFlags.ParFlags.maxFishes = MAX_FISHES;
1997 IF_PAR_DEBUG(verbose,
1998 errorBelch("-qf<n>: max %d fishes sent out at one time",
1999 RtsFlags.ParFlags.maxFishes));
2003 if (rts_argv[arg][3] != '\0') {
2004 RtsFlags.ParFlags.fishDelay
2005 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2007 errorBelch("missing fish delay time for -qF\n");
2010 IF_PAR_DEBUG(verbose,
2011 errorBelch("-qF<n>: fish delay time %d us",
2012 RtsFlags.ParFlags.fishDelay));
2016 RtsFlags.ParFlags.outputDisabled = rtsTrue;
2017 IF_PAR_DEBUG(verbose,
2018 errorBelch("-qO: output disabled"));
2021 case 'g': /* -qg<n> ... globalisation scheme */
2022 if (rts_argv[arg][3] != '\0') {
2023 RtsFlags.ParFlags.globalising = decode(rts_argv[arg]+3);
2025 errorBelch("missing identifier for globalisation scheme (for -qg)\n");
2028 IF_PAR_DEBUG(verbose,
2029 debugBelch("-qg<n>: globalisation scheme set to %d",
2030 RtsFlags.ParFlags.globalising));
2033 case 'h': /* -qh<n> ... max number of thunks (except root) in packet */
2034 if (rts_argv[arg][3] != '\0') {
2035 RtsFlags.ParFlags.thunksToPack = decode(rts_argv[arg]+3);
2037 errorBelch("missing number of thunks per packet (for -qh)\n");
2040 IF_PAR_DEBUG(verbose,
2041 debugBelch("-qh<n>: thunks per packet set to %d",
2042 RtsFlags.ParFlags.thunksToPack));
2045 case 'P': /* -qP for writing a log file */
2046 //RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2047 /* same encoding as in GranSim after -bP */
2048 switch(rts_argv[arg][3]) {
2049 case '\0': RtsFlags.ParFlags.ParStats.Full = rtsTrue;
2050 break; // nothing special, just an ordinary profile
2051 case '0': RtsFlags.ParFlags.ParStats.Suppressed = rtsTrue;
2052 RtsFlags.ParFlags.ParStats.Full = rtsFalse;
2054 case 'b': RtsFlags.ParFlags.ParStats.Binary = rtsTrue;
2056 case 's': RtsFlags.ParFlags.ParStats.Sparks = rtsTrue;
2058 //case 'h': RtsFlags.parFlags.ParStats.Heap = rtsTrue;
2060 case 'n': RtsFlags.ParFlags.ParStats.NewLogfile = rtsTrue;
2063 # if defined(PAR_TICKY)
2064 RtsFlags.ParFlags.ParStats.Global = rtsTrue;
2066 errorBelch("-qPg is only possible for a PAR_TICKY RTS, which this is not");
2067 stg_exit(EXIT_FAILURE);
2070 default: barf("Unknown option -qP%c", rts_argv[arg][2]);
2072 IF_PAR_DEBUG(verbose,
2073 debugBelch("(-qP) writing to log-file (RtsFlags.ParFlags.ParStats.Full=%s)",
2074 (RtsFlags.ParFlags.ParStats.Full ? "rtsTrue" : "rtsFalse")));
2077 case 'Q': /* -qQ<n> ... set pack buffer size to <n> */
2078 if (rts_argv[arg][3] != '\0') {
2079 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+3);
2081 errorBelch("missing size of PackBuffer (for -qQ)\n");
2084 IF_PAR_DEBUG(verbose,
2085 debugBelch("-qQ<n>: pack buffer size set to %d",
2086 RtsFlags.ParFlags.packBufferSize));
2090 RtsFlags.ParFlags.doFairScheduling = rtsTrue;
2091 IF_PAR_DEBUG(verbose,
2092 debugBelch("-qR: fair-ish scheduling"));
2097 if (rts_argv[arg][3] != '\0') {
2098 RtsFlags.ParFlags.wait
2099 = strtol(rts_argv[arg]+3, (char **) NULL, 10);
2101 RtsFlags.ParFlags.wait = 1000;
2103 IF_PAR_DEBUG(verbose,
2104 debugBelch("-qw<n>: length of wait loop after synchr before reduction: %d",
2105 RtsFlags.ParFlags.wait));
2108 case 'D': /* -qD ... all the debugging options */
2109 if (isdigit(rts_argv[arg][3])) {/* Set all debugging options in one */
2110 /* hack warning: interpret the flags as a binary number */
2111 nat n = decode(rts_argv[arg]+3);
2112 set_par_debug_options(n);
2115 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2116 if (rts_argv[arg][3] == par_debug_opts_flags[i])
2119 if (i==MAX_PAR_DEBUG_OPTION+1) {
2120 errorBelch("Valid GUM debug options are:\n");
2121 help_par_debug_options(MAX_PAR_DEBUG_MASK);
2122 bad_option( rts_argv[arg] );
2123 } else { // flag found; now set it
2124 set_par_debug_options(PAR_DEBUG_MASK(i)); // 2^i
2130 errorBelch("Unknown option -q%c (%d opts in total)",
2131 rts_argv[arg][2], *rts_argc);
2137 Interpret n as a binary number masking Par debug options and set the
2138 correxponding option. See par_debug_opts_strs for explanations of the flags.
2141 set_par_debug_options(nat n) {
2144 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2146 debugBelch(par_debug_opts_strs[i]);
2148 case 0: RtsFlags.ParFlags.Debug.verbose = rtsTrue; break;
2149 case 1: RtsFlags.ParFlags.Debug.bq = rtsTrue; break;
2150 case 2: RtsFlags.ParFlags.Debug.schedule = rtsTrue; break;
2151 case 3: RtsFlags.ParFlags.Debug.free = rtsTrue; break;
2152 case 4: RtsFlags.ParFlags.Debug.resume = rtsTrue; break;
2153 case 5: RtsFlags.ParFlags.Debug.weight = rtsTrue; break;
2154 case 6: RtsFlags.ParFlags.Debug.fetch = rtsTrue; break;
2155 //case 7: RtsFlags.ParFlags.Debug.ack = rtsTrue; break;
2156 case 7: RtsFlags.ParFlags.Debug.fish = rtsTrue; break;
2157 case 8: RtsFlags.ParFlags.Debug.tables = rtsTrue; break;
2158 case 9: RtsFlags.ParFlags.Debug.packet = rtsTrue; break;
2159 case 10: RtsFlags.ParFlags.Debug.pack = rtsTrue; break;
2160 case 11: RtsFlags.ParFlags.Debug.paranoia = rtsTrue; break;
2161 default: barf("set_par_debug_options: only %d debug options expected",
2162 MAX_PAR_DEBUG_OPTION);
2168 Print one line explanation for each of the GranSim debug options specified
2172 help_par_debug_options(nat n) {
2175 for (i=0; i<=MAX_PAR_DEBUG_OPTION; i++)
2177 debugBelch(par_debug_opts_strs[i]);
2183 stats_fprintf(FILE *f, char *s, ...)
2195 static int /* return -1 on error */
2198 int argc, char *argv[],
2199 int rts_argc, char *rts_argv[],
2200 const char *FILENAME_FMT,
2205 if (strequal(rts_argv[arg]+2, "stderr")) { /* use debugBelch */
2206 f = NULL; /* NULL means use debugBelch */
2208 if (rts_argv[arg][2] != '\0') { /* stats file specified */
2209 f = fopen(rts_argv[arg]+2,"w");
2211 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
2212 sprintf(stats_filename, FILENAME_FMT, argv[0]);
2213 f = fopen(stats_filename,"w");
2216 errorBelch("Can't open stats file %s\n", rts_argv[arg]+2);
2223 /* Write argv and rtsv into start of stats file */
2225 for(count = 0; count < argc; count++) {
2226 stats_fprintf(f, "%s ", argv[count]);
2228 stats_fprintf(f, "+RTS ");
2229 for(count = 0; count < rts_argc; count++)
2230 stats_fprintf(f, "%s ", rts_argv[count]);
2231 stats_fprintf(f, "\n");
2239 decode(const char *s)
2250 if (c == 'g' || c == 'G')
2251 m *= 1000*1000*1000; /* UNchecked! */
2252 else if (c == 'm' || c == 'M')
2253 m *= 1000*1000; /* We do not use powers of 2 (1024) */
2254 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
2255 m *= 1000; /* a direct-mapped cache. */
2256 else if (c == 'w' || c == 'W')
2263 bad_option(const char *s)
2265 errorBelch("bad RTS option: %s", s);
2266 stg_exit(EXIT_FAILURE);
2269 /* -----------------------------------------------------------------------------
2270 Getting/Setting the program's arguments.
2272 These are used by System.Environment, and parts of the RTS.
2273 -------------------------------------------------------------------------- */
2276 setProgName(char *argv[])
2278 /* Remove directory from argv[0] -- default files in current directory */
2279 #if !defined(mingw32_HOST_OS)
2281 if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
2282 prog_name = last_slash+1;
2284 prog_name = argv[0];
2287 char* last_slash = argv[0] + (strlen(argv[0]) - 1);
2288 while ( last_slash > argv[0] ) {
2289 if ( *last_slash == '/' || *last_slash == '\\' ) {
2290 prog_name = last_slash+1;
2295 prog_name = argv[0];
2300 getProgArgv(int *argc, char **argv[])
2302 if (argc) { *argc = prog_argc; }
2303 if (argv) { *argv = prog_argv; }
2307 setProgArgv(int argc, char *argv[])
2309 /* Usually this is done by startupHaskell, so we don't need to call this.
2310 However, sometimes Hugs wants to change the arguments which Haskell
2311 getArgs >>= ... will be fed. So you can do that by calling here
2312 _after_ calling startupHaskell.
2316 setProgName(prog_argv);