aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/sys/unix
diff options
context:
space:
mode:
authorRickard Green <[email protected]>2015-03-23 16:39:56 +0100
committerRickard Green <[email protected]>2015-03-23 17:16:09 +0100
commite52829ceb614b36c31a650dea455a463fc490698 (patch)
tree425d5f2a6286f0545c4f70b12ba94584fd468de5 /erts/emulator/sys/unix
parentd07319f790eb38c867bd04a23de674e2393825ff (diff)
downloadotp-e52829ceb614b36c31a650dea455a463fc490698.tar.gz
otp-e52829ceb614b36c31a650dea455a463fc490698.tar.bz2
otp-e52829ceb614b36c31a650dea455a463fc490698.zip
erts_sys_hrtime() for lcnt
Diffstat (limited to 'erts/emulator/sys/unix')
-rw-r--r--erts/emulator/sys/unix/erl_unix_sys.h12
-rw-r--r--erts/emulator/sys/unix/sys.c12
-rw-r--r--erts/emulator/sys/unix/sys_time.c44
3 files changed, 57 insertions, 11 deletions
diff --git a/erts/emulator/sys/unix/erl_unix_sys.h b/erts/emulator/sys/unix/erl_unix_sys.h
index 303ebeee7c..a14a4b3eae 100644
--- a/erts/emulator/sys/unix/erl_unix_sys.h
+++ b/erts/emulator/sys/unix/erl_unix_sys.h
@@ -161,8 +161,10 @@ typedef struct tms SysTimes;
#if SIZEOF_LONG == 8
typedef long ErtsMonotonicTime;
+typedef long ErtsSysHrTime;
#elif SIZEOF_LONG_LONG == 8
typedef long long ErtsMonotonicTime;
+typedef long long ErtsSysHrTime;
#else
#error No signed 64-bit type found...
#endif
@@ -201,6 +203,7 @@ ErtsMonotonicTime erts_os_monotonic_time(void);
#elif defined(OS_MONOTONIC_TIME_USING_GETHRTIME)
#define erts_os_monotonic() ((ErtsMonotonicTime) gethrtime())
+#define erts_sys_hrtime() ((ErtsSysHrTime) gethrtime())
#elif defined(OS_MONOTONIC_TIME_USING_MACH_CLOCK_GET_TIME) \
|| defined(OS_MONOTONIC_TIME_USING_TIMES)
@@ -221,6 +224,15 @@ ErtsMonotonicTime erts_os_monotonic_time(void);
#endif
+/*
+ * erts_sys_hrtime() is the highest resolution
+ * time function found. Time unit is nano-seconds.
+ * It may or may not be monotonic.
+ */
+#ifndef erts_sys_hrtime
+extern ErtsSysHrTime erts_sys_hrtime(void);
+#endif
+
struct erts_sys_time_read_only_data__ {
#ifdef ERTS_OS_MONOTONIC_INLINE_FUNC_PTR_CALL__
ErtsMonotonicTime (*os_monotonic_time)(void);
diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c
index 58b01c094e..3647ea6a88 100644
--- a/erts/emulator/sys/unix/sys.c
+++ b/erts/emulator/sys/unix/sys.c
@@ -528,18 +528,18 @@ erts_sys_pre_init(void)
erts_thr_init(&eid);
-#endif /* USE_THREADS */
-
- erts_init_sys_time_sup();
-
-#ifdef USE_THREADS
-
report_exit_list = NULL;
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_lcnt_init();
#endif
+#endif /* USE_THREADS */
+
+ erts_init_sys_time_sup();
+
+#ifdef USE_THREADS
+
#if CHLDWTHR || defined(ERTS_SMP)
erts_mtx_init(&chld_stat_mtx, "child_status");
#endif
diff --git a/erts/emulator/sys/unix/sys_time.c b/erts/emulator/sys/unix/sys_time.c
index 9db727b111..134e3a67b0 100644
--- a/erts/emulator/sys/unix/sys_time.c
+++ b/erts/emulator/sys/unix/sys_time.c
@@ -85,8 +85,8 @@ ErtsSysTimeData__ erts_sys_time_data__ erts_align_attribute(ERTS_CACHE_LINE_SIZE
#define ERTS_SYS_TIME_INTERNAL_STATE_WRITE_FREQ__
-ErtsMonotonicTime clock_gettime_monotonic_raw(void);
-ErtsMonotonicTime clock_gettime_monotonic_verified(void);
+static ErtsMonotonicTime clock_gettime_monotonic_raw(void);
+static ErtsMonotonicTime clock_gettime_monotonic_verified(void);
#endif /* defined(__linux__) && defined(OS_MONOTONIC_TIME_USING_CLOCK_GETTIME) */
@@ -306,7 +306,7 @@ clock_gettime_monotonic(void)
#if defined(__linux__)
-ErtsMonotonicTime clock_gettime_monotonic_verified(void)
+static ErtsMonotonicTime clock_gettime_monotonic_verified(void)
{
ErtsMonotonicTime mtime;
@@ -322,7 +322,7 @@ ErtsMonotonicTime clock_gettime_monotonic_verified(void)
return mtime;
}
-ErtsMonotonicTime clock_gettime_monotonic_raw(void)
+static ErtsMonotonicTime clock_gettime_monotonic_raw(void)
{
return clock_gettime_monotonic();
}
@@ -336,6 +336,12 @@ ErtsMonotonicTime erts_os_monotonic_time(void)
#endif /* !defined(__linux__) */
+ErtsSysHrTime
+erts_sys_hrtime(void)
+{
+ return (ErtsSysHrTime) clock_gettime_monotonic();
+}
+
#elif defined(OS_MONOTONIC_TIME_USING_MACH_CLOCK_GET_TIME)
#include <mach/clock.h>
@@ -369,6 +375,12 @@ ErtsMonotonicTime erts_os_monotonic_time(void)
return mtime;
}
+ErtsSysHrTime
+erts_sys_hrtime(void)
+{
+ return (ErtsSysHrTime) erts_os_monotonic_time();
+}
+
#elif defined(OS_MONOTONIC_TIME_USING_TIMES)
ErtsMonotonicTime
@@ -381,7 +393,29 @@ erts_os_monotonic_time(void)
ticks) << internal_state.r.o.times_shift;
}
-#endif /* !defined(OS_MONOTONIC_TIME_USING_TIMES) */
+# define ERTS_NEED_ERTS_SYS_HRTIME_FALLBACK
+
+#else /* !defined(OS_MONOTONIC_TIME_USING_TIMES) */
+/* No os-monotonic-time */
+# define ERTS_NEED_ERTS_SYS_HRTIME_FALLBACK
+#endif
+
+#ifdef ERTS_NEED_ERTS_SYS_HRTIME_FALLBACK
+
+ErtsSysHrTime
+erts_sys_hrtime(void)
+{
+ ErtsSysHrTime time;
+ struct timeval tv;
+ gettimeofday(&tv);
+ time = (ErtsSysHrTime) tv.tv_sec;
+ time *= (ErtsSysHrTime) 1000*1000*1000;
+ time += ((ErtsSysHrTime) tv.tv_usec)*1000;
+ return time;
+}
+
+#endif
+
#ifdef HAVE_GETHRVTIME_PROCFS_IOCTL