That was actually someone else's suggestion, but I'm inclined to agree.
Currently they are always synchronous on x86, but there is sometimes
an offset. Since the counters can be written, that can be fixed
at boot time and forgotten about. (Until someone starts doing evil things
with APM on multiprocessors.)
The problem is that some architectures might, and the Alpha currently
*does*, use asynchronous clocks. This makes things much hairier, because
the phases drift as the system runs, and you need to know the processor
you're running on to interpret the cycle counter.
On an x86, I've thought of just exporting the conversion factors
(from cycle counter to real time) to userland through shared memory
and letting the library implement gettimeofday() without a system call.
(There would, of course, be an exported "valid" flag without which
the library would do an old-fashioned system call.)
This doesn't work, however, unless you can determine the cycle counter
and the processor number atomically with respect to process scheduling.
(The Alpha only provides a 32-bit cycle counter; the upper 32 bits of
the register are software controllable, which permits a fix for it,
but other systems may have problems.)
My ambition is to phase-lock the counters almost exactly, to within 1
tick (3 ns or less). This requires symmetric round-trip message timing,
like what NTP does over the net, but over the bus. That's the only way to
correct for the ~50-clock one-way multiprocessor synchronization overhead.
This doesn't take a lot of wall-clock time to do once at boot time, but
it requires a lot of blocking on spin locks, which is extremely painful
on a running system. I'm not sure how to accurately measure the
interprocessor phases on a running system.
(Measuring phases without bidirectional communication is *very*
difficult. I'm working on algorithms for it, but they're a pain
and I'm not sure about their stability.)
-- -Colin- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/