diff options
author | Sridhar Periyasamy <sridhper@microsoft.com> | 2015-07-28 09:43:37 -0700 |
---|---|---|
committer | Sridhar Periyasamy <sridhper@microsoft.com> | 2015-07-28 09:43:37 -0700 |
commit | 9553016acce3671e4cfa60bd6bbef9ba20709283 (patch) | |
tree | 9c89b02998667096e528931e611d948231722ce6 | |
parent | 6b020fe3f7a83aa28f57edd936e1b25ce4b50ca7 (diff) | |
parent | d2086d64f08a3ad28c58e0dffa268c79913060a8 (diff) | |
download | coreclr-9553016acce3671e4cfa60bd6bbef9ba20709283.tar.gz coreclr-9553016acce3671e4cfa60bd6bbef9ba20709283.tar.bz2 coreclr-9553016acce3671e4cfa60bd6bbef9ba20709283.zip |
Merge pull request #1269 from Sridhar-MS/osx-tickcount
Fix to get the correct value for Environment.TickCount in OSX
-rw-r--r-- | src/pal/src/config.h.in | 1 | ||||
-rw-r--r-- | src/pal/src/configure.cmake | 12 | ||||
-rw-r--r-- | src/pal/src/include/pal/misc.h | 11 | ||||
-rw-r--r-- | src/pal/src/init/pal.cpp | 6 | ||||
-rw-r--r-- | src/pal/src/misc/sysinfo.cpp | 1 | ||||
-rw-r--r-- | src/pal/src/misc/time.cpp | 64 |
6 files changed, 94 insertions, 1 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in index 5de45b3d09..354f455bf4 100644 --- a/src/pal/src/config.h.in +++ b/src/pal/src/config.h.in @@ -85,6 +85,7 @@ #cmakedefine01 HAVE_WORKING_GETTIMEOFDAY #cmakedefine01 HAVE_WORKING_CLOCK_GETTIME #cmakedefine01 HAVE_CLOCK_MONOTONIC +#cmakedefine01 HAVE_MACH_ABSOLUTE_TIME #cmakedefine01 STATVFS64_PROTOTYPE_BROKEN #cmakedefine01 HAVE_MMAP_DEV_ZERO #cmakedefine01 MMAP_IGNORES_HINT diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake index 6d1f141d49..20a9193f3c 100644 --- a/src/pal/src/configure.cmake +++ b/src/pal/src/configure.cmake @@ -331,6 +331,18 @@ int main() }" HAVE_CLOCK_MONOTONIC) check_cxx_source_runs(" #include <stdlib.h> +#include <mach/mach_time.h> + +int main() +{ + int ret; + mach_timebase_info_data_t timebaseInfo; + ret = mach_timebase_info(&timebaseInfo); + mach_absolute_time(); + exit(ret); +}" HAVE_MACH_ABSOLUTE_TIME) +check_cxx_source_runs(" +#include <stdlib.h> #include <sys/types.h> #include <sys/mman.h> #include <fcntl.h> diff --git a/src/pal/src/include/pal/misc.h b/src/pal/src/include/pal/misc.h index 83bcc2fdf5..ac593836e9 100644 --- a/src/pal/src/include/pal/misc.h +++ b/src/pal/src/include/pal/misc.h @@ -49,6 +49,17 @@ Function : int __cdecl PAL_rand(void); /*++ +Function: +TIMEInitialize + +Return value: +TRUE if initialize succeeded +FALSE otherwise + +--*/ +BOOL TIMEInitialize( void ); + +/*++ Function : MsgBoxInitialize diff --git a/src/pal/src/init/pal.cpp b/src/pal/src/init/pal.cpp index 882c9e2bb7..d4a52b5432 100644 --- a/src/pal/src/init/pal.cpp +++ b/src/pal/src/init/pal.cpp @@ -486,6 +486,12 @@ Initialize( goto CLEANUP5; } + if (FALSE == TIMEInitialize()) + { + ERROR("Unable to initialize TIME support\n"); + goto CLEANUP6; + } + /* Initialize the File mapping critical section. */ if (FALSE == MAPInitialize()) { diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index 9b4e2b8f64..5bb13bd90f 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -285,6 +285,7 @@ GlobalMemoryStatusEx( lpBuffer->dwMemoryLoad = (DWORD)((used_memory * 100) / lpBuffer->ullTotalPhys); } } + mach_port_deallocate(mach_task_self(), mach_port); #endif // __APPLE__ } diff --git a/src/pal/src/misc/time.cpp b/src/pal/src/misc/time.cpp index 8ce7dfd643..23b14ad68d 100644 --- a/src/pal/src/misc/time.cpp +++ b/src/pal/src/misc/time.cpp @@ -28,9 +28,44 @@ Abstract: #include <errno.h> #include <string.h> +#if HAVE_MACH_ABSOLUTE_TIME +#include <mach/mach_time.h> +static mach_timebase_info_data_t s_TimebaseInfo; +#endif + SET_DEFAULT_DEBUG_CHANNEL(MISC); /*++ +Function : +TIMEInitialize + +Initialize all Time-related stuff related + +(no parameters) + +Return value : +TRUE if Time support initialization succeeded +FALSE otherwise +--*/ +BOOL TIMEInitialize(void) +{ + BOOL bRet = FALSE; + +#if HAVE_MACH_ABSOLUTE_TIME + kern_return_t machRet; + if ((machRet = mach_timebase_info(&s_TimebaseInfo)) != KERN_SUCCESS) + { + ASSERT("mach_timebase_info() failed: %s\n", mach_error_string(machRet)); + goto Exit; + } +#endif + bRet = TRUE; +Exit: + return bRet; +} + + +/*++ Function: GetSystemTime @@ -179,6 +214,10 @@ QueryPerformanceCounter( lpPerformanceCount->QuadPart = (LONGLONG)ts.tv_sec * (LONGLONG)tccSecondsToNanoSeconds + (LONGLONG)ts.tv_nsec; } +#elif HAVE_MACH_ABSOLUTE_TIME + { + lpPerformanceCount->QuadPart = (LONGLONG)mach_absolute_time(); + } #elif HAVE_GETHRTIME { lpPerformanceCount->QuadPart = (LONGLONG)gethrtime(); @@ -221,16 +260,28 @@ QueryPerformanceFrequency( OUT LARGE_INTEGER *lpFrequency ) { + BOOL retval = TRUE; PERF_ENTRY(QueryPerformanceFrequency); ENTRY("QueryPerformanceFrequency()\n"); #if HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds; +#elif HAVE_MACH_ABSOLUTE_TIME + // use denom == 0 to indicate that s_TimebaseInfo is uninitialised. + if (s_TimebaseInfo.denom == 0) + { + ASSERT("s_TimebaseInfo is uninitialized.\n"); + retval = FALSE; + } + else + { + lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds * ((LONGLONG)s_TimebaseInfo.denom / (LONGLONG)s_TimebaseInfo.numer); + } #else lpFrequency->QuadPart = (LONGLONG)tccSecondsToMicroSeconds; #endif // HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC LOGEXIT("QueryPerformanceFrequency\n"); PERF_EXIT(QueryPerformanceFrequency); - return TRUE; + return retval; } BOOL @@ -270,6 +321,16 @@ GetTickCount64() } retval = (ts.tv_sec * tccSecondsToMillieSeconds)+(ts.tv_nsec / tccMillieSecondsToNanoSeconds); } +#elif HAVE_MACH_ABSOLUTE_TIME + { + // use denom == 0 to indicate that s_TimebaseInfo is uninitialised. + if (s_TimebaseInfo.denom == 0) + { + ASSERT("s_TimebaseInfo is uninitialized.\n"); + goto EXIT; + } + retval = (mach_absolute_time() * s_TimebaseInfo.numer / s_TimebaseInfo.denom) / tccMillieSecondsToNanoSeconds; + } #elif HAVE_GETHRTIME { retval = (ULONGLONG)(gethrtime() / tccMillieSecondsToNanoSeconds); @@ -299,3 +360,4 @@ GetTickCount64() EXIT: return retval; } + |