Subject: New, improved delay()
To: None <port-m68k@NetBSD.ORG>
From: Gordon W. Ross <gwr@mc.com>
List: port-m68k
Date: 02/16/1996 14:01:59
If you are using a delay based on the CPU clock, you might want to
check out the implementation I just did for the sun3 port.  The new
implementation achieves much lower overhead, making short delays
much more accurate.  (A call to delay(2) takes about 2uSec. not 5).

The interesting part of the design is to use a "fixed-point" number
as the loop count, where the denominator is adjusted for CPU speed,
and the numerator is a constant.  My loop count is:

	loops = (256 * microseconds) / delay_divisor

The implementation is trivial, and is checked into arch/sun3.

By the way, if anyone feels like writing a routine to automatically
find the correct delay_divisor, that would be nice.  It can probably
be done with an iterative predictor/corrector algorithm that uses
the clock interrupt as its reference.

Gordon