Consistently use <sect1> etc rather than <section>; fixes #5009
[ghc-hetmet.git] / docs / users_guide / runtime_control.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="runtime-control">
3   <title>Running a compiled program</title>
4
5   <indexterm><primary>runtime control of Haskell programs</primary></indexterm>
6   <indexterm><primary>running, compiled program</primary></indexterm>
7   <indexterm><primary>RTS options</primary></indexterm>
8
9   <para>To make an executable program, the GHC system compiles your
10   code and then links it with a non-trivial runtime system (RTS),
11   which handles storage management, thread scheduling, profiling, and
12   so on.</para>
13
14   <para>
15     The RTS has a lot of options to control its behaviour.  For
16     example, you can change the context-switch interval, the default
17     size of the heap, and enable heap profiling.  These options can be
18     passed to the runtime system in a variety of different ways; the
19     next section (<xref linkend="setting-rts-options" />) describes
20     the various methods, and the following sections describe the RTS
21     options themselves.
22   </para>
23
24   <sect2 id="setting-rts-options">
25     <title>Setting RTS options</title>
26     <indexterm><primary>RTS options, setting</primary></indexterm>
27
28     <para>
29       There are four ways to set RTS options:
30
31       <itemizedlist>
32         <listitem>
33           <para>
34           on the command line between <literal>+RTS ... -RTS</literal>, when running the program
35            (<xref linkend="rts-opts-cmdline" />)
36           </para>
37         </listitem>
38         <listitem>
39           <para>at compile-time, using <option>--with-rtsopts</option>
40             (<xref linkend="rts-opts-compile-time" />)
41           </para>
42         </listitem>
43         <listitem>
44           <para>with the environment variable <envar>GHCRTS</envar>
45           (<xref linkend="rts-options-environment" />)
46           </para>
47         </listitem>
48         <listitem>
49           <para>by overriding &ldquo;hooks&rdquo; in the runtime system
50             (<xref linkend="rts-hooks" />)
51           </para>
52         </listitem>
53       </itemizedlist>
54     </para>
55
56     <sect3 id="rts-opts-cmdline">
57       <title>Setting RTS options on the command line</title>
58
59       <para>
60         If you set the <literal>-rtsopts</literal> flag appropriately
61         when linking (see <xref linkend="options-linker" />), you can
62         give RTS options on the command line when running your
63         program.
64       </para>
65
66       <para>
67         When your Haskell program starts up, the RTS extracts
68         command-line arguments bracketed between
69         <option>+RTS</option><indexterm><primary><option>+RTS</option></primary></indexterm>
70         and
71         <option>-RTS</option><indexterm><primary><option>-RTS</option></primary></indexterm>
72         as its own.  For example:
73       </para>
74
75 <screen>
76 $ ghc prog.hs -rtsopts
77 [1 of 1] Compiling Main             ( prog.hs, prog.o )
78 Linking prog ...
79 $ ./prog -f +RTS -H32m -S -RTS -h foo bar
80 </screen>
81
82         <para>
83           The RTS will
84           snaffle <option>-H32m</option> <option>-S</option> for itself,
85           and the remaining arguments <literal>-f -h foo bar</literal>
86           will be available to your program if/when it calls
87           <function>System.Environment.getArgs</function>.
88         </para>
89
90         <para>
91           No <option>-RTS</option> option is required if the
92           runtime-system options extend to the end of the command line, as in
93           this example:
94         </para>
95
96 <screen>
97 % hls -ltr /usr/etc +RTS -A5m
98 </screen>
99
100         <para>
101           If you absolutely positively want all the rest of the options
102           in a command line to go to the program (and not the RTS), use a
103           <option>&ndash;&ndash;RTS</option><indexterm><primary><option>--RTS</option></primary></indexterm>.
104         </para>
105
106         <para>
107           As always, for RTS options that take
108           <replaceable>size</replaceable>s: If the last character of
109           <replaceable>size</replaceable> is a K or k, multiply by 1000; if an
110           M or m, by 1,000,000; if a G or G, by 1,000,000,000.  (And any
111           wraparound in the counters is <emphasis>your</emphasis>
112           fault!)
113         </para>
114
115         <para>
116           Giving a <literal>+RTS -?</literal>
117           <indexterm><primary><option>-?</option></primary><secondary>RTS option</secondary></indexterm> option
118           will print out the RTS options actually available in your program
119           (which vary, depending on how you compiled).</para>
120
121         <para>
122           NOTE: since GHC is itself compiled by GHC, you can change RTS
123           options in the compiler using the normal
124           <literal>+RTS ... -RTS</literal>
125           combination.  eg. to set the maximum heap
126           size for a compilation to 128M, you would add
127           <literal>+RTS -M128m -RTS</literal>
128           to the command line.
129         </para>
130       </sect3>
131
132       <sect3 id="rts-opts-compile-time">
133         <title>Setting RTS options at compile time</title>
134
135         <para>
136           GHC lets you change the default RTS options for a program at
137           compile time, using the <literal>-with-rtsopts</literal>
138           flag (<xref linkend="options-linker" />). For example, to
139           set <literal>-H128m -K64m</literal>, link
140           with <literal>-with-rtsopts="-H128m -K64m"</literal>.
141         </para>
142       </sect3>
143
144       <sect3 id="rts-options-environment">
145         <title>Setting RTS options with the <envar>GHCRTS</envar>
146           environment variable</title>
147
148         <indexterm><primary>RTS options</primary><secondary>from the environment</secondary></indexterm>
149         <indexterm><primary>environment variable</primary><secondary>for
150             setting RTS options</secondary></indexterm>
151
152         <para>
153           If the <literal>-rtsopts</literal> flag is set to
154           something other than <literal>none</literal> when linking,
155           RTS options are also taken from the environment variable
156           <envar>GHCRTS</envar><indexterm><primary><envar>GHCRTS</envar></primary>
157           </indexterm>.  For example, to set the maximum heap size
158           to 2G for all GHC-compiled programs (using an
159           <literal>sh</literal>-like shell):
160         </para>
161
162 <screen>
163    GHCRTS='-M2G'
164    export GHCRTS
165 </screen>
166
167         <para>
168           RTS options taken from the <envar>GHCRTS</envar> environment
169           variable can be overridden by options given on the command
170           line.
171         </para>
172
173         <para>
174           Tip: setting something like <literal>GHCRTS=-M2G</literal>
175           in your environment is a handy way to avoid Haskell programs
176           growing beyond the real memory in your machine, which is
177           easy to do by accident and can cause the machine to slow to
178           a crawl until the OS decides to kill the process (and you
179           hope it kills the right one).
180         </para>
181       </sect3>
182
183   <sect3 id="rts-hooks">
184     <title>&ldquo;Hooks&rdquo; to change RTS behaviour</title>
185
186     <indexterm><primary>hooks</primary><secondary>RTS</secondary></indexterm>
187     <indexterm><primary>RTS hooks</primary></indexterm>
188     <indexterm><primary>RTS behaviour, changing</primary></indexterm>
189
190     <para>GHC lets you exercise rudimentary control over the RTS
191     settings for any given program, by compiling in a
192     &ldquo;hook&rdquo; that is called by the run-time system.  The RTS
193     contains stub definitions for all these hooks, but by writing your
194     own version and linking it on the GHC command line, you can
195     override the defaults.</para>
196
197     <para>Owing to the vagaries of DLL linking, these hooks don't work
198     under Windows when the program is built dynamically.</para>
199
200     <para>The hook <literal>ghc_rts_opts</literal><indexterm><primary><literal>ghc_rts_opts</literal></primary>
201       </indexterm>lets you set RTS
202     options permanently for a given program, in the same way as the
203     newer <option>-with-rtsopts</option> linker option does.  A common use for this is
204     to give your program a default heap and/or stack size that is
205     greater than the default.  For example, to set <literal>-H128m
206     -K1m</literal>, place the following definition in a C source
207     file:</para>
208
209 <programlisting>
210 char *ghc_rts_opts = "-H128m -K1m";
211 </programlisting>
212
213     <para>Compile the C file, and include the object file on the
214     command line when you link your Haskell program.</para>
215
216     <para>These flags are interpreted first, before any RTS flags from
217     the <literal>GHCRTS</literal> environment variable and any flags
218     on the command line.</para>
219
220     <para>You can also change the messages printed when the runtime
221     system &ldquo;blows up,&rdquo; e.g., on stack overflow.  The hooks
222     for these are as follows:</para>
223
224     <variablelist>
225
226       <varlistentry>
227         <term>
228           <function>void OutOfHeapHook (unsigned long, unsigned long)</function>
229           <indexterm><primary><function>OutOfHeapHook</function></primary></indexterm>
230         </term>
231         <listitem>
232           <para>The heap-overflow message.</para>
233         </listitem>
234       </varlistentry>
235
236       <varlistentry>
237         <term>
238           <function>void StackOverflowHook (long int)</function>
239           <indexterm><primary><function>StackOverflowHook</function></primary></indexterm>
240         </term>
241         <listitem>
242           <para>The stack-overflow message.</para>
243         </listitem>
244       </varlistentry>
245
246       <varlistentry>
247         <term>
248           <function>void MallocFailHook (long int)</function>
249           <indexterm><primary><function>MallocFailHook</function></primary></indexterm>
250         </term>
251         <listitem>
252           <para>The message printed if <function>malloc</function>
253           fails.</para>
254         </listitem>
255       </varlistentry>
256     </variablelist>
257
258     <para>For examples of the use of these hooks, see GHC's own
259     versions in the file
260     <filename>ghc/compiler/parser/hschooks.c</filename> in a GHC
261     source tree.</para>
262   </sect3>
263
264     </sect2>
265
266   <sect2 id="rts-options-misc">
267     <title>Miscellaneous RTS options</title>
268
269     <variablelist>
270      <varlistentry>
271        <term><option>-V<replaceable>secs</replaceable></option>
272        <indexterm><primary><option>-V</option></primary><secondary>RTS
273        option</secondary></indexterm></term>
274        <listitem>
275          <para>Sets the interval that the RTS clock ticks at.  The
276          runtime uses a single timer signal to count ticks; this timer
277          signal is used to control the context switch timer (<xref
278          linkend="using-concurrent" />) and the heap profiling
279          timer <xref linkend="rts-options-heap-prof" />.  Also, the
280          time profiler uses the RTS timer signal directly to record
281          time profiling samples.</para>
282
283          <para>Normally, setting the <option>-V</option> option
284          directly is not necessary: the resolution of the RTS timer is
285          adjusted automatically if a short interval is requested with
286          the <option>-C</option> or <option>-i</option> options.
287          However, setting <option>-V</option> is required in order to
288          increase the resolution of the time profiler.</para>
289
290          <para>Using a value of zero disables the RTS clock
291          completely, and has the effect of disabling timers that
292          depend on it: the context switch timer and the heap profiling
293          timer.  Context switches will still happen, but
294          deterministically and at a rate much faster than normal.
295          Disabling the interval timer is useful for debugging, because
296          it eliminates a source of non-determinism at runtime.</para>
297        </listitem>
298      </varlistentry>
299
300      <varlistentry>
301        <term><option>--install-signal-handlers=<replaceable>yes|no</replaceable></option>
302        <indexterm><primary><option>--install-signal-handlers</option></primary><secondary>RTS
303        option</secondary></indexterm></term>
304        <listitem>
305          <para>If yes (the default), the RTS installs signal handlers to catch
306          things like ctrl-C. This option is primarily useful for when
307          you are using the Haskell code as a DLL, and want to set your
308          own signal handlers.</para>
309
310          <para>Note that even
311            with <option>--install-signal-handlers=no</option>, the RTS
312            interval timer signal is still enabled.  The timer signal
313            is either SIGVTALRM or SIGALRM, depending on the RTS
314            configuration and OS capabilities.  To disable the timer
315            signal, use the <literal>-V0</literal> RTS option (see
316            above).
317          </para>
318        </listitem>
319      </varlistentry>
320
321      <varlistentry>
322        <term><option>-xm<replaceable>address</replaceable></option>
323        <indexterm><primary><option>-xm</option></primary><secondary>RTS
324        option</secondary></indexterm></term>
325        <listitem>
326          <para>
327            WARNING: this option is for working around memory
328            allocation problems only.  Do not use unless GHCi fails
329            with a message like &ldquo;<literal>failed to mmap() memory below 2Gb</literal>&rdquo;.  If you need to use this option to get GHCi working
330            on your machine, please file a bug.
331          </para>
332          
333          <para>
334            On 64-bit machines, the RTS needs to allocate memory in the
335            low 2Gb of the address space.  Support for this across
336            different operating systems is patchy, and sometimes fails.
337            This option is there to give the RTS a hint about where it
338            should be able to allocate memory in the low 2Gb of the
339            address space.  For example, <literal>+RTS -xm20000000
340            -RTS</literal> would hint that the RTS should allocate
341            starting at the 0.5Gb mark.  The default is to use the OS's
342            built-in support for allocating memory in the low 2Gb if
343            available (e.g. <literal>mmap</literal>
344            with <literal>MAP_32BIT</literal> on Linux), or
345            otherwise <literal>-xm40000000</literal>.
346          </para>
347        </listitem>
348      </varlistentry>
349     </variablelist>
350   </sect2>
351
352   <sect2 id="rts-options-gc">
353     <title>RTS options to control the garbage collector</title>
354
355     <indexterm><primary>garbage collector</primary><secondary>options</secondary></indexterm>
356     <indexterm><primary>RTS options</primary><secondary>garbage collection</secondary></indexterm>
357
358     <para>There are several options to give you precise control over
359     garbage collection.  Hopefully, you won't need any of these in
360     normal operation, but there are several things that can be tweaked
361     for maximum performance.</para>
362
363     <variablelist>
364
365       <varlistentry>
366         <term>
367           <option>-A</option><replaceable>size</replaceable>
368           <indexterm><primary><option>-A</option></primary><secondary>RTS option</secondary></indexterm>
369           <indexterm><primary>allocation area, size</primary></indexterm>
370         </term>
371         <listitem>
372           <para>&lsqb;Default: 512k&rsqb; Set the allocation area size
373           used by the garbage collector.  The allocation area
374           (actually generation 0 step 0) is fixed and is never resized
375           (unless you use <option>-H</option>, below).</para>
376
377           <para>Increasing the allocation area size may or may not
378           give better performance (a bigger allocation area means
379           worse cache behaviour but fewer garbage collections and less
380           promotion).</para>
381
382           <para>With only 1 generation (<option>-G1</option>) the
383           <option>-A</option> option specifies the minimum allocation
384           area, since the actual size of the allocation area will be
385           resized according to the amount of data in the heap (see
386           <option>-F</option>, below).</para>
387         </listitem>
388       </varlistentry>
389
390       <varlistentry>
391         <term>
392           <option>-c</option>
393           <indexterm><primary><option>-c</option></primary><secondary>RTS option</secondary></indexterm>
394           <indexterm><primary>garbage collection</primary><secondary>compacting</secondary></indexterm>
395           <indexterm><primary>compacting garbage collection</primary></indexterm>
396         </term>
397         <listitem>
398           <para>Use a compacting algorithm for collecting the oldest
399           generation.  By default, the oldest generation is collected
400           using a copying algorithm; this option causes it to be
401           compacted in-place instead.  The compaction algorithm is
402           slower than the copying algorithm, but the savings in memory
403           use can be considerable.</para>
404
405           <para>For a given heap size (using the <option>-H</option>
406           option), compaction can in fact reduce the GC cost by
407           allowing fewer GCs to be performed.  This is more likely
408           when the ratio of live data to heap size is high, say
409           &gt;30&percnt;.</para>
410
411           <para>NOTE: compaction doesn't currently work when a single
412           generation is requested using the <option>-G1</option>
413           option.</para>
414         </listitem>
415       </varlistentry>
416
417       <varlistentry>
418         <term><option>-c</option><replaceable>n</replaceable></term>
419
420         <listitem>
421           <para>&lsqb;Default: 30&rsqb; Automatically enable
422           compacting collection when the live data exceeds
423           <replaceable>n</replaceable>&percnt; of the maximum heap size
424           (see the <option>-M</option> option).  Note that the maximum
425           heap size is unlimited by default, so this option has no
426           effect unless the maximum heap size is set with
427           <option>-M</option><replaceable>size</replaceable>. </para>
428         </listitem>
429       </varlistentry>
430
431       <varlistentry>
432         <term>
433           <option>-F</option><replaceable>factor</replaceable>
434           <indexterm><primary><option>-F</option></primary><secondary>RTS option</secondary></indexterm>
435           <indexterm><primary>heap size, factor</primary></indexterm>
436         </term>
437         <listitem>
438
439           <para>&lsqb;Default: 2&rsqb; This option controls the amount
440           of memory reserved for the older generations (and in the
441           case of a two space collector the size of the allocation
442           area) as a factor of the amount of live data.  For example,
443           if there was 2M of live data in the oldest generation when
444           we last collected it, then by default we'll wait until it
445           grows to 4M before collecting it again.</para>
446
447           <para>The default seems to work well here.  If you have
448           plenty of memory, it is usually better to use
449           <option>-H</option><replaceable>size</replaceable> than to
450           increase
451           <option>-F</option><replaceable>factor</replaceable>.</para>
452
453           <para>The <option>-F</option> setting will be automatically
454           reduced by the garbage collector when the maximum heap size
455           (the <option>-M</option><replaceable>size</replaceable>
456           setting) is approaching.</para>
457         </listitem>
458       </varlistentry>
459
460       <varlistentry>
461         <term>
462           <option>-G</option><replaceable>generations</replaceable>
463           <indexterm><primary><option>-G</option></primary><secondary>RTS option</secondary></indexterm>
464           <indexterm><primary>generations, number of</primary></indexterm>
465         </term>
466         <listitem>
467           <para>&lsqb;Default: 2&rsqb; Set the number of generations
468           used by the garbage collector.  The default of 2 seems to be
469           good, but the garbage collector can support any number of
470           generations.  Anything larger than about 4 is probably not a
471           good idea unless your program runs for a
472           <emphasis>long</emphasis> time, because the oldest
473           generation will hardly ever get collected.</para>
474
475           <para>Specifying 1 generation with <option>+RTS -G1</option>
476           gives you a simple 2-space collector, as you would expect.
477           In a 2-space collector, the <option>-A</option> option (see
478           above) specifies the <emphasis>minimum</emphasis> allocation
479           area size, since the allocation area will grow with the
480           amount of live data in the heap.  In a multi-generational
481           collector the allocation area is a fixed size (unless you
482           use the <option>-H</option> option, see below).</para>
483         </listitem>
484       </varlistentry>
485
486       <varlistentry>
487         <term>
488           <option>-qg<optional><replaceable>gen</replaceable></optional></option>
489           <indexterm><primary><option>-qg</option><secondary>RTS
490           option</secondary></primary></indexterm>
491         </term>
492         <listitem>
493           <para>&lsqb;New in GHC 6.12.1&rsqb; &lsqb;Default: 0&rsqb;
494             Use parallel GC in
495             generation <replaceable>gen</replaceable> and higher.
496             Omitting <replaceable>gen</replaceable> turns off the
497             parallel GC completely, reverting to sequential GC.</para>
498           
499           <para>The default parallel GC settings are usually suitable
500             for parallel programs (i.e. those
501             using <literal>par</literal>, Strategies, or with multiple
502             threads).  However, it is sometimes beneficial to enable
503             the parallel GC for a single-threaded sequential program
504             too, especially if the program has a large amount of heap
505             data and GC is a significant fraction of runtime.  To use
506             the parallel GC in a sequential program, enable the
507             parallel runtime with a suitable <literal>-N</literal>
508             option, and additionally it might be beneficial to
509             restrict parallel GC to the old generation
510             with <literal>-qg1</literal>.</para>
511         </listitem>
512       </varlistentry>        
513
514       <varlistentry>
515         <term>
516           <option>-qb<optional><replaceable>gen</replaceable></optional></option>
517           <indexterm><primary><option>-qb</option><secondary>RTS
518           option</secondary></primary></indexterm>
519         </term>
520         <listitem>
521           <para>
522             &lsqb;New in GHC 6.12.1&rsqb; &lsqb;Default: 1&rsqb; Use
523             load-balancing in the parallel GC in
524             generation <replaceable>gen</replaceable> and higher.
525             Omitting <replaceable>gen</replaceable> disables
526             load-balancing entirely.</para>
527           
528           <para>
529             Load-balancing shares out the work of GC between the
530             available cores.  This is a good idea when the heap is
531             large and we need to parallelise the GC work, however it
532             is also pessimal for the short young-generation
533             collections in a parallel program, because it can harm
534             locality by moving data from the cache of the CPU where is
535             it being used to the cache of another CPU.  Hence the
536             default is to do load-balancing only in the
537             old-generation.  In fact, for a parallel program it is
538             sometimes beneficial to disable load-balancing entirely
539             with <literal>-qb</literal>.
540           </para>
541         </listitem>
542       </varlistentry>
543
544       <varlistentry>
545         <term>
546           <option>-H</option><replaceable>size</replaceable>
547           <indexterm><primary><option>-H</option></primary><secondary>RTS option</secondary></indexterm>
548           <indexterm><primary>heap size, suggested</primary></indexterm>
549         </term>
550         <listitem>
551           <para>&lsqb;Default: 0&rsqb; This option provides a
552           &ldquo;suggested heap size&rdquo; for the garbage collector.  The
553           garbage collector will use about this much memory until the
554           program residency grows and the heap size needs to be
555           expanded to retain reasonable performance.</para>
556
557           <para>By default, the heap will start small, and grow and
558           shrink as necessary.  This can be bad for performance, so if
559           you have plenty of memory it's worthwhile supplying a big
560           <option>-H</option><replaceable>size</replaceable>.  For
561           improving GC performance, using
562           <option>-H</option><replaceable>size</replaceable> is
563           usually a better bet than
564           <option>-A</option><replaceable>size</replaceable>.</para>
565         </listitem>
566       </varlistentry>
567
568       <varlistentry>
569         <term>
570           <option>-I</option><replaceable>seconds</replaceable>
571           <indexterm><primary><option>-I</option></primary>
572             <secondary>RTS option</secondary>
573           </indexterm>
574           <indexterm><primary>idle GC</primary>
575           </indexterm>
576           </term>
577         <listitem>
578           <para>(default: 0.3) In the threaded and SMP versions of the RTS (see
579             <option>-threaded</option>, <xref linkend="options-linker" />), a
580             major GC is automatically performed if the runtime has been idle
581             (no Haskell computation has been running) for a period of time.
582             The amount of idle time which must pass before a GC is performed is
583             set by the <option>-I</option><replaceable>seconds</replaceable>
584             option.  Specifying <option>-I0</option> disables the idle GC.</para>
585
586           <para>For an interactive application, it is probably a good idea to
587             use the idle GC, because this will allow finalizers to run and
588             deadlocked threads to be detected in the idle time when no Haskell
589             computation is happening.  Also, it will mean that a GC is less
590             likely to happen when the application is busy, and so
591             responsiveness may be improved.   However, if the amount of live data in
592             the heap is particularly large, then the idle GC can cause a
593             significant delay, and too small an interval could adversely affect
594             interactive responsiveness.</para>
595
596           <para>This is an experimental feature, please let us know if it
597             causes problems and/or could benefit from further tuning.</para>
598         </listitem>
599       </varlistentry>
600
601       <varlistentry>
602         <term>
603          <option>-ki</option><replaceable>size</replaceable>
604          <indexterm><primary><option>-k</option></primary><secondary>RTS option</secondary></indexterm>
605          <indexterm><primary>stack, initial size</primary></indexterm>
606         </term>
607         <listitem>
608           <para>
609             &lsqb;Default: 1k&rsqb; Set the initial stack size for new
610             threads.  (Note: this flag used to be
611             simply <option>-k</option>, but was renamed
612             to <option>-ki</option> in GHC 7.2.1.  The old name is
613             still accepted for backwards compatibility, but that may
614             be removed in a future version).
615           </para>
616
617           <para>
618             Thread stacks (including the main thread's stack) live on
619             the heap.  As the stack grows, new stack chunks are added
620             as required; if the stack shrinks again, these extra stack
621             chunks are reclaimed by the garbage collector.  The
622             default initial stack size is deliberately small, in order
623             to keep the time and space overhead for thread creation to
624             a minimum, and to make it practical to spawn threads for
625             even tiny pieces of work.
626           </para>
627         </listitem>
628       </varlistentry>
629
630       <varlistentry>
631         <term>
632           <option>-kc</option><replaceable>size</replaceable>
633           <indexterm><primary><option>-kc</option></primary><secondary>RTS
634           option</secondary></indexterm>
635           <indexterm><primary>stack</primary><secondary>chunk size</secondary></indexterm>
636         </term>
637         <listitem>
638           <para>
639             &lsqb;Default: 32k&rsqb; Set the size of &ldquo;stack
640             chunks&rdquo;.  When a thread's current stack overflows, a
641             new stack chunk is created and added to the thread's
642             stack, until the limit set by <option>-K</option> is
643             reached.
644           </para>
645
646           <para>
647             The advantage of smaller stack chunks is that the garbage
648             collector can avoid traversing stack chunks if they are
649             known to be unmodified since the last collection, so
650             reducing the chunk size means that the garbage collector
651             can identify more stack as unmodified, and the GC overhead
652             might be reduced.  On the other hand, making stack chunks
653             too small adds some overhead as there will be more
654             overflow/underflow between chunks.  The default setting of
655             32k appears to be a reasonable compromise in most cases.
656           </para>
657         </listitem>
658       </varlistentry>
659
660       <varlistentry>
661         <term>
662           <option>-kb</option><replaceable>size</replaceable>
663           <indexterm><primary><option>-kc</option></primary><secondary>RTS
664           option</secondary></indexterm>
665           <indexterm><primary>stack</primary><secondary>chunk buffer size</secondary></indexterm>
666         </term>
667         <listitem>
668           <para>
669             &lsqb;Default: 1k&rsqb; Sets the stack chunk buffer size.
670             When a stack chunk overflows and a new stack chunk is
671             created, some of the data from the previous stack chunk is
672             moved into the new chunk, to avoid an immediate underflow
673             and repeated overflow/underflow at the boundary.  The
674             amount of stack moved is set by the <option>-kb</option>
675             option.
676           </para>
677           <para>
678             Note that to avoid wasting space, this value should
679             typically be less than 10&percnt; of the size of a stack
680             chunk (<option>-kc</option>), because in a chain of stack
681             chunks, each chunk will have a gap of unused space of this
682             size.
683           </para>
684         </listitem>
685       </varlistentry>
686
687       <varlistentry>
688         <term>
689           <option>-K</option><replaceable>size</replaceable>
690           <indexterm><primary><option>-K</option></primary><secondary>RTS option</secondary></indexterm>
691           <indexterm><primary>stack, maximum size</primary></indexterm>
692         </term>
693         <listitem>
694           <para>&lsqb;Default: 8M&rsqb; Set the maximum stack size for
695           an individual thread to <replaceable>size</replaceable>
696           bytes.  If the thread attempts to exceed this limit, it will
697             be send the <literal>StackOverflow</literal> exception.
698           </para>
699           <para>
700             This option is there mainly to stop the program eating up
701             all the available memory in the machine if it gets into an
702             infinite loop.
703           </para>
704         </listitem>
705       </varlistentry>
706
707       <varlistentry>
708         <term>
709           <option>-m</option><replaceable>n</replaceable>
710           <indexterm><primary><option>-m</option></primary><secondary>RTS option</secondary></indexterm>
711           <indexterm><primary>heap, minimum free</primary></indexterm>
712         </term>
713         <listitem>
714           <para>Minimum &percnt; <replaceable>n</replaceable> of heap
715           which must be available for allocation.  The default is
716           3&percnt;.</para>
717         </listitem>
718       </varlistentry>
719
720       <varlistentry>
721         <term>
722           <option>-M</option><replaceable>size</replaceable>
723           <indexterm><primary><option>-M</option></primary><secondary>RTS option</secondary></indexterm>
724           <indexterm><primary>heap size, maximum</primary></indexterm>
725         </term>
726         <listitem>
727           <para>&lsqb;Default: unlimited&rsqb; Set the maximum heap size to
728           <replaceable>size</replaceable> bytes.  The heap normally
729           grows and shrinks according to the memory requirements of
730           the program.  The only reason for having this option is to
731           stop the heap growing without bound and filling up all the
732           available swap space, which at the least will result in the
733           program being summarily killed by the operating
734           system.</para>
735
736           <para>The maximum heap size also affects other garbage
737           collection parameters: when the amount of live data in the
738           heap exceeds a certain fraction of the maximum heap size,
739           compacting collection will be automatically enabled for the
740           oldest generation, and the <option>-F</option> parameter
741           will be reduced in order to avoid exceeding the maximum heap
742           size.</para>
743         </listitem>
744       </varlistentry>
745
746       <varlistentry>
747         <term>
748           <option>-t</option><optional><replaceable>file</replaceable></optional>
749           <indexterm><primary><option>-t</option></primary><secondary>RTS option</secondary></indexterm>
750         </term>
751         <term>
752           <option>-s</option><optional><replaceable>file</replaceable></optional>
753           <indexterm><primary><option>-s</option></primary><secondary>RTS option</secondary></indexterm>
754         </term>
755         <term>
756           <option>-S</option><optional><replaceable>file</replaceable></optional>
757           <indexterm><primary><option>-S</option></primary><secondary>RTS option</secondary></indexterm>
758         </term>
759         <term>
760           <option>--machine-readable</option>
761           <indexterm><primary><option>--machine-readable</option></primary><secondary>RTS option</secondary></indexterm>
762         </term>
763         <listitem>
764           <para>These options produce runtime-system statistics, such
765           as the amount of time spent executing the program and in the
766           garbage collector, the amount of memory allocated, the
767           maximum size of the heap, and so on.  The three
768           variants give different levels of detail:
769           <option>-t</option> produces a single line of output in the
770           same format as GHC's <option>-Rghc-timing</option> option,
771           <option>-s</option> produces a more detailed summary at the
772           end of the program, and <option>-S</option> additionally
773           produces information about each and every garbage
774           collection.</para>
775
776           <para>The output is placed in
777           <replaceable>file</replaceable>.  If
778           <replaceable>file</replaceable> is omitted, then the output
779           is sent to <constant>stderr</constant>.</para>
780
781     <para>
782         If you use the <literal>-t</literal> flag then, when your
783         program finishes, you will see something like this:
784     </para>
785
786 <programlisting>
787 &lt;&lt;ghc: 36169392 bytes, 69 GCs, 603392/1065272 avg/max bytes residency (2 samples), 3M in use, 0.00 INIT (0.00 elapsed), 0.02 MUT (0.02 elapsed), 0.07 GC (0.07 elapsed) :ghc&gt;&gt;
788 </programlisting>
789
790     <para>
791         This tells you:
792     </para>
793
794     <itemizedlist>
795       <listitem>
796         <para>
797           The total number of bytes allocated by the program over the
798           whole run.
799         </para>
800       </listitem>
801       <listitem>
802         <para>
803           The total number of garbage collections performed.
804         </para>
805       </listitem>
806       <listitem>
807         <para>
808           The average and maximum "residency", which is the amount of
809           live data in bytes.  The runtime can only determine the
810           amount of live data during a major GC, which is why the
811           number of samples corresponds to the number of major GCs
812           (and is usually relatively small).  To get a better picture
813           of the heap profile of your program, use
814           the <option>-hT</option> RTS option
815           (<xref linkend="rts-profiling" />).
816         </para>
817       </listitem>
818       <listitem>
819         <para>
820           The peak memory the RTS has allocated from the OS. 
821         </para>
822       </listitem>
823       <listitem>
824         <para>
825           The amount of CPU time and elapsed wall clock time while
826           initialising the runtime system (INIT), running the program
827           itself (MUT, the mutator), and garbage collecting (GC).
828         </para>
829       </listitem>
830     </itemizedlist>
831
832     <para>
833         You can also get this in a more future-proof, machine readable
834         format, with <literal>-t --machine-readable</literal>:
835     </para>
836
837 <programlisting>
838  [("bytes allocated", "36169392")
839  ,("num_GCs", "69")
840  ,("average_bytes_used", "603392")
841  ,("max_bytes_used", "1065272")
842  ,("num_byte_usage_samples", "2")
843  ,("peak_megabytes_allocated", "3")
844  ,("init_cpu_seconds", "0.00")
845  ,("init_wall_seconds", "0.00")
846  ,("mutator_cpu_seconds", "0.02")
847  ,("mutator_wall_seconds", "0.02")
848  ,("GC_cpu_seconds", "0.07")
849  ,("GC_wall_seconds", "0.07")
850  ]
851 </programlisting>
852
853     <para>
854         If you use the <literal>-s</literal> flag then, when your
855         program finishes, you will see something like this (the exact
856         details will vary depending on what sort of RTS you have, e.g.
857         you will only see profiling data if your RTS is compiled for
858         profiling):
859     </para>
860
861 <programlisting>
862       36,169,392 bytes allocated in the heap
863        4,057,632 bytes copied during GC
864        1,065,272 bytes maximum residency (2 sample(s))
865           54,312 bytes maximum slop
866                3 MB total memory in use (0 MB lost due to fragmentation)
867
868   Generation 0:    67 collections,     0 parallel,  0.04s,  0.03s elapsed
869   Generation 1:     2 collections,     0 parallel,  0.03s,  0.04s elapsed
870
871   SPARKS: 359207 (557 converted, 149591 pruned)
872
873   INIT  time    0.00s  (  0.00s elapsed)
874   MUT   time    0.01s  (  0.02s elapsed)
875   GC    time    0.07s  (  0.07s elapsed)
876   EXIT  time    0.00s  (  0.00s elapsed)
877   Total time    0.08s  (  0.09s elapsed)
878
879   %GC time      89.5%  (75.3% elapsed)
880
881   Alloc rate    4,520,608,923 bytes per MUT second
882
883   Productivity  10.5% of total user, 9.1% of total elapsed
884 </programlisting>
885
886     <itemizedlist>
887       <listitem>
888         <para>
889         The "bytes allocated in the heap" is the total bytes allocated
890         by the program over the whole run.
891         </para>
892       </listitem>
893       <listitem>
894         <para>
895         GHC uses a copying garbage collector by default. "bytes copied
896         during GC" tells you how many bytes it had to copy during
897         garbage collection.
898         </para>
899       </listitem>
900       <listitem>
901         <para>
902         The maximum space actually used by your program is the
903         "bytes maximum residency" figure. This is only checked during
904         major garbage collections, so it is only an approximation;
905         the number of samples tells you how many times it is checked.
906         </para>
907       </listitem>
908       <listitem>
909         <para>
910         The "bytes maximum slop" tells you the most space that is ever
911         wasted due to the way GHC allocates memory in blocks.  Slop is
912         memory at the end of a block that was wasted.  There's no way
913         to control this; we just like to see how much memory is being
914         lost this way.
915         </para>
916       </listitem>
917       <listitem>
918         <para>
919         The "total memory in use" tells you the peak memory the RTS has
920         allocated from the OS.
921         </para>
922       </listitem>
923       <listitem>
924         <para>
925         Next there is information about the garbage collections done.
926         For each generation it says how many garbage collections were
927         done, how many of those collections were done in parallel,
928         the total CPU time used for garbage collecting that generation,
929         and the total wall clock time elapsed while garbage collecting
930         that generation.
931         </para>
932       </listitem>
933       <listitem>
934         <para>The <literal>SPARKS</literal> statistic refers to the
935           use of <literal>Control.Parallel.par</literal> and related
936           functionality in the program.  Each spark represents a call
937           to <literal>par</literal>; a spark is "converted" when it is
938           executed in parallel; and a spark is "pruned" when it is
939           found to be already evaluated and is discarded from the pool
940           by the garbage collector.  Any remaining sparks are
941           discarded at the end of execution, so "converted" plus
942           "pruned" does not necessarily add up to the total.</para>
943       </listitem>
944       <listitem>
945         <para>
946         Next there is the CPU time and wall clock time elapsed broken
947         down by what the runtime system was doing at the time.
948         INIT is the runtime system initialisation.
949         MUT is the mutator time, i.e. the time spent actually running
950         your code.
951         GC is the time spent doing garbage collection.
952         RP is the time spent doing retainer profiling.
953         PROF is the time spent doing other profiling.
954         EXIT is the runtime system shutdown time.
955         And finally, Total is, of course, the total.
956         </para>
957         <para>
958         %GC time tells you what percentage GC is of Total.
959         "Alloc rate" tells you the "bytes allocated in the heap" divided
960         by the MUT CPU time.
961         "Productivity" tells you what percentage of the Total CPU and wall
962         clock elapsed times are spent in the mutator (MUT).
963         </para>
964       </listitem>
965     </itemizedlist>
966
967     <para>
968         The <literal>-S</literal> flag, as well as giving the same
969         output as the <literal>-s</literal> flag, prints information
970         about each GC as it happens:
971     </para>
972
973 <programlisting>
974     Alloc    Copied     Live    GC    GC     TOT     TOT  Page Flts
975     bytes     bytes     bytes  user  elap    user    elap
976    528496     47728    141512  0.01  0.02    0.02    0.02    0    0  (Gen:  1)
977 [...]
978    524944    175944   1726384  0.00  0.00    0.08    0.11    0    0  (Gen:  0)
979 </programlisting>
980
981     <para>
982         For each garbage collection, we print:
983     </para>
984
985     <itemizedlist>
986       <listitem>
987         <para>
988           How many bytes we allocated this garbage collection.
989         </para>
990       </listitem>
991       <listitem>
992         <para>
993           How many bytes we copied this garbage collection.
994         </para>
995       </listitem>
996       <listitem>
997         <para>
998           How many bytes are currently live.
999         </para>
1000       </listitem>
1001       <listitem>
1002         <para>
1003           How long this garbage collection took (CPU time and elapsed
1004           wall clock time).
1005         </para>
1006       </listitem>
1007       <listitem>
1008         <para>
1009           How long the program has been running (CPU time and elapsed
1010           wall clock time).
1011         </para>
1012       </listitem>
1013       <listitem>
1014         <para>
1015           How many page faults occured this garbage collection.
1016         </para>
1017       </listitem>
1018       <listitem>
1019         <para>
1020           How many page faults occured since the end of the last garbage
1021           collection.
1022         </para>
1023       </listitem>
1024       <listitem>
1025         <para>
1026           Which generation is being garbage collected.
1027         </para>
1028       </listitem>
1029     </itemizedlist>
1030
1031         </listitem>
1032       </varlistentry>
1033     </variablelist>
1034
1035   </sect2>
1036
1037   <sect2>
1038     <title>RTS options for concurrency and parallelism</title>
1039
1040     <para>The RTS options related to concurrency are described in
1041       <xref linkend="using-concurrent" />, and those for parallelism in
1042       <xref linkend="parallel-options"/>.</para>
1043   </sect2>
1044
1045   <sect2 id="rts-profiling">
1046     <title>RTS options for profiling</title>
1047
1048     <para>Most profiling runtime options are only available when you
1049     compile your program for profiling (see
1050     <xref linkend="prof-compiler-options" />, and
1051     <xref linkend="rts-options-heap-prof" /> for the runtime options).
1052     However, there is one profiling option that is available
1053     for ordinary non-profiled executables:</para>
1054
1055     <variablelist>
1056       <varlistentry>
1057         <term>
1058           <option>-hT</option>
1059           <indexterm><primary><option>-hT</option></primary><secondary>RTS
1060               option</secondary></indexterm>
1061         </term>
1062         <listitem>
1063           <para>Generates a basic heap profile, in the
1064             file <literal><replaceable>prog</replaceable>.hp</literal>.
1065             To produce the heap profile graph,
1066             use <command>hp2ps</command> (see <xref linkend="hp2ps"
1067                                                     />).  The basic heap profile is broken down by data
1068             constructor, with other types of closures (functions, thunks,
1069             etc.) grouped into broad categories
1070             (e.g. <literal>FUN</literal>, <literal>THUNK</literal>).  To
1071             get a more detailed profile, use the full profiling
1072             support (<xref linkend="profiling" />).</para>
1073         </listitem>
1074       </varlistentry>
1075     </variablelist>
1076   </sect2>
1077
1078   <sect2 id="rts-eventlog">
1079     <title>Tracing</title>
1080
1081     <indexterm><primary>tracing</primary></indexterm>
1082     <indexterm><primary>events</primary></indexterm>
1083     <indexterm><primary>eventlog files</primary></indexterm>
1084
1085     <para>
1086       When the program is linked with the <option>-eventlog</option>
1087       option (<xref linkend="options-linker" />), runtime events can
1088       be logged in two ways:
1089     </para>
1090
1091     <itemizedlist>
1092       <listitem>
1093         <para>
1094           In binary format to a file for later analysis by a
1095           variety of tools.  One such tool
1096           is <ulink url="http://hackage.haskell.org/package/ThreadScope">ThreadScope</ulink><indexterm><primary>ThreadScope</primary></indexterm>,
1097           which interprets the event log to produce a visual parallel
1098           execution profile of the program.
1099         </para>
1100       </listitem>
1101       <listitem>
1102         <para>
1103           As text to standard output, for debugging purposes.
1104         </para>
1105       </listitem>
1106     </itemizedlist>
1107
1108     <variablelist>
1109       <varlistentry>
1110         <term>
1111           <option>-l<optional><replaceable>flags</replaceable></optional></option>
1112           <indexterm><primary><option>-l</option></primary><secondary>RTS option</secondary></indexterm>
1113         </term>
1114         <listitem>
1115           <para>
1116             Log events in binary format to the
1117             file <filename><replaceable>program</replaceable>.eventlog</filename>,
1118             where <replaceable>flags</replaceable> is a sequence of
1119             zero or more characters indicating which kinds of events
1120             to log.  Currently there is only one type
1121             supported: <literal>-ls</literal>, for scheduler events.
1122           </para>
1123
1124           <para>
1125             The format of the log file is described by the header
1126             <filename>EventLogFormat.h</filename> that comes with
1127             GHC, and it can be parsed in Haskell using
1128             the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1129             library.  To dump the contents of
1130             a <literal>.eventlog</literal> file as text, use the
1131             tool <literal>show-ghc-events</literal> that comes with
1132             the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1133             package.
1134           </para>
1135         </listitem>
1136       </varlistentry>
1137
1138       <varlistentry>
1139         <term>
1140           <option>-v</option><optional><replaceable>flags</replaceable></optional>
1141           <indexterm><primary><option>-v</option></primary><secondary>RTS option</secondary></indexterm>
1142         </term>
1143         <listitem>
1144           <para>
1145             Log events as text to standard output, instead of to
1146             the <literal>.eventlog</literal> file.
1147             The <replaceable>flags</replaceable> are the same as
1148             for <option>-l</option>, with the additional
1149             option <literal>t</literal> which indicates that the
1150             each event printed should be preceded by a timestamp value
1151             (in the binary <literal>.eventlog</literal> file, all
1152             events are automatically associated with a timestamp).
1153           </para>
1154         </listitem>
1155       </varlistentry>
1156
1157     </variablelist>
1158
1159     <para>
1160       The debugging
1161       options <option>-D<replaceable>x</replaceable></option> also
1162       generate events which are logged using the tracing framework.
1163       By default those events are dumped as text to stdout
1164       (<option>-D<replaceable>x</replaceable></option>
1165       implies <option>-v</option>), but they may instead be stored in
1166       the binary eventlog file by using the <option>-l</option>
1167       option.
1168     </para>
1169   </sect2>
1170
1171   <sect2 id="rts-options-debugging">
1172     <title>RTS options for hackers, debuggers, and over-interested
1173     souls</title>
1174
1175     <indexterm><primary>RTS options, hacking/debugging</primary></indexterm>
1176
1177     <para>These RTS options might be used (a)&nbsp;to avoid a GHC bug,
1178     (b)&nbsp;to see &ldquo;what's really happening&rdquo;, or
1179     (c)&nbsp;because you feel like it.  Not recommended for everyday
1180     use!</para>
1181
1182     <variablelist>
1183
1184       <varlistentry>
1185         <term>
1186           <option>-B</option>
1187           <indexterm><primary><option>-B</option></primary><secondary>RTS option</secondary></indexterm>
1188         </term>
1189         <listitem>
1190           <para>Sound the bell at the start of each (major) garbage
1191           collection.</para>
1192
1193           <para>Oddly enough, people really do use this option!  Our
1194           pal in Durham (England), Paul Callaghan, writes: &ldquo;Some
1195           people here use it for a variety of
1196           purposes&mdash;honestly!&mdash;e.g., confirmation that the
1197           code/machine is doing something, infinite loop detection,
1198           gauging cost of recently added code. Certain people can even
1199           tell what stage &lsqb;the program&rsqb; is in by the beep
1200           pattern. But the major use is for annoying others in the
1201           same office&hellip;&rdquo;</para>
1202         </listitem>
1203       </varlistentry>
1204
1205       <varlistentry>
1206         <term>
1207           <option>-D</option><replaceable>x</replaceable>
1208           <indexterm><primary>-D</primary><secondary>RTS option</secondary></indexterm>
1209         </term>
1210         <listitem>
1211           <para>
1212             An RTS debugging flag; only availble if the program was
1213             linked with the <option>-debug</option> option.  Various
1214             values of <replaceable>x</replaceable> are provided to
1215             enable debug messages and additional runtime sanity checks
1216             in different subsystems in the RTS, for
1217             example <literal>+RTS -Ds -RTS</literal> enables debug
1218             messages from the scheduler.
1219             Use <literal>+RTS&nbsp;-?</literal> to find out which
1220             debug flags are supported.
1221           </para>
1222
1223           <para>
1224             Debug messages will be sent to the binary event log file
1225             instead of stdout if the <option>-l</option> option is
1226             added.  This might be useful for reducing the overhead of
1227             debug tracing.
1228           </para>
1229         </listitem>
1230       </varlistentry>
1231
1232       <varlistentry>
1233         <term>
1234           <option>-r</option><replaceable>file</replaceable>
1235           <indexterm><primary><option>-r</option></primary><secondary>RTS option</secondary></indexterm>
1236           <indexterm><primary>ticky ticky profiling</primary></indexterm>
1237           <indexterm><primary>profiling</primary><secondary>ticky ticky</secondary></indexterm>
1238         </term>
1239         <listitem>
1240           <para>Produce &ldquo;ticky-ticky&rdquo; statistics at the
1241           end of the program run (only available if the program was
1242           linked with <option>-debug</option>).
1243           The <replaceable>file</replaceable> business works just like
1244           on the <option>-S</option> RTS option, above.</para>
1245
1246           <para>For more information on ticky-ticky profiling, see
1247           <xref linkend="ticky-ticky"/>.</para>
1248         </listitem>
1249       </varlistentry>
1250
1251       <varlistentry>
1252         <term>
1253           <option>-xc</option>
1254           <indexterm><primary><option>-xc</option></primary><secondary>RTS option</secondary></indexterm>
1255         </term>
1256         <listitem>
1257           <para>(Only available when the program is compiled for
1258           profiling.)  When an exception is raised in the program,
1259           this option causes the current cost-centre-stack to be
1260           dumped to <literal>stderr</literal>.</para>
1261
1262           <para>This can be particularly useful for debugging: if your
1263           program is complaining about a <literal>head []</literal>
1264           error and you haven't got a clue which bit of code is
1265           causing it, compiling with <literal>-prof
1266           -auto-all</literal> and running with <literal>+RTS -xc
1267           -RTS</literal> will tell you exactly the call stack at the
1268           point the error was raised.</para>
1269
1270           <para>The output contains one line for each exception raised
1271           in the program (the program might raise and catch several
1272           exceptions during its execution), where each line is of the
1273           form:</para>
1274
1275 <screen>
1276 &lt; cc<subscript>1</subscript>, ..., cc<subscript>n</subscript> &gt;
1277 </screen>
1278           <para>each <literal>cc</literal><subscript>i</subscript> is
1279           a cost centre in the program (see <xref
1280           linkend="cost-centres"/>), and the sequence represents the
1281           &ldquo;call stack&rdquo; at the point the exception was
1282           raised.  The leftmost item is the innermost function in the
1283           call stack, and the rightmost item is the outermost
1284           function.</para>
1285
1286         </listitem>
1287       </varlistentry>
1288
1289       <varlistentry>
1290         <term>
1291           <option>-Z</option>
1292           <indexterm><primary><option>-Z</option></primary><secondary>RTS option</secondary></indexterm>
1293         </term>
1294         <listitem>
1295           <para>Turn <emphasis>off</emphasis> &ldquo;update-frame
1296           squeezing&rdquo; at garbage-collection time.  (There's no
1297           particularly good reason to turn it off, except to ensure
1298           the accuracy of certain data collected regarding thunk entry
1299           counts.)</para>
1300         </listitem>
1301       </varlistentry>
1302     </variablelist>
1303
1304   </sect2>
1305
1306   <sect2>
1307     <title>Getting information about the RTS</title>
1308
1309     <indexterm><primary>RTS</primary></indexterm>
1310
1311     <para>It is possible to ask the RTS to give some information about
1312     itself. To do this, use the <option>--info</option> flag, e.g.</para>
1313 <screen>
1314 $ ./a.out +RTS --info
1315  [("GHC RTS", "YES")
1316  ,("GHC version", "6.7")
1317  ,("RTS way", "rts_p")
1318  ,("Host platform", "x86_64-unknown-linux")
1319  ,("Host architecture", "x86_64")
1320  ,("Host OS", "linux")
1321  ,("Host vendor", "unknown")
1322  ,("Build platform", "x86_64-unknown-linux")
1323  ,("Build architecture", "x86_64")
1324  ,("Build OS", "linux")
1325  ,("Build vendor", "unknown")
1326  ,("Target platform", "x86_64-unknown-linux")
1327  ,("Target architecture", "x86_64")
1328  ,("Target OS", "linux")
1329  ,("Target vendor", "unknown")
1330  ,("Word size", "64")
1331  ,("Compiler unregisterised", "NO")
1332  ,("Tables next to code", "YES")
1333  ]
1334 </screen>
1335     <para>The information is formatted such that it can be read as a
1336     of type <literal>[(String, String)]</literal>. Currently the following
1337     fields are present:</para>
1338
1339     <variablelist>
1340
1341       <varlistentry>
1342         <term><literal>GHC RTS</literal></term>
1343         <listitem>
1344           <para>Is this program linked against the GHC RTS? (always
1345           "YES").</para>
1346         </listitem>
1347       </varlistentry>
1348
1349       <varlistentry>
1350         <term><literal>GHC version</literal></term>
1351         <listitem>
1352           <para>The version of GHC used to compile this program.</para>
1353         </listitem>
1354       </varlistentry>
1355
1356       <varlistentry>
1357         <term><literal>RTS way</literal></term>
1358         <listitem>
1359           <para>The variant (&ldquo;way&rdquo;) of the runtime. The
1360           most common values are <literal>rts</literal> (vanilla),
1361           <literal>rts_thr</literal> (threaded runtime, i.e. linked using the
1362           <literal>-threaded</literal> option) and <literal>rts_p</literal>
1363           (profiling runtime, i.e. linked using the <literal>-prof</literal>
1364           option). Other variants include <literal>debug</literal>
1365           (linked using <literal>-debug</literal>),
1366           <literal>t</literal> (ticky-ticky profiling) and
1367           <literal>dyn</literal> (the RTS is
1368           linked in dynamically, i.e. a shared library, rather than statically
1369           linked into the executable itself). These can be combined,
1370           e.g. you might have <literal>rts_thr_debug_p</literal>.</para>
1371         </listitem>
1372       </varlistentry>
1373
1374       <varlistentry>
1375         <term>
1376             <literal>Target platform</literal>,
1377             <literal>Target architecture</literal>,
1378             <literal>Target OS</literal>,
1379             <literal>Target vendor</literal>
1380         </term>
1381         <listitem>
1382           <para>These are the platform the program is compiled to run on.</para>
1383         </listitem>
1384       </varlistentry>
1385
1386       <varlistentry>
1387         <term>
1388             <literal>Build platform</literal>,
1389             <literal>Build architecture</literal>,
1390             <literal>Build OS</literal>,
1391             <literal>Build vendor</literal>
1392         </term>
1393         <listitem>
1394           <para>These are the platform where the program was built
1395           on. (That is, the target platform of GHC itself.) Ordinarily
1396           this is identical to the target platform. (It could potentially
1397           be different if cross-compiling.)</para>
1398         </listitem>
1399       </varlistentry>
1400
1401       <varlistentry>
1402         <term>
1403             <literal>Host platform</literal>,
1404             <literal>Host architecture</literal>
1405             <literal>Host OS</literal>
1406             <literal>Host vendor</literal>
1407         </term>
1408         <listitem>
1409           <para>These are the platform where GHC itself was compiled.
1410           Again, this would normally be identical to the build and
1411           target platforms.</para>
1412         </listitem>
1413       </varlistentry>
1414
1415       <varlistentry>
1416         <term><literal>Word size</literal></term>
1417         <listitem>
1418           <para>Either <literal>"32"</literal> or <literal>"64"</literal>,
1419           reflecting the word size of the target platform.</para>
1420         </listitem>
1421       </varlistentry>
1422
1423       <varlistentry>
1424         <term><literal>Compiler unregistered</literal></term>
1425         <listitem>
1426           <para>Was this program compiled with an &ldquo;unregistered&rdquo;
1427           version of GHC? (I.e., a version of GHC that has no platform-specific
1428           optimisations compiled in, usually because this is a currently
1429           unsupported platform.) This value will usually be no, unless you're
1430           using an experimental build of GHC.</para>
1431         </listitem>
1432       </varlistentry>
1433
1434       <varlistentry>
1435         <term><literal>Tables next to code</literal></term>
1436         <listitem>
1437           <para>Putting info tables directly next to entry code is a useful
1438           performance optimisation that is not available on all platforms.
1439           This field tells you whether the program has been compiled with
1440           this optimisation. (Usually yes, except on unusual platforms.)</para>
1441         </listitem>
1442       </varlistentry>
1443
1444     </variablelist>
1445
1446   </sect2>
1447 </sect1>
1448
1449 <!-- Emacs stuff:
1450      ;;; Local Variables: ***
1451      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
1452      ;;; End: ***
1453  -->