Subject: Re: microtime(9) slow on i386?
To: Perry E. Metzger <perry@wasabisystems.com>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
List: port-i386
Date: 10/23/2001 22:39:56
Perry E. Metzger wrote:
> We can check the cycle timer, but the problem there is that we can
> easily lose on a machine with a variable rate clock.
True, but we might use aproximation like this:
1. In hardclock(9), remember rdtsc value (to, say 'hardclock_rdtsc')
2. change microtime(9) to compute the time like:
struct timeval tv;
int s = splclock();
tv = mono_time;
splx(s);
tv.tv_usec += (current_rdtsc - hardclock_rdtsc) * curr_proc_clock_rate;
iv (tv.tv_usec > 1000000) {
tv.tv_sec++;
tv.tv_usec -= 1000000;
}
This should be much faster. This should be as accurate as current
method on fixed-clock-rate processors, and since the base ('mono_time')
is updated each 1/100 s on i386, the difference in accuracy of time
on variable rate processors should be negliable too.
Jaromir
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.NetBSD.org/Ports/i386/ps2.html
-= Those who would give up liberty for a little temporary safety deserve =-
-= neither liberty nor safety, and will lose both. -- Benjamin Franklin =-