summaryrefslogtreecommitdiff
path: root/rts/win32
Commit message (Collapse)AuthorAgeFilesLines
* 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-4/+7
| | | | | | | | | | | | | | | | | | 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.
* 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
* 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: Move thread labels into TSOBen Gamari2022-08-062-2/+2
| | | | | | | 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.
* typosEric Lindblad2022-06-012-3/+3
|
* base: Introduce [sg]etFinalizerExceptionHandlerBen Gamari2022-05-191-1/+1
| | | | | This introduces a global hook which is called when an exception is thrown during finalization.
* rts: Drop setExecutableBen Gamari2022-05-111-13/+0
| | | | | Since f6e366c058b136f0789a42222b8189510a3693d1 setExecutable has been dead code. Drop it.
* Fix a few Note inconsistenciesBen Gamari2022-02-011-0/+1
|
* rts/winio: Fix #18382Ben Gamari2022-01-181-6/+3
| | | | | | | | | | | | | | | | | | | Here we refactor WinIO's IO completion scheme, squashing a memory leak and fixing #18382. To fix #18382 we drop the special thread status introduced for IoPort blocking, BlockedOnIoCompletion, as well as drop the non-threaded RTS's special dead-lock detection logic (which is redundant to the GC's deadlock detection logic), as proposed in #20947. Previously WinIO relied on foreign import ccall "wrapper" to create an adjustor thunk which can be attached to the OVERLAPPED structure passed to the operating system. It would then use foreign import ccall "dynamic" to back out the original continuation from the adjustor. This roundtrip is significantly more expensive than the alternative, using a StablePtr. Furthermore, the implementation let the adjustor leak, meaning that every IO request would leak a page of memory. Fixes T18382.
* winio: fix heap corruption and various leaks.Tamar Christina2022-01-155-3/+21
|
* rts: use allocation helpers from RtsUtilsnineonine2021-12-101-2/+2
| | | | | | | Just a tiny cleanup inspired by the following comment: https://gitlab.haskell.org/ghc/ghc/-/issues/19437#note_334271 I was just getting familiar with rts code base so I thought might as well do this.
* Hadrian: fix windows cross-build (#20657)Sylvain Henry2021-11-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many small things to fix: * Hadrian: platform triple is "x86_64-w64-mingw32" and this wasn't recognized by Hadrian (note "w64" instead of "unknown") * Hadrian was using the build platform ("isWindowsHost") to detect the use of the Windows toolchain, which was wrong. We now use the "targetOs" setting. * Hadrian was doing the same thing for Darwin so we fixed both at once, even if cross-compilation to Darwin is unlikely to happen afaik (cf "osxHost" vs "osxTarget" changes) * Hadrian: libffi name was computed in two different places and one of them wasn't taking the different naming on Windows into account. * Hadrian was passing "-Irts/include" when building the stage1 compiler leading to the same error as in #18143 (which is using make). stage1's RTS is stage0's one so mustn't do this. * Hadrian: Windows linker doesn't seem to support "-zorigin" so we don't pass it (similarly to Darwin) * Hadrian: hsc2hs in cross-compilation mode uses a trick (taken from autoconf): it defines "static int test_array[SOME_EXPR]" where SOME_EXPR is a constant expression. However GCC reports an error because SOME_EXPR is supposedly not constant. This is fixed by using another method enabled with the `--via-asm` flag of hsc2hs. It has been fixed in `make` build system (5f6fcf7808b16d066ad0fb2068225b3f2e8363f7) but not in Hadrian. * Hadrian: some packages are specifically built only on Windows but they shouldn't be when building a cross-compiler (`touchy` and `ghci-wrapper`). We now correctly detect this case and disable these packages. * Base: we use `iNVALID_HANDLE_VALUE` in a few places. It fixed some hsc2hs issues before we switched to `--via-asm` (see above). I've kept these changes are they make the code nicer. * Base: `base`'s configure tries to detect if it is building for Windows but for some reason the `$host_alias` value is `x86_64-windows` in my case and it wasn't properly detected. * Base: libraries/base/include/winio_structs.h imported "Windows.h" with a leading uppercase. It doesn't work on case-sensitive systems when cross-compiling so we have to use "windows.h". * RTS: rts/win32/ThrIOManager.c was importin "rts\OSThreads.h" but this path isn't valid when cross-compiling. We replaced "\" with "/". * DeriveConstants: this tool derives the constants from the target RTS header files. However these header files define `StgAsyncIOResult` only when `mingw32_HOST_OS` is set hence it seems we have to set it explicitly. Note that deriveConstants is called more than once (why? there is only one target for now so it shouldn't) and in the second case this value is correctly defined (probably coming indirectly from the import of "rts/PosixSource.h"). A better fix would probably be to disable the unneeded first run of deriveconstants.
* rts/OSThreads: Improve error handling consistencyBen Gamari2021-07-271-9/+12
| | | | | | | | | | | | 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.
* rts: Fix joinOSThread on WindowsBen Gamari2021-03-271-1/+6
| | | | | Previously we were treating the thread ID as a HANDLE, but it is not. We must first OpenThread.
* Add error information to osCommitMemory on failure.Moritz Angermann2021-03-201-1/+1
|
* Fix typosBrian Wignall2021-02-061-3/+3
|
* Remove ioManager{Start,Die,Wakeup} from IOManager.hDuncan Coutts2021-01-253-0/+20
| | | | | | | | | 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
* Rename includes/rts/IOManager.h to IOInterface.hDuncan Coutts2021-01-251-1/+1
| | | | | | | | | | | | | | | | | | | | | Naming is hard. Where we want to get to is to have a clear internal and external API for the IO manager within the RTS. What we have right now is just the external API (used in base for the Haskell side of the threaded IO manager impls) living in includes/rts/IOManager.h. We want to add a clear RTS internal API, which really ought to live in rts/IOManager.h. Several people think it's too confusing to have both: * includes/rts/IOManager.h for the external API * rts/IOManager.h for the internal API So the plan is to add rts/IOManager.{h,c} as the internal parts, and rename the external part to be includes/rts/IOInterface.h. It is admittidly not great to have .h files in includes/rts/ called "interface" since by definition, every .h fle under includes/ is an interface! Alternative naming scheme suggestions welcome!
* Move win32/IOManager to win32/MIOManagerDuncan Coutts2021-01-254-4/+4
| | | | | It is only for MIO, and we want to use the generic name IOManager for the name of the common parts of the interface and dispatch.
* rts: add timedWaitConditionDouglas Wilson2021-01-171-0/+10
|
* rts: Use CHECK instead of assertBen Gamari2020-11-301-2/+1
| | | | Use the GHC wrappers instead of <assert.h>.
* rts: Allocate MBlocks with MAP_TOP_DOWN on WindowsBen Gamari2020-11-271-1/+4
| | | | | | | As noted in #18991, we would previously allocate heap in low memory. Due to this the linker, which typically *needs* low memory, would end up competing with the heap. In longer builds we end up running out of low memory entirely, leading to linking failures.
* Merge remote-tracking branch 'origin/wip/tsan/all'Ben Gamari2020-11-081-0/+9
|\
| * rts: Join to concurrent mark thread during shutdownBen Gamari2020-10-301-0/+9
| | | | | | | | | | Previously we would take all capabilities but fail to join on the thread itself, potentially resulting in a leaked thread.
* | winio: Fix unused variables warningsTamar Christina2020-10-312-9/+2
|/
* winio: fixed timeouts non-threaded.Tamar Christina2020-10-091-13/+9
|
* rts/win32: Fix missing #include'sBen Gamari2020-09-172-1/+3
| | | | These slipped through CI.
* rts: Consistently use stgMallocBytes instead of mallocGHC GitLab CI2020-09-053-24/+17
| | | | | This can help in debugging RTS memory leaks since all allocations go through the same interface.
* rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit failsBen Gamari2020-07-261-1/+1
| | | | | | | | Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms.
* winio: restore console cp on exitTamar Christina2020-07-241-0/+1
|
* winio: update lockfile signature and remove mistaken symbol in rts.Tamar Christina2020-07-151-1/+0
|
* winio: clarify wording on conditional variables.Tamar Christina2020-07-151-1/+2
|
* winio: Remove obsolete comment about cond. variablesAndreas Klebinger2020-07-151-5/+0
|
* winio: Minor comments/renamingsBen Gamari2020-07-152-3/+3
|
* winio: Fix rebase artifactsTamar Christina2020-07-151-14/+7
|
* winio: Various fixes related to rebase and testdriverTamar Christina2020-07-151-6/+14
|
* winio: Remove outstanding_requests from runner.Andreas Klebinger2020-07-151-18/+10
| | | | | | | | | | | | | | | | We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port.
* winio: Refactor non-threaded runner thread and scheduler interface.Andreas Klebinger2020-07-152-98/+151
| | | | | | | | Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event.
* winio: Always lock win32 event queueAndreas Klebinger2020-07-151-10/+17
|
* winio: Update placeholder comment with actual function name.Andreas Klebinger2020-07-151-1/+1
|
* winio: Queue IO processing threads at the front of the queue.Andreas Klebinger2020-07-151-1/+1
| | | | | This will unblock the IO thread sooner hopefully leading to higher throughput in some situations.
* winio: nonthreaded: Create io processing threads in main thread.Andreas Klebinger2020-07-152-34/+86
| | | | | | | | | | | | | | | | | | | | We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread.
* winio: Make last_event a local variableAndreas Klebinger2020-07-151-3/+8
|
* winio: Mark outstanding_service_requests volatile.Andreas Klebinger2020-07-151-2/+8
| | | | | | | | | | | | | | | As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration.
* winio: Clean up code surrounding IOPort primitives.Andreas Klebinger2020-07-151-1/+2
| | | | | | | | | | | | | | According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc.
* winio: Expand comments describing non-threaded loopAndreas Klebinger2020-07-151-5/+37
|
* winio: Remove some barf statements that are a bit strict.Tamar Christina2020-07-151-2/+0
|
* winio: Fix issues with non-threaded I/O manager after split.Tamar Christina2020-07-151-0/+3
|
* winio: Relaxing some constraints in io-manager.Tamar Christina2020-07-151-1/+1
|