summaryrefslogtreecommitdiff
path: root/rts/posix/Select.c
Commit message (Collapse)AuthorAgeFilesLines
* Corrected types of thread ids obtained from the RTSMann mit Hut2021-10-061-6/+6
| | | | | | | | | | | | | | While the thread ids had been changed to 64 bit words in e57b7cc6d8b1222e0939d19c265b51d2c3c2b4c0 the return type of the foreign import function used to retrieve these ids - namely 'GHC.Conc.Sync.getThreadId' - was never updated accordingly. In order to fix that this function returns now a 'CUULong'. In addition to that the types used in the thread labeling subsystem were adjusted as well and several format strings were modified throughout the whole RTS to display thread ids in a consistent and correct way. Fixes #16761
* Make `PosixSource.h` installed and under `rts/`John Ericson2021-08-091-1/+1
| | | | | | is used outside of the rts so we do this rather than just fish it out of the repo in ad-hoc way, in order to make packages in this repo more self-contained.
* Fix typos, via a Levenshtein-style correctorBrian Wignall2020-01-041-1/+1
|
* Expunge #ifdef and #ifndef from the codebaseJohn Ericson2019-07-141-2/+2
| | | | | | | | These are unexploded minds as far as the linter is concerned. I don't want to hit in my MRs by mistake! I did this with `sed`, and then rolled back some changes in the docs, config.guess, and the linter itself.
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-151-1/+1
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* rts: Update comment about FreeBSD's unsigned FD_SETSIZENiklas Hambüchen2017-09-191-1/+6
| | | | | | | | | | Reviewers: bgamari, austin, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3957
* Use C99's boolBen Gamari2016-11-291-7/+7
| | | | | | | | | | | | Test Plan: Validate on lots of platforms Reviewers: erikd, simonmar, austin Reviewed By: erikd, simonmar Subscribers: michalt, thomie Differential Revision: https://phabricator.haskell.org/D2699
* Kill Itimer.hBen Gamari2016-05-011-1/+0
| | | | It declared nothing.
* fix EBADF unqueueing in select backend (Trac #10590)Sergei Trofimovich2015-07-071-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Alexander found a interesting case: 1. We have a queue of two waiters in a blocked_queue 2. first file descriptor changes state to RUNNABLE, second changes to INVALID 3. awaitEvent function dequeued RUNNABLE thread to a run queue and attempted to dequeue INVALID descriptor to a run queue. Unqueueing INVALID fails thusly: #3 0x000000000045cf1c in barf (s=0x4c1cb0 "removeThreadFromDeQueue: not found") at rts/RtsMessages.c:42 #4 0x000000000046848b in removeThreadFromDeQueue (...) at rts/Threads.c:249 #5 0x000000000049a120 in removeFromQueues (...) at rts/RaiseAsync.c:719 #6 0x0000000000499502 in throwToSingleThreaded__ (...) at rts/RaiseAsync.c:67 #7 0x0000000000499555 in throwToSingleThreaded (..) at rts/RaiseAsync.c:75 #8 0x000000000047c27d in awaitEvent (wait=rtsFalse) at rts/posix/Select.c:415 The problem here is a throwToSingleThreaded function that tries to unqueue a TSO from blocked_queue, but awaitEvent function leaves blocked_queue in a inconsistent state while traverses over blocked_queue: case RTS_FD_IS_READY: IF_DEBUG(scheduler, debugBelch("Waking up blocked thread %lu\n", (unsigned long)tso->id)); tso->why_blocked = NotBlocked; tso->_link = END_TSO_QUEUE; // Here we break the queue head pushOnRunQueue(&MainCapability,tso); break; Signed-off-by: Sergei Trofimovich <siarheit@google.com> Test Plan: tested on a sample from T10590 Reviewers: austin, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: qnikst, thomie, bgamari Differential Revision: https://phabricator.haskell.org/D1024 GHC Trac Issues: #10590, #4934
* *Really*, really fix RTS crash due to bad coercion.Merijn Verstraaten2014-11-071-1/+24
| | | | | | | | | | | | | | | | | | | | | Summary: My previous attempt to fix the new coercion bug introduced by my fix actually just reverted back to the *old* bug. This time it should properly handle all three size scenarios. Signed-off-by: Merijn Verstraaten <merijn@inconsistent.nl> Test Plan: validate Reviewers: dfeuer, austin, hvr Reviewed By: austin, hvr Subscribers: thomie, carter, simonmar Differential Revision: https://phabricator.haskell.org/D407 GHC Trac Issues: #8089
* Revert "rts: add Emacs 'Local Variables' to every .c file"Simon Marlow2014-09-291-8/+0
| | | | This reverts commit 39b5c1cbd8950755de400933cecca7b8deb4ffcd.
* rts: add Emacs 'Local Variables' to every .c fileAustin Seipp2014-07-281-0/+8
| | | | | | | | This will hopefully help ensure some basic consistency in the forward by overriding buffer variables. In particular, it sets the wrap length, the offset to 4, and turns off tabs. Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace Select.cAustin Seipp2014-07-281-83/+90
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* Raise exceptions when blocked in bad FDs (fixes Trac #4934)Sergei Trofimovich2014-06-081-46/+133
| | | | | | | | | | | | | | | Before the patch any call to 'select()' with 'bad_fd' led to: - unblocking of all threads - hiding exception for 'threadWaitRead bad_fd' The patch fixes both cases in this way: after 'select()' failure we iterate over each blocked descriptor and poll individually to see it's actual status, which is: - READY (move to run queue) - BLOCKED (leave in blocked queue) - INVALID (send an IOErrror exception) Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* Revert "Disable the timer signal while blocked in select() (#5991)"Simon Marlow2012-09-241-13/+4
| | | | | | | | | This reverts commit dd24d6bc37879c6b32a3d5ac4ee765e59e13501c. This attempt to fix the problem was misguided: the program might be stuck in a foreign call rather than awaitEvent(), and then the timer signal will never get disabled. The only way to turn off the timer signal in this case is in the timer interrupt handler itself.
* Add cast to placate gcc 4.6 on linux-powerpc (#7113).Erik de Castro Lopo2012-08-091-1/+1
|
* Fix #7087 (integer overflow in getDelayTarget())Simon Marlow2012-07-311-3/+12
|
* Use monotonic clock in Select.c (#5865)Paolo Capriotti2012-04-161-10/+5
|
* Improve the handling of threadDelay in the non-threaded RTSSimon Marlow2012-04-111-12/+33
| | | | | | | Firstly, we were rounding up too much, such that the smallest delay was 20ms. Secondly, there is no need to use millisecond resolution on a 64-bit machine where we have room in the TSO to use the normal nanosecond resolution that we use elsewhere in the RTS.
* Disable the timer signal while blocked in select() (#5991)Simon Marlow2012-04-111-4/+13
| | | | | The threaded RTS had a fix for this a long time ago (#1623) but this patch applies a similar fix to the non-threaded RTS.
* small cleanupSimon Marlow2012-04-111-5/+5
|
* Fix bug introduced in fac8ecbbafde17dd92439c41747223c43e9d2b80Simon Marlow2012-01-191-6/+6
| | | | Fixes recent failures in hGetBuf001.
* Fix bug causing polling instead of blocking in the non-threaded RTS (#5773)Simon Marlow2012-01-161-18/+17
| | | | | | | | | This was a regression introduced accidentally in 6b1098511aaabd2c9503ee7be6da1944466f9cb4. We were previously passing a large time value to select() to simulate blocking, and this broke due to a change from unsigned to signed arithmetic. I've refactored it to be less fragile now - we just pass NULL as the timeval parameter to select(), which is the correct way to do blocking.
* Time handling overhaulSimon Marlow2011-11-251-14/+25
| | | | | | | | | | | | | | | | | | | | | Terminology cleanup: the type "Ticks" has been renamed "Time", which is an StgWord64 in units of TIME_RESOLUTION (currently nanoseconds). The terminology "tick" is now used consistently to mean the interval between timer signals. The ticker now always ticks in realtime (actually CLOCK_MONOTONIC if we have it). Before it used CPU time in the non-threaded RTS and realtime in the threaded RTS, but I've discovered that the CPU timer has terrible resolution (at least on Linux) and isn't much use for profiling. So now we always use realtime. This should also fix The default tick interval is now 10ms, except when profiling where we drop it to 1ms. This gives more accurate profiles without affecting runtime too much (<1%). Lots of cleanups - the resolution of Time is now in one place only (Rts.h) rather than having calculations that depend on the resolution scattered all over the RTS. I hope I found them all.
* Implement stack chunks and separate TSO/STACK objectsSimon Marlow2010-12-151-9/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* give a better error message in the non-threaded RTS for out-of-range FDsSimon Marlow2010-09-291-2/+10
| | | | | | # ./aw aw: file descriptor 1027 out of range for select (0--1024). Recompile with -threaded to work around this.
* Test for (fd < 0) before trying to FD_SET itIan Lynagh2010-08-041-2/+2
|
* #include <sys/select.h> if we have it (#3760)Simon Marlow2009-12-161-0/+4
|
* RTS tidyup sweep, first phaseSimon Marlow2009-08-021-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* cope with ThreadRelocated on the sleeping_queueSimon Marlow2009-02-171-2/+8
|
* Cope with ThreadRelocated when traversing the blocked_queueSimon Marlow2008-11-061-0/+5
| | | | Fixes "invalid what_next field" in ioref001 on Windows, and perhaps others
* Add a write barrier to the TSO link field (#1589)Simon Marlow2008-04-161-7/+7
|
* FIX BUILD FD_SETSIZE signedjochemberndsen@dse.nl2007-09-271-2/+6
| | | | | On FreeBSD FD_SETSIZE is unsigned. Cast it to a signed int for portability.
* wakeUpSleepingThreads: fix off by oneSimon Marlow2007-07-181-1/+1
| | | | | | The symptom of this bug is after the time of a threadDelay has expired, the RTS does a whole slew of extra select() calls. This should help with #1523, but it's not the whole story.
* Add an --install-signal-handlers=<yes|no> RTS flag; fixes trac #804Ian Lynagh2007-03-221-1/+1
|
* Split GC.c, and move storage manager into sm/ directorySimon Marlow2006-10-241-0/+1
| | | | | | | | | | | | | | | | | 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.
* new RTS flag: -V to modify the resolution of the RTS timerIan Lynagh2006-09-051-1/+1
| | | | | | | | | Fixed version of an old patch by Simon Marlow. His description read: Also, now an arbitrarily short context switch interval may now be specified, as we increase the RTS ticker's resolution to match the requested context switch interval. This also applies to +RTS -i (heap profiling) and +RTS -I (the idle GC timer). +RTS -V is actually only required for increasing the resolution of the profile timer.
* Match format strings and arguments for printf-like functionssven.panne@aedion.de2006-08-101-2/+2
|
* Reorganisation of the source treeSimon Marlow2006-04-071-0/+279
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.