[project @ 2005-10-21 14:02:17 by simonmar]
authorsimonmar <unknown>
Fri, 21 Oct 2005 14:02:18 +0000 (14:02 +0000)
committersimonmar <unknown>
Fri, 21 Oct 2005 14:02:18 +0000 (14:02 +0000)
commit03a9ff01812afc81eb5236fd3063cbec44cf469e
treee02ce9ff95e7ed47b811ec2014fa43027d9a175f
parent63e8af080a7e779a48e812e6caa9ea519b046260
[project @ 2005-10-21 14:02:17 by simonmar]
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
77 files changed:
ghc/compiler/deSugar/DsForeign.lhs
ghc/includes/Block.h
ghc/includes/Cmm.h
ghc/includes/Constants.h
ghc/includes/Makefile
ghc/includes/OSThreads.h
ghc/includes/Regs.h
ghc/includes/Rts.h
ghc/includes/RtsAPI.h
ghc/includes/RtsConfig.h
ghc/includes/RtsExternal.h
ghc/includes/STM.h
ghc/includes/SchedAPI.h
ghc/includes/Storage.h
ghc/includes/TSO.h
ghc/includes/Updates.h
ghc/includes/mkDerivedConstants.c
ghc/rts/AwaitEvent.h [new file with mode: 0644]
ghc/rts/BlockAlloc.c
ghc/rts/Capability.c
ghc/rts/Capability.h
ghc/rts/Disassembler.h
ghc/rts/Exception.cmm
ghc/rts/Exception.h
ghc/rts/FrontPanel.h
ghc/rts/GC.c
ghc/rts/GCCompact.c
ghc/rts/GCCompact.h
ghc/rts/Hash.h
ghc/rts/Interpreter.c
ghc/rts/Itimer.h
ghc/rts/Linker.c
ghc/rts/LinkerInternals.h
ghc/rts/MBlock.h
ghc/rts/Main.c
ghc/rts/Makefile
ghc/rts/PosixSource.h
ghc/rts/Prelude.h
ghc/rts/PrimOps.cmm
ghc/rts/Printer.h
ghc/rts/ProfHeap.c
ghc/rts/ProfHeap.h
ghc/rts/Profiling.h
ghc/rts/Proftimer.h
ghc/rts/RtsAPI.c
ghc/rts/RtsFlags.c
ghc/rts/RtsSignals.h [new file with mode: 0644]
ghc/rts/RtsStartup.c
ghc/rts/RtsUtils.h
ghc/rts/STM.c
ghc/rts/Sanity.h
ghc/rts/Schedule.c
ghc/rts/Schedule.h
ghc/rts/Signals.h [deleted file]
ghc/rts/Sparks.h
ghc/rts/Stats.c
ghc/rts/Stats.h
ghc/rts/StgMiscClosures.cmm
ghc/rts/Storage.c
ghc/rts/Task.c
ghc/rts/Task.h
ghc/rts/Ticker.h [new file with mode: 0644]
ghc/rts/Timer.c
ghc/rts/Timer.h
ghc/rts/Weak.c
ghc/rts/Weak.h
ghc/rts/posix/Itimer.c [moved from ghc/rts/Itimer.c with 96% similarity]
ghc/rts/posix/Itimer.h [new file with mode: 0644]
ghc/rts/posix/OSThreads.c [new file with mode: 0644]
ghc/rts/posix/Select.c [moved from ghc/rts/Select.c with 95% similarity]
ghc/rts/posix/Select.h [new file with mode: 0644]
ghc/rts/posix/Signals.c [moved from ghc/rts/Signals.c with 88% similarity]
ghc/rts/posix/Signals.h [new file with mode: 0644]
ghc/rts/win32/AwaitEvent.c
ghc/rts/win32/ConsoleHandler.h
ghc/rts/win32/OSThreads.c [moved from ghc/rts/OSThreads.c with 54% similarity]
ghc/rts/win32/Ticker.h [deleted file]