| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
Warning police (unused parameter)
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Removed the annoying "Id" CVS keywords, they're a real PITA when it
comes to merging...
|
|
|
|
|
|
|
|
|
|
|
|
| |
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).
|
|
|
|
| |
Merge backend-hacking-branch onto HEAD. Yay!
|
|
|
|
| |
tidy up siginterrupt() use
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Alpha fixes.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
win32 tidyup: exclude Select.c, Itimer.c and Signals.c from SRCS
|
|
|
|
| |
code wibbles
|
|
|
|
| |
Initialize stp->n_to_blocks as 0. Add function for MinGW32 in Signals.c.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit fixes many bugs and limitations in the threaded RTS.
There are still some issues remaining, though.
The following bugs should have been fixed:
- [+] "safe" calls could cause crashes
- [+] yieldToReturningWorker/grabReturnCapability
- It used to deadlock.
- [+] couldn't wake blocked workers
- Calls into the RTS could go unanswered for a long time, and
that includes ordinary callbacks in some circumstances.
- [+] couldn't block on an MVar and expect to be woken up by a signal
handler
- Depending on the exact situation, the RTS shut down or
blocked forever and ignored the signal.
- [+] The locking scheme in RtsAPI.c didn't work
- [+] run_thread label in wrong place (schedule())
- [+] Deadlock in GHC.Handle
- if a signal arrived at the wrong time, an mvar was never
filled again
- [+] Signals delivered to the "wrong" thread were ignored or handled
too late.
Issues:
*) If GC can move TSO objects (I don't know - can it?), then ghci
will occasionally crash when calling foreign functions, because the
parameters are stored on the TSO stack.
*) There is still a race condition lurking in the code
(both threaded and non-threaded RTS are affected):
If a signal arrives after the check for pending signals in
schedule(), but before the call to select() in awaitEvent(),
select() will be called anyway. The signal handler will be
executed much later than expected.
*) For Win32, GHC doesn't yet support non-blocking IO, so while a
thread is waiting for IO, no call-ins can happen. If the RTS is
blocked in awaitEvent, it uses a polling loop on Win32, so call-ins
should work (although the polling loop looks ugly).
*) Deadlock detection is disabled for the threaded rts, because I
don't know how to do it properly in the presence of foreign call-ins
from foreign threads.
This causes the tests conc031, conc033 and conc034 to fail.
*) "safe" is currently treated as "threadsafe". Implementing "safe" in
a way that blocks other Haskell threads is more difficult than was
thought at first. I think it could be done with a few additional lines
of code, but personally, I'm strongly in favour of abolishing the
distinction.
*) Running finalizers at program termination is inefficient - there
are two OS threads passing messages back and forth for every finalizer
that is run. Also (just as in the non-threaded case) the finalizers
are run in parallel to any remaining haskell threads and to any
foreign call-ins that might still happen.
|
|
|
|
|
|
|
| |
blockUserSignal() should use SIG_BLOCK instead of SIG_SETMASK, otherwise it
would also sometimes unblock signals that should be blocked.
MERGE TO STABLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Merge the eval-apply-branch on to the HEAD
------------------------------------------
This is a change to GHC's evaluation model in order to ultimately make
GHC more portable and to reduce complexity in some areas.
At some point we'll update the commentary to describe the new state of
the RTS. Pending that, the highlights of this change are:
- No more Su. The Su register is gone, update frames are one
word smaller.
- Slow-entry points and arg checks are gone. Unknown function calls
are handled by automatically-generated RTS entry points (AutoApply.hc,
generated by the program in utils/genapply).
- The stack layout is stricter: there are no "pending arguments" on
the stack any more, the stack is always strictly a sequence of
stack frames.
This means that there's no need for LOOKS_LIKE_GHC_INFO() or
LOOKS_LIKE_STATIC_CLOSURE() any more, and GHC doesn't need to know
how to find the boundary between the text and data segments (BIG WIN!).
- A couple of nasty hacks in the mangler caused by the neet to
identify closure ptrs vs. info tables have gone away.
- Info tables are a bit more complicated. See InfoTables.h for the
details.
- As a side effect, GHCi can now deal with polymorphic seq. Some bugs
in GHCi which affected primitives and unboxed tuples are now
fixed.
- Binary sizes are reduced by about 7% on x86. Performance is roughly
similar, some programs get faster while some get slower. I've seen
GHCi perform worse on some examples, but haven't investigated
further yet (GHCi performance *should* be about the same or better
in theory).
- Internally the code generator is rather better organised. I've moved
info-table generation from the NCG into the main codeGen where it is
shared with the C back-end; info tables are now emitted as arrays
of words in both back-ends. The NCG is one step closer to being able
to support profiling.
This has all been fairly thoroughly tested, but no doubt I've messed
up the commit in some way.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add SA_RESETHAND (aka SA_ONESHOT) support.
Requested by: John Meacham
> module Main where
> import System.Posix.Signals
> main = do
> installHandler sigUSR1 (Catch (print "usr1")) Nothing
> installHandler sigUSR2 (CatchOnce (print "usr2")) Nothing
> _ <- getLine
> return ()
|
|
|
|
|
|
|
|
|
|
|
| |
The GC wasn't properly marking pending signal handlers, which could
lead to "EVACUATED object entered!" errors. Also, a race occurs if a
signal arrives during GC. Two fixes:
(a) mark all pending signal handlers during GC, and
(b) block signals during GC
MERGE TO STABLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Partial rewrite of the POSIX library.
The main purpose of this sweep is to remove the last dependencies of
the compiler on hslibs. When I've committed the associated compiler
changes, only the 'base' package will be required to bootstrap the
compiler. Additionally to build GHCi, the 'readline' and 'unix'
packages will be required.
The new POSIX library lives mostly in libraries/unix, with a few bits
required for compiler bootstrapping in libraries/base. The 'base'
package is mostly free of hsc2hs code to make bootstrapping from HC
files easier, but the 'unix' package will use hsc2hs liberally.
The old POSIX library continues to provide more-or-less the same
interface as before, although some of the types are more correct now
(previously lots of POSIX types were just mapped to Int). The new
interface is largely the same as the old, except that some new
functionality from the latest POSIX spec has been added (eg. symbolic
links).
So far, the new POSIX library has signal support, directory/file
operations and lots of stuff from unistd.h. The module names are:
System.Posix
The main dude, exports everything
System.Posix.Types
All the POSIX types, using the same naming scheme as
Foreign.C.Types, Eg. CUid, COff, etc. Many of these types
were previously exported by GHC.Posix.
Additionally exports the "nicer" names used by the old POSIX
library for compatibility (eg. ProcessID == CPid, FileMode ==
CMode, etc.)
All reasonable instances are derived for these types.
System.Posix.Signals
Signal support, contains most of which was in PosixProcPrim before.
The RTS interface to the signal handling support has been
rationalised slightly.
System.Posix.Directory
Directory support, most were in PosixFiles before.
System.Posix.Files
File operations, most were in PosixFiles before.
System.Posix.Unistd
(for want of a better name) Miscellaneous bits that mostly come
from the unistd.h header file. PosixProcEnv before.
The rest of the library should pan out like so:
System.Posix.IO
System.Posix.Error (maybe)
System.Posix.Process
System.Posix.Terminal
(I've no doubt broken Win32 support, but I'm checking the build at the moment).
|
|
|
|
|
| |
stg_sig_install: restore the old signal mask at the end, rather than
unconditionally unblocking the signal we just installed the handler for.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Remove most #includes of system headers from Stg.h, and instead
#include any required headers directly in each RTS source file.
The idea is to (a) reduce namespace pollution from system headers that
we don't need, (c) be clearer about dependencies on system things in
the RTS, and (c) improve via-C compilation times (maybe).
In practice though, HsBase.h #includes everything anyway, so the
difference from the point of view of .hc source is minimal. However,
this makes it easier to move to zero-includes if we wanted to (see
discussion on the FFI list; I'm still not sure that's possible but
at least this is a step in the right direction).
|
|
|
|
|
|
|
|
|
|
| |
Don't install a SIGFPE handler: this causes us to go into an infinite
loop on a divide by zero on some systems (BSD, but not Linux it
seems). I don't think we really ought to be ignoring SIGFPE: for
floating point exceptions, the system usually has a way to request
that operations generate exceptional values rather than signals (this
is the required IEEE behaviour), and for integral division we should
really check beforehand for division by zero (we don't yet).
|
|
|
|
| |
initDefaultHandlers(): siginterrupt() not supported w/ cygwin
|
|
|
|
|
|
|
|
|
|
|
| |
If we are in a deadlock situation but there are signal handlers
installed, pause() instead of reporting deadlock. One of the signal
handlers may allow the process to continue after being triggered.
Fixes bug #525772.
I've made a half-hearted attempt to clean up the deadlock code in the
scheduler, it now looks slightly better.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Fix a problem when a Haskell process is suspended/resumed using shell
job control in Unix. The shell tends to put stdin back into blocking
mode before resuming the process, so we have to catch SIGCONT and put
it back into O_NONBLOCK.
Also:
- fix a bug in the scheduler: reverse the order of the check
for pending signals and the call to awaitEvent to block on I/O.
- do a style sweep in Signals.c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Change the story about POSIX headers in C compilation.
Until now, all C code in the RTS and library cbits has by default been
compiled with settings for POSIXness enabled, that is:
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 199309L
#define _ISOC9X_SOURCE
If you wanted to negate this, you'd have to define NON_POSIX_SOURCE
before including headers.
This scheme has some bad effects:
* It means that ccall-unfoldings exported via interfaces from a
module compiled with -DNON_POSIX_SOURCE may not compile when
imported into a module which does not -DNON_POSIX_SOURCE.
* It overlaps with the feature tests we do with autoconf.
* It seems to have caused borkage in the Solaris builds for some
considerable period of time.
The New Way is:
* The default changes to not-being-in-Posix mode.
* If you want to force a C file into Posix mode, #include as
the **first** include the new file ghc/includes/PosixSource.h.
Most of the RTS C sources have this include now.
* NON_POSIX_SOURCE is almost totally expunged. Unfortunately
we have to retain some vestiges of it in ghc/compiler so that
modules compiled via C on Solaris using older compilers don't
break.
|
|
|
|
|
|
| |
In addition to handling SIGINT, also handle SIGFPE by ignoring it.
Apparently IEEE requires floating-point exceptions to be ignored by
default, but alpha-dec-osf3 doesn't seem to do so.
|
|
|
|
| |
rename sig_install to stg_sig_install
|
|
|
|
|
|
|
|
| |
Change the way threadDelay# is implemented.
We now use a list of sleeping threads sorted in increasing order by
the time at which they will wake up. This avoids us having to
traverse the entire queue on each context switch.
|
|
|
|
|
| |
Reduce number of warnings and raise chances of successful compilation
when *not* building an interpreter :-)
|
|
|
|
|
|
|
|
| |
- make the second ^C kill the program immediately (the first one tries
to interrupt it safely by killing all the threads, running
finalizers etc.).
- don't ignore SIGPIPE by default, the program can do this itself.
|
|
|
|
| |
Unbreak signals.
|
|
|
|
|
|
|
|
| |
Ctrl-C now interrupts the RTS safely. Previously it called
shutdownHaskellAndExit() from the signal handler directly, which isn't
safe because we may have been interrupted during GC or whatever. Now
we set the interrupted flag and wait for the RTS to shut down by
itself.
|
|
|
|
|
|
|
|
|
| |
Ignore SIGPIPE, since our I/O library handles EPIPE properly and
SIGPIPE tends to cause the Haskell program to exit silently and
mysteriously.
Found-by: furiously pressing the refresh button in a browser connected
to my Haskell web server :-)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- remove AllBlocked scheduler return code. Nobody owned up to having
created it or even knowing what it was there for.
- clean up fatal error condition handling somewhat. The process
exit code from a GHC program now indicates the kind of failure
for certain kinds of exit:
general internal RTS error 254
program deadlocked 253
program interrupted (ctrl-C) 252
heap overflow 251
main thread killed 250
and we leave exit codes 1-199 for the user (as is traditional at MS,
200-249 are reserved for future expansion, and may contain
undocumented extensions :-)
|
|
|
|
| |
Add 'par' and sparking support to the SMP implementation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A slew of SMP-related changes.
- New locking scheme for thunks: we now check whether the thunk
being entered is in our private allocation area, and if so
we don't lock it. Well, that's the upshot. In practice it's
a lot more fiddly than that.
- I/O blocking is handled a bit more sanely now (but still not
properly, methinks)
- deadlock detection is back
- remove old pre-SMP scheduler code
- revamp the timing code. We actually get reasonable-looking
timing info for SMP programs now.
- fix a bug in the garbage collector to do with IND_OLDGENs appearing
on the mutable list of the old generation.
- move BDescr() function from rts/BlockAlloc.h to includes/Block.h.
- move struct generation and struct step into includes/StgStorage.h (sigh)
- add UPD_IND_NOLOCK for updating with an indirection where locking
the black hole is not required.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit adds in the current state of our SMP support. Notably,
this allows the new way 's' to be built, providing support for running
multiple Haskell threads simultaneously on top of any pthreads
implementation, the idea being to take advantage of commodity SMP
boxes.
Don't expect to get much of a speedup yet; due to the excessive
locking required to synchronise access to mutable heap objects, you'll
see a slowdown in most cases, even on a UP machine. The best I've
seen is a 1.6-1.7 speedup on an example that did no locking (two
optimised nfibs in parallel).
- new RTS -N flag specifies how many pthreads to start.
- new driver -smp flag, tells the driver to use way 's'.
- new compiler -fsmp option (not for user comsumption)
tells the compiler not to generate direct jumps to
thunk entry code.
- largely rewritten scheduler
- _ccall_GC is now done by handing back a "token" to the
RTS before executing the ccall; it should now be possible
to execute blocking ccalls in the current thread while
allowing the RTS to continue running Haskell threads as
normal.
- you can only call thread-safe C libraries from a way 's'
build, of course.
Pthread support is still incomplete, and weird things (including
deadlocks) are likely to happen.
|
|
|
|
|
| |
At startup time, install a SIGINT termination handler which calls
shutdownHaskellAndExit(), if invoked.
|
|
|
|
|
| |
Workaround bug in Linux's glibc 2.1: don't fflush(stdout) before
writing to stderr.
|
|
|
|
|
| |
Set context_switch to 1 after scheduling a signal handler. This will
ensure the running thread is interrupted as soon as possible.
|
|
|
|
| |
No signal support with mingw32
|
|
|
|
| |
Copyright police.
|
|
|
|
|
|
|
|
| |
- Add Stable Names
- Stable pointers and stable names are now both provided by the
"Stable" module in ghc/lib/exts. Documentation is updated, and Foriegn
still exports the stable pointer operations for backwards compatibility.
|
|
Move 4.01 onto the main trunk.
|