Kernel release status
Posted Feb 21, 2003 1:15 UTC (Fri) by
zooko (subscriber, #2589)
In reply to:
Kernel release status by Ross
Parent article:
Kernel release status
I need a timer for internal scheduling purposes in my app. It need not be, and indeed should not be the same as the timer used for human-meaningful things like file timestamps. If it were the same, then the human sysadmin may need to change it, for example because his clock is out of sync with UTC, which breaks my app.
The whole "gettimeofday() is more or less much monotonically non-decreasing" argument is classic "worse is better" (and I mean "w-i-b" in the bad way here). gettimeofday() cannot guarantee both non-decreasing and synchronization with UTC. In practice, it fails in both of these sometimes. Failure to be synced to UTC is generally just a hassle for the human to deal with. Failure to be non-decreasing can cause unpredictable behavior in your applications that depend on non-decreasingness.
The worse-is-better approach is just to say "Yep, gettimeofday() tries to be non-decreasing. That's pretty much good.".
For what it's worth, I became intimately aware of this problem last year when my gettimeofday was experiencing jitter due to my laptop CPU slowing down to save energy. This manifested as events in my application code going off in a different order than I had specified them. Boy was that tricky to debug.
The worse-is-better approach is to change the behavior in this particular instance so that gettimeofday is non-decreasing even in the presence of CPU throttling. The Right Way To Do It is specify a service that actually guarantees non-decreasingness in all cases up to very unusual hardware failure or a bug in the implementation. Therefore, this service cannot also guarantee synchronization with UTC, so the Right Way To Do It is to specify clearly that this service is not synchronized in any way with UTC.
The fact that a lot of people don't understand the difference between these two approaches is the worse-is-better legacy.
Regards,
Zooko
(
Log in to post comments)