1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

Kernel: Let TimeManagement keep epoch time as timespec

Previously, it was kept as just a time_t and the sub-second
offset was inferred from the monotonic clock. This means that
sub-second time adjustments were ignored.

Now that `ntpquery -s` can pass in a time with sub-second
precision, it makes sense to keep time at that granularity
in the kernel.

After this, `ntpquery -s` immediately followed by `ntpquery` shows
an offset of 0.02s (that is, on the order of network roundtrip time)
instead of up to 0.75s previously.
This commit is contained in:
Nico Weber 2020-09-06 19:52:24 -04:00 committed by Andreas Kling
parent 4ac5cc2461
commit e8131f503d
3 changed files with 22 additions and 15 deletions

View file

@ -43,8 +43,7 @@ int Process::sys$clock_gettime(clockid_t clock_id, Userspace<timespec*> user_ts)
ts.tv_nsec = TimeManagement::the().ticks_this_second() * 1000000;
break;
case CLOCK_REALTIME:
ts.tv_sec = TimeManagement::the().epoch_time();
ts.tv_nsec = TimeManagement::the().ticks_this_second() * 1000000;
ts = TimeManagement::the().epoch_time();
break;
default:
return -EINVAL;
@ -67,7 +66,7 @@ int Process::sys$clock_settime(clockid_t clock_id, Userspace<const timespec*> us
switch (clock_id) {
case CLOCK_REALTIME:
TimeManagement::the().set_epoch_time(ts.tv_sec);
TimeManagement::the().set_epoch_time(ts);
break;
default:
return -EINVAL;