Loren Wilton wrote:
So it appears that the only thing that can be done if you need
timestamps below 1ms on a multiproc system is to implement a routine
that has a thread per proc at realtime priority, and will periodically
all sync together burning processor until they can get a
near-simultaneous RDTSC value from each processor. You can then be
careful of which processor you read the timestamp counter from and use
a correction factor based on the last known offset and speed for that
processor.
The time-stamp counter is a writable register. A suitably motivated
person should be able to write a kernel driver to sync them on the fly.
How often you have to get the base sync values probably depends on the
environment. I deal with datacenter servers, so I can probably get
away with getting a sync value every 100 seconds or so. On a laptop
with active power management you might have to get sync values several
times per second to have actual accuracies in the millisecond range.
I’m surprised at how dynamic this delta is. I have a little test app
that I wrote many years ago to test the counter synchronization. I ran
it a few minutes ago on my desktop AMD 64 X2 3800+, and they were
11,976,000 cycles apart. I ran it two minutes later, and they were
11,951,000 cycles apart. Right now, they are 12,058,000 cycles apart.
The population is large enough that I believe these to be accurate to 5
places.
The clock runs at 2GHz, which means they are about 6ms apart. But even
more interesting, the delta between them varied by as much as 50us over
a period of 10 minutes.
It appears that, short of a special hardware timer plugin card, it is
no longer possible to get reliable timestamps that are good to less
than 1ms, and even those might be questionable in a number of
circumstances.
Yes. I am actually quite surprised that a simple, free-running
microsecond counter has not become part of the standard PC by now.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.