Change the representation of the MVar blocked queue
authorSimon Marlow <marlowsd@gmail.com>
Thu, 1 Apr 2010 09:16:05 +0000 (09:16 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Thu, 1 Apr 2010 09:16:05 +0000 (09:16 +0000)
commitf4692220c7cbdadaa633f50eb2b30b59edb30183
tree3d29f1b4770bedb7c69c31b2828f9b5acca3e2c3
parent7c4cb84efd774a21f11fb03118feb0434282ecf3
Change the representation of the MVar blocked queue

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.
18 files changed:
includes/mkDerivedConstants.c
includes/rts/Constants.h
includes/rts/storage/Block.h
includes/rts/storage/Closures.h
includes/rts/storage/TSO.h
includes/stg/MiscClosures.h
rts/Capability.h
rts/HeapStackCheck.cmm
rts/Inlines.c
rts/Messages.c
rts/PrimOps.cmm
rts/RaiseAsync.c
rts/Schedule.c
rts/StgMiscClosures.cmm
rts/Threads.c
rts/Threads.h
rts/sm/Compact.c
rts/sm/Scav.c