|
|
Subscribe / Log in / New account

Why CLOCK_MONOTONIC?

Why CLOCK_MONOTONIC?

Posted Mar 9, 2018 17:30 UTC (Fri) by pbonzini (subscriber, #60935)
In reply to: Why CLOCK_MONOTONIC? by glenn
Parent article: Time-based packet transmission

Doesn't CLOCK_REALTIME jump around in daylight savings time changes?


to post comments

Why CLOCK_MONOTONIC?

Posted Mar 9, 2018 20:13 UTC (Fri) by wahern (subscriber, #37304) [Link] (3 responses)

A Unix timestamp (i.e. CLOCK_REALTIME) is always GMT0, so it's not effected by daylight savings. But a "POSIX second" is not the same thing as an SI second as POSIX says there are _exactly_ 86400 seconds per calendar day. That cheat makes calendar arithmetic incredibly simple. But when there's a leap second in UTC, one or more "POSIX seconds" need to be stretched. Thus, if there's a leap second within (or near) the interval between two Unix timestamps, the difference doesn't reflect the number of elapsed SI seconds. Similarly, depending on the skewing algorithm, a single Unix timestamp could represent two SI seconds.

For many engineering use cases what people normally would want is CLOCK_TAI. But, AFAIU, CLOCK_TAI can go backwards if the sysadmin or faulty hardware demands it, so often CLOCK_MONOTONIC is the safest choice to avoid weird arithmetic errors (as opposed to errors from poor accuracy or precision).

There's a movement to remove leap seconds from UTC so that UTC becomes a fixed offset from TAI. IMO that's short-sighted. It doesn't really improve things much as a practical matter (see TAI vs monotonic, above). Nor even as a theoretical matter (see special relativity). Anyhow, if we wanted to ignore the inherent complexity of time synchronization we may as well jump straight to BCT (https://en.wikipedia.org/wiki/Barycentric_Coordinate_Time)

Why CLOCK_MONOTONIC?

Posted Mar 9, 2018 20:50 UTC (Fri) by k8to (guest, #15413) [Link] (2 responses)

Note of course that faulty hardware *could* cause CLOCK_MONOTONIC to misbehave, but you'd need a whole new level of faulty hardware for this, probably the kind where all software on the system will be randomly crashing.

Why CLOCK_MONOTONIC?

Posted Mar 9, 2018 20:58 UTC (Fri) by vadim (subscriber, #35271) [Link] (1 responses)

Long ago I had a computer where time randomly jumped backwards by a second or two then resumed ticking forwards. Caused a lot of very confusing problems and baffled the hell out of me.

I'm wondering if you might know what it could have been. It was a dual CPU Athlon MP.

Why CLOCK_MONOTONIC?

Posted Mar 9, 2018 22:58 UTC (Fri) by zlynx (guest, #2285) [Link]

I seem to remember that some of these non-Intel SMP systems had problems with TSC synchronization and switching CPUs. Linux did patch it eventually. I think?

Anyway, if a program was using TSC, an AMD system might run TSC at different rates on different CPUs since TSC was actually pegged to the CPU's clock rate. Whereas on Intel TSC was a virtual clock. No matter the clock rate, TSC ran at the same speed.

I could only find this: https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds