summaryrefslogtreecommitdiff
path: root/rts/posix
Commit message (Collapse)AuthorAgeFilesLines
* rts: drop unused getThreadCPUTimeSergei Trofimovich2016-02-071-30/+0
| | | | | | | | | | | | | | | | Use of this helper function was removed in: commit 3c9fc104337a142fe4f375d30d7a6b81d55a70c1 Author: Brian Brooks <brooks.brian@gmail.com> Date: Thu Jul 10 02:55:33 2014 -0500 Avoid unnecessary clock_gettime() syscalls in GC stats. Noticed by uselex.rb: getThreadCPUTime: [R]: exported from: ./rts/dist/build/posix/GetTime.p_o Signed-off-by: Sergei Trofimovich <siarheit@google.com>
* rts/posix: Fail with HEAPOVERFLOW when out of memory during mmapBen Gamari2016-01-171-1/+1
| | | | | | | | | | | | Test Plan: Validate Reviewers: simonmar, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1787 GHC Trac Issues: #11300
* Allow to compile OSMem.c when MEM_NORESERVE is not availableHerbert Valerio Riedel2015-12-051-0/+7
| | | | | | | | | | | | On some OSes such as AIX `MEM_NORESERVE` is not available. Since this feature is only needed when the new two-step allocator (see #9706) is enabled we can simply turn this into a runtime error to avoid a larger refactoring of this already quite platform-sensitive code. Reviewed By: bgamari, ezyang Differential Revision: https://phabricator.haskell.org/D1568
* Use Autoconf's AC_USE_SYSTEM_EXTENSIONSHerbert Valerio Riedel2015-12-041-6/+0
| | | | | | | | | | | | | | | | | | | | | | This takes care of setting feature test macros (i.e. let Autoconf decide when those can be set safely) to allow subsequent Autoconf tests to better detect available OS features. This also includes a submodule update of unix which enables the use of `AC_USE_SYSTEM_EXTENSIONS` in there as well. Specifically, this takes care of setting `_GNU_SOURCE` (which allows to remove two occurences where it's set manually) and `_ALL_SOURCE` (which fixes issues on AIX). See also https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Posix-Variants.html for details. At some point we may want to reconsider the purpose of "rts/PosixSource.h" and rely more on Autoconf instead.
* rts: Kill PAPI supportBen Gamari2015-11-181-24/+5
| | | | | | | | | | | | | | | This hasn't been used for a very long time and will soon be superceded by perf_events support. Test Plan: validate Reviewers: austin, simonmar Reviewed By: austin, simonmar Subscribers: thomie, erikd Differential Revision: https://phabricator.haskell.org/D1493
* Libdw: Fix symbol namingBen Gamari2015-11-011-5/+5
| | | | RTS convention is to use camel-case.
* rts/posix: Reduce heap allocation amount on mmap failureBen Gamari2015-11-011-8/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since the two-step allocator the RTS asks the kernel for a large upfront mmap'd region of memory (on the order of terabytes). While we have no expectation that this entire region will be backed by physical memory, this scheme nevertheless fails on some systems with resource limits. Here we use a back-off scheme to reduce our allocation request until we find a size agreeable to the kernel. Fixes #10877. This also fixes a latent bug wherein the heap reservation retry logic would fail to free the previously reserved address space, which would likely result in a heap allocation failure. Test Plan: set address space limit with `ulimit -v 67108864` and try running a compiled program Reviewers: simonmar, austin Reviewed By: simonmar Subscribers: thomie, RyanGlScott Differential Revision: https://phabricator.haskell.org/D1405 GHC Trac Issues: #10877
* Signals: Ensure libdw session is freedBen Gamari2015-10-311-0/+1
|
* rts: Make MBLOCK_SPACE_SIZE dynamicBen Gamari2015-10-301-9/+10
| | | | | | | | | | | | | | | | | | | | | | | Previously this was introduced in D524 as a compile-time constant. Sadly, this isn't flexible enough to allow for environments where ulimits restrict the maximum address space size (see, for instance, Consequently, we are forced to make this dynamic. In principle this shouldn't be so terrible as we can place both the beginning and end addresses within the same cache line, likely incurring only one or so additional instruction in HEAP_ALLOCED. Test Plan: validate Reviewers: austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1353 GHC Trac Issues: #10877
* Signals: Always install SIGUSR2 handlerBen Gamari2015-10-181-2/+0
| | | | Even if libdw isn't available.
* Signals: Print backtrace on SIGUSR2Ben Gamari2015-10-171-0/+30
| | | | | | | | | | | | | | | This uses the backtrace support introduced in D1196 to provide backtraces from Haskell processes when SIGUSR2 is thrown. Test Plan: Need to add a test. Reviewers: scpmw, simonmar, Tarrasch, austin Reviewed By: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1197
* fix 64bit two-stage allocator on Solaris/AMD64 platform (#10790)Karel Gardas2015-08-251-1/+1
| | | | | | | | | | Test Plan: tested on Solaris 11/AMD64 when previous build failed Reviewers: bgamari, austin, simonmar, gcampax, ezyang Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1169
* Rejigger OSMem.my_mmap to allow building on MacRichard Eisenberg2015-08-061-28/+31
| | | | | | | | Previously, the prot and flags variables were set but never used on Mac (darwin). This caused a warning, and the build setup stopped compilation. This commit is intended simply to omit these variables when building with darwin_HOST_OS set. No change in behavior on any platform is intended.
* Two step allocator for 64-bit systemsGiovanni Campagna2015-07-221-24/+176
| | | | | | | | | | | | | | | | | | | | | | | Summary: The current OS memory allocator conflates the concepts of allocating address space and allocating memory, which makes the HEAP_ALLOCED() implementation excessively complicated (as the only thing it cares about is address space layout) and slow. Instead, what we want is to allocate a single insanely large contiguous block of address space (to make HEAP_ALLOCED() checks fast), and then commit subportions of that in 1MB blocks as we did before. This is currently behind a flag, USE_LARGE_ADDRESS_SPACE, that is only enabled for certain OSes. Test Plan: validate Reviewers: simonmar, ezyang, austin Subscribers: thomie, carter Differential Revision: https://phabricator.haskell.org/D524 GHC Trac Issues: #9706
* 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
* RTS/IOManager: fix trac issue #9722.Andreas Voellmy2015-03-091-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Whenever the RTS has been inactive for idleGCDelayTime, the idle timer fires and calls wakeUpRts(), which in turn calls ioManagerWakeup(), which in turn writes a byte (or a few) to a file descriptor (stored in the io_manager_wakeup_fd variable) registered by the TimerManager and on which the TimerManager will wait. (Note that the write will only occur if the file descriptor is non-negative.) When the RTS shuts down, it shuts down the TimerManager, and in this process the file descriptor stored in io_manager_wakeup_fd is closed. In the error case, the idle timer fires after the close of the file occurs, and then the write() call in ioManagerWakeup() fails and the aforementioned error message gets printed. This patch solves the problem by (1) having the TimerManager (via Control) write -1 to io_manager_wakeup_fd just before closing the file descriptor written in io_manager_wakeup_fd, and (2) having ioManagerWakeup() ignore an error returned by write() in the case that the write returned -1 and the io_manager_wakeup_fd is -1. Reviewers: austin, simonmar, hvr, thomie Reviewed By: thomie Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D722 GHC Trac Issues: #9722
* Fix #10017Andreas Voellmy2015-02-021-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | Summary: In the threaded RTS, a signal is delivered from the RTS to Haskell user code by writing to file that one of the IO managers watches (via an instance of GHC.Event.Control.Control). When the IO manager receives the signal, it calls GHC.Conc.Signal.runHandlers to invoke Haskell signal handler. In the move from a single IO manager to one IO manager per capability, the behavior was (wrongly) extended so that a signal is delivered to every event manager (see #9423), each of which invoke Haskell signal handlers, leading to multiple invocations of Haskell signal handlers for a single signal. This change fixes this problem by having the RTS (in generic_handler()) notify only the Control instance used by the TimerManager, rather than all the per-capability IO managers. Reviewers: austin, hvr, simonmar, Mikolaj Reviewed By: simonmar, Mikolaj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D641
* compiler: fix trac issue #9817Marios Titas2014-12-101-1/+1
| | | | | | | | | | | | | | | | | | | Summary: When we call runHandlers, we must pass it a ForeignPtr. To ensure that this happens, we introduce a wrapper that receives a plain Ptr and converts it into a ForeignPtr. Then we adjust startSignalHandlers in rts/posix/Signals.c to call the wrapper instead of calling runHandlers directly. Reviewers: hvr, austin, rwbarton, simonmar Reviewed By: austin, simonmar Subscribers: simonmar, thomie, carter Differential Revision: https://phabricator.haskell.org/D515 GHC Trac Issues: #9817
* arm64: 64bit iOS and SMP support (#7942)Luke Iannini2014-11-191-1/+1
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* *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 "Rename _closure to _static_closure, apply naming consistently."Edward Z. Yang2014-10-201-2/+2
| | | | | | | This reverts commit 35672072b4091d6f0031417bc160c568f22d0469. Conflicts: compiler/main/DriverPipeline.hs
* rts: fix unused parameter warningAustin Seipp2014-10-171-1/+1
| | | | | | | | | | | | | | | | | | | Summary: If `pthread_setname_np` is not available, then a regular ./validate will fail due to warnings; the `name` parameter to `createOSThread` becomes unused. Signed-off-by: Austin Seipp <austin@well-typed.com> Test Plan: iiam Reviewers: simonmar, nomeata, jstolarek, hvr Reviewed By: nomeata, jstolarek, hvr Subscribers: nomeata, thomie, carter, ezyang, simonmar Differential Revision: https://phabricator.haskell.org/D344
* Add a configure test for pthread_setname_npSimon Marlow2014-10-141-0/+2
|
* Name worker threads using pthread_setname_npSimon Marlow2014-10-101-2/+5
| | | | | This helps identify threads in gdb particularly in processes with a lot of threads.
* Rename _closure to _static_closure, apply naming consistently.Edward Z. Yang2014-10-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In preparation for indirecting all references to closures, we rename _closure to _static_closure to ensure any old code will get an undefined symbol error. In order to reference a closure foobar_closure (which is now undefined), you should instead use STATIC_CLOSURE(foobar). For convenience, a number of these old identifiers are macro'd. Across C-- and C (Windows and otherwise), there were differing conventions on whether or not foobar_closure or &foobar_closure was the address of the closure. Now, all foobar_closure references are addresses, and no & is necessary. CHARLIKE/INTLIKE were not changed, simply alpha-renamed. Part of remove HEAP_ALLOCED patch set (#8199) Depends on D265 Signed-off-by: Edward Z. Yang <ezyang@mit.edu> Test Plan: validate Reviewers: simonmar, austin Subscribers: simonmar, ezyang, carter, thomie Differential Revision: https://phabricator.haskell.org/D267 GHC Trac Issues: #8199
* Revert "rts: add Emacs 'Local Variables' to every .c file"Simon Marlow2014-09-2913-104/+0
| | | | This reverts commit 39b5c1cbd8950755de400933cecca7b8deb4ffcd.
* Revert "Revert "rts/base: Fix #9423"" and resolve issue that caused the revert.Andreas Voellmy2014-09-161-30/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This reverts commit 4748f5936fe72d96edfa17b153dbfd84f2c4c053. The fix for #9423 was reverted because this commit introduced a C function setIOManagerControlFd() (defined in Schedule.c) defined for all OS types, while the prototype (in includes/rts/IOManager.h) was only included when mingw32_HOST_OS is not defined. This broke Windows builds. This commit reverts the original commit and resolves the problem by only defining setIOManagerControlFd() when mingw32_HOST_OS is defined. Hence the missing prototype error should not occur on Windows. In addition, since the io_manager_control_wr_fd field of the Capability struct is only usd by the setIOManagerControlFd, this commit includes the io_manager_control_wr_fd field in the Capability struct only when mingw32_HOST_OS is not defined. Test Plan: Try to compile successfully on all platforms. Reviewers: austin Reviewed By: austin Subscribers: simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D174
* Revert "rts/base: Fix #9423"Austin Seipp2014-08-221-50/+30
| | | | | | | | | This should fix the Windows fallout, and hopefully this will be fixed once that's sorted out. This reverts commit f9f89b7884ccc8ee5047cf4fffdf2b36df6832df. Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts/base: Fix #9423Andreas Voellmy2014-08-191-30/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Fix #9423. The problem in #9423 is caused when code invoked by `hs_exit()` waits on all foreign calls to return, but some IO managers are in `safe` foreign calls and do not return. The previous design signaled to the timer manager (via its control pipe) that it should "die" and when the timer manager returned to Haskell-land, the Haskell code in timer manager then signalled to the IO manager threads that they should return from foreign calls and `die`. Unfortunately, in the shutdown sequence the timer manager is unable to return to Haskell-land fast enough and so the code that signals to the IO manager threads (via their control pipes) is never executed and the IO manager threads remain out in the foreign calls. This patch solves this problem by having the RTS signal to all the IO manager threads (via their control pipes; and in addition to signalling to the timer manager thread) that they should shutdown (in `ioManagerDie()` in `rts/Signals.c`. To do this, we arrange for each IO manager thread to register its control pipe with the RTS (in `GHC.Thread.startIOManagerThread`). In addition, `GHC.Thread.startTimerManagerThread` registers its control pipe. These are registered via C functions `setTimerManagerControlFd` (in `rts/Signals.c`) and `setIOManagerControlFd` (in `rts/Capability.c`). The IO manager control pipe file descriptors are stored in a new field of the `Capability_ struct`. Test Plan: See the notes on #9423 to recreate the problem and to verify that it no longer occurs with the fix. Auditors: simonmar Reviewers: simonmar, edsko, ezyang, austin Reviewed By: austin Subscribers: phaskell, simonmar, ezyang, carter, relrod Differential Revision: https://phabricator.haskell.org/D129 GHC Trac Issues: #9423, #9284
* rts: add Emacs 'Local Variables' to every .c fileAustin Seipp2014-07-2813-0/+104
| | | | | | | | 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>
* rts: delint/detab/dewhitespace Signals.cAustin Seipp2014-07-281-62/+67
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace Signals.hAustin Seipp2014-07-281-1/+0
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace TTY.cAustin Seipp2014-07-281-15/+17
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace OSThreads.cAustin Seipp2014-07-281-21/+24
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace OSMem.cAustin Seipp2014-07-281-14/+19
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace Itimer.cAustin Seipp2014-07-281-5/+5
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace GetTime.cAustin Seipp2014-07-281-19/+26
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: delint/detab/dewhitespace GetEnv.cAustin Seipp2014-07-281-1/+1
| | | | 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>
* Check return value of sigactionNicolas Trangez2014-04-271-1/+3
| | | | | | Issue discovered by Coverity scan, CID 43142. Signed-off-by: Austin Seipp <austin@well-typed.com>
* Test return value of clock_gettime() for errors.Simon Marlow2014-04-041-3/+13
| | | | | I don't want to fall back to gettimeofday(), because that might have a different absolute value.
* Fix typo in error messageHerbert Valerio Riedel2014-01-111-1/+1
| | | | Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Extend getPhysicalMemorySize to iOS (#8533)Austin Seipp2013-11-221-1/+1
| | | | | Authored-by: Authored-by: Luke Iannini <lukexi@me.com> Signed-off-by: Austin Seipp <austin@well-typed.com>
* Fix getPhysicalMemorySize on OS X (#8481)Austin Seipp2013-10-261-3/+19
| | | | | | | Darwin doesn't support _SC_PHYS_PAGES, but we can get the exact number of bytes of physical memory via 'hw.memsize', so we use that instead. Signed-off-by: Austin Seipp <austin@well-typed.com>
* rts: Add getPhysicalMemorySizeBen Gamari2013-10-251-0/+20
|
* Nuke tabs in rts/posix/OSMem.cAustin Seipp2013-09-141-31/+31
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* Fix getPageSize to actually cache the page size.Austin Seipp2013-09-141-7/+8
| | | | | | This fixes #8289. Signed-off-by: Austin Seipp <austin@well-typed.com>
* Treat EPERM error from mmap as an OOM (#7500)Reid Barton2013-08-291-0/+21
| | | | | | | | | | | | | | | | | | | | | | | Linux can give back EPERM from an mmap call when a user program attempts to map pages near `mmap_min_addr`, which is a kernel security measure to prevent people from mapping pages at address 0. We may do this when we hint to mmap what address to map the pages to. However, it's theoretically possible we're not actually out of memory - we could have continuously mapped pages at some other place far away from `mmap_min_addr` and succeeded instead. So as an added precaution, if mmap for a given addr gives us EPERM, we'll also attempt to map *again*, but without the address hint. Maybe the kernel can do the right thing. However, while testing #7500, the amount of free address space we could have otherwise used only turns out to be about 139MB. Which isn't really a lot. So, given that, we *also* otherwise treat EPERM as an out of memory error. This fixes #7500. Signed-off-by: Austin Seipp <aseipp@pobox.com>
* Revert "Check for integer overflow in osGetMBlocks"Austin Seipp2013-08-291-12/+1
| | | | | | This reverts commit 48865521de6638240819b3979edbb3d33401dc8e. Signed-off-by: Austin Seipp <aseipp@pobox.com>