Date: Tue, 5 Aug 1997 01:46:33 -0700 (PDT) From: "Jamil J. Weatherbee" <jamil@counterintelligence.ml.org> To: freebsd-hackers@freebsd.org Cc: freebsd-realtime@freebsd.org Subject: ?? The right way to do a microsecond resolution wait Message-ID: <Pine.BSF.3.96.970805013644.501A-100000@counterintelligence.ml.org>
next in thread | raw e-mail | index | archive | help
Is this the best way to do a microsecond resolution wait under freebsd
(usleep only appears good to 10,000 microseconds). Doing small waits is an
important part of realtime software -- something that it would be
interesting to see addressed, particularily making a usleep that actually
sleeps microseconds.
With the following (unless i am off my rocker) i can get a 4 microsecond
wait on a ppro 180, a 25 microsecond wait on a pentium 100, and a 12
microsecond wait on a nexgen-100.
What I want to know is this the best way to get a highly accurate wait in
a thread of execution, is this even doing what I think it is, and why
doesnt usleep do something like this? I guess I could use it to output a
square wave on a paralell pin and look at that with an oscilliscope. For
the application I use it for the usleeps for the significant portion of
the time bring the cpu% down from 99% to about 1.5% pretty significant.
#define USLEEP_RESOLUTION 10000
/* Don't use for times > 2000 seconds */
void rsleep (long usecs)
{
struct timeval begin_time, cur_time;
long elapsed, utm;
gettimeofday (&begin_time, NULL); /* record the starting time */
if (utm = (usecs / USLEEP_RESOLUTION)*USLEEP_RESOLUTION) usleep (utm);
do gettimeofday (&cur_time, NULL); /* get the current time */
while (((cur_time.tv_sec - begin_time.tv_sec) * 1000000 +
(cur_time.tv_usec - begin_time.tv_usec)) < usecs);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.970805013644.501A-100000>
