diff options
author | Cheng Shao <astrohavoc@gmail.com> | 2022-10-23 12:15:38 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-11 00:26:55 -0500 |
commit | 65b82542b6b031cb63933944e35de317ffed7a06 (patch) | |
tree | 0aec2fd7aafc1b76228c432e5ad6ced39aacdaac | |
parent | 65ba328539c3a6f0fa26a7dc182c2de450d836ea (diff) | |
download | haskell-65b82542b6b031cb63933944e35de317ffed7a06.tar.gz |
rts: no timer for wasm32
Due to the lack of threads, on wasm32 there can't be a background
timer that periodically resets the context switch flag. This patch
disables timer for wasm32, and also makes the scheduler default to -C0
on wasm32 to avoid starving threads.
-rw-r--r-- | rts/Timer.c | 13 | ||||
-rw-r--r-- | rts/include/rts/Flags.h | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/rts/Timer.c b/rts/Timer.c index e6666856a6..332334129d 100644 --- a/rts/Timer.c +++ b/rts/Timer.c @@ -26,6 +26,11 @@ #include "RtsSignals.h" #include "rts/EventLogWriter.h" +// See Note [No timer on wasm32] +#if !defined(wasm32_HOST_ARCH) +#define HAVE_PREEMPTION +#endif + // This global counter is used to allow multiple threads to stop the // timer temporarily with a stopTimer()/startTimer() pair. If // timer_enabled == 0 timer is enabled @@ -174,37 +179,45 @@ handle_tick(int unused STG_UNUSED) void initTimer(void) { +#if defined(HAVE_PREEMPTION) initProfTimer(); if (RtsFlags.MiscFlags.tickInterval != 0) { initTicker(RtsFlags.MiscFlags.tickInterval, handle_tick); } SEQ_CST_STORE(&timer_disabled, 1); +#endif } void startTimer(void) { +#if defined(HAVE_PREEMPTION) if (atomic_dec(&timer_disabled) == 0) { if (RtsFlags.MiscFlags.tickInterval != 0) { startTicker(); } } +#endif } void stopTimer(void) { +#if defined(HAVE_PREEMPTION) if (atomic_inc(&timer_disabled, 1) == 1) { if (RtsFlags.MiscFlags.tickInterval != 0) { stopTicker(); } } +#endif } void exitTimer (bool wait) { +#if defined(HAVE_PREEMPTION) if (RtsFlags.MiscFlags.tickInterval != 0) { exitTicker(wait); } +#endif } diff --git a/rts/include/rts/Flags.h b/rts/include/rts/Flags.h index eb38e80794..e33d97b17c 100644 --- a/rts/include/rts/Flags.h +++ b/rts/include/rts/Flags.h @@ -198,7 +198,19 @@ typedef struct _CONCURRENT_FLAGS { * * It is changed by the +RTS -V<secs> flag. */ + +// Note [No timer on wasm32] +// ~~~~~~~~~~~~~~~~~~~~~~~~~ +// Due to the lack of threads and preemption semantics, on wasm32 +// there can't be a background timer that periodically resets the +// context switch flag. So it makes sense to make the scheduler +// default to -C0 on wasm32 for better fairness and avoid starving +// threads. +#if defined(wasm32_HOST_ARCH) +#define DEFAULT_TICK_INTERVAL USToTime(0) +#else #define DEFAULT_TICK_INTERVAL USToTime(10000) +#endif /* * When linkerAlwaysPic is true, the runtime linker assume that all object |