summaryrefslogtreecommitdiff
path: root/rts/posix
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
* Update error message to suggest the user consider OOM over RTS bug.Thomas M. DuBuisson2021-09-171-1/+3
| | | | Fix #17039
* Make `PosixSource.h` installed and under `rts/`John Ericson2021-08-0910-16/+16
| | | | | | 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 ASSERTS_ENABLED CPPSylvain Henry2021-08-031-1/+1
|
* rts/OSThreads: Fix reference clock of timedWaitConditionBen Gamari2021-08-021-12/+33
| | | | | | | | | | | | | | | Previously `timedWaitCondition` assumed that timeouts were referenced against `CLOCK_MONOTONIC`. This is wrong; by default `pthread_cond_timedwait` references against `CLOCK_REALTIME`, although this can be overridden using `pthread_condattr_setclock`. Fix this and add support for using `CLOCK_MONOTONIC` whenever possible as it is more robust against system time changes and is likely cheaper to query. Unfortunately, this is complicated by the fact that older versions of Darwin did not provide `clock_gettime`, which means we also need to introduce a fallback path using `gettimeofday`. Fixes #20144.
* Add configure flag to enable ASSERTs in all waysDaniel Gröber2021-07-291-1/+1
| | | | | | | | Running the test suite with asserts enabled is somewhat tricky at the moment as running it with a GHC compiled the DEBUG way has some hundred failures from the start. These seem to be unrelated to assertions though. So this provides a toggle to make it easier to debug failing assertions using the test suite.
* rts/OSThreads: Improve error handling consistencyBen Gamari2021-07-271-11/+17
| | | | | | | | | | | | Previously we relied on the caller to check the return value from broadcastCondition and friends, most of whom neglected to do so. Given that these functions should not fail anyways, I've opted to drop the return value entirely and rather move the result check into the OSThreads functions. This slightly changes the semantics of timedWaitCondition which now returns false only in the case of timeout, rather than any error as previously done.
* Use pthread if available on linuxAndreas Klebinger2021-07-271-4/+2
|
* Rename itimer to ticker in rts/posix for consistency.Andreas Klebinger2021-07-275-21/+21
|
* RTS: try to fix timer racesSylvain Henry2021-07-261-1/+1
| | | | | | | | | | | | | | | | | | * Pthread based timer was initialized started while some other parts of the RTS assume it is initialized stopped, e.g. in hs_init_ghc: /* Start the "ticker" and profiling timer but don't start until the * scheduler is up. However, the ticker itself needs to be initialized * before the scheduler to ensure that the ticker mutex is initialized as * moreCapabilities will attempt to acquire it. */ * after a fork, don't start the timer before the IOManager is initialized: the timer handler (handle_tick) might call wakeUpRts to perform an idle GC, which calls wakeupIOManager/ioManagerWakeup Found while debugging #18033/#20132 but I couldn't confirm if it fixes them.
* rts: Correctly call pthread_setname_np() on NetBSDPHO2021-05-073-5/+17
| | | | | | NetBSD supports pthread_setname_np() but it expects a printf-style format string and a string argument. Also use pthread for itimer on this platform.
* rts/posix/OSThreads.c: Implement getNumberOfProcessors() for NetBSDPHO2021-05-071-6/+19
|
* rts/posix/GetTime.c: Use Solaris-specific gethrvtime(3) on OpenSolaris ↵PHO2021-05-061-0/+10
| | | | | | derivatives The constant CLOCK_THREAD_CPUTIME_ID is defined in a system header but it isn't acutally usable. clock_gettime(2) always returns EINVAL.
* Tighten scope of non-POSIX visibility macrosViktor Dukhovni2021-04-302-4/+34
| | | | | | | The __BSD_VISIBLE and _DARWIN_C_SOURCE macros expose non-POSIX prototypes in system header files. We should scope these to just the ".c" modules that actually need them, and avoid defining them in header files used in other C modules.
* Block signals in the ticker threadViktor Dukhovni2021-04-221-1/+21
| | | | | | This avoids surprises in the non-threaded runtime with blocked signals killing the process because they're only blocked in the main thread and not in the ticker thread.
* Add background note in elf_tlsgd.c.Viktor Dukhovni2021-04-221-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | Also some code cleanup, and a fix for an (extant unrelated) missing <pthread_np.h> include that should hopefully resolve a failure in the FreeBSD CI build, since it is best to make sure that this MR actually builds on FreeBSD systems other than mine. Some unexpected metric changes on FreeBSD (perhaps because CI had been failing for a while???): Metric Decrease: T3064 T5321Fun T5642 T9020 T12227 T13253-spj T15164 T18282 WWRec Metric Increase: haddock.compiler
* rts: Fix usage of pthread_setname_npBen Gamari2021-04-051-2/+6
| | | | | | | Previously we used this non-portable function unconditionally, breaking FreeBSD. Fixes #19637.
* Remove ioManager{Start,Die,Wakeup} from IOManager.hDuncan Coutts2021-01-251-0/+10
| | | | | | | | | They are not part of the IOManager interface used within the rest of the RTS. They are the part of the interface of specific I/O manager implementations. They are no longer called directly elsewhere in the RTS, and are now only called by the dispatch functions in IOManager.c
* Move ioManager{Start,Wakeup,Die} to internal IOManager.hDuncan Coutts2021-01-251-0/+1
| | | | | | | | Move them from the external IOInterface.h to the internal IOManager.h. The functions are all in fact internal. They are not used from the base library at all. Remove ioManagerWakeup as an exported symbol. It is not used elsewhere.
* rts: add timedWaitConditionDouglas Wilson2021-01-171-0/+16
|
* OSMem.c: Use proper type for mbinds mask argument.Andreas Klebinger2020-12-181-1/+1
| | | | | StgWord has different widths on 32/64bit. So use the proper type instead.
* rts: don't use siginterrupt (#19019)Sylvain Henry2020-12-111-5/+1
|
* OSThreads: Fix error code checkingGHC GitLab CI2020-11-291-2/+3
| | | | pthread_join returns its error code and apparently doesn't set errno.
* Merge branch 'wip/tsan/timer' into wip/tsan/allBen Gamari2020-11-011-8/+11
|\
| * rts: Fix races in Pthread timer backend shudownwip/tsan/timerBen Gamari2020-10-241-8/+11
| | | | | | | | | | We can generally be pretty relaxed in the barriers here since the timer thread is a loop.
* | Merge branch 'wip/tsan/event-mgr' into wip/tsan/allBen Gamari2020-11-011-20/+28
|\ \
| * | Mitigate data races in event manager startup/shutdownwip/tsan/event-mgrBen Gamari2020-10-241-20/+28
| |/
* | Merge branch 'wip/tsan/misc' into wip/tsan/allBen Gamari2020-11-011-2/+4
|\ \
| * | rts: Use proper relaxe operations in getCurrentThreadCPUTimewip/tsan/miscGHC GitLab CI2020-10-241-2/+4
| |/ | | | | | | | | Here we are doing lazy initialization; it's okay if we do the check more than once, hence relaxed operation is fine.
* | rts: Join to concurrent mark thread during shutdownBen Gamari2020-10-301-0/+8
|/ | | | | Previously we would take all capabilities but fail to join on the thread itself, potentially resulting in a leaked thread.
* rts/OSThreads: Fix data raceBen Gamari2020-10-241-2/+4
| | | | | Previously we would race on the cached processor count. Avoiding this is straightforward; just use relaxed operations.
* Workaround for #18623: GHC crashes bc. under rlimit for vmem it will reserveBenjamin Maurer2020-09-291-5/+52
| | | | | | _all_ of it, leaving nothing for, e.g., thread stacks. Fix will only allocate 2/3rds and check whether remainder is at least large enough for minimum amount of thread stacks.
* rts: Drop field initializer on thread_basic_info_data_tBen Gamari2020-09-191-1/+1
| | | | | This struct has a number of fields and we only care that the value is initialized with zeros. This eliminates the warnings noted in #17905.
* rts: Teach getNumProcessors to return available processorsBen Gamari2020-05-301-10/+34
| | | | | | | | | | | | Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781.
* Always define USE_PTHREAD_FOR_ITIMER for FreeBSD.Gleb Popov2020-05-291-1/+1
|
* RTS: workaround a Linux kernel bug in timerfdSylvain Henry2020-04-221-4/+12
| | | | | | | | | | | | | | Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9
* Fix build warning; add more informative information to the linker; fix ↵Moritz Angermann2020-04-221-1/+0
| | | | linker for empty sections
* rts: Ensure that sigaction structs are initializedBen Gamari2020-04-221-2/+3
| | | | | | I noticed these may have uninitialized fields when looking into #18037. The reporter says that zeroing them doesn't fix the MSAN failures they observe but zeroing them is the right thing to do regardless.
* Rts: show errno on failure (#18033)Sylvain Henry2020-04-091-5/+5
|
* rts: Prefer darwin-specific getCurrentThreadCPUTimeBen Gamari2020-03-111-15/+25
| | | | | | | macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906.
* rts: Add getCurrentThreadCPUTime helperBen Gamari2020-03-051-21/+56
|
* rts: Use nanosleep instead of usleepBen Gamari2020-02-111-2/+3
| | | | usleep was removed in POSIX.1-2008.
* Fix typos, via a Levenshtein-style correctorBrian Wignall2020-01-041-1/+1
|
* Fix more typosBrian Wignall2019-12-021-1/+1
|
* Enable USE_PTHREAD_FOR_ITIMER also on FreeBSDViktor Dukhovni2019-11-191-0/+3
| | | | | | | | | | | If using a pthread instead of a timer signal is more reliable, and has no known drawbacks, then FreeBSD is also capable of supporting this mode of operation (tested on FreeBSD 12 with GHC 8.8.1, but no reason why it would not also work on FreeBSD 11 or GHC 8.6). Proposed by Kevin Zhang in: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241849
* Add +RTS --disable-delayed-os-memory-return. Fixes #17411.Niklas Hambüchen2019-11-011-13/+37
| | | | | | Sets `MiscFlags.disableDelayedOsMemoryReturn`. See the added `Note [MADV_FREE and MADV_DONTNEED]` for details.
* 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.