Base idle time calculations on a CPU counter, not a wall clock#527
Base idle time calculations on a CPU counter, not a wall clock#527djs55 merged 1 commit intomoby:masterfrom
Conversation
9a4dee3 to
efccf5a
Compare
Previously we used the wall clock via `Unix.gettimeofday()` to compute the idle time for "endpoints" (remote destinations). When a laptop wakes from sleep, the wall clock jumps forward and suddenly all the endpoints are idle and the connections are dropped. This patch switches to a monotonic clock which is driven by a CPU counter. The counter is paused while the computer sleeps and therefore does not jump forwards on wake. Signed-off-by: David Scott <dave@recoil.org>
d2169a0 to
ba39cbf
Compare
|
|
||
| let touch t = | ||
| t.last_active_time <- Unix.gettimeofday () | ||
| t.last_active_time_ns <- Clock.elapsed_ns t.clock |
There was a problem hiding this comment.
Clock.elapsed_ns calls into https://github.com/mirage/mirage-clock/blob/987d197802f80778b7b3daa642caee0c27a1ce43/unix/mclock.ml#L19 which is https://github.com/mirage/mirage-clock/blob/987d197802f80778b7b3daa642caee0c27a1ce43/unix/clock_stubs.c#L67
According to https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time
Returns current value of a clock that increments monotonically in tick units (starting at an arbitrary point), this clock does not increment while the system is asleep.
StefanScherer
left a comment
There was a problem hiding this comment.
I've tested a Docker Desktop build on a M1 machine leaving unattended over night and Docker is still working and docker commands from the command line still work as expected. The machine went to sleep mode (I have disabled the "Prevent from sleeping" system setting in macOS).
Previously we used the wall clock via
Unix.gettimeofday()to compute the idle time for "endpoints" (remote destinations). When a laptop wakes from sleep, the wall clock jumps forward and suddenly all the endpoints are idle and the connections are dropped.This patch switches to a monotonic clock which is driven by a CPU counter. The counter is paused while the computer sleeps and therefore does not jump forwards on wake.
This patch also adds a log message whenever an "endpoint" is deleted, to make debugging problems easier.
Signed-off-by: David Scott dave@recoil.org