Skip to content

Commit 737dcdd

Browse files
CopilotjkotasAaronRobinsonMSFTstephentoub
authored
Remove HAVE_CLOCK_MONOTONIC and dead fallback code (#124120)
HAVE_CLOCK_MONOTONIC is always defined as 1 on all Unix-like platforms, so we can remove the macro and all associated fallback code. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Aaron R Robinson <arobins@microsoft.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
1 parent 407f9f1 commit 737dcdd

18 files changed

Lines changed: 31 additions & 111 deletions

File tree

eng/native/tryrun.browser.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ set(HAVE_CFSETSPEED 1 CACHE INTERNAL "")
130130
set(HAVE_CHMOD 1 CACHE INTERNAL "")
131131
set(HAVE_CLOCK_GETTIME_NSEC_NP "" CACHE INTERNAL "")
132132
set(HAVE_CLOCK_MONOTONIC_COARSE 1 CACHE INTERNAL "")
133-
set(HAVE_CLOCK_MONOTONIC_COMPILED TRUE CACHE INTERNAL "")
134-
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
135-
set(HAVE_CLOCK_MONOTONIC 1 CACHE INTERNAL "")
136133
set(HAVE_CLOCK_THREAD_CPUTIME_COMPILED TRUE CACHE INTERNAL "")
137134
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 255)
138135
set(HAVE_CLOCK_THREAD_CPUTIME "" CACHE INTERNAL "")

eng/native/tryrun.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ if(DARWIN AND NOT DEFINED ANDROID_BUILD)
5454
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
5555
set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1)
5656
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
57-
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
5857
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
5958
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
6059
set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0)
@@ -75,7 +74,6 @@ if(DARWIN AND NOT DEFINED ANDROID_BUILD)
7574
endif()
7675
else()
7776
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 0)
78-
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
7977
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
8078
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
8179
set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 0)
@@ -96,7 +94,6 @@ else()
9694

9795
if (FREEBSD)
9896
set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP 1)
99-
set_cache_value(HAVE_CLOCK_MONOTONIC 1)
10097
set_cache_value(HAVE_CLOCK_REALTIME 1)
10198
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
10299
set_cache_value(HAVE_PROCFS_STAT 0)

eng/native/tryrun_ios_tvos.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ endmacro()
55

66
set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1)
77
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
8-
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
98

109

1110
# TODO: these are taken from macOS, check these whether they're correct for iOS

src/coreclr/pal/src/config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
#cmakedefine01 HAVE_WORKING_GETTIMEOFDAY
8888
#cmakedefine01 HAVE_WORKING_CLOCK_GETTIME
8989
#cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME
90-
#cmakedefine01 HAVE_CLOCK_MONOTONIC
9190
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
9291
#cmakedefine01 MMAP_ANON_IGNORES_PROTECTION
9392
#cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS

src/coreclr/pal/src/configure.cmake

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,7 @@ int main()
366366
}" HAVE_WORKING_CLOCK_GETTIME)
367367
set(CMAKE_REQUIRED_LIBRARIES)
368368

369-
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_RT_LIBS})
370-
check_cxx_source_runs("
371-
#include <stdlib.h>
372-
#include <time.h>
373-
#include <sys/time.h>
374-
375-
int main()
376-
{
377-
int ret;
378-
struct timespec ts;
379-
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
380369

381-
exit(ret);
382-
}" HAVE_CLOCK_MONOTONIC)
383-
set(CMAKE_REQUIRED_LIBRARIES)
384370

385371
check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK)
386372

src/coreclr/pal/src/synchmgr/synchmanager.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ namespace CorUnix
386386
if (dwTimeout != INFINITE)
387387
{
388388
// Calculate absolute timeout
389-
palErr = GetAbsoluteTimeout(dwTimeout, &tsAbsTmo, /*fPreferMonotonicClock*/ TRUE);
389+
palErr = GetAbsoluteTimeout(dwTimeout, &tsAbsTmo);
390390
if (NO_ERROR != palErr)
391391
{
392392
ERROR("Failed to convert timeout to absolute timeout\n");
@@ -1051,7 +1051,7 @@ namespace CorUnix
10511051
ptnwdWorkerThreadNativeData =
10521052
&pSynchManager->m_pthrWorker->synchronizationInfo.m_tnwdNativeData;
10531053

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

2674-
#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
2674+
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
26752675
attrsPtr = &attrs;
26762676
iRet = pthread_condattr_init(&attrs);
26772677
if (0 != iRet)
@@ -2699,7 +2699,7 @@ namespace CorUnix
26992699
pthread_condattr_destroy(&attrs);
27002700
goto IPrC_exit;
27012701
}
2702-
#endif // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
2702+
#endif // HAVE_PTHREAD_CONDATTR_SETCLOCK
27032703

27042704
iEagains = 0;
27052705
Mutex_retry:
@@ -2990,41 +2990,32 @@ namespace CorUnix
29902990
29912991
Converts a relative timeout to an absolute one.
29922992
--*/
2993-
PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo, BOOL fPreferMonotonicClock)
2993+
PAL_ERROR CPalSynchronizationManager::GetAbsoluteTimeout(DWORD dwTimeout, struct timespec * ptsAbsTmo)
29942994
{
29952995
PAL_ERROR palErr = NO_ERROR;
29962996
int iRet;
29972997

2998-
#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
2999-
if (fPreferMonotonicClock)
2998+
#if HAVE_PTHREAD_CONDATTR_SETCLOCK
2999+
iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
3000+
#elif HAVE_WORKING_CLOCK_GETTIME
3001+
// Not every platform implements a (working) clock_gettime
3002+
iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
3003+
#elif HAVE_WORKING_GETTIMEOFDAY
3004+
// Not every platform implements a (working) gettimeofday
3005+
struct timeval tv;
3006+
iRet = gettimeofday(&tv, NULL);
3007+
if (0 == iRet)
30003008
{
3001-
iRet = clock_gettime(CLOCK_MONOTONIC, ptsAbsTmo);
3009+
ptsAbsTmo->tv_sec = tv.tv_sec;
3010+
ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
30023011
}
3003-
else
3004-
{
3005-
#endif
3006-
#if HAVE_WORKING_CLOCK_GETTIME
3007-
// Not every platform implements a (working) clock_gettime
3008-
iRet = clock_gettime(CLOCK_REALTIME, ptsAbsTmo);
3009-
#elif HAVE_WORKING_GETTIMEOFDAY
3010-
// Not every platform implements a (working) gettimeofday
3011-
struct timeval tv;
3012-
iRet = gettimeofday(&tv, NULL);
3013-
if (0 == iRet)
3014-
{
3015-
ptsAbsTmo->tv_sec = tv.tv_sec;
3016-
ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
3017-
}
30183012
#else
30193013
#ifdef DBI_COMPONENT_MONO
30203014
return ERROR_INTERNAL_ERROR;
30213015
#else
30223016
#error "Don't know how to get hi-res current time on this platform"
30233017
#endif
30243018
#endif // HAVE_WORKING_CLOCK_GETTIME, HAVE_WORKING_GETTIMEOFDAY
3025-
#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
3026-
}
3027-
#endif
30283019
if (0 == iRet)
30293020
{
30303021
ptsAbsTmo->tv_sec += dwTimeout / tccSecondsToMilliSeconds;

src/coreclr/pal/src/synchmgr/synchmanager.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,7 @@ namespace CorUnix
775775

776776
static PAL_ERROR GetAbsoluteTimeout(
777777
DWORD dwTimeout,
778-
struct timespec * ptsAbsTmo,
779-
BOOL fPreferMonotonicClock);
778+
struct timespec * ptsAbsTmo);
780779
};
781780
}
782781

src/mono/cmake/config.h.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@
260260
/* Define to 1 if you have the `sigaction' function. */
261261
#cmakedefine HAVE_SIGACTION 1
262262

263-
/* CLOCK_MONOTONIC */
264-
#cmakedefine HAVE_CLOCK_MONOTONIC 1
265263

266264
/* clockid_t */
267265
#cmakedefine HAVE_CLOCKID_T 1

src/mono/cmake/configure.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
112112

113113
check_symbol_exists(madvise "sys/mman.h" HAVE_MADVISE)
114114
check_symbol_exists(pthread_mutexattr_setprotocol "pthread.h" HAVE_DECL_PTHREAD_MUTEXATTR_SETPROTOCOL)
115-
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
116115

117116
check_symbol_exists(sys_signame "signal.h" HAVE_SYSSIGNAME)
118117
check_symbol_exists(pthread_jit_write_protect_np "pthread.h" HAVE_PTHREAD_JIT_WRITE_PROTECT_NP)

src/mono/mono/eventpipe/ep-rt-mono.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,6 @@ static const int64_t SECS_BETWEEN_1601_AND_1970_EPOCHS = 11644473600LL;
386386
static const int64_t SECS_TO_100NS = 10000000;
387387
static const int64_t MSECS_TO_MIS = 1000;
388388

389-
/* clock_gettime () is found by configure on Apple builds, but its only present from ios 10, macos 10.12, tvos 10 and watchos 3 */
390-
#if defined (HAVE_CLOCK_MONOTONIC) && (defined(HOST_IOS) || defined(HOST_OSX) || defined(HOST_WATCHOS) || defined(HOST_TVOS))
391-
#undef HAVE_CLOCK_MONOTONIC
392-
#endif
393-
394-
#ifndef HAVE_CLOCK_MONOTONIC
395-
static const int64_t MISECS_TO_NS = 1000;
396-
#endif
397-
398389
static
399390
int64_t
400391
system_time_to_int64 (
@@ -466,15 +457,9 @@ system_time_to_int64 (
466457
int64_t
467458
ep_rt_mono_system_timestamp_get (void)
468459
{
469-
#if HAVE_CLOCK_MONOTONIC
470460
struct timespec time;
471461
if (clock_gettime (CLOCK_REALTIME, &time) == 0)
472462
return system_time_to_int64 (time.tv_sec, time.tv_nsec);
473-
#else
474-
struct timeval time;
475-
if (gettimeofday (&time, NULL) == 0)
476-
return system_time_to_int64 (time.tv_sec, time.tv_usec * MISECS_TO_NS);
477-
#endif
478463
else
479464
return system_time_to_int64 (0, 0);
480465
}

0 commit comments

Comments
 (0)