summaryrefslogtreecommitdiff
path: root/rts/posix
Commit message (Collapse)AuthorAgeFilesLines
* rts: Encapsulate sched_stateBen Gamari2022-12-162-4/+4
|
* rts: Encapsulate access to capabilities arrayBen Gamari2022-12-161-2/+2
|
* rts: Introduce getNumCapabilitiesBen Gamari2022-12-161-1/+1
| | | | | | And ensure accesses to n_capabilities are atomic (although with relaxed ordering). This is necessary as RTS API callers may concurrently call into the RTS without holding a capability.
* Pass the Capability *cap explicitly to awaitEventDuncan Coutts2022-11-221-24/+24
| | | | | | It is currently only used in the non-threaded RTS so it works to use MainCapability, but it's a bit nicer to pass the cap anyway. It's certainly shorter.
* Move the awaitEvent declaration into IOManager.hDuncan Coutts2022-11-221-1/+1
| | | | And add or adjust comments at the use sites of awaitEvent.
* Move {blocked,sleeping}_queue from scheduler global vars to CapIOManagerDuncan Coutts2022-11-221-10/+18
| | | | | | | | | | | | | | | | | | The blocked_queue_{hd,tl} and the sleeping_queue are currently cooperatively managed between the scheduler and (some but not all of) the non-threaded I/O manager implementations. They lived as global vars with the scheduler, but are poked by I/O primops and the I/O manager backends. This patch is a step on the path towards making the management of I/O or timer blocking belong to the I/O managers and not the scheduler. Specifically, this patch moves the {blocked,sleeping}_queue from being global vars in the scheduler to being members of the CapIOManager struct within each Capability. They are not yet exclusively used by the I/O managers: they are still poked from a couple other places, notably in the scheduler before calling awaitEvent.
* Introduce CapIOManager as the per-cap I/O mangager stateDuncan Coutts2022-11-221-2/+2
| | | | | | | | | | | | | | | Rather than each I/O manager adding things into the Capability structure ad-hoc, we should have a common CapIOManager iomgr member of the Capability structure, with a common interface to initialise etc. The content of the CapIOManager struct will be defined differently for each I/O manager implementation. Eventually we should be able to have the CapIOManager be opaque to the rest of the RTS, and known just to the I/O manager implementation. We plan for that by making the Capability contain a pointer to the CapIOManager rather than containing the structure directly. Initially just move the Unix threaded I/O manager's control FD.
* rts: don't define RTS_USER_SIGNALS when signal.h is not presentCheng Shao2022-11-111-1/+1
| | | | | | | | In the rts, we have a RTS_USER_SIGNALS macro, and most signal-related logic is guarded with RTS_USER_SIGNALS. This patch extends the range of code guarded with RTS_USER_SIGNALS, and define RTS_USER_SIGNALS iff signal.h is actually detected by autoconf. This is required for wasm32-wasi to work, which lacks signals.
* rts: consistently use `STG_UNUSED`Nicolas Trangez2022-11-021-1/+1
|
* rts: introduce (and use) `STG_NORETURN`Nicolas Trangez2022-11-021-1/+1
| | | | | | | Instead of sprinkling the codebase with `GNU(C3)_ATTRIBUTE(__noreturn__)`, add a `STG_NORETURN` macro (for, basically, the same thing) similar to `STG_UNUSED` and others, and update the code to use this macro where applicable.
* rts: fix OS thread naming in tickerNicolas Trangez2022-11-012-26/+16
| | | | | | | | | | | | | | | Since ee0deb805, the use of `pthread_setname_np` on Darwin was fixed when invoking `createOSThread`. However, the 'ticker' has some thread-creation code which doesn't rely on `createOSThread`, yet also uses `pthread_setname_np`. This patch enforces all thread creation to go through a single function, which uses the (correct) thread-naming code introduced in ee0deb805. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2 See: https://gitlab.haskell.org/ghc/ghc/-/issues/22206 See: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9066
* rts: fix lifetime of `start_thread`s `name` valueNicolas Trangez2022-11-011-8/+14
| | | | | | | | | | Since, unlike the code in ee0deb8054da2^, usage of the `name` value passed to `createOSThread` now outlives said function's lifetime, and could hence be released by the caller by the time the new thread runs `start_thread`, it needs to be copied. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2#note_460080 See: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9066
* rts: `name` argument of `createOSThread` can be `const`Nicolas Trangez2022-11-011-1/+1
| | | | | | | | | | Since we don't intend to ever change the incoming string, declare this to be true. Also, in the POSIX implementation, the argument is no longer `STG_UNUSED` (since ee0deb8054da2a597fc5624469b4c44fd769ada2) in any code path. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2#note_460080
* rts: remove use of `TIME_WITH_SYS_TIME`Nicolas Trangez2022-10-212-22/+8
| | | | | | | | | | | | | | | | | | | | | | | `autoreconf` will insert an `m4_warning` when the obsolescent `AC_HEADER_TIME` macro is used: > Update your code to rely only on HAVE_SYS_TIME_H, > then remove this warning and the obsolete code below it. > All current systems provide time.h; it need not be checked for. > Not all systems provide sys/time.h, but those that do, all allow > you to include it and time.h simultaneously. Presence of `sys/time.h` was already checked in an earlier `AC_CHECK_HEADERS` invocation, so `AC_HEADER_TIME` can be dropped and guards relying on `TIME_WITH_SYS_TIME` can be reworked to (unconditionally) include `time.h` and include `sys/time.h` based on `HAVE_SYS_TIME_H`. Note the documentation of `AC_HEADER_TIME` in (at least) Autoconf 2.67 says > This macro is obsolescent, as current systems can include both files > when they exist. New programs need not use this macro.
* build: get rid of `HAVE_TIME_H`Nicolas Trangez2022-10-211-3/+1
| | | | | | | | | | | | As advertized by `autoreconf`: > All current systems provide time.h; it need not be checked for. Hence, remove the check for it in `configure.ac` and remove conditional inclusion of the header in `HAVE_TIME_H` blocks where applicable. The `time.h` header was being included in various source files without a `HAVE_TIME_H` guard already anyway.
* rts: Use pthread_setname_np correctly on DarwinBen Gamari2022-10-141-10/+36
| | | | | | As noted in #22206, pthread_setname_np on Darwin only supports setting the name of the calling thread. Consequently we must introduce a trampoline which first sets the thread name before entering the thread entrypoint.
* rts: Move thread labels into TSOBen Gamari2022-08-061-1/+1
| | | | | | | This eliminates the thread label HashTable and instead tracks this information in the TSO, allowing us to use proper StgArrBytes arrays for backing the label and greatly simplifying management of object lifetimes when we expose them to the user with the coming `threadLabel#` primop.
* getProcessCPUTime: Fix the getrusage fallback to account for system CPU timeMatthew Pickering2022-06-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | clock_gettime reports the combined total or user AND system time so in order to replicate it with getrusage we need to add both system and user time together. See https://stackoverflow.com/questions/7622371/getrusage-vs-clock-gettime Some sample measurements when building Cabal with this patch t1: rusage t2: clock_gettime t1: 62347518000; t2: 62347520873 t1: 62395687000; t2: 62395690171 t1: 62432435000; t2: 62432437313 t1: 62478489000; t2: 62478492465 t1: 62514990000; t2: 62514992534 t1: 62515479000; t2: 62515480327 t1: 62515485000; t2: 62515486344 Fixes #21656
* typosEric Lindblad2022-06-012-2/+2
|
* rts: Drop setExecutableBen Gamari2022-05-111-15/+0
| | | | | Since f6e366c058b136f0789a42222b8189510a3693d1 setExecutable has been dead code. Drop it.
* Fix build on recent FreeBSD.Gleb Popov2022-02-081-1/+1
| | | | | Recent FreeBSD versions gained the sched_getaffinity function, which made two mutually exclusive #ifdef blocks to be enabled.
* Fix a few Note inconsistenciesBen Gamari2022-02-011-1/+1
|
* rts: Annotate benign race in pthread ticker's exit test Ben Gamari2021-12-011-0/+1
| | | | | | | | Previously TSAN would report spurious data races due to the unsynchronized access of `exited`. I would have thought that using a relaxed load on `exited` would be enough to convince TSAN that the race was intentional, but apparently not. Closes #20690.
* RTS: open timerfd synchronously (#20618)Sylvain Henry2021-11-091-19/+32
|
* 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
|\ \