Timekeeping [Was: Re: cvs commit: src/usr.bin/vmstat vmstat.c src/usr.bin/w w.c]

Bruce Evans bde at zeta.org.au
Sat Oct 22 04:32:02 PDT 2005


On Sat, 22 Oct 2005, Poul-Henning Kamp wrote:

> In message <20051022185422.Q8268 at delplex.bde.org>, Bruce Evans writes:
>
>> What's a UTC delta?  Deltas don't (shouldn't) depend on the calendar.
>
> As easy as it would be to stick our head in the sand, ignore
> international treaties,geophysics and astronomy, point to POSIX and
> ignore leapseconds, it is not an feasible way out for us as an
> operating system project.
>
> UTC deltas does depend on the calendar for now.

Um, my question was rhetorical.  We don't have times in UTC, so calandars
are irrelvant.  If we had times in UTC, then the right way to determine
the delta time seems to be to convert the times to time_t's using timegm(),
then subtract using difftime().  Times in UTC cannot be simply be subracted
by subtracting in minutes and multiplying by 60, etc.  But we can just use
difftime().  Provided difftime() actually works.

> There is proposal from USA to make them DTRT pending in ITU-R Working
> Party 7A, but it is meeting fierce opposition from astronomers and
> geophysicists who hold the position that we can just ignore computers

They already DTRT IMO.  It is what the astronomers want.

> Until the future of leapseconds are resolved, something that could
> easily take 25 years, we have to deal with them.
>
> So an UTC offect contains any leap seconds we are aware off, and
> consequently, it depends on the calendar.

Sure, but we don't have UTC.  We have broken time_t's for real times
but non-broken time_t's for monotonic times.  To subtract these times,
the opposite methods to the ones stated by Andre should work (but
don't): numerical deltas don't work for either UTC or real times --
they don't work for UTC because UTC isn't numeric, and they don't
work for real times since POSIX left out the leap seconds -- difftime()
should work for subtracting real times; OTOH, numerical deltas work
for monotonic times while difftime() doesn't -- although difftime()
takes time_t's as args you can't pass the time_t's given by
CLOCK_MONOTONIC to it, since the latter are differences relative to
an undocumented start time but difftime() only handles absolute times.

Bruce


More information about the cvs-src mailing list