TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Twisty Maze of Linux Clocks, All Slightly Different

105 pointsby jrepinover 11 years ago

11 comments

claudiusover 11 years ago
While the article in general is great, the author’s assumption of one true time is rather cute :).<p>At the very least, there are:<p>- the actual number of seconds that passed since the epoch, i.e. the number a perfect egg timer would show if you had set it off at 12 AM on 1970-01-01.<p>- International Atomic Time (IAT), the closest thing to the aforementioned egg timer we currently have (though with some offset, naturally).<p>- Terrestrial Time (TT), which is 32.odd seconds ahead of IAT, apparently for historical reasons.<p>- Universial Time (UT&lt;timezoneoffset&gt;), which is supposed to be the solar time at one particular location, Greenwhich for UT1.<p>- Coordinated Universal Time (UTC), probably the closest thing to The One True Time, which jumps around merrily depending on the rotational speed of Earth, trying to keep days of 86400 SI seconds.<p>Oh, and we’re not even considering relativistic effects here.
评论 #6396922 未加载
评论 #6395109 未加载
yidover 11 years ago
This bit makes me wonder about the entropy of the nanosecond clock, for adding entropy to an PRNG:<p>&gt; Given scheduling jitter and so forth, it&#x27;s not clear what it means to get a timestamp with nanosecond resolution from the operating system. It probably takes thousands, if not millions, of instructions between the time the timestamp is retrieved and the time your program looks at it
评论 #6394773 未加载
评论 #6394516 未加载
评论 #6394398 未加载
评论 #6395519 未加载
hobsover 11 years ago
This article is: 1. Useful 2. Interesting 3. Actually has comments from people on the internet trying to get information in a polite and well explained manner. (WHAT?!)
myself248over 11 years ago
It gets even more interesting when you put the machine into suspend, and time starts passing without timer interrupts getting serviced.<p>Or when NTP notices that your local clock is drifting, and attempts to discipline it.<p>As they say on the time-nuts listserv: A man with one clock always knows what time it is. A man with two clocks is never quite sure...
ChuckMcMover 11 years ago
From 2010 but still interesting. Time an programming are inexorably intertwined, either by the time to do something is short enough, or the time when to do something is accurate enough. Having done some real time work (trying to get Linux running a robot back in the day) it was amazing at how challenging it was to keep things in sync. Given the cheapness of transistors there are a bazillion timers and clocks in ARM chips. At some point I expect to see a dedicated small core which does nothing but manage the observation of, and reporting on, the passage of time.
评论 #6395344 未加载
Scramblejamsover 11 years ago
So let&#x27;s say I want easy cross-platform access to a monotonic timer which gives me the number of egg timer (to use the phrase here) milliseconds since a certain UTC time. Assume that I&#x27;ve got an NTP server available to keep me somewhat near atomic reality, and let&#x27;s neglect relativistic shenanigans. Is there such a function call?
评论 #6397893 未加载
cafover 11 years ago
It&#x27;s not true that if you pass a pointer to a &#x27;struct timezone&#x27; to gettimeofday() it just gets filled with zeroes - the tz_minuteswest field <i>is</i> filled with the current local timezone offset (based either on the TZ environment variable or on &#x2F;etc&#x2F;localtime).
PaulHouleover 11 years ago
If you think it&#x27;s complicated in Linux, just try writing a mobile drag racing game for Windows 8.<p>If you try to index a GPS trace of a car driving the quarter mile by the system clock, good luck, because you can experience astonishing precision without accuracy.
LnxPrgr3over 11 years ago
I&#x27;m sad the newer time functions are still &quot;esoteric&quot;—it&#x27;s the only sane POSIX timer API I&#x27;m aware of, but it&#x27;s not available on Mac OS X or FreeBSD the last I checked.
zbowlingover 11 years ago
Can&#x27;t forget about CLOCK_MONOTONIC_RAW in addition add to CLOCK_MONOTONIC
cmccabeover 11 years ago
I wrote a blog post about clocks and timers earlier: <a href="http://www.club.cc.cmu.edu/~cmccabe/blog_time_and_time_again.html" rel="nofollow">http:&#x2F;&#x2F;www.club.cc.cmu.edu&#x2F;~cmccabe&#x2F;blog_time_and_time_again...</a><p>It gets especially interesting when you start thinking about mutexes and condition variables with timeouts.
评论 #6397780 未加载