]> dgit.raspbian.org Git - git-annex.git/commitdiff
use Boottime clock on linux
authorJoey Hess <joeyh@joeyh.name>
Wed, 3 Jul 2024 22:44:38 +0000 (18:44 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 3 Jul 2024 22:44:38 +0000 (18:44 -0400)
Better to advance while suspended, that way a stale content retention
lock will expire while suspended.

The fallback the Monotonic to support older kernels assumes that there
are not systems where Boottime sometimes succeeds and sometimes fails.
If that ever happened, the clock would probably not monotonically
advance as it read from different clocks on different calls! I don't see
any indication in clock_gettime(2) errono list that it can fail
intermittently so probably this is ok.

Utility/MonotonicClock.hs

index af5c20cd9452e17bc17f0a26bb3cf2e87df5b2e2..1af10187e3ad7cca99d3b2922e49c8720d89a53a 100644 (file)
@@ -14,11 +14,23 @@ import qualified System.Clock as Clock
 #else
 import qualified System.Posix.Clock as Clock
 #endif
+#ifdef linux_HOST_OS
+import Utility.Exception
+#endif
 
 newtype MonotonicTimestamp = MonotonicTimestamp Integer
        deriving (Show, Eq, Ord)
 
+-- On linux, this uses a clock that advances while the system is suspended,
+-- except for on very old kernels (eg 2.6.32).
+-- On other systems, that is not available, and the monotonic clock will
+-- not advance while suspended.
 currentMonotonicTimestamp :: IO MonotonicTimestamp
 currentMonotonicTimestamp =
-       (MonotonicTimestamp . fromIntegral . Clock.sec)
-               <$> Clock.getTime Clock.Monotonic
+       (MonotonicTimestamp . fromIntegral . Clock.sec) <$>
+#ifdef linux_HOST_OS
+               (tryNonAsync (Clock.getTime Clock.Boottime)
+                       >>= either (const $ Clock.getTime Clock.Monotonic) return)
+#else
+               Clock.getTime Clock.Monotonic
+#endif