Subject: Re: mono_time exported? (how to make timer work correctly across settimeofday() call?)
To: Tad Hunt <>
From: Simon Burge <>
List: tech-kern
Date: 01/26/2002 14:29:32
Tad Hunt wrote:

> I've got the following problem.  I have a list of
> callbacks set to expire in terms of time(3).
> I compute the delta from the smallest expire time
> to now, and call select(2) with the appropriate timeout.
> However, using time(3) causes problems, because
> someone may change the system time while this
> process is running.  I don't want that change to
> mess up my timers.
> looking through the kernel, I see that it has a
> "mono_time" variable.  This is exactly what I'm
> looking for, so I can service my callback functions
> in terms of mono_time, rather than time(2).
> However, unlike "boottime", I don't see any way
> to get access to mono_time from userland.  I am
> considering adding a machdep sysctl(3) to my
> kernel to get this, but obviously this isn't
> portable.  Any other suggestions?

I'd suggest either adding a gethrtime() syscall (ala solaris and
possibly other SVR4-type OS's), or (probably better) adding a
CLOCK_MONOTIME or CLOCK_MONOTONIC for clock_{getres,gettime,settime}(2)
to use.  If we do the latter, we can easily do gethrtime() as a libc
function that calls clock_gettime() with the right arguments.

I might try and put some patches together to do that sometime today
if boredom strikes.

Simon Burge                            <>
NetBSD CDs, Support and Service: