summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-11-25 13:11:39 +0000
committerSimon Marlow <marlowsd@gmail.com>2011-11-25 16:11:36 +0000
commit6b1098511aaabd2c9503ee7be6da1944466f9cb4 (patch)
tree83b3001603c7e6a5cfb3ac04adbb99c40504942e /includes
parent18aae18503442276e14a47eabf4786bc7210662e (diff)
downloadhaskell-6b1098511aaabd2c9503ee7be6da1944466f9cb4.tar.gz
Time handling overhaul
Terminology cleanup: the type "Ticks" has been renamed "Time", which is an StgWord64 in units of TIME_RESOLUTION (currently nanoseconds). The terminology "tick" is now used consistently to mean the interval between timer signals. The ticker now always ticks in realtime (actually CLOCK_MONOTONIC if we have it). Before it used CPU time in the non-threaded RTS and realtime in the threaded RTS, but I've discovered that the CPU timer has terrible resolution (at least on Linux) and isn't much use for profiling. So now we always use realtime. This should also fix The default tick interval is now 10ms, except when profiling where we drop it to 1ms. This gives more accurate profiles without affecting runtime too much (<1%). Lots of cleanups - the resolution of Time is now in one place only (Rts.h) rather than having calculations that depend on the resolution scattered all over the RTS. I hope I found them all.
Diffstat (limited to 'includes')
-rw-r--r--includes/Rts.h30
-rw-r--r--includes/rts/Flags.h21
-rw-r--r--includes/rts/storage/TSO.h6
3 files changed, 51 insertions, 6 deletions
diff --git a/includes/Rts.h b/includes/Rts.h
index 5caba59dbe..45c09f8fb7 100644
--- a/includes/Rts.h
+++ b/includes/Rts.h
@@ -155,6 +155,36 @@ void _assertFail(const char *filename, unsigned int linenum)
#endif
/* -----------------------------------------------------------------------------
+ Time values in the RTS
+ -------------------------------------------------------------------------- */
+
+// For most time values in the RTS we use a fixed resolution of nanoseconds,
+// normalising the time we get from platform-dependent APIs to this
+// resolution.
+#define TIME_RESOLUTION 1000000000
+typedef StgInt64 Time;
+
+#if TIME_RESOLUTION == 1000000000
+// I'm being lazy, but it's awkward to define fully general versions of these
+#define TimeToUS(t) (t / 1000)
+#define TimeToNS(t) (t)
+#define USToTime(t) ((Time)(t) * 1000)
+#define NSToTime(t) ((Time)(t))
+#else
+#error Fix TimeToNS(), TimeToUS() etc.
+#endif
+
+#define SecondsToTime(t) ((Time)(t) * TIME_RESOLUTION)
+#define TimeToSeconds(t) ((t) / TIME_RESOLUTION)
+
+// Use instead of SecondsToTime() when we have a floating-point
+// seconds value, to avoid truncating it.
+INLINE_HEADER Time fsecondsToTime (double t)
+{
+ return (Time)(t * TIME_RESOLUTION);
+}
+
+/* -----------------------------------------------------------------------------
Include everything STG-ish
-------------------------------------------------------------------------- */
diff --git a/includes/rts/Flags.h b/includes/rts/Flags.h
index 2d1516f586..439b261fd8 100644
--- a/includes/rts/Flags.h
+++ b/includes/rts/Flags.h
@@ -52,7 +52,7 @@ struct GC_FLAGS {
rtsBool ringBell;
rtsBool frontpanel;
- int idleGCDelayTime; /* in milliseconds */
+ Time idleGCDelayTime; /* units: TIME_RESOLUTION */
StgWord heapBase; /* address to ask the OS for memory */
};
@@ -99,8 +99,8 @@ struct PROFILING_FLAGS {
# define HEAP_BY_CLOSURE_TYPE 8
- nat profileInterval; /* delta between samples (in ms) */
- nat profileIntervalTicks; /* delta between samples (in 'ticks') */
+ Time heapProfileInterval; /* time between samples */
+ nat heapProfileIntervalTicks; /* ticks between samples (derived) */
rtsBool includeTSOs;
@@ -135,12 +135,21 @@ struct TRACE_FLAGS {
};
struct CONCURRENT_FLAGS {
- int ctxtSwitchTime; /* in milliseconds */
- int ctxtSwitchTicks; /* derived */
+ Time ctxtSwitchTime; /* units: TIME_RESOLUTION */
+ int ctxtSwitchTicks; /* derived */
};
+/*
+ * The tickInterval is the time interval between "ticks", ie.
+ * timer signals (see Timer.{c,h}). It is the frequency at
+ * which we sample CCCS for profiling.
+ *
+ * It is changed by the +RTS -V<secs> flag.
+ */
+#define DEFAULT_TICK_INTERVAL USToTime(10000)
+
struct MISC_FLAGS {
- int tickInterval; /* in milliseconds */
+ Time tickInterval; /* units: TIME_RESOLUTION */
rtsBool install_signal_handlers;
rtsBool machineReadable;
StgWord linkerMemBase; /* address to ask the OS for memory
diff --git a/includes/rts/storage/TSO.h b/includes/rts/storage/TSO.h
index 04e673fb12..20c6ebf4f2 100644
--- a/includes/rts/storage/TSO.h
+++ b/includes/rts/storage/TSO.h
@@ -54,7 +54,13 @@ typedef union {
#if defined(mingw32_HOST_OS)
StgAsyncIOResult *async_result;
#endif
+#if !defined(THREADED_RTS)
StgWord target;
+ // Only for the non-threaded RTS: the target time for a thread
+ // blocked in threadDelay, in units of 10ms. This is a
+ // compromise: we don't want to take up much space in the TSO. If
+ // you want better resolution for threadDelay, use -threaded.
+#endif
} StgTSOBlockInfo;