diff options
author | Araq <rumpf_a@web.de> | 2012-04-21 16:38:25 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-04-21 16:38:25 +0200 |
commit | 7e7c514dfcb6fcd83356ecadf5fec5526d7c332d (patch) | |
tree | ca0ad40a57c54eb69b3dd02e46f91606bc191ab5 | |
parent | 7511a05b27e919c61703fea31f8d6d99cb2eae05 (diff) | |
download | Nim-7e7c514dfcb6fcd83356ecadf5fec5526d7c332d.tar.gz |
documentation improvements; GC_step improved
-rw-r--r-- | doc/gc.txt | 52 | ||||
-rwxr-xr-x | doc/lib.txt | 4 | ||||
-rwxr-xr-x | doc/nimrodc.txt | 9 | ||||
-rwxr-xr-x | lib/system.nim | 4 | ||||
-rwxr-xr-x | lib/system/gc.nim | 12 | ||||
-rwxr-xr-x | todo.txt | 2 | ||||
-rwxr-xr-x | web/news.txt | 6 | ||||
-rwxr-xr-x | web/nimrod.ini | 2 |
8 files changed, 68 insertions, 23 deletions
diff --git a/doc/gc.txt b/doc/gc.txt index e052135eb..26fa1e8a3 100644 --- a/doc/gc.txt +++ b/doc/gc.txt @@ -2,11 +2,15 @@ Nimrod's Garbage Collector ========================== +:Author: Andreas Rumpf +:Version: |nimrodversion| + + Introduction ============ -This document describes how the GC works and how to tune it for (soft) -realtime systems. +This document describes how the GC works and how to tune it for +(soft) `realtime systems`:idx:. The basic algorithm is *Deferrent Reference Counting* with cycle detection. References on the stack are not counted for better performance (and easier C @@ -15,22 +19,49 @@ delta-subgraph of the heap that changed since its last run. The GC is only triggered in a memory allocation operation. It it not triggered -by some timer or background thread. +by some timer and does not run in a background thread. + +The cycle collector can be en-/disabled independently from the other parts of +the GC with ``GC_enableMarkAndSweep`` and ``GC_disableMarkAndSweep``. + +To force a full collection call ``GC_fullCollect``. Note that it is generally +better to let the GC do its work and not enforce a full collection. Realtime support ================ -To enable realtime support, the switch `useRealtimeGC`:idx: needs to be +To enable realtime support, the symbol `useRealtimeGC`:idx: needs to be defined. With this switch the GC supports the following operations: .. code-block:: nimrod proc GC_setMaxPause*(MaxPauseInUs: int) proc GC_step*(us: int, strongAdvice = false) -After calling ``GC_setMaxPause`` any GC run tries to finish within -``MaxPauseInUs`` microseconds. XXX complete documentation +The unit of the parameters ``MaxPauseInUs`` and ``us`` is microseconds. + +These two procs are the two modus operandi of the realtime GC: +(1) GC_SetMaxPause Mode + + You can call ``GC_SetMaxPause`` at program startup and then each triggered + GC run tries to not take longer than ``MaxPause`` time. However, it is + possible (and common) that the work is nevertheless not evenly distributed + as each call to ``new`` can trigger the GC and thus take ``MaxPause`` + time. + +(2) GC_step Mode + + This allows the GC to perform some work for up to ``us`` time. This is + useful to call in a main loop to ensure the GC can do its work. To + bind all GC activity to a ``GC_step`` call, deactivate the GC with + ``GC_disable`` at program startup. + +These procs provide a "best effort" realtime guarantee; in particular the +cycle collector is not aware of deadlines yet. Deactivate it to get more +predictable realtime behaviour. Tests show that a 2ms max pause +time will be met in almost all cases on modern CPUs unless the cycle collector +is triggered. Time measurement @@ -53,6 +84,11 @@ later versions of the collector. Tweaking the GC -=============== +--------------- + +The collector checks whether there is still time left for its work after +every ``workPackage``'th iteration. This is currently set to 100 which means +that up to 100 objects are traversed and freed before it checks again. Thus +``workPackage`` affects the timing granularity and may need to be tweaked in +highly specialized environments or for older hardware. -To be written. diff --git a/doc/lib.txt b/doc/lib.txt index 4f42bb1ca..3f2e3e0c3 100755 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -201,6 +201,10 @@ Internet Protocols and Support * `ftpclient <ftpclient.html>`_ This module implements an FTP client. +* `cookies <cookies.html>`_ + This module contains helper procs for parsing and generating cookies. + + Parsers ------- diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt index 9c165d499..0fda5bb88 100755 --- a/doc/nimrodc.txt +++ b/doc/nimrodc.txt @@ -386,7 +386,7 @@ input management. To start Nimrod in interactive mode use the command ``nimrod i``. To quit use the ``quit()`` command. To determine whether an input line is an incomplete statement to be continued these rules are used: -1. The line ends with ``[-+*/\\<>!\?\|%&$@~,;:=#^]\s*$`` (operator symbol followed by optional whitespace). +1. The line ends with ``[-+*/\\<>!\?\|%&$@~,;:=#^]\s*$`` (operator symbol followed by optional whitespace). 2. The line starts with a space (indentation). 3. The line is within a triple quoted string literal. However, the detection does not work if the line contains more than one ``"""``. @@ -407,6 +407,13 @@ So to generate code for an `AVR`:idx: processor use this command:: nimrod c --cpu:avr --os:standalone --gc:none -d:useMalloc --genScript x.nim + +Nimrod for realtime systems +=========================== + +See the documentation of Nimrod's soft realtime `GC <gc.html>`_ for further +information. + Debugging with Nimrod ===================== diff --git a/lib/system.nim b/lib/system.nim index 128ec921c..ae6e4dc9f 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -807,7 +807,6 @@ const taintMode = compileOption("taintmode") when taintMode: - # XXX use a compile time option for it! type TaintedString* = distinct string ## a distinct string type that ## is `tainted`:idx:. It is an alias for ## ``string`` if the taint mode is not @@ -1486,8 +1485,9 @@ type gcOptimizeTime, ## optimize for speed gcOptimizeSpace ## optimize for memory footprint -proc GC_setStrategy*(strategy: TGC_Strategy) {.rtl.} +proc GC_setStrategy*(strategy: TGC_Strategy) {.rtl, deprecated.} ## tells the GC the desired strategy for the application. + ## **Deprecated** since version 0.8.14. This has always been a nop. proc GC_enableMarkAndSweep*() {.rtl.} proc GC_disableMarkAndSweep*() {.rtl.} diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 1fdb1d335..ea30754a6 100755 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -856,15 +856,11 @@ when withRealtime: proc GC_step(gch: var TGcHeap, us: int, strongAdvice: bool) = acquire(gch) - var oldThreshold = gch.cycleThreshold - # disable cycle collection: - gch.cycleThreshold = high(gch.cycleThreshold)-1 gch.maxPause = us.toNano - if strongAdvice: - if gch.recGcLock == 0: collectCTBody(gch) - else: - collectCT(gch) - gch.cycleThreshold = oldThreshold + if (gch.zct.len >= ZctThreshold or (cycleGC and + getOccupiedMem(gch.region)>=gch.cycleThreshold) or alwaysGC) or + strongAdvice: + collectCTBody(gch) release(gch) proc GC_step*(us: int, strongAdvice = false) = GC_step(gch, us, strongAdvice) diff --git a/todo.txt b/todo.txt index 83c97739b..722f5cef7 100755 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,6 @@ version 0.9.0 ============= -- complete GC's documentation -- make ``cookies`` part of the stdlib's documentation - make templates hygienic by default - ``=`` should be overloadable; requires specialization for ``=`` - fix remaining generics bugs diff --git a/web/news.txt b/web/news.txt index a1816d474..090458d02 100755 --- a/web/news.txt +++ b/web/news.txt @@ -13,12 +13,15 @@ Bugfixes - Fixed a bug where the compiler would "optimize away" valid constant parts of a string concatenation. - Fixed a bug concerning implicit type conversions in ``case`` statements. +- Fixed a serious code generation bug that caused ``algorithm.sort`` to + produce segmentation faults. Library Additions ----------------- - Added the (already existing) module ``htmlgen`` to the documentation. +- Added the (already existing) module ``cookies`` to the documentation. - Added ``system.shallow`` that can be used to speed up string and sequence assignments. - Added ``system.eval`` that can execute an anonymous block of code at @@ -58,9 +61,10 @@ Changes affecting backwards compatibility ``PNimrodNode`` which unfortunately breaks the old macro system. - ``pegs.@`` has been renamed to ``pegs.!*`` and ``pegs.@@`` has been renamed to ``pegs.!*\`` as ``@`` operators now have different precedence. -- the type ``proc`` (without any params or return type) is now considered a +- The type ``proc`` (without any params or return type) is now considered a type class matching all proc types. Use ``proc ()`` to get the old meaning denoting a proc expecing no arguments and returing no value. +- Deprecated ``system.GC_setStrategy``. Compiler Additions diff --git a/web/nimrod.ini b/web/nimrod.ini index 6192c6f3d..e39c41ee0 100755 --- a/web/nimrod.ini +++ b/web/nimrod.ini @@ -41,7 +41,7 @@ srcdoc: "pure/json;pure/base64;pure/scgi;pure/redis;impure/graphics" srcdoc: "impure/rdstdin;wrappers/zmq;wrappers/sphinx" srcdoc: "pure/collections/tables;pure/collections/sets;pure/collections/lists" srcdoc: "pure/collections/intsets;pure/collections/queues;pure/encodings" -srcdoc: "pure/events;pure/collections/sequtils;pure/irc;ecmas/dom" +srcdoc: "pure/events;pure/collections/sequtils;pure/irc;ecmas/dom;pure/cookies" srcdoc: "pure/ftpclient;pure/memfiles;pure/subexes;pure/collections/critbits" srcdoc: "pure/asyncio;pure/actors;core/locks;pure/oids;pure/endians" |