Skip to content
Snippets Groups Projects
Commit 477b9427 authored by Nadav Har'El's avatar Nadav Har'El Committed by Pekka Enberg
Browse files

clock: base timers on monotonic clock


sched::timer_base, used to implement all forms of timeouts in OSv, is
currently based on the wall-clock time in s64 form. This is problematic
for two reasons:

1. The type s64 doesn't say which units should be used, whether the time
is absolute or relative or what is its epoch.

2. wall-clock time is a bad choice for short-term timers: If a thread
intends to sleep for a millisecond, and the wall-clock goes back a minute,
the thread will end up sleeping a whole minute.

So this patch changes the basis of sched::timer_base to strongly-typed
time points from a monotonic clock, osv::clock::uptime::time_point.

We also allow setting timers using the wall-clock time, but with a big
caveat: The expiration time is converted from wall to uptime clocks at
the moment of timer_base::set(), so if the wall-clock is adjusted later,
the wall time at expiration may not be exactly the one intended.

So that we don't have to change all timer users in this one patch, we
also temporarily implement the old weakly-typed timer_base::set(s64)
using the new mechanism. This variant will be removed in a later patch
in this series, when it is no longer used.

Reviewed-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 0b462341
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment