summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2015-12-10 14:19:10 -0500
committerStephen Toub <stoub@microsoft.com>2015-12-10 14:19:10 -0500
commit2aa39eac5c9472437d85ba45ad3b359e7a307c3a (patch)
tree43bd44b94d2496e7d525da7b67ae1ad709fa1b2b /src/pal
parent11525936373fd439bb770f7fbf21393746d3cf07 (diff)
parent79b6d5df3dee969ebf89559c90ccc8636783d01b (diff)
downloadcoreclr-2aa39eac5c9472437d85ba45ad3b359e7a307c3a.tar.gz
coreclr-2aa39eac5c9472437d85ba45ad3b359e7a307c3a.tar.bz2
coreclr-2aa39eac5c9472437d85ba45ad3b359e7a307c3a.zip
Merge pull request #2293 from stephentoub/tickcount_perf
Use CLOCK_MONOTONIC_COARSE in GetTickCount64
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/config.h.in1
-rw-r--r--src/pal/src/configure.cmake13
-rw-r--r--src/pal/src/misc/time.cpp12
3 files changed, 23 insertions, 3 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in
index 143679d5a7..672cfe1d31 100644
--- a/src/pal/src/config.h.in
+++ b/src/pal/src/config.h.in
@@ -82,6 +82,7 @@
#cmakedefine01 HAVE_WORKING_GETTIMEOFDAY
#cmakedefine01 HAVE_WORKING_CLOCK_GETTIME
#cmakedefine01 HAVE_CLOCK_MONOTONIC
+#cmakedefine01 HAVE_CLOCK_MONOTONIC_COARSE
#cmakedefine01 HAVE_MACH_ABSOLUTE_TIME
#cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME
#cmakedefine01 STATVFS64_PROTOTYPE_BROKEN
diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake
index 333f0094c5..d130e14123 100644
--- a/src/pal/src/configure.cmake
+++ b/src/pal/src/configure.cmake
@@ -343,6 +343,19 @@ int main()
}" HAVE_CLOCK_MONOTONIC)
check_cxx_source_runs("
#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+
+int main()
+{
+ int ret;
+ struct timespec ts;
+ ret = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
+
+ exit(ret);
+}" HAVE_CLOCK_MONOTONIC_COARSE)
+check_cxx_source_runs("
+#include <stdlib.h>
#include <mach/mach_time.h>
int main()
diff --git a/src/pal/src/misc/time.cpp b/src/pal/src/misc/time.cpp
index 2f20c60914..939c86996a 100644
--- a/src/pal/src/misc/time.cpp
+++ b/src/pal/src/misc/time.cpp
@@ -337,12 +337,18 @@ GetTickCount64()
{
ULONGLONG retval = 0;
-#if HAVE_CLOCK_MONOTONIC
+#if HAVE_CLOCK_MONOTONIC_COARSE || HAVE_CLOCK_MONOTONIC
{
+ clockid_t clockType =
+#if HAVE_CLOCK_MONOTONIC_COARSE
+ CLOCK_MONOTONIC_COARSE; // good enough resolution, fastest speed
+#else
+ CLOCK_MONOTONIC;
+#endif
struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+ if (clock_gettime(clockType, &ts) != 0)
{
- ASSERT("clock_gettime(CLOCK_MONOTONIC) failed; errno is %d (%s)\n", errno, strerror(errno));
+ ASSERT("clock_gettime(CLOCK_MONOTONIC*) failed; errno is %d (%s)\n", errno, strerror(errno));
goto EXIT;
}
retval = (ts.tv_sec * tccSecondsToMillieSeconds)+(ts.tv_nsec / tccMillieSecondsToNanoSeconds);