summaryrefslogtreecommitdiff
path: root/rts/ThreadPaused.c
Commit message (Collapse)AuthorAgeFilesLines
* fix commentSimon Marlow2011-06-011-4/+6
|
* Fix a cause of very occasional <<loop>> with parallel programs andSimon Marlow2011-05-311-2/+32
| | | | -feager-blackholing (#5226). See comments for details.
* Implement stack chunks and separate TSO/STACK objectsSimon Marlow2010-12-151-30/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes two changes to the way stacks are managed: 1. The stack is now stored in a separate object from the TSO. This means that it is easier to replace the stack object for a thread when the stack overflows or underflows; we don't have to leave behind the old TSO as an indirection any more. Consequently, we can remove ThreadRelocated and deRefTSO(), which were a pain. This is obviously the right thing, but the last time I tried to do it it made performance worse. This time I seem to have cracked it. 2. Stacks are now represented as a chain of chunks, rather than a single monolithic object. The big advantage here is that individual chunks are marked clean or dirty according to whether they contain pointers to the young generation, and the GC can avoid traversing clean stack chunks during a young-generation collection. This means that programs with deep stacks will see a big saving in GC overhead when using the default GC settings. A secondary advantage is that there is much less copying involved as the stack grows. Programs that quickly grow a deep stack will see big improvements. In some ways the implementation is simpler, as nothing special needs to be done to reclaim stack as the stack shrinks (the GC just recovers the dead stack chunks). On the other hand, we have to manage stack underflow between chunks, so there's a new stack frame (UNDERFLOW_FRAME), and we now have separate TSO and STACK objects. The total amount of code is probably about the same as before. There are new RTS flags: -ki<size> Sets the initial thread stack size (default 1k) Egs: -ki4k -ki2m -kc<size> Sets the stack chunk size (default 32k) -kb<size> Sets the stack chunk buffer size (default 1k) -ki was previously called just -k, and the old name is still accepted for backwards compatibility. These new options are documented.
* threadPaused: fix pointer arithmeticSimon Marlow2010-07-011-1/+1
| | | | Noticed by Henrique Ferreiro <hferreiro@udc.es>, thanks!
* New implementation of BLACKHOLEsSimon Marlow2010-03-291-28/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces the global blackhole_queue with a clever scheme that enables us to queue up blocked threads on the closure that they are blocked on, while still avoiding atomic instructions in the common case. Advantages: - gets rid of a locked global data structure and some tricky GC code (replacing it with some per-thread data structures and different tricky GC code :) - wakeups are more prompt: parallel/concurrent performance should benefit. I haven't seen anything dramatic in the parallel benchmarks so far, but a couple of threading benchmarks do improve a bit. - waking up a thread blocked on a blackhole is now O(1) (e.g. if it is the target of throwTo). - less sharing and better separation of Capabilities: communication is done with messages, the data structures are strictly owned by a Capability and cannot be modified except by sending messages. - this change will utlimately enable us to do more intelligent scheduling when threads block on each other. This is what started off the whole thing, but it isn't done yet (#3838). I'll be documenting all this on the wiki in due course.
* tweak the totally-bogus arbitrary stack-squeezing heuristic to fix #2797Simon Marlow2010-01-281-1/+2
| | | | | | | | | | | In #2797, a program that ran in constant stack space when compiled needed linear stack space when interpreted. It turned out to be nothing more than stack-squeezing not happening. We have a heuristic to avoid stack-squeezing when it would be too expensive (shuffling a large amount of memory to save a few words), but in some cases even expensive stack-squeezing is necessary to avoid linear stack usage. One day we should implement stack chunks, which would make this less expensive.
* Use local mut lists in UPD_IND(), also clean up Updates.hSimon Marlow2009-12-311-3/+3
|
* threadStackOverflow: check whether stack squeezing released some stack (#3677)Simon Marlow2009-11-251-0/+5
| | | | | | | | | | | | | | | | | In a stack overflow situation, stack squeezing may reduce the stack size, but we don't know whether it has been reduced enough for the stack check to succeed if we try again. Fortunately stack squeezing is idempotent, so all we need to do is record whether *any* squeezing happened. If we are at the stack's absolute -K limit, and stack squeezing happened, then we try running the thread again. We also want to avoid enlarging the stack if squeezing has already released some of it. However, we don't want to get into a pathalogical situation where a thread has a nearly full stack (near its current limit, but not near the absolute -K limit), keeps allocating a little bit, squeezing removes a little bit, and then it runs again. So to avoid this, if we squeezed *and* there is still less than BLOCK_SIZE_W words free, then we enlarge the stack anyway.
* RTS tidyup sweep, first phaseSimon Marlow2009-08-021-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* cruft removalSimon Marlow2009-01-061-1/+1
|
* Small refactoring, and add commentsSimon Marlow2008-11-191-0/+4
| | | | | I discovered a new invariant while experimenting (blackholing is not optional when using parallel GC), so documented it.
* Add optional eager black-holing, with new flag -feager-blackholingSimon Marlow2008-11-181-4/+1
| | | | | | | | | | | | | | | 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.
* Fix #2783: detect black-hole loops properlySimon Marlow2008-11-171-4/+7
| | | | | | | | At some point we regressed on detecting simple black-hole loops. This happened due to the introduction of duplicate-work detection for parallelism: a black-hole loop looks very much like duplicate work, except it's duplicate work being performed by the very same thread. So we have to detect and handle this case.
* tiny tweak to the stack squeezing heuristic (fixes cg060)Simon Marlow2008-06-041-1/+1
|
* Tweaks to stack squeezingSimon Marlow2008-02-071-2/+7
| | | | | | | | | 1. We weren't squeezing two frames if one of them was a marked update frame. This is easy to fix. 2. The heuristic to decide whether to squeeze was a little conservative. It's worth copying 3 words to save an update frame.
* THREADED_RTS: use cas() when claiming thunksSimon Marlow2007-03-061-1/+21
| | | | | | I guess I forgot to do this the first time around; the upshot is that there could be some uncaught duplication of work on a multiprocessor (but unlikely).
* Make all needed prototypes visible to avoid warningssven.panne@aedion.de2006-11-101-0/+1
|
* Split GC.c, and move storage manager into sm/ directorySimon Marlow2006-10-241-0/+290
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.