summaryrefslogtreecommitdiff
path: root/rts/posix/GetTime.c
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 /rts/posix/GetTime.c
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 'rts/posix/GetTime.c')
-rw-r--r--rts/posix/GetTime.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index eab7177fe5..c31b319af4 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -44,7 +44,7 @@
// we'll implement getProcessCPUTime() and getProcessElapsedTime()
// separately, using getrusage() and gettimeofday() respectively
-Ticks getProcessCPUTime(void)
+Time getProcessCPUTime(void)
{
#if !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_CPUTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) && defined(HAVE_SYSCONF)
static int checked_sysconf = 0;
@@ -59,8 +59,7 @@ Ticks getProcessCPUTime(void)
int res;
res = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
if (res == 0) {
- return ((Ticks)ts.tv_sec * TICKS_PER_SECOND +
- ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
+ return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec);
}
}
#endif
@@ -69,20 +68,18 @@ Ticks getProcessCPUTime(void)
{
struct rusage t;
getrusage(RUSAGE_SELF, &t);
- return ((Ticks)t.ru_utime.tv_sec * TICKS_PER_SECOND +
- ((Ticks)t.ru_utime.tv_usec * TICKS_PER_SECOND)/1000000);
+ return SecondsToTime(t.ru_utime.tv_sec) + USToTime(t.ru_utime.tv_usec);
}
}
-Ticks getProcessElapsedTime(void)
+Time getProcessElapsedTime(void)
{
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
- return ((Ticks)tv.tv_sec * TICKS_PER_SECOND +
- ((Ticks)tv.tv_usec * TICKS_PER_SECOND)/1000000);
+ return SecondsToTime(tv.tv_sec) + USToTime(tv.tv_usec);
}
-void getProcessTimes(Ticks *user, Ticks *elapsed)
+void getProcessTimes(Time *user, Time *elapsed)
{
*user = getProcessCPUTime();
*elapsed = getProcessElapsedTime();
@@ -92,29 +89,29 @@ void getProcessTimes(Ticks *user, Ticks *elapsed)
// we'll use the old times() API.
-Ticks getProcessCPUTime(void)
+Time getProcessCPUTime(void)
{
#if !defined(THREADED_RTS) && USE_PAPI
long long usec;
if ((usec = PAPI_get_virt_usec()) < 0) {
barf("PAPI_get_virt_usec: %lld", usec);
}
- return ((usec * TICKS_PER_SECOND) / 1000000);
+ return USToTime(usec);
#else
- Ticks user, elapsed;
+ Time user, elapsed;
getProcessTimes(&user,&elapsed);
return user;
#endif
}
-Ticks getProcessElapsedTime(void)
+Time getProcessElapsedTime(void)
{
- Ticks user, elapsed;
+ Time user, elapsed;
getProcessTimes(&user,&elapsed);
return elapsed;
}
-void getProcessTimes(Ticks *user, Ticks *elapsed)
+void getProcessTimes(Time *user, Time *elapsed)
{
static nat ClockFreq = 0;
@@ -141,20 +138,20 @@ void getProcessTimes(Ticks *user, Ticks *elapsed)
struct tms t;
clock_t r = times(&t);
- *user = (((Ticks)t.tms_utime * TICKS_PER_SECOND) / ClockFreq);
- *elapsed = (((Ticks)r * TICKS_PER_SECOND) / ClockFreq);
+ *user = SecondsToTime(t.tms_utime) / ClockFreq;
+ *elapsed = SecondsToTime(r) / ClockFreq;
}
#endif // HAVE_TIMES
-Ticks getThreadCPUTime(void)
+Time getThreadCPUTime(void)
{
#if USE_PAPI
long long usec;
if ((usec = PAPI_get_virt_usec()) < 0) {
barf("PAPI_get_virt_usec: %lld", usec);
}
- return ((usec * TICKS_PER_SECOND) / 1000000);
+ return USToTime(usec);
#elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
{
@@ -172,8 +169,7 @@ Ticks getThreadCPUTime(void)
int res;
res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
if (res == 0) {
- return ((Ticks)ts.tv_sec * TICKS_PER_SECOND +
- ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
+ return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec);
}
}
}