Skip to content
Merged
3 changes: 0 additions & 3 deletions eng/native/tryrun.browser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ set(HAVE_CFSETSPEED 1 CACHE INTERNAL "")
set(HAVE_CHMOD 1 CACHE INTERNAL "")
set(HAVE_CLOCK_GETTIME_NSEC_NP "" CACHE INTERNAL "")
set(HAVE_CLOCK_MONOTONIC_COARSE 1 CACHE INTERNAL "")
set(HAVE_CLOCK_MONOTONIC_COMPILED TRUE CACHE INTERNAL "")
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
set(HAVE_CLOCK_MONOTONIC 1 CACHE INTERNAL "")
set(HAVE_CLOCK_THREAD_CPUTIME_COMPILED TRUE CACHE INTERNAL "")
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 255)
set(HAVE_CLOCK_THREAD_CPUTIME "" CACHE INTERNAL "")
Expand Down
3 changes: 0 additions & 3 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ if(DARWIN AND NOT DEFINED ANDROID_BUILD)
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1)
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0)
Expand All @@ -75,7 +74,6 @@ if(DARWIN AND NOT DEFINED ANDROID_BUILD)
endif()
else()
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 0)
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 0)
Expand All @@ -96,7 +94,6 @@ else()

if (FREEBSD)
set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP 1)
set_cache_value(HAVE_CLOCK_MONOTONIC 1)
set_cache_value(HAVE_CLOCK_REALTIME 1)
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
set_cache_value(HAVE_PROCFS_STAT 0)
Expand Down
1 change: 0 additions & 1 deletion eng/native/tryrun_ios_tvos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ endmacro()

set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1)
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)


# TODO: these are taken from macOS, check these whether they're correct for iOS
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
#cmakedefine01 HAVE_WORKING_GETTIMEOFDAY
#cmakedefine01 HAVE_WORKING_CLOCK_GETTIME
#cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME
#cmakedefine01 HAVE_CLOCK_MONOTONIC
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
#cmakedefine01 MMAP_ANON_IGNORES_PROTECTION
#cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
Expand Down
14 changes: 0 additions & 14 deletions src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,7 @@ int main()
}" HAVE_WORKING_CLOCK_GETTIME)
set(CMAKE_REQUIRED_LIBRARIES)

set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_RT_LIBS})
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, &ts);

exit(ret);
}" HAVE_CLOCK_MONOTONIC)
set(CMAKE_REQUIRED_LIBRARIES)

check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK)

Expand Down
43 changes: 17 additions & 26 deletions src/coreclr/pal/src/synchmgr/synchmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ namespace CorUnix
if (dwTimeout != INFINITE)
{
// Calculate absolute timeout
palErr = GetAbsoluteTimeout(dwTimeout, &tsAbsTmo, /*fPreferMonotonicClock*/ TRUE);
palErr = GetAbsoluteTimeout(dwTimeout, &tsAbsTmo);
if (NO_ERROR != palErr)
{
ERROR("Failed to convert timeout to absolute timeout\n");
Expand Down Expand Up @@ -1051,7 +1051,7 @@ namespace CorUnix
ptnwdWorkerThreadNativeData =
&pSynchManager->m_pthrWorker->synchronizationInfo.m_tnwdNativeData;

palErr = GetAbsoluteTimeout(WorkerThreadTerminationTimeout, &tsAbsTmo, /*fPreferMonotonicClock*/ TRUE);
palErr = GetAbsoluteTimeout(WorkerThreadTerminationTimeout, &tsAbsTmo);
if (NO_ERROR != palErr)
{
ERROR("Failed to convert timeout to absolute timeout\n");
Expand Down Expand Up @@ -2671,7 +2671,7 @@ namespace CorUnix
VolatileStore<DWORD>(pdwWaitState, TWS_ACTIVE);
m_tsThreadState = TS_STARTING;

#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
attrsPtr = &attrs;
iRet = pthread_condattr_init(&attrs);
if (0 != iRet)
Expand Down Expand Up @@ -2699,7 +2699,7 @@ namespace CorUnix
pthread_condattr_destroy(&attrs);
goto IPrC_exit;
}
#endif // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
#endif // HAVE_PTHREAD_CONDATTR_SETCLOCK

iEagains = 0;
Mutex_retry:
Expand Down Expand Up @@ -2990,41 +2990,32 @@ namespace CorUnix
Converts a relative timeout to an absolute one.
--*/
PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo, BOOL fPreferMonotonicClock)
PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo)
{
PAL_ERROR palErr = NO_ERROR;
int iRet;

#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
if (fPreferMonotonicClock)
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
#elif HAVE_WORKING_CLOCK_GETTIME
// Not every platform implements a (working) clock_gettime
iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
#elif HAVE_WORKING_GETTIMEOFDAY
// Not every platform implements a (working) gettimeofday
struct timeval tv;
iRet = gettimeofday(&tv, NULL);
if (0 == iRet)
{
iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
ptsAbsTmo->tv_sec = tv.tv_sec;
ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
}
else
{
#endif
#if HAVE_WORKING_CLOCK_GETTIME
// Not every platform implements a (working) clock_gettime
iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
#elif HAVE_WORKING_GETTIMEOFDAY
// Not every platform implements a (working) gettimeofday
struct timeval tv;
iRet = gettimeofday(&tv, NULL);
if (0 == iRet)
{
ptsAbsTmo->tv_sec = tv.tv_sec;
ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
}
#else
#ifdef DBI_COMPONENT_MONO
return ERROR_INTERNAL_ERROR;
#else
#error "Don't know how to get hi-res current time on this platform"
#endif
#endif // HAVE_WORKING_CLOCK_GETTIME, HAVE_WORKING_GETTIMEOFDAY
#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
}
#endif
if (0 == iRet)
{
ptsAbsTmo->tv_sec += dwTimeout / tccSecondsToMilliSeconds;
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/pal/src/synchmgr/synchmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,7 @@ namespace CorUnix

static PAL_ERROR GetAbsoluteTimeout(
DWORD dwTimeout,
struct timespec * ptsAbsTmo,
BOOL fPreferMonotonicClock);
struct timespec * ptsAbsTmo);
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@
/* Define to 1 if you have the `sigaction' function. */
#cmakedefine HAVE_SIGACTION 1

/* CLOCK_MONOTONIC */
#cmakedefine HAVE_CLOCK_MONOTONIC 1

/* clockid_t */
#cmakedefine HAVE_CLOCKID_T 1
Expand Down
1 change: 0 additions & 1 deletion src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)

check_symbol_exists(madvise "sys/mman.h" HAVE_MADVISE)
check_symbol_exists(pthread_mutexattr_setprotocol "pthread.h" HAVE_DECL_PTHREAD_MUTEXATTR_SETPROTOCOL)
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)

check_symbol_exists(sys_signame "signal.h" HAVE_SYSSIGNAME)
check_symbol_exists(pthread_jit_write_protect_np "pthread.h" HAVE_PTHREAD_JIT_WRITE_PROTECT_NP)
Expand Down
15 changes: 0 additions & 15 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,6 @@ static const int64_t SECS_BETWEEN_1601_AND_1970_EPOCHS = 11644473600LL;
static const int64_t SECS_TO_100NS = 10000000;
static const int64_t MSECS_TO_MIS = 1000;

/* clock_gettime () is found by configure on Apple builds, but its only present from ios 10, macos 10.12, tvos 10 and watchos 3 */
#if defined (HAVE_CLOCK_MONOTONIC) && (defined(HOST_IOS) || defined(HOST_OSX) || defined(HOST_WATCHOS) || defined(HOST_TVOS))
#undef HAVE_CLOCK_MONOTONIC
#endif

#ifndef HAVE_CLOCK_MONOTONIC
static const int64_t MISECS_TO_NS = 1000;
#endif

static
int64_t
system_time_to_int64 (
Expand Down Expand Up @@ -466,15 +457,9 @@ system_time_to_int64 (
int64_t
ep_rt_mono_system_timestamp_get (void)
{
#if HAVE_CLOCK_MONOTONIC
struct timespec time;
if (clock_gettime (CLOCK_REALTIME, &time) == 0)
return system_time_to_int64 (time.tv_sec, time.tv_nsec);
#else
struct timeval time;
if (gettimeofday (&time, NULL) == 0)
return system_time_to_int64 (time.tv_sec, time.tv_usec * MISECS_TO_NS);
#endif
else
return system_time_to_int64 (0, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/utils/mono-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mono_clock_get_time_ns (mono_clock_id_t clk_id)
void
mono_clock_init (mono_clock_id_t *clk_id)
{
#ifdef HAVE_CLOCK_MONOTONIC
#ifdef CLOCK_MONOTONIC
*clk_id = CLOCK_MONOTONIC;
#endif
}
Expand Down
1 change: 0 additions & 1 deletion src/native/libs/Common/pal_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
#cmakedefine01 HAVE_LINUX_ERRQUEUE_H
#cmakedefine01 HAVE_GETDOMAINNAME_SIZET
#cmakedefine01 HAVE_INOTIFY
#cmakedefine01 HAVE_CLOCK_MONOTONIC
#cmakedefine01 HAVE_CLOCK_REALTIME
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Native/pal_crossprocessmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static int32_t AcquirePThreadMutexWithTimeout(pthread_mutex_t* mutex, int32_t ti
timeoutTimeSpec.tv_nsec = (timeoutMilliseconds % 1000) * 1000 * 1000;

error = pthread_mutex_reltimedlock_np(mutex, &timeoutTimeSpec);
#elif HAVE_PTHREAD_MUTEX_CLOCKLOCK && HAVE_CLOCK_MONOTONIC
#elif HAVE_PTHREAD_MUTEX_CLOCKLOCK
error = clock_gettime(CLOCK_MONOTONIC, &timeoutTimeSpec);
assert(error == 0);

Expand Down
4 changes: 2 additions & 2 deletions src/native/libs/System.Native/pal_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LowLevelMonitor* SystemNative_LowLevelMonitor_Create(void)
return NULL;
}

#if HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_CLOCK_MONOTONIC
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_t conditionAttributes;
error = pthread_condattr_init(&conditionAttributes);
if (error != 0)
Expand Down Expand Up @@ -176,7 +176,7 @@ int32_t SystemNative_LowLevelMonitor_TimedWait(LowLevelMonitor *monitor, int32_t

error = pthread_cond_timedwait_relative_np(&monitor->Condition, &monitor->Mutex, &timeoutTimeSpec);
#else
#if HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_CLOCK_MONOTONIC
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
error = clock_gettime(CLOCK_MONOTONIC, &timeoutTimeSpec);
assert(error == 0);
#else
Expand Down
19 changes: 0 additions & 19 deletions src/native/libs/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -558,28 +558,24 @@ if(CLR_CMAKE_TARGET_IOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_MACCATALYST)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_TVOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_ANDROID)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on newer Android
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
elseif(CLR_CMAKE_TARGET_WASI)
set(HAVE_FORK 0)
Expand Down Expand Up @@ -617,21 +613,6 @@ else()
"
HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)

check_c_source_runs(
"
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
int main(void)
{
int ret;
struct timespec ts;
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
exit(ret);
return 0;
}
"
HAVE_CLOCK_MONOTONIC)

check_c_source_runs(
"
Expand Down
1 change: 0 additions & 1 deletion src/native/minipal/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ check_function_exists(fsync HAVE_FSYNC)
check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF)
check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
check_symbol_exists(O_CLOEXEC fcntl.h HAVE_O_CLOEXEC)
check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
check_symbol_exists(CLOCK_MONOTONIC_COARSE time.h HAVE_CLOCK_MONOTONIC_COARSE)
check_symbol_exists(clock_gettime_nsec_np time.h HAVE_CLOCK_GETTIME_NSEC_NP)

Expand Down
1 change: 0 additions & 1 deletion src/native/minipal/minipalconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#cmakedefine01 HAVE_RESOURCE_H
#cmakedefine01 HAVE_O_CLOEXEC
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_CLOCK_MONOTONIC
#cmakedefine01 HAVE_CLOCK_MONOTONIC_COARSE
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 BIGENDIAN
Expand Down
26 changes: 9 additions & 17 deletions src/native/minipal/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,21 @@ int64_t minipal_hires_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#elif HAVE_CLOCK_MONOTONIC
#else
struct timespec ts;
int result = clock_gettime(CLOCK_MONOTONIC, &ts);
if (result != 0)
{
assert(!"clock_gettime(CLOCK_MONOTONIC) failed");
}
int result;
result = clock_gettime(CLOCK_MONOTONIC, &ts);
assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");

return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToNanoSeconds)) + (int64_t)(ts.tv_nsec);
#else
#error "minipal_hires_ticks requires clock_gettime_nsec_np or clock_gettime to be supported."
#endif
}

int64_t minipal_lowres_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / (int64_t)(tccMilliSecondsToNanoSeconds);
#elif HAVE_CLOCK_MONOTONIC
#else
struct timespec ts;

// emscripten exposes CLOCK_MONOTONIC_COARSE but doesn't implement it
Expand All @@ -129,19 +125,15 @@ int64_t minipal_lowres_ticks(void)
const clockid_t clockType = CLOCK_MONOTONIC;
#endif

int result = clock_gettime(clockType, &ts);
if (result != 0)
{
int result;
result = clock_gettime(clockType, &ts);
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
assert(!"clock_gettime(CLOCK_MONOTONIC_COARSE) failed");
assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC_COARSE) failed");
#else
assert(!"clock_gettime(CLOCK_MONOTONIC) failed");
assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");
#endif
}

return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToMilliSeconds)) + ((int64_t)(ts.tv_nsec) / (int64_t)(tccMilliSecondsToNanoSeconds));
#else
#error "minipal_lowres_ticks requires clock_gettime_nsec_np or clock_gettime to be supported."
#endif
}

Expand Down
Loading