lkml.org 
[lkml]   [2020]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Missing CLOCK_BOOTTIME_RAW?
Date
Pali,

Pali Rohár <pali@kernel.org> writes:

> I'm looking at clocks which are provided by kernel for userspace
> applications via clock_gettime() syscall and I think that there is
> missing clock variant CLOCK_BOOTTIME_RAW.
>
> If userspace application wants to measure time difference between two
> events then I think all of available clocks CLOCK_REALTIME,
> CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW and CLOCK_BOOTTIME have some issues
> for such task.
...
> CLOCK_BOOTTIME is affected by NTP jumps but provides correct time
> difference when system was suspended during measurement.

What do you mean with NTP jumps?

Neither CLOCK_BOOTTIME nor CLOCK_MONOTONIC jump. They are frequency
corrected when NTP, PTP or PPS are in use. The frequency correction is
incremental an smothed. They really don't jump and they give you proper
time in nanoseconds which is as close to the real nanoseconds as it
gets.

CLOCK_MONOTONIC_RAW converts some assumed clock frequency into something
which looks like time. But it's raw and subject to drift. The only
reason why it's exposed is because NTP/PTP need it to calculate the
frequency difference between the hardware counter and the master clock.

> So for me it looks like that there is missing CLOCK_BOOTTIME_RAW clock
> which would not be affected by NTP jumps (like CLOCK_MONOTONIC_RAW) and
> also would not be affected by system suspend (like CLOCK_BOOTTIME).
>
> Please correct me if I'm wrong in some of my above assumptions. It is
> how I understood documentation for clock_gettime() function from Linux
> manpage.

I don't know how you read jumps into this:

CLOCK_MONOTONIC

Clock that cannot be set and represents monotonic time since some
unspecified starting point. This clock is not affected by
discontinuous jumps in the system time (e.g., if the system
administrator manually changes the clock), but is affected by the
incremental adjustments performed by adjtime(3) and NTP.

And CLOCK_BOOTTIME is the same except that it accounts time in suspend
while MONOTONIC stops in suspend.

> Is there any reason why kernel does not provide such CLOCK_BOOTTIME_RAW
> clock for userspace applications which would be interested in measuring
> time difference which occurred between two events?

Nobody needs it and there is even no guarantee that it can be
reconstructed on resume.

If you want accurate time deltas then use either CLOCK_MONOTONIC or
CLOCK_BOOTTIME depending on your interest in suspend time.

Thanks,

tglx

\
 
 \ /
  Last update: 2020-05-08 23:00    [W:0.309 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site