summaryrefslogtreecommitdiff
path: root/rts/posix
Commit message (Collapse)AuthorAgeFilesLines
* Expunge #ifdef and #ifndef from the codebaseJohn Ericson2019-07-142-5/+5
| | | | | | | | 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.
* RTS: Fix restrictive castAlec Theriault2019-05-221-2/+2
| | | | | | | | | | | | | Commit e75a9afd2989e0460f9b49fa07c1667299d93ee9 added an `unsigned` cast to account for OSes that have signed `rlim_t` signed. Unfortunately, the `unsigned` cast has the unintended effect of narrowing `rlim_t` to only 4 bytes. This leads to some spurious out of memory crashes (in particular: Haddock crashes with OOM whenn building docs of `ghc`-the-library). In this case, `W_` is a better type to cast to: we know it will be unsigned too and it has the same type as `*len` (so we don't suffer from accidental narrowing).
* osReserveHeapMemory: handle signed rlim_tFraser Tweedale2019-04-231-2/+4
| | | | | | rlim_t is a signed type on FreeBSD, and the build fails with a sign-compare error. Add explicit (unsigned) cast to handle this case.
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-152-2/+2
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* A few typofixesGabor Greif2019-01-231-1/+1
|
* rts: Use always-available locking operations in pthread Itimer implementationBen Gamari2019-01-141-6/+6
| | | | | | Previously we ACQUIRE_LOCK and RELEASE_LOCK but these compile to a noop in the non-threaded RTS, as noted in #16150. Use OS_ACQUIRE_LOCK and OS_RELEASE_LOCK instead.
* itimer: Don't free condvar until we know ticker is stoppedBen Gamari2019-01-141-2/+2
| | | | | | | | | | | When we are shutting down the pthread ticker we signal the start_cond condition variable to ensure that the ticker thread wakes up and exits in a reasonable amount of time. Previously, when the ticker thread would shut down it was responsible for freeing the start_cond condition variable. However, this would lead to a race wherein the ticker would free start_cond, then the main thread would try to signal it in an effort to wake the ticker (#16150). Avoid this by moving the mutex destruction to the main thread.
* Finish stable splitDavid Feuer2018-08-291-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Long ago, the stable name table and stable pointer tables were one. Now, they are separate, and have significantly different implementations. I believe the time has come to finish the split that began in #7674. * Divide `rts/Stable` into `rts/StableName` and `rts/StablePtr`. * Give each table its own mutex. * Add FFI functions `hs_lock_stable_ptr_table` and `hs_unlock_stable_ptr_table` and document them. These are intended to replace the previously undocumented `hs_lock_stable_tables` and `hs_lock_stable_tables`, which are now documented as deprecated synonyms. * Make `eqStableName#` use pointer equality instead of unnecessarily comparing stable name table indices. Reviewers: simonmar, bgamari, erikd Reviewed By: bgamari Subscribers: rwbarton, carter GHC Trac Issues: #15555 Differential Revision: https://phabricator.haskell.org/D5084
* rts: Fix unused functionBen Gamari2018-08-011-1/+2
|
* Enable two-step allocator on FreeBSDBen Gamari2018-07-311-53/+88
| | | | | | Simplify #ifdef nesting and use MAP_GUARD on FreeBSD and similar systems. This allows the two-step allocator to be used on FreeBSD, fixing #15348.
* fix osReserveHeapMemory block alignmentSergei Trofimovich2018-07-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before the change osReserveHeapMemory() attempted to allocate chunks of memory via osTryReserveHeapMemory() not multiple of MBLOCK_SIZE in the following fallback code: ``` if (at == NULL) { *len -= *len / 8; ``` and caused assertion failure: ``` $ make fulltest TEST=T11607 WAY=threaded1 T11607: internal error: ASSERTION FAILED: file rts/posix/OSMem.c, line 457 (GHC version 8.7.20180716 for riscv64_unknown_linux) ``` The change applies alignment mask before each MBLOCK allocation attempt and fixes WAY=threaded1 test failures on qemu-riscv64. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Test Plan: run 'make fulltest WAY=threaded1' Reviewers: simonmar, bgamari, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4982
* Revert "rts: Enable two-step allocator on FreeBSD"Ben Gamari2018-07-061-8/+3
| | | | | | This reverts commit 8736715857d08cc1f88d766c257b39c05df20639. I hadn't intended on merging this.
* rts: Enable two-step allocator on FreeBSDBen Gamari2018-07-061-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we would prevent any operating system not providing the MEM_NORESERVE flag from using the two-step allocator. Afterall, Linux will reserve swap-space for a mapping unless this flag is given, which is most certainly not what we want. However, it seems that FreeBSD provides the reservation-only mapping behavior that we expect despite not providing the MEM_NORESERVE macro. In fact, it provided the macro until 2014, when it was removed on account of not being implemented in the kernel. However, empirical evidence suggests that just plain mmap does what we want. Reviewers: erikd, simonmar Subscribers: rwbarton, thomie, erikd, carter GHC Trac Issues: #15348 Differential Revision: https://phabricator.haskell.org/D4939
* rts: Abort if timerfd read failsBen Gamari2018-06-221-1/+1
| | | | | | | | | | | | | | | | | | | | Currently we belch some output to stderr but fail to abort, resulting in a busy loop. Fixes #15292. Test Plan: * Validate * try running program under environment without timerfd capabilities; ensure we don't busy-loop Reviewers: simonmar, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #15929 Differential Revision: https://phabricator.haskell.org/D4875
* rts: A bit of cleanup of posix itimer implementationBen Gamari2018-06-201-12/+9
| | | | | | | | | | | | | * Use bool instead of HsBool * Use barf instead of sysErrorBelch; stg_exit Test Plan: Validate Reviewers: erikd, simonmar Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4874
* rts: Ignore RLIMIT_AS if it is zeroBen Gamari2018-06-141-1/+3
| | | | | | | | | | | | Reviewers: erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14492 Differential Revision: https://phabricator.haskell.org/D4811
* rts: Query system rlimit for maximum address-space sizeBen Gamari2018-06-021-0/+11
| | | | | | | | | | | | | | | | | When we attempt to reserve the heap, we query the system's rlimit to establish the starting point for our search over sizes. Test Plan: Validate Reviewers: erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14492 Differential Revision: https://phabricator.haskell.org/D4754
* rts/posix: Use less aggressive backoff schedule for heap reservation sizingBen Gamari2018-05-301-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When we allocate the heap on POSIX platforms we generally just ask for a 1TB chunk of address space and call it a day. However, if the user has set a ulimit then this request will fail. In this case we would previously try successively smaller allocation requests, reducing the request size by a factor of two each time. However, this means that GHC will significantly allocate a significantly smaller heap than the available physical memory size in some circumstances. Imagine, for instance, a machine with 512 GB of physical memory but a ulimit of 511 GB: we would be limited to a 256 GB heap. We now use a less aggressive back-off policy, reducing by one-eighth the last allocation size each try. Thanks to luispedro for the suggested approach. Test Plan: Validate Reviewers: simonmar, erikd Subscribers: rwbarton, thomie GHC Trac Issues: #14492 Differential Revision: https://phabricator.haskell.org/D4215
* rts: Don't madvise if mmap failedBen Gamari2018-05-301-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | On 32-bit Linux `outofmem` did not fail with the expected out-of-memory error message, instead failing with, outofmem: internal error: getMBlock: mmap: Invalid argument This happened because, `my_mmap` would attempt to `madvise` even if the `mmap` call failed. So while `mmap` returns `ENOMEM` we nevertheless try to `madvise`, which clobbers `errno`, giving us the unexpected `EINVAL` error. Consequently we don't detect this to be an out-of-memory error. This should fix #15060. Test Plan: `make test TEST=outofmem` on i386 Reviewers: simonmar, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #15060 Differential Revision: https://phabricator.haskell.org/D4704
* Fix a few GCC warningsMichal Terepeta2018-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC 8 now generates warnings for incompatible function pointer casts [-Werror=cast-function-type]. Apparently there are a few of those in rts code, which makes `./validate` unhappy (since we compile with `-Werror`) This commit tries to fix these issues by changing the functions to have the correct type (and, if necessary, moving the casts into those functions). For instance, hash/comparison function are declared (`Hash.h`) to take `StgWord` but we want to use `StgWord64[2]` in `StaticPtrTable.c`. Instead of casting the function pointers, we can cast the `StgWord` parameter to `StgWord*`. I think this should be ok since `StgWord` should be the same size as a pointer. Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com> Test Plan: ./validate Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4673
* rts: Throw better error if --numa is used without libnuma supportBen Gamari2018-05-031-0/+9
| | | | | | | | | | | | | Test Plan: Validate, run program with `+RTS --numa` without libnuma support compiled in Reviewers: erikd, simonmar Subscribers: thomie, carter GHC Trac Issues: #14956 Differential Revision: https://phabricator.haskell.org/D4556
* Remove markSignalHandlersÖmer Sinan Ağacan2018-04-161-10/+0
| | | | | | | | | | | | It's no-op on all platforms Reviewers: bgamari, simonmar, erikd, dfeuer Reviewed By: dfeuer Subscribers: dfeuer, thomie, carter Differential Revision: https://phabricator.haskell.org/D4588
* Fix typoGabor Greif2018-03-191-1/+1
|
* rts: fix some barf format specifiers.Douglas Wilson2018-02-061-1/+1
| | | | | | | | | | Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4390
* rts: Fix format of failed memory commit messageBen Gamari2018-02-061-1/+1
| | | | | | | | | | | | Test Plan: Validate Reviewers: erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4373
* rts: Ensure that forkOS releases Task on terminationBen Gamari2018-01-311-0/+1
| | | | | | | | | | | | | | Test Plan: validate Reviewers: simonmar, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14725 Differential Revision: https://phabricator.haskell.org/D4346
* rts/posix: Ensure that memory commit succeedsBen Gamari2017-10-161-1/+4
| | | | | | | | | | | | | | | | | Previously we wouldn't check that mmap would succeed. I suspect this may have been the cause of #14329. Test Plan: Validate under low-memory condition Reviewers: simonmar, austin, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie GHC Trac Issues: #14329 Differential Revision: https://phabricator.haskell.org/D4075
* rts: Label all threads created by the RTSBen Gamari2017-10-161-7/+10
| | | | | | | | | | Reviewers: austin, erikd, simonmar Reviewed By: simonmar Subscribers: pacak, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4068
* rts: Inform kernel that we won't need reserved address spaceBen Gamari2017-09-261-0/+13
| | | | | | | | | | | | | | | | | | | | | Trac #14192 points out that currently GHC's two-step allocator results in extremely large coredumps. It seems like WebKit may have encountered similar issues and their apparent solution uses madvise(MADV_DONTNEED) while reserving address space to inform the kernel that the address space we just requested needs no backing. Perhaps this is used by the core dump logic to trim out uncommitted pages. Test Plan: Validate, try core-dumping a compiled executable Reviewers: austin, erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie GHC Trac Issues: #14192, #14193 Differential Revision: https://phabricator.haskell.org/D3929
* Use SIGQUIT for DWARF backtraces instead of SIGUSR2Ben Gamari2017-09-251-6/+6
| | | | | | | | Reviewers: austin, erikd, simonmar Subscribers: NicolasT, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3979
* 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
* rts: Print message before SIGUSR2 backtraceBen Gamari2017-09-131-0/+1
| | | | | | | | Reviewers: austin, erikd, simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3942
* fix a memory leak in osNumaMaskKubo Kovac2017-05-221-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | got an error when using asan: ``` ==1866689==ERROR: LeakSanitizer: detected memory leaks Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x10640568 in malloc ??:? #1 0x154d867e in numa_bitmask_alloc .../numactl-2.0.8/libnuma_nosymve r.c:204 #2 0x154d867e in numa_allocate_nodemask .../numactl-2.0.8/libnuma_nosymve r.c:724 #3 0x154d867e in numa_get_mems_allowed .../numactl-2.0.8/libnuma_nosymve r.c:1141 #4 0x10b54a45 in osNumaMask ...ghc-8.0.2/rts/posix/OSMem.c:59 8 ``` Test Plan: compile, validate Reviewers: simonmar, niteria, austin, bgamari, erikd Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3537
* Typos in comments [ci skip]Gabor Greif2017-05-051-1/+1
|
* Prefer #if defined to #ifdefBen Gamari2017-04-2810-48/+48
| | | | Our new CPP linter enforces this.
* Enable new warning for fragile/incorrect CPP #if usageErik de Castro Lopo2017-04-284-9/+9
| | | | | | | | | | | | | | | | The C code in the RTS now gets built with `-Wundef` and the Haskell code (stages 1 and 2 only) with `-Wcpp-undef`. We now get warnings whereever `#if` is used on undefined identifiers. Test Plan: Validate on Linux and Windows Reviewers: austin, angerman, simonmar, bgamari, Phyx Reviewed By: bgamari Subscribers: thomie, snowleopard Differential Revision: https://phabricator.haskell.org/D3278
* cpp: Use #pragma once instead of #ifndef guardsBen Gamari2017-04-234-16/+4
| | | | | | | | | | | | | | This both says what we mean and silences a bunch of spurious CPP linting warnings. This pragma is supported by all CPP implementations which we support. Reviewers: austin, erikd, simonmar, hvr Reviewed By: simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3482
* Fix build on DragonflyBSDBen Gamari2017-04-211-3/+3
| | | | | | | | | | | | Test Plan: Validate on DragonflyBSD Reviewers: austin, erikd, simonmar Reviewed By: erikd Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3480
* Revert "Enable new warning for fragile/incorrect CPP #if usage"Ben Gamari2017-04-054-9/+9
| | | | | | | | This is causing too much platform dependent breakage at the moment. We will need a more rigorous testing strategy before this can be merged again. This reverts commit 7e340c2bbf4a56959bd1e95cdd1cfdb2b7e537c2.
* Enable new warning for fragile/incorrect CPP #if usageErik de Castro Lopo2017-04-054-9/+9
| | | | | | | | | | | | | | | | The C code in the RTS now gets built with `-Wundef` and the Haskell code (stages 1 and 2 only) with `-Wcpp-undef`. We now get warnings whereever `#if` is used on undefined identifiers. Test Plan: Validate on Linux and Windows Reviewers: austin, angerman, simonmar, bgamari, Phyx Reviewed By: bgamari Subscribers: thomie, snowleopard Differential Revision: https://phabricator.haskell.org/D3278
* rts: Use pthread itimer implementation on DarwinBen Gamari2016-12-071-0/+9
| | | | | | | | | | | | | | | | | We want to avoid using SIGALRM whenever possible since we will interrupt long-running system calls. See #10840. Test Plan: Validate on Darwin Reviewers: austin, erikd, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2796 GHC Trac Issues: #10840
* Fix x86 Windows build and testsuiteTamar Christina2016-12-061-1/+1
| | | | | | | | | | | | | | | | Summary: Fix issues preventing x86 GHC to build on Windows and fix segfault in the testsuite. Test Plan: ./validate Reviewers: austin, erikd, simonmar, bgamari Reviewed By: bgamari Subscribers: #ghc_windows_task_force, thomie Differential Revision: https://phabricator.haskell.org/D2789
* rts: Ensure we always give MADV_DONTNEED a chance in osDecommitMemoryBen Gamari2016-12-011-3/+16
| | | | | | | | | | | | | | | | | | | | | As described in #12865, newer Linux kernels support both MADV_FREE and MADV_DONTNEED. Previously a runtime would fail to try MADV_DONTNEED if MADV_FREE failed (e.g. since the kernel which the image is running on doesn't support the latter). Now we try MADV_DONTNEED if MADV_FREE failed to ensure that binaries compiled on a kernel supporting MADV_FREE don't fail on decommit. Test Plan: Validate Reviewers: austin, erikd, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2780 GHC Trac Issues: #12865
* Use C99's boolBen Gamari2016-11-298-27/+27
| | | | | | | | | | | | 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
* Define thread primitives if they're supported.Shea Levy2016-11-291-18/+19
| | | | | | | | | | | | | | | | | | | On iOS, we use the pthread-based implementation of Itimer.c even for a non-threaded RTS. Since 999c464, this relies on synchronization primitives like Mutex, so ensure those primitives are defined whenever they are supported, even if !THREADED_RTS. Fixes #12799. Reviewers: erikd, austin, simonmar, bgamari Reviewed By: simonmar, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2712 GHC Trac Issues: #12799
* Spelling in comment onlyGabor Greif2016-11-181-1/+1
|
* Fix numa001 failure with "too many NUMA nodes"Simon Marlow2016-11-141-2/+2
| | | | | | | It seems that recent versions of the Linux kernel are using larger NUMA bitmasks; I see 1024 on my laptop running a 4.6.5 kernel. This causes the NUMA tests to fail. I'm fixing it to only fail if we have that many actual *nodes*, rather than failing if the size of the mask is too big.
* Cleanup PosixSource.hMoritz Angermann2016-10-091-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to build arm64-apple-iso, the build fell over `strdup`, as the arm64-apple-ios build did not fall into `darwin_HOST_OS`, and would need `ios_HOST_OS`. This diff tries to clean up PosixSource.h, instead of layering another define on top. As we use `strnlen` in sources that include PosixSource.h, and `strnlen` is defined in POSIX.1-2008, the `_POSIX_C_SOURCE` and `_XOPEN_SOURCE` are increased accordingly. Furthermore the `_DARWIN_C_SOURCE` (required for `u_char`, etc. used in sysctl.h) define is moved into `OSThreads.h` alongside a similar ifdef for freebsd. Test Plan: Build on all supported platforms. Reviewers: austin, simonmar, erikd, kgardas, bgamari Reviewed By: simonmar, erikd, kgardas, bgamari Subscribers: Phyx, hvr, thomie Differential Revision: https://phabricator.haskell.org/D2579 GHC Trac Issues: #12624
* Support more than 64 logical processors on WindowsTamar Christina2016-10-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Windows support for more than 64 logical processors are implemented using processor groups. Essentially what it's doing is keeping the existing maximum of 64 processors and keeping the affinity mask a 64 bit value, but adds an hierarchy above that. This support was added to Windows 7 and so we need to at runtime detect if the APIs are still there due to our minimum supported version being Windows Vista. The Maximum number of groups supported at this time is 4, so 256 logical cores. The group indices are 0 based. One thread can have affinity with multiple groups. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms684251.aspx and particularly helpful is the whitepaper: 'Supporting Systems that have more than 64 processors' at https://msdn.microsoft.com/en-us/library/windows/hardware/dn653313.aspx Processor groups are not guaranteed to be uniformly distributed nor guaranteed to be filled before a next group is needed. The OS will assign processors to groups based on physical proximity and will never partially assign cores from one physical cpu to more than one group. If one has two 48 core CPUs then you'd end up with two groups of 48 logical cpus. Now add a 3rd CPU with 10 cores and the group it is assigned to depends where the socket is on the board. Test Plan: ./validate or make test -c . in the rts test folder. This tests for regressions, to test this particular functionality itself: <program> +RTS -N -qa -RTS Test is detailed in description. Reviewers: bgamari, simonmar, austin, erikd Reviewed By: simonmar Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2533 GHC Trac Issues: #11054
* Make start address of `osReserveHeapMemory` tunable via command line -xbFrancesco Mazzoli2016-09-091-7/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We stumbled upon a case where an external library (OpenCL) does not work if a specific address (0x200000000) is taken. It so happens that `osReserveHeapMemory` starts trying to mmap at 0x200000000: ``` void *hint = (void*)((W_)8 * (1 << 30) + attempt * BLOCK_SIZE); at = osTryReserveHeapMemory(*len, hint); ``` This makes it impossible to use Haskell programs compiled with GHC 8 with C functions that use OpenCL. See this example ​https://github.com/chpatrick/oclwtf for a repro. This patch allows the user to work around this kind of behavior outside our control by letting the user override the starting address through an RTS command line flag. Reviewers: bgamari, Phyx, simonmar, erikd, austin Reviewed By: Phyx, simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D2513