1. 12 Jun, 2009 1 commit
    • Duncan Coutts's avatar
      Add and export rts_unsafeGetMyCapability from rts · 85df606a
      Duncan Coutts authored
      We need this, or something equivalent, to be able to implement
      stgAllocForGMP outside of the rts. That's because we want to use
      allocateLocal which allocates from the given capability without
      having to take any locks. In the gmp primops we're basically in
      an unsafe foreign call, that is a context where we hold a current
      capability. So it's safe for us to use allocateLocal. We just
      need a way to get the current capability. The method to get the
      current capability varies depends on whether we're using the
      threaded rts or not. When stgAllocForGMP is built inside the rts
      that's ok because we can do it conditionally on THREADED_RTS.
      Outside the rts we need a single api we can call without knowing
      if we're talking to a threaded rts or not, hence this addition.
      85df606a
  2. 02 Jun, 2009 1 commit
  3. 03 Apr, 2009 1 commit
  4. 17 Mar, 2009 1 commit
    • Simon Marlow's avatar
      Add fast event logging · 8b18faef
      Simon Marlow authored
      Generate binary log files from the RTS containing a log of runtime
      events with timestamps.  The log file can be visualised in various
      ways, for investigating runtime behaviour and debugging performance
      problems.  See for example the forthcoming ThreadScope viewer.
      
      New GHC option:
      
        -eventlog   (link-time option) Enables event logging.
      
        +RTS -l     (runtime option) Generates <prog>.eventlog with
                    the binary event information.
      
      This replaces some of the tracing machinery we already had in the RTS:
      e.g. +RTS -vg  for GC tracing (we should do this using the new event
      logging instead).
      
      Event logging has almost no runtime cost when it isn't enabled, though
      in the future we might add more fine-grained events and this might
      change; hence having a link-time option and compiling a separate
      version of the RTS for event logging.  There's a small runtime cost
      for enabling event-logging, for most programs it shouldn't make much
      difference.
      
      (Todo: docs)
      8b18faef
  5. 13 Mar, 2009 1 commit
    • Simon Marlow's avatar
      Instead of a separate context-switch flag, set HpLim to zero · 304e7fb7
      Simon Marlow authored
      This reduces the latency between a context-switch being triggered and
      the thread returning to the scheduler, which in turn should reduce the
      cost of the GC barrier when there are many cores.
      
      We still retain the old context_switch flag which is checked at the
      end of each block of allocation.  The idea is that setting HpLim may
      fail if the the target thread is modifying HpLim at the same time; the
      context_switch flag is a fallback.  It also allows us to "context
      switch soon" without forcing an immediate switch, which can be costly.
      304e7fb7
  6. 12 Jan, 2009 1 commit
    • Simon Marlow's avatar
      Keep the remembered sets local to each thread during parallel GC · 6a405b1e
      Simon Marlow authored
      This turns out to be quite vital for parallel programs:
      
        - The way we discover which threads to traverse is by finding
          dirty threads via the remembered sets (aka mutable lists).
      
        - A dirty thread will be on the remembered set of the capability
          that was running it, and we really want to traverse that thread's
          stack using the GC thread for the capability, because it is in
          that CPU's cache.  If we get this wrong, we get penalised badly by
          the memory system.
      
      Previously we had per-capability mutable lists but they were
      aggregated before GC and traversed by just one of the GC threads.
      This resulted in very poor performance particularly for parallel
      programs with deep stacks.
      
      Now we keep per-capability remembered sets throughout GC, which also
      removes a lock (recordMutableGen_sync).
      6a405b1e
  7. 21 Nov, 2008 1 commit
    • Simon Marlow's avatar
      Use mutator threads to do GC, instead of having a separate pool of GC threads · 3ebcd3de
      Simon Marlow authored
      Previously, the GC had its own pool of threads to use as workers when
      doing parallel GC.  There was a "leader", which was the mutator thread
      that initiated the GC, and the other threads were taken from the pool.
      
      This was simple and worked fine for sequential programs, where we did
      most of the benchmarking for the parallel GC, but falls down for
      parallel programs.  When we have N mutator threads and N cores, at GC
      time we would have to stop N-1 mutator threads and start up N-1 GC
      threads, and hope that the OS schedules them all onto separate cores.
      It practice it doesn't, as you might expect.
      
      Now we use the mutator threads to do GC.  This works quite nicely,
      particularly for parallel programs, where each mutator thread scans
      its own spark pool, which is probably in its cache anyway.
      
      There are some flag changes:
      
        -g<n> is removed (-g1 is still accepted for backwards compat).
        There's no way to have a different number of GC threads than mutator
        threads now.
      
        -q1       Use one OS thread for GC (turns off parallel GC)
        -qg<n>    Use parallel GC for generations >= <n> (default: 1)
      
      Using parallel GC only for generations >=1 works well for sequential
      programs.  Compiling an ordinary sequential program with -threaded and
      running it with -N2 or more should help if you do a lot of GC.  I've
      found that adding -qg0 (do parallel GC for generation 0 too) speeds up
      some parallel programs, but slows down some sequential programs.
      Being conservative, I left the threshold at 1.
      
      ToDo: document the new options.
      3ebcd3de
  8. 14 Nov, 2008 1 commit
  9. 18 Nov, 2008 1 commit
    • Simon Marlow's avatar
      Add optional eager black-holing, with new flag -feager-blackholing · d600bf7a
      Simon Marlow authored
      Eager blackholing can improve parallel performance by reducing the
      chances that two threads perform the same computation.  However, it
      has a cost: one extra memory write per thunk entry.  
      
      To get the best results, any code which may be executed in parallel
      should be compiled with eager blackholing turned on.  But since
      there's a cost for sequential code, we make it optional and turn it on
      for the parallel package only.  It might be a good idea to compile
      applications (or modules) with parallel code in with
      -feager-blackholing.
      
      ToDo: document -feager-blackholing.
      d600bf7a
  10. 13 Nov, 2008 1 commit
  11. 06 Nov, 2008 2 commits
  12. 24 Oct, 2008 1 commit
  13. 23 Oct, 2008 1 commit
  14. 22 Oct, 2008 2 commits
    • Simon Marlow's avatar
    • Simon Marlow's avatar
      Refactoring and reorganisation of the scheduler · 99df892c
      Simon Marlow authored
      Change the way we look for work in the scheduler.  Previously,
      checking to see whether there was anything to do was a
      non-side-effecting operation, but this has changed now that we do
      work-stealing.  This lead to a refactoring of the inner loop of the
      scheduler.
      
      Also, lots of cleanup in the new work-stealing code, but no functional
      changes.
      
      One new statistic is added to the +RTS -s output:
      
        SPARKS: 1430 (2 converted, 1427 pruned)
      
      lets you know something about the use of `par` in the program.
      99df892c
  15. 15 Sep, 2008 1 commit
    • berthold@mathematik.uni-marburg.de's avatar
      Work stealing for sparks · cf9650f2
      berthold@mathematik.uni-marburg.de authored
         Spark stealing support for PARALLEL_HASKELL and THREADED_RTS versions of the RTS.
        
        Spark pools are per capability, separately allocated and held in the Capability 
        structure. The implementation uses Double-Ended Queues (deque) and cas-protected 
        access.
        
        The write end of the queue (position bottom) can only be used with
        mutual exclusion, i.e. by exactly one caller at a time.
        Multiple readers can steal()/findSpark() from the read end
        (position top), and are synchronised without a lock, based on a cas
        of the top position. One reader wins, the others return NULL for a
        failure.
        
        Work stealing is called when Capabilities find no other work (inside yieldCapability),
        and tries all capabilities 0..n-1 twice, unless a theft succeeds.
        
        Inside schedulePushWork, all considered cap.s (those which were idle and could 
        be grabbed) are woken up. Future versions should wake up capabilities immediately when 
        putting a new spark in the local pool, from newSpark().
      
      Patch has been re-recorded due to conflicting bugfixes in the sparks.c, also fixing a 
      (strange) conflict in the scheduler.
      cf9650f2
  16. 19 Sep, 2008 1 commit
  17. 09 Sep, 2008 1 commit
    • Simon Marlow's avatar
      Fix race condition in wakeupThreadOnCapability() (#2574) · d572aed6
      Simon Marlow authored
      wakeupThreadOnCapbility() is used to signal another capability that
      there is a thread waiting to be added to its run queue.  It adds the
      thread to the (locked) wakeup queue on the remote capability.  In
      order to do this, it has to modify the TSO's link field, which has a
      write barrier.  The write barrier might put the TSO on the mutable
      list, and the bug was that it was using the mutable list of the
      *target* capability, which we do not have exclusive access to.  We
      should be using the current Capabilty's mutable list in this case.
      d572aed6
  18. 19 Aug, 2008 1 commit
  19. 23 Jul, 2008 1 commit
  20. 24 Apr, 2008 1 commit
  21. 16 Apr, 2008 1 commit
  22. 24 Jul, 2007 1 commit
    • Simon Marlow's avatar
      hs_exit()/shutdownHaskell(): wait for outstanding foreign calls to complete before returning · 681aad99
      Simon Marlow authored
      This is pertinent to #1177.  When shutting down a DLL, we need to be
      sure that there are no OS threads that can return to the code that we
      are about to unload, and previously the threaded RTS was unsafe in
      this respect.
      
      When exiting a standalone program we don't have to be quite so
      paranoid: all the code will disappear at the same time as any running
      threads.  Happily exiting a program happens via a different path:
      shutdownHaskellAndExit().  If we're about to exit(), then there's no
      need to wait for foreign calls to complete.
      681aad99
  23. 03 Feb, 2007 1 commit
  24. 01 Feb, 2007 1 commit
    • Simon Marlow's avatar
      Partial fix for #926 · e4fdc426
      Simon Marlow authored
      It seems that when a program exits with open DLLs on Windows, the
      system attempts to shut down the DLLs, but it also terminates (some
      of?) the running threads.  The RTS isn't prepared for threads to die
      unexpectedly, so it sits around waiting for its workers to finish.
      This bites in two places: ShutdownIOManager() in the the unthreaded
      RTS, and shutdownCapability() in the threaded RTS.  So far I've
      modified the latter to notice when worker threads have died
      unexpectedly and continue shutting down.  It seems a bit trickier to
      fix the unthreaded RTS, so for now the workaround for #926 is to use
      the threaded RTS.
      e4fdc426
  25. 15 Dec, 2006 2 commits
  26. 15 Nov, 2006 1 commit
  27. 24 Oct, 2006 1 commit
    • Simon Marlow's avatar
      Split GC.c, and move storage manager into sm/ directory · ab0e778c
      Simon Marlow authored
      In preparation for parallel GC, split up the monolithic GC.c file into
      smaller parts.  Also in this patch (and difficult to separate,
      unfortunatley):
        
        - Don't include Stable.h in Rts.h, instead just include it where
          necessary.
        
        - consistently use STATIC_INLINE in source files, and INLINE_HEADER
          in header files.  STATIC_INLINE is now turned off when DEBUG is on,
          to make debugging easier.
        
        - The GC no longer takes the get_roots function as an argument.
          We weren't making use of this generalisation.
      ab0e778c
  28. 07 Oct, 2006 1 commit
  29. 31 Aug, 2006 1 commit
    • Simon Marlow's avatar
      don't closeMutex() the Capability lock · afdbaf48
      Simon Marlow authored
      There might be threads in foreign calls that will attempt to return
      via resumeThread() and grab this lock, so we can't safely destroy it.
      
      Fixes one cause of
      
         internal error: ASSERTION FAILED: file Capability.c, line 90
      
      although I haven't repeated that assertion failure in the wild, only
      with a specially crafted test case, so I can't be sure I really got
      it.
      afdbaf48
  30. 25 Aug, 2006 1 commit
  31. 23 Aug, 2006 1 commit
  32. 16 Jun, 2006 1 commit
    • Simon Marlow's avatar
      Asynchronous exception support for SMP · b1953bbb
      Simon Marlow authored
      This patch makes throwTo work with -threaded, and also refactors large
      parts of the concurrency support in the RTS to clean things up.  We
      have some new files:
      
        RaiseAsync.{c,h}	asynchronous exception support
        Threads.{c,h}         general threading-related utils
      
      Some of the contents of these new files used to be in Schedule.c,
      which is smaller and cleaner as a result of the split.
      
      Asynchronous exception support in the presence of multiple running
      Haskell threads is rather tricky.  In fact, to my annoyance there are
      still one or two bugs to track down, but the majority of the tests run
      now.
      b1953bbb
  33. 08 Jun, 2006 1 commit
    • Simon Marlow's avatar
      New tracing interface · 5a2769f0
      Simon Marlow authored
      A simple interface for generating trace messages with timestamps and
      thread IDs attached to them.  Most debugging output goes through this
      interface now, so it is straightforward to get timestamped debugging
      traces with +RTS -vt.  Also, we plan to use this to generate
      parallelism profiles from the trace output.
      5a2769f0
  34. 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
  35. 24 Mar, 2006 1 commit
    • Simon Marlow's avatar
      Add some more flexibility to the multiproc scheduler · 4368121d
      Simon Marlow authored
      There are two new options in the -threaded RTS:
       
        -qm       Don't automatically migrate threads between CPUs
        -qw       Migrate a thread to the current CPU when it is woken up
      
      previously both of these were effectively off, i.e. threads were
      migrated between CPUs willy-milly, and threads were always migrated to
      the current CPU when woken up.  This is the first step in tweaking the
      scheduling for more effective work balancing, there will no doubt be
      more to come.
      4368121d
  36. 15 Mar, 2006 1 commit
    • Simon Marlow's avatar
      Improvements to shutting down of the runtime · 5638488b
      Simon Marlow authored
      Yet another attempt at shutdown & interruption.  This one appears to
      work better; ^C is more responsive in multi threaded / SMP, and I
      fixed one case where the runtime wasn't responding to ^C at all.
      5638488b
  37. 13 Mar, 2006 1 commit