1. 11 Nov, 2009 1 commit
    • Simon Marlow's avatar
      Second attempt to fix #1185 (forkProcess and -threaded) · 2d5e052d
      Simon Marlow authored
      Patch 1/2: second part of the patch is to libraries/base
      
      This time without dynamic linker hacks, instead I've expanded the
      existing rts/Globals.c to cache more CAFs, specifically those in
      GHC.Conc.  We were already using this trick for signal handlers, I
      should have realised before.
      
      It's still quite unsavoury, but we can do away with rts/Globals.c in
      the future when we switch to a dynamically-linked GHCi.
      2d5e052d
  2. 06 Nov, 2009 1 commit
    • Simon Marlow's avatar
      Rollback #1185 fix · c3685050
      Simon Marlow authored
      As far as I can tell, the hack I was using in rts/Linker.c won't work
      on OS X.  Back to the drawing board.
      
      rolling back:
      
      Tue Nov  3 16:05:47 GMT 2009  Simon Marlow <marlowsd@gmail.com>
        * Fix #1185 (RTS part, also needs corresponding change to libraries/base)
        GHC.Conc.ensureIOManagerIsRunning now creates an IO manager thread if
        one does not exist or has died/exited.
        
        Unfortunately this exposed a problem caused by the fact that we have
        two base packages, and hence two IO managers, in GHCi: see NOTE
        [io-manager-ghci] in rts/Linker.c.  The workaround can go away if/when
        we switch to a dynamically linked GHCi.
        
      
          M ./rts/Linker.c -6 +47
          M ./rts/Schedule.c +4
          M ./rts/package.conf.in +16
          M ./rts/posix/Signals.c -1 +7
          M ./rts/posix/Signals.h +2
      
      Wed Nov  4 10:11:03 GMT 2009  Simon Marlow <marlowsd@gmail.com>
        * hopefully fix validate breakage on OS X and Windows
      
          M ./rts/Linker.c -1 +1
      
      Wed Nov  4 16:27:40 GMT 2009  Simon Marlow <marlowsd@gmail.com>
        * fix build failure on Windows
      
          M ./rts/Linker.c -1 +1
      c3685050
  3. 03 Nov, 2009 1 commit
    • Simon Marlow's avatar
      Fix #1185 (RTS part, also needs corresponding change to libraries/base) · 3501ac6a
      Simon Marlow authored
      GHC.Conc.ensureIOManagerIsRunning now creates an IO manager thread if
      one does not exist or has died/exited.
      
      Unfortunately this exposed a problem caused by the fact that we have
      two base packages, and hence two IO managers, in GHCi: see NOTE
      [io-manager-ghci] in rts/Linker.c.  The workaround can go away if/when
      we switch to a dynamically linked GHCi.
      3501ac6a
  4. 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
  5. 23 Apr, 2009 1 commit
  6. 22 Mar, 2009 1 commit
  7. 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
  8. 19 Feb, 2009 2 commits
    • Simon Marlow's avatar
      1e0f3154
    • Simon Marlow's avatar
      Rewrite of signal-handling (ghc patch; see also base and unix patches) · 7ed3f755
      Simon Marlow authored
      The API is the same (for now).  The new implementation has the
      capability to define signal handlers that have access to the siginfo
      of the signal (#592), but this functionality is not exposed in this
      patch.
      
      #2451 is the ticket for the new API.
      
      The main purpose of bringing this in now is to fix race conditions in
      the old signal handling code (#2858).  Later we can enable the new
      API in the HEAD.
      
      Implementation differences:
      
       - More of the signal-handling is moved into Haskell.  We store the
         table of signal handlers in an MVar, rather than having a table of
         StablePtrs in the RTS.
      
       - In the threaded RTS, the siginfo of the signal is passed down the
         pipe to the IO manager thread, which manages the business of
         starting up new signal handler threads.  In the non-threaded RTS,
         the siginfo of caught signals is stored in the RTS, and the
         scheduler starts new signal handler threads.
      7ed3f755
  9. 04 Nov, 2008 1 commit
  10. 19 Sep, 2008 1 commit
  11. 09 Jul, 2008 1 commit
    • Simon Marlow's avatar
      FIX part of #2301, and #1619 · addff19a
      Simon Marlow authored
      2301: Control-C now causes the new exception (AsyncException
      UserInterrupt) to be raised in the main thread.  The signal handler
      is set up by GHC.TopHandler.runMainIO, and can be overriden in the
      usual way by installing a new signal handler.  The advantage is that
      now all programs will get a chance to clean up on ^C.
      
      When UserInterrupt is caught by the topmost handler, we now exit the
      program via kill(getpid(),SIGINT), which tells the parent process that
      we exited as a result of ^C, so the parent can take appropriate action
      (it might want to exit too, for example).
      
      One subtlety is that we have to use a weak reference to the ThreadId
      for the main thread, so that the signal handler doesn't prevent the
      main thread from being subject to deadlock detection.
      
      1619: we now ignore SIGPIPE by default.  Although POSIX says that a
      SIGPIPE should terminate the process by default, I wonder if this
      decision was made because many C applications failed to check the exit
      code from write().  In Haskell a failed write due to a closed pipe
      will generate an exception anyway, so the main difference is that we
      now get a useful error message instead of silent program termination.
      See #1619 for more discussion.
      addff19a
  12. 08 Jul, 2008 2 commits
  13. 16 Apr, 2008 1 commit
  14. 04 Jul, 2007 1 commit
    • Simon Marlow's avatar
      We don't need a SIGCONT handler any more · 10ba2ab9
      Simon Marlow authored
      The SIGCONT handler was used to put stdin back in O_NONBLOCK mode,
      after the process is resumed, but we don't want to do that now: the
      standard handles are kept in blocking mode.
      10ba2ab9
  15. 03 Apr, 2007 1 commit
  16. 30 Dec, 2006 1 commit
  17. 15 Dec, 2006 1 commit
  18. 15 Nov, 2006 1 commit
  19. 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
  20. 30 Aug, 2006 1 commit
  21. 26 Jul, 2006 1 commit
  22. 24 May, 2006 1 commit
    • Simon Marlow's avatar
      Better control of the IO manager thread; improvements to deadlock checking · 7a1f8fbd
      Simon Marlow authored
          
      In the threaded RTS on *nix platforms:
          
       - we now start the IO manager thread eagerly at startup time
         (previously was started on demand).
      
       - we now ask the IO manager thread to stop at shutdown
          
       - In Timer.c:handle_tick, if it looks like we might be in a
         deadlock, instead of calling prodOneCapability() which was known to be
         wrong, we now send a byte down the IO manager's pipe to wake it up.
        
      This also avoids a case of double-acquisition of a mutex, which
      happened if prodOneCapability() was called while the current thread
      was holding a mutex.
      7a1f8fbd
  23. 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
  24. 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
  25. 03 Nov, 2005 2 commits
  26. 21 Oct, 2005 1 commit
    • simonmar's avatar
      [project @ 2005-10-21 14:02:17 by simonmar] · 03a9ff01
      simonmar authored
      Big re-hash of the threaded/SMP runtime
      
      This is a significant reworking of the threaded and SMP parts of
      the runtime.  There are two overall goals here:
      
        - To push down the scheduler lock, reducing contention and allowing
          more parts of the system to run without locks.  In particular,
          the scheduler does not require a lock any more in the common case.
      
        - To improve affinity, so that running Haskell threads stick to the
          same OS threads as much as possible.
      
      At this point we have the basic structure working, but there are some
      pieces missing.  I believe it's reasonably stable - the important
      parts of the testsuite pass in all the (normal,threaded,SMP) ways.
      
      In more detail:
      
        - Each capability now has a run queue, instead of one global run
          queue.  The Capability and Task APIs have been completely
          rewritten; see Capability.h and Task.h for the details.
      
        - Each capability has its own pool of worker Tasks.  Hence, Haskell
          threads on a Capability's run queue will run on the same worker
          Task(s).  As long as the OS is doing something reasonable, this
          should mean they usually stick to the same CPU.  Another way to
          look at this is that we're assuming each Capability is associated
          with a fixed CPU.
      
        - What used to be StgMainThread is now part of the Task structure.
          Every OS thread in the runtime has an associated Task, and it
          can ask for its current Task at any time with myTask().
      
        - removed RTS_SUPPORTS_THREADS symbol, use THREADED_RTS instead
          (it is now defined for SMP too).
      
        - The RtsAPI has had to change; we must explicitly pass a Capability
          around now.  The previous interface assumed some global state.
          SchedAPI has also changed a lot.
      
        - The OSThreads API now supports thread-local storage, used to
          implement myTask(), although it could be done more efficiently
          using gcc's __thread extension when available.
      
        - I've moved some POSIX-specific stuff into the posix subdirectory,
          moving in the direction of separating out platform-specific
          implementations.
      
        - lots of lock-debugging and assertions in the runtime.  In particular,
          when DEBUG is on, we catch multiple ACQUIRE_LOCK()s, and there is
          also an ASSERT_LOCK_HELD() call.
      
      What's missing so far:
      
        - I have almost certainly broken the Win32 build, will fix soon.
      
        - any kind of thread migration or load balancing.  This is high up
          the agenda, though.
      
        - various performance tweaks to do
      
        - throwTo and forkProcess still do not work in SMP mode
      03a9ff01
  27. 24 Apr, 2005 1 commit
  28. 07 Apr, 2005 1 commit
    • simonmar's avatar
      [project @ 2005-04-07 14:33:30 by simonmar] · 5a148f04
      simonmar authored
      Support handling signals in the threaded RTS by passing the signal
      number down the pipe to the IO manager.  This avoids needing
      synchronisation in the signal handler.
      
      Signals should now work with -threaded.  Since this is a bugfix, I'll
      merge the changes into the 6.4 branch.
      5a148f04
  29. 28 Jan, 2005 1 commit
    • simonmar's avatar
      [project @ 2005-01-28 12:55:17 by simonmar] · 153b9cb9
      simonmar authored
      Rationalise the BUILD,HOST,TARGET defines.
      
      Recall that:
      
        - build is the platform we're building on
        - host is the platform we're running on
        - target is the platform we're generating code for
      
      The change is that now we take these definitions as applying from the
      point of view of the particular source code being built, rather than
      the point of view of the whole build tree.
      
      For example, in RTS and library code, we were previously testing the
      TARGET platform.  But under the new rule, the platform on which this
      code is going to run is the HOST platform.  TARGET only makes sense in
      the compiler sources.
      
      In practical terms, this means that the values of BUILD, HOST & TARGET
      may vary depending on which part of the build tree we are in.
      
      Actual changes:
      
       - new file: includes/ghcplatform.h contains platform defines for
         the RTS and library code.
      
       - new file: includes/ghcautoconf.h contains the autoconf settings
         only (HAVE_BLAH).  This is so that we can get hold of these
         settings independently of the platform defines when necessary
         (eg. in GHC).
      
       - ghcconfig.h now #includes both ghcplatform.h and ghcautoconf.h.
      
       - MachRegs.h, which is included into both the compiler and the RTS,
         now has to cope with the fact that it might need to test either
         _TARGET_ or _HOST_ depending on the context.
      
       - the compiler's Makefile now generates
           stage{1,2,3}/ghc_boot_platform.h
         which contains platform defines for the compiler.  These differ
         depending on the stage, of course: in stage2, the HOST is the
         TARGET of stage1.  This was wrong before.
      
       - The compiler doesn't get platform info from Config.hs any more.
         Previously it did (sometimes), but unless we want to generate
         a new Config.hs for each stage we can't do this.
      
       - GHC now helpfully defines *_{BUILD,HOST}_{OS,ARCH} automatically
         in CPP'd Haskell source.
      
       - ghcplatform.h defines *_TARGET_* for backwards compatibility
         (ghcplatform.h is included by ghcconfig.h, which is included by
         config.h, so code which still #includes config.h will get the TARGET
         settings as before).
      
       - The Users's Guide is updated to mention *_HOST_* rather than
         *_TARGET_*.
      
       - coding-style.html in the commentary now contains a section on
         platform defines.  There are further doc updates to come.
      
      Thanks to Wolfgang Thaller for pointing me in the right direction.
      153b9cb9
  30. 14 Oct, 2004 1 commit
    • simonmar's avatar
      [project @ 2004-10-14 14:58:37 by simonmar] · bb01a96b
      simonmar authored
      Threaded RTS improvements:
      
       - Unix only: implement waitRead#, waitWrite# and delay# in Haskell,
         by having a single Haskell thread (the IO manager) performing a blocking
         select() operation.  Threads communicate with the IO manager
         via channels.  This is faster than doing the select() in the RTS,
         because we only restart the select() when a new request arrives,
         rather than each time around the scheduler.
      
         On Windows we just make blocking IO calls, we don't have a fancy IO
         manager (yet).
      
       - Simplify the scheduler for the threaded RTS, now that we don't have
         to wait for IO in the scheduler loop.
      
       - Remove detectBlackHoles(), which isn't used now (not sure how long
         this has been unused for... perhaps it was needed back when main threads
         used to be GC roots, so we had to check for blackholes manually rather
         than relying on the GC.)
      
      Signals aren't quite right in the threaded RTS.  In fact, they're
      slightly worse than before, because the thread receiving signals might
      be blocked in a C call - previously there always be another thread
      stuck in awaitEvent() that would notice the signal, but that's not
      true now.  I can't see an easy fix yet.
      bb01a96b
  31. 12 Sep, 2004 1 commit
  32. 03 Sep, 2004 1 commit
    • simonmar's avatar
      [project @ 2004-09-03 15:28:18 by simonmar] · 95ca6bff
      simonmar authored
      Cleanup: all (well, most) messages from the RTS now go through the
      functions in RtsUtils: barf(), debugBelch() and errorBelch().  The
      latter two were previously called belch() and prog_belch()
      respectively.  See the comments for the right usage of these message
      functions.
      
      One reason for doing this is so that we can avoid spurious uses of
      stdout/stderr by Haskell apps on platforms where we shouldn't be using
      them (eg. non-console apps on Windows).
      95ca6bff
  33. 13 Aug, 2004 1 commit
  34. 31 Oct, 2003 1 commit
  35. 20 Oct, 2003 1 commit
    • sof's avatar
      [project @ 2003-10-20 17:15:27 by sof] · d0c6e4ec
      sof authored
      Console event handling support (i.e., Haskell-side support for SIGINT under win32).
      
      win32/ConsoleHandler.h implements the Signals.h API. No library support
      for installing user event handlers included in this commit.
      d0c6e4ec
  36. 21 Sep, 2003 1 commit
  37. 01 Apr, 2003 1 commit
    • sof's avatar
      [project @ 2003-04-01 15:05:13 by sof] · c49a6ca9
      sof authored
      Tidy up code that supports user/Haskell signal handlers.
      
      Signals.h now defines RTS_USER_SIGNALS when this is supported,
      which is then used elsewhere.
      c49a6ca9