summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rts/Timer.c13
-rw-r--r--rts/include/rts/Flags.h12
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