Subject: Re: /dev/clock pseudodevice
From: Bill Sommerfeld <email@example.com>
Date: 07/28/2001 19:02:08
> An interesting idea. You'd lose the ability to get sub-tick timings out of
> it like that, though, and anything calling gettimeofday() hundreds of times
> a second probably wants better than 10ms resolution.
Actually, on architectures with userland-readable cycle counters, this
page could also contain cycle-counter base and scaling values for each
cpu, allowing userland to compute a exact time.
(see sys/arch/alpha/alpha/microtime.c for an example of what would
have to be replicated into userland).
To be completely usable, you need a fast userland "which cpu am i".
you'd then do something like the following:
(this is intended to be pseudocode..)
beforescaling = beforecpu->scaling
read cycle counter
afterscaling = beforecpu->scaling
} while ((beforescaling != afterscaling) || (beforecpu != aftercpu))
time = beforescaling.base + counter / beforescaling.denominator
I think this handles (a) clock interrupt in the middle of the
operation, and (b) preemption and cpu switch in the middle.