1. 09 Apr, 2020 1 commit
    • Ömer Sinan Ağacan's avatar
      Fix CNF handling in compacting GC · 39075176
      Ömer Sinan Ağacan authored
      Fixes #17937
      
      Previously compacting GC simply ignored CNFs. This is mostly fine as
      most (see "What about small compacts?" below) CNF objects don't have
      outgoing pointers, and are "large" (allocated in large blocks) and large
      objects are not moved or compacted.
      
      However if we do GC *during* sharing-preserving compaction then the CNF
      will have a hash table mapping objects that have been moved to the CNF
      to their location in the CNF, to be able to preserve sharing.
      
      This case is handled in the copying collector, in `scavenge_compact`,
      where we evacuate hash table entries and then rehash the table.
      
      Compacting GC ignored this case.
      
      We now visit CNFs in all generations when threading pointers to the
      compacted heap and thread hash table keys. A visited CNF is added to the
      list `nfdata_chain`. After compaction is done, we re-visit the CNFs in
      that list and rehash the tables.
      
      The overhead is minimal: the list is static in `Compact.c`, and link
      field is added to `StgCompactNFData` closure. Programs that don't use
      CNFs should not be affected.
      
      To test this CNF tests are now also run in a new way 'compacting_gc',
      which just passes `-c` to the RTS, enabling compacting GC for the oldest
      generation. Before this patch the result would be:
      
          Unexpected failures:
             compact_gc.run          compact_gc [bad exit code (139)] (compacting_gc)
             compact_huge_array.run  compact_huge_array [bad exit code (1)] (compacting_gc)
      
      With this patch all tests pass. I can also pass `-c -DS` without any
      failures.
      
      What about small compacts? Small CNFs are still not handled by the
      compacting GC. However so far I'm unable to write a test that triggers a
      runtime panic ("update_fwd: unknown/strange object") by allocating a
      small CNF in a compated heap. It's possible that I'm missing something
      and it's not possible to have a small CNF.
      
      NoFib Results:
      
      --------------------------------------------------------------------------------
              Program           Size    Allocs    Instrs     Reads    Writes
      --------------------------------------------------------------------------------
                   CS          +0.1%      0.0%      0.0%     +0.0%     +0.0%
                  CSD          +0.1%      0.0%      0.0%      0.0%      0.0%
                   FS          +0.1%      0.0%      0.0%      0.0%      0.0%
                    S          +0.1%      0.0%      0.0%      0.0%      0.0%
                   VS          +0.1%      0.0%      0.0%      0.0%      0.0%
                  VSD          +0.1%      0.0%     +0.0%     +0.0%     -0.0%
                  VSM          +0.1%      0.0%     +0.0%     -0.0%      0.0%
                 anna          +0.0%      0.0%     -0.0%     -0.0%     -0.0%
                 ansi          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 atom          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               awards          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               banner          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
           bernouilli          +0.1%      0.0%      0.0%     -0.0%     +0.0%
         binary-trees          +0.1%      0.0%     -0.0%     -0.0%      0.0%
                boyer          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               boyer2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 bspt          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
            cacheprof          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
             calendar          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             cichelli          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
              circsim          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             clausify          +0.1%      0.0%     -0.0%     +0.0%     +0.0%
        comp_lab_zift          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             compress          +0.1%      0.0%     +0.0%     +0.0%      0.0%
            compress2          +0.1%      0.0%     -0.0%      0.0%      0.0%
          constraints          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
         cryptarithm1          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
         cryptarithm2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                  cse          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
         digits-of-e1          +0.1%      0.0%     +0.0%     -0.0%     -0.0%
         digits-of-e2          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               dom-lt          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                eliza          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                event          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
          exact-reals          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               exp3_8          +0.1%      0.0%     +0.0%     -0.0%      0.0%
               expert          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
       fannkuch-redux          +0.1%      0.0%     -0.0%      0.0%      0.0%
                fasta          +0.1%      0.0%     -0.0%     +0.0%     +0.0%
                  fem          +0.1%      0.0%     -0.0%     +0.0%      0.0%
                  fft          +0.1%      0.0%     -0.0%     +0.0%     +0.0%
                 fft2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             fibheaps          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 fish          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                fluid          +0.0%      0.0%     +0.0%     +0.0%     +0.0%
               fulsom          +0.1%      0.0%     -0.0%     +0.0%      0.0%
               gamteb          +0.1%      0.0%     +0.0%     +0.0%      0.0%
                  gcd          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
          gen_regexps          +0.1%      0.0%     -0.0%     +0.0%      0.0%
               genfft          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                   gg          +0.1%      0.0%      0.0%     +0.0%     +0.0%
                 grep          +0.1%      0.0%     -0.0%     +0.0%     +0.0%
               hidden          +0.1%      0.0%     +0.0%     -0.0%      0.0%
                  hpg          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
                  ida          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                infer          +0.1%      0.0%     +0.0%      0.0%     -0.0%
              integer          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
            integrate          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
         k-nucleotide          +0.1%      0.0%     +0.0%     +0.0%      0.0%
                kahan          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
              knights          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               lambda          +0.1%      0.0%     +0.0%     +0.0%     -0.0%
           last-piece          +0.1%      0.0%     +0.0%      0.0%      0.0%
                 lcss          +0.1%      0.0%     +0.0%     +0.0%      0.0%
                 life          +0.1%      0.0%     -0.0%     +0.0%     +0.0%
                 lift          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               linear          +0.1%      0.0%     -0.0%     +0.0%      0.0%
            listcompr          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             listcopy          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             maillist          +0.1%      0.0%     +0.0%     -0.0%     -0.0%
               mandel          +0.1%      0.0%     +0.0%     +0.0%      0.0%
              mandel2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 mate          +0.1%      0.0%     +0.0%      0.0%     +0.0%
              minimax          +0.1%      0.0%     -0.0%      0.0%     -0.0%
              mkhprog          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
           multiplier          +0.1%      0.0%     +0.0%      0.0%      0.0%
               n-body          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             nucleic2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 para          +0.1%      0.0%      0.0%     +0.0%     +0.0%
            paraffins          +0.1%      0.0%     +0.0%     -0.0%      0.0%
               parser          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
              parstof          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                  pic          +0.1%      0.0%     -0.0%     -0.0%      0.0%
             pidigits          +0.1%      0.0%     +0.0%     -0.0%     -0.0%
                power          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               pretty          +0.1%      0.0%     -0.0%     -0.0%     -0.1%
               primes          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
            primetest          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               prolog          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               puzzle          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               queens          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
              reptile          +0.1%      0.0%     -0.0%     -0.0%     +0.0%
      reverse-complem          +0.1%      0.0%     +0.0%      0.0%     -0.0%
              rewrite          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
                 rfib          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                  rsa          +0.1%      0.0%     -0.0%     +0.0%     -0.0%
                  scc          +0.1%      0.0%     -0.0%     -0.0%     -0.1%
                sched          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                  scs          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               simple          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
                solid          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
              sorting          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
        spectral-norm          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
               sphere          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
               symalg          +0.1%      0.0%     -0.0%     -0.0%     -0.0%
                  tak          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
            transform          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
             treejoin          +0.1%      0.0%     +0.0%     -0.0%     -0.0%
            typecheck          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
              veritas          +0.0%      0.0%     +0.0%     +0.0%     +0.0%
                 wang          +0.1%      0.0%      0.0%     +0.0%     +0.0%
            wave4main          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
         wheel-sieve1          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
         wheel-sieve2          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
                 x2n1          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
      --------------------------------------------------------------------------------
                  Min          +0.0%      0.0%     -0.0%     -0.0%     -0.1%
                  Max          +0.1%      0.0%     +0.0%     +0.0%     +0.0%
       Geometric Mean          +0.1%     -0.0%     -0.0%     -0.0%     -0.0%
      
      Bumping numbers of nonsensical perf tests:
      
      Metric Increase:
          T12150
          T12234
          T12425
          T13035
          T5837
          T6048
      
      It's simply not possible for this patch to increase allocations, and
      I've wasted enough time on these test in the past (see #17686). I think
      these tests should not be perf tests, but for now I'll bump the numbers.
      39075176
  2. 29 Feb, 2020 1 commit
  3. 22 Oct, 2019 1 commit
    • Ben Gamari's avatar
      Fix unregisterised build · 06d51c4e
      Ben Gamari authored
      This required some fiddling around with the location of forward
      declarations since the C sources generated by GHC's C backend only
      includes Stg.h.
      06d51c4e
  4. 22 Sep, 2019 1 commit
  5. 16 Jan, 2019 1 commit
  6. 24 Sep, 2018 1 commit
  7. 02 Jun, 2018 1 commit
  8. 16 Apr, 2018 1 commit
  9. 30 Mar, 2018 1 commit
  10. 29 Apr, 2017 1 commit
  11. 23 Apr, 2017 1 commit
  12. 07 Dec, 2016 1 commit
    • Simon Marlow's avatar
      Overhaul of Compact Regions (#12455) · 7036fde9
      Simon Marlow authored
      Summary:
      This commit makes various improvements and addresses some issues with
      Compact Regions (aka Compact Normal Forms).
      
      This was the most important thing I wanted to fix.  Compaction
      previously prevented GC from running until it was complete, which
      would be a problem in a multicore setting.  Now, we compact using a
      hand-written Cmm routine that can be interrupted at any point.  When a
      GC is triggered during a sharing-enabled compaction, the GC has to
      traverse and update the hash table, so this hash table is now stored
      in the StgCompactNFData object.
      
      Previously, compaction consisted of a deepseq using the NFData class,
      followed by a traversal in C code to copy the data.  This is now done
      in a single pass with hand-written Cmm (see rts/Compact.cmm). We no
      longer use the NFData instances, instead the Cmm routine evaluates
      components directly as it compacts.
      
      The new compaction is about 50% faster than the old one with no
      sharing, and a little faster on average with sharing (the cost of the
      hash table dominates when we're doing sharing).
      
      Static objects that don't (transitively) refer to any CAFs don't need
      to be copied into the compact region.  In particular this means we
      often avoid copying Char values and small Int values, because these
      are static closures in the runtime.
      
      Each Compact# object can support a single compactAdd# operation at any
      given time, so the Data.Compact library now enforces mutual exclusion
      using an MVar stored in the Compact object.
      
      We now get exceptions rather than killing everything with a barf()
      when we encounter an object that cannot be compacted (a function, or a
      mutable object).  We now also detect pinned objects, which can't be
      compacted either.
      
      The Data.Compact API has been refactored and cleaned up.  A new
      compactSize operation returns the size (in bytes) of the compact
      object.
      
      Most of the documentation is in the Haddock docs for the compact
      library, which I've expanded and improved here.
      
      Various comments in the code have been improved, especially the main
      Note [Compact Normal Forms] in rts/sm/CNF.c.
      
      I've added a few tests, and expanded a few of the tests that were
      there.  We now also run the tests with GHCi, and in a new test way
      that enables sanity checking (+RTS -DS).
      
      There's a benchmark in libraries/compact/tests/compact_bench.hs for
      measuring compaction speed and comparing sharing vs. no sharing.
      
      The field totalDataW in StgCompactNFData was unnecessary.
      
      Test Plan:
      * new unit tests
      * validate
      * tested manually that we can compact Data.Aeson data
      
      Reviewers: gcampax, bgamari, ezyang, austin, niteria, hvr, erikd
      
      Subscribers: thomie, simonpj
      
      Differential Revision: https://phabricator.haskell.org/D2751
      
      GHC Trac Issues: #12455
      7036fde9
  13. 20 Jul, 2016 1 commit
    • gcampax's avatar
      Compact Regions · cf989ffe
      gcampax authored
      This brings in initial support for compact regions, as described in the
      ICFP 2015 paper "Efficient Communication and Collection with Compact
      Normal Forms" (Edward Z. Yang et.al.) and implemented by Giovanni
      Campagna.
      
      Some things may change before the 8.2 release, but I (Simon M.) wanted
      to get the main patch committed so that we can iterate.
      
      What documentation there is is in the Data.Compact module in the new
      compact package.  We'll need to extend and polish the documentation
      before the release.
      
      Test Plan:
      validate
      (new test cases included)
      
      Reviewers: ezyang, simonmar, hvr, bgamari, austin
      
      Subscribers: vikraman, Yuras, RyanGlScott, qnikst, mboes, facundominguez, rrnewton, thomie, erikd
      
      Differential Revision: https://phabricator.haskell.org/D1264
      
      GHC Trac Issues: #11493
      cf989ffe
  14. 18 Apr, 2016 1 commit
  15. 11 Sep, 2015 1 commit
  16. 20 Aug, 2014 1 commit
  17. 29 Mar, 2014 1 commit
    • tibbe's avatar
      Add SmallArray# and SmallMutableArray# types · 90329b6c
      tibbe authored
      These array types are smaller than Array# and MutableArray# and are
      faster when the array size is small, as they don't have the overhead
      of a card table. Having no card table reduces the closure size with 2
      words in the typical small array case and leads to less work when
      updating or GC:ing the array.
      
      Reduces both the runtime and memory allocation by 8.8% on my insert
      benchmark for the HashMap type in the unordered-containers package,
      which makes use of lots of small arrays. With tuned GC settings
      (i.e. `+RTS -A6M`) the runtime reduction is 15%.
      
      Fixes #8923.
      90329b6c
  18. 22 Nov, 2013 1 commit
  19. 15 Jun, 2013 1 commit
    • aljee@hyper.cx's avatar
      Allow multiple C finalizers to be attached to a Weak# · d61c623e
      aljee@hyper.cx authored
      The commit replaces mkWeakForeignEnv# with addCFinalizerToWeak#.
      This new primop mutates an existing Weak# object and adds a new
      C finalizer to it.
      
      This change removes an invariant in MarkWeak.c, namely that the relative
      order of Weak# objects in the list needs to be preserved across GC. This
      makes it easier to split the list into per-generation structures.
      
      The patch also removes a race condition between two threads calling
      finalizeWeak# on the same WEAK object at that same time.
      d61c623e
  20. 21 May, 2013 1 commit
  21. 01 Nov, 2012 1 commit
  22. 08 Oct, 2012 1 commit
    • Simon Marlow's avatar
      Produce new-style Cmm from the Cmm parser · a7c0387d
      Simon Marlow authored
      The main change here is that the Cmm parser now allows high-level cmm
      code with argument-passing and function calls.  For example:
      
      foo ( gcptr a, bits32 b )
      {
        if (b > 0) {
           // we can make tail calls passing arguments:
           jump stg_ap_0_fast(a);
        }
      
        return (x,y);
      }
      
      More details on the new cmm syntax are in Note [Syntax of .cmm files]
      in CmmParse.y.
      
      The old syntax is still more-or-less supported for those occasional
      code fragments that really need to explicitly manipulate the stack.
      However there are a couple of differences: it is now obligatory to
      give a list of live GlobalRegs on every jump, e.g.
      
        jump %ENTRY_CODE(Sp(0)) [R1];
      
      Again, more details in Note [Syntax of .cmm files].
      
      I have rewritten most of the .cmm files in the RTS into the new
      syntax, except for AutoApply.cmm which is generated by the genapply
      program: this file could be generated in the new syntax instead and
      would probably be better off for it, but I ran out of enthusiasm.
      
      Some other changes in this batch:
      
       - The PrimOp calling convention is gone, primops now use the ordinary
         NativeNodeCall convention.  This means that primops and "foreign
         import prim" code must be written in high-level cmm, but they can
         now take more than 10 arguments.
      
       - CmmSink now does constant-folding (should fix #7219)
      
       - .cmm files now go through the cmmPipeline, and as a result we
         generate better code in many cases.  All the object files generated
         for the RTS .cmm files are now smaller.  Performance should be
         better too, but I haven't measured it yet.
      
       - RET_DYN frames are removed from the RTS, lots of code goes away
      
       - we now have some more canned GC points to cover unboxed-tuples with
         2-4 pointers, which will reduce code size a little.
      a7c0387d
  23. 02 Feb, 2011 1 commit
  24. 15 Dec, 2010 1 commit
    • Simon Marlow's avatar
      Implement stack chunks and separate TSO/STACK objects · f30d5273
      Simon Marlow authored
      This patch makes two changes to the way stacks are managed:
      
      1. The stack is now stored in a separate object from the TSO.
      
      This means that it is easier to replace the stack object for a thread
      when the stack overflows or underflows; we don't have to leave behind
      the old TSO as an indirection any more.  Consequently, we can remove
      ThreadRelocated and deRefTSO(), which were a pain.
      
      This is obviously the right thing, but the last time I tried to do it
      it made performance worse.  This time I seem to have cracked it.
      
      2. Stacks are now represented as a chain of chunks, rather than
         a single monolithic object.
      
      The big advantage here is that individual chunks are marked clean or
      dirty according to whether they contain pointers to the young
      generation, and the GC can avoid traversing clean stack chunks during
      a young-generation collection.  This means that programs with deep
      stacks will see a big saving in GC overhead when using the default GC
      settings.
      
      A secondary advantage is that there is much less copying involved as
      the stack grows.  Programs that quickly grow a deep stack will see big
      improvements.
      
      In some ways the implementation is simpler, as nothing special needs
      to be done to reclaim stack as the stack shrinks (the GC just recovers
      the dead stack chunks).  On the other hand, we have to manage stack
      underflow between chunks, so there's a new stack frame
      (UNDERFLOW_FRAME), and we now have separate TSO and STACK objects.
      The total amount of code is probably about the same as before.
      
      There are new RTS flags:
      
         -ki<size> Sets the initial thread stack size (default 1k)  Egs: -ki4k -ki2m
         -kc<size> Sets the stack chunk size (default 32k)
         -kb<size> Sets the stack chunk buffer size (default 1k)
      
      -ki was previously called just -k, and the old name is still accepted
      for backwards compatibility.  These new options are documented.
      f30d5273
  25. 08 Jul, 2010 1 commit
    • Simon Marlow's avatar
      New asynchronous exception control API (ghc parts) · ad3b79d2
      Simon Marlow authored
      As discussed on the libraries/haskell-cafe mailing lists
        http://www.haskell.org/pipermail/libraries/2010-April/013420.html
      
      This is a replacement for block/unblock in the asychronous exceptions
      API to fix a problem whereby a function could unblock asynchronous
      exceptions even if called within a blocked context.
      
      The new terminology is "mask" rather than "block" (to avoid confusion
      due to overloaded meanings of the latter).
      
      In GHC, we changed the names of some primops:
      
        blockAsyncExceptions#   -> maskAsyncExceptions#
        unblockAsyncExceptions# -> unmaskAsyncExceptions#
        asyncExceptionsBlocked# -> getMaskingState#
      
      and added one new primop:
      
        maskUninterruptible#
      
      See the accompanying patch to libraries/base for the API changes.
      ad3b79d2
  26. 01 Jan, 2010 1 commit
  27. 01 Apr, 2010 1 commit
    • Simon Marlow's avatar
      Change the representation of the MVar blocked queue · f4692220
      Simon Marlow authored
      The list of threads blocked on an MVar is now represented as a list of
      separately allocated objects rather than being linked through the TSOs
      themselves.  This lets us remove a TSO from the list in O(1) time
      rather than O(n) time, by marking the list object.  Removing this
      linear component fixes some pathalogical performance cases where many
      threads were blocked on an MVar and became unreachable simultaneously
      (nofib/smp/threads007), or when sending an asynchronous exception to a
      TSO in a long list of thread blocked on an MVar.
      
      MVar performance has actually improved by a few percent as a result of
      this change, slightly to my surprise.
      
      This is the final cleanup in the sequence, which let me remove the old
      way of waking up threads (unblockOne(), MSG_WAKEUP) in favour of the
      new way (tryWakeupThread and MSG_TRY_WAKEUP, which is idempotent).  It
      is now the case that only the Capability that owns a TSO may modify
      its state (well, almost), and this simplifies various things.  More of
      the RTS is based on message-passing between Capabilities now.
      f4692220
  28. 29 Mar, 2010 1 commit
    • Simon Marlow's avatar
      New implementation of BLACKHOLEs · 5d52d9b6
      Simon Marlow authored
      This replaces the global blackhole_queue with a clever scheme that
      enables us to queue up blocked threads on the closure that they are
      blocked on, while still avoiding atomic instructions in the common
      case.
      
      Advantages:
      
       - gets rid of a locked global data structure and some tricky GC code
         (replacing it with some per-thread data structures and different
         tricky GC code :)
      
       - wakeups are more prompt: parallel/concurrent performance should
         benefit.  I haven't seen anything dramatic in the parallel
         benchmarks so far, but a couple of threading benchmarks do improve
         a bit.
      
       - waking up a thread blocked on a blackhole is now O(1) (e.g. if
         it is the target of throwTo).
      
       - less sharing and better separation of Capabilities: communication
         is done with messages, the data structures are strictly owned by a
         Capability and cannot be modified except by sending messages.
      
       - this change will utlimately enable us to do more intelligent
         scheduling when threads block on each other.  This is what started
         off the whole thing, but it isn't done yet (#3838).
      
      I'll be documenting all this on the wiki in due course.
      5d52d9b6
  29. 11 Mar, 2010 1 commit
    • Simon Marlow's avatar
      Use message-passing to implement throwTo in the RTS · 7408b392
      Simon Marlow authored
      This replaces some complicated locking schemes with message-passing
      in the implementation of throwTo. The benefits are
      
       - previously it was impossible to guarantee that a throwTo from
         a thread running on one CPU to a thread running on another CPU
         would be noticed, and we had to rely on the GC to pick up these
         forgotten exceptions. This no longer happens.
      
       - the locking regime is simpler (though the code is about the same
         size)
      
       - threads can be unblocked from a blocked_exceptions queue without
         having to traverse the whole queue now.  It's a rare case, but
         replaces an O(n) operation with an O(1).
      
       - generally we move in the direction of sharing less between
         Capabilities (aka HECs), which will become important with other
         changes we have planned.
      
      Also in this patch I replaced several STM-specific closure types with
      a generic MUT_PRIM closure type, which allowed a lot of code in the GC
      and other places to go away, hence the line-count reduction.  The
      message-passing changes resulted in about a net zero line-count
      difference.
      7408b392
  30. 17 Dec, 2009 1 commit
    • Simon Marlow's avatar
      Fix #650: use a card table to mark dirty sections of mutable arrays · 0417404f
      Simon Marlow authored
      The card table is an array of bytes, placed directly following the
      actual array data.  This means that array reading is unaffected, but
      array writing needs to read the array size from the header in order to
      find the card table.
      
      We use a bytemap rather than a bitmap, because updating the card table
      must be multi-thread safe.  Each byte refers to 128 entries of the
      array, but this is tunable by changing the constant
      MUT_ARR_PTRS_CARD_BITS in includes/Constants.h.
      0417404f
  31. 02 Aug, 2009 1 commit
    • Simon Marlow's avatar
      RTS tidyup sweep, first phase · a2a67cd5
      Simon Marlow authored
      The first phase of this tidyup is focussed on the header files, and in
      particular making sure we are exposinng publicly exactly what we need
      to, and no more.
      
       - Rts.h now includes everything that the RTS exposes publicly,
         rather than a random subset of it.
      
       - Most of the public header files have moved into subdirectories, and
         many of them have been renamed.  But clients should not need to
         include any of the other headers directly, just #include the main
         public headers: Rts.h, HsFFI.h, RtsAPI.h.
      
       - All the headers needed for via-C compilation have moved into the
         stg subdirectory, which is self-contained.  Most of the headers for
         the rest of the RTS APIs have moved into the rts subdirectory.
      
       - I left MachDeps.h where it is, because it is so widely used in
         Haskell code.
       
       - I left a deprecated stub for RtsFlags.h in place.  The flag
         structures are now exposed by Rts.h.
      
       - Various internal APIs are no longer exposed by public header files.
      
       - Various bits of dead code and declarations have been removed
      
       - More gcc warnings are turned on, and the RTS code is more
         warning-clean.
      
       - More source files #include "PosixSource.h", and hence only use
         standard POSIX (1003.1c-1995) interfaces.
      
      There is a lot more tidying up still to do, this is just the first
      pass.  I also intend to standardise the names for external RTS APIs
      (e.g use the rts_ prefix consistently), and declare the internal APIs
      as hidden for shared libraries.
      a2a67cd5
  32. 24 Jun, 2009 1 commit
  33. 02 Jun, 2009 1 commit
  34. 10 Dec, 2008 1 commit
  35. 17 Apr, 2008 1 commit
  36. 01 Aug, 2007 1 commit
    • Simon Marlow's avatar
      FIX recent PPC crashes introduced by the pointer-tagging patch (I hope) · e7c08550
      Simon Marlow authored
      There was an accidental endian-dependency in changes related to RET_FUN.
      The changes in question weren't strictly necessary - they were left
      over from the original workaround for the compacting GC problems, so
      I've just reverted those changes in this patch, which should hopefully
      fix the PPC problems.
      e7c08550
  37. 27 Jul, 2007 1 commit
    • Simon Marlow's avatar
      Pointer Tagging · 6015a94f
      Simon Marlow authored
        
      This patch implements pointer tagging as per our ICFP'07 paper "Faster
      laziness using dynamic pointer tagging".  It improves performance by
      10-15% for most workloads, including GHC itself.
      
      The original patches were by Alexey Rodriguez Yakushev
      <mrchebas@gmail.com>, with additions and improvements by me.  I've
      re-recorded the development as a single patch.
      
      The basic idea is this: we use the low 2 bits of a pointer to a heap
      object (3 bits on a 64-bit architecture) to encode some information
      about the object pointed to.  For a constructor, we encode the "tag"
      of the constructor (e.g. True vs. False), for a function closure its
      arity.  This enables some decisions to be made without dereferencing
      the pointer, which speeds up some common operations.  In particular it
      enables us to avoid costly indirect jumps in many cases.
      
      More information in the commentary:
      
      http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/HaskellExecution/PointerTagging
      6015a94f
  38. 27 Feb, 2007 1 commit
  39. 07 Oct, 2006 1 commit
  40. 07 Apr, 2006 1 commit
    • Simon Marlow's avatar
      Reorganisation of the source tree · 0065d5ab
      Simon Marlow authored
      Most of the other users of the fptools build system have migrated to
      Cabal, and with the move to darcs we can now flatten the source tree
      without losing history, so here goes.
      
      The main change is that the ghc/ subdir is gone, and most of what it
      contained is now at the top level.  The build system now makes no
      pretense at being multi-project, it is just the GHC build system.
      
      No doubt this will break many things, and there will be a period of
      instability while we fix the dependencies.  A straightforward build
      should work, but I haven't yet fixed binary/source distributions.
      Changes to the Building Guide will follow, too.
      0065d5ab