From 57b97a4c910e3294b1ed441acea55da2f9ca3cb1 Mon Sep 17 00:00:00 2001 From: Harry Sintonen Date: Sat, 5 Dec 2020 21:21:14 +0200 Subject: [PATCH 1/2] Use CLOCK_MONOTONIC_RAW when available --- src/util/timestamp.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/timestamp.cc b/src/util/timestamp.cc index 2e2efe2..a50f734 100644 --- a/src/util/timestamp.cc +++ b/src/util/timestamp.cc @@ -48,6 +48,12 @@ #include #endif +#ifdef CLOCK_MONOTONIC_RAW +#define CLOCKTYPE CLOCK_MONOTONIC_RAW +#else +#define CLOCKTYPE CLOCK_MONOTONIC +#endif + static uint64_t millis_cache = -1; uint64_t frozen_timestamp( void ) @@ -73,7 +79,7 @@ void freeze_timestamp( void ) // Check for presence, for OS X SDK >= 10.12 and runtime < 10.12 &clock_gettime != NULL && #endif - clock_gettime( CLOCK_MONOTONIC, &tp ) == 0 ) { + clock_gettime( CLOCKTYPE, &tp ) == 0 ) { uint64_t millis = tp.tv_nsec / 1000000; millis += uint64_t( tp.tv_sec ) * 1000; From 87fd565268c5498409d81584b34467bd7e16a81f Mon Sep 17 00:00:00 2001 From: Harry Sintonen Date: Thu, 21 Oct 2021 16:43:41 +0300 Subject: [PATCH 2/2] Only use CLOCK_MONOTONIC_RAW with __APPLE__ systems. --- src/util/timestamp.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/timestamp.cc b/src/util/timestamp.cc index a50f734..59a833f 100644 --- a/src/util/timestamp.cc +++ b/src/util/timestamp.cc @@ -48,7 +48,11 @@ #include #endif -#ifdef CLOCK_MONOTONIC_RAW +// On Apple systems CLOCK_MONOTONIC is unfortunately able to go +// backwards in time. This breaks mosh when system is returning from +// suspend as described in ticket #1014. To avoid this issue prefer +// CLOCK_MONOTONIC_RAW on Apple systems when available. +#if defined(__APPLE__) && defined(CLOCK_MONOTONIC_RAW) #define CLOCKTYPE CLOCK_MONOTONIC_RAW #else #define CLOCKTYPE CLOCK_MONOTONIC