Hi all,
First of all, I'd like to thank everyone that have answered, I never
expected so many solutions :)
A couple of results:
1) The rdtscll Pentium instruction (Eran's answer) is very useful. It's
super accurate and right now I decided to use it mostly to benchmark
other solutions, and to estimate the CPU frequency with a fancy version
of -
<CODE>
rdtscll(time1);
sleep(1);
rdtscll(time2);
frequency = time2 - time1;
</CODE>
The use of rdtscll as a long sleep function (above 1 msec) is not very
recommended, since even with the nops, it hogs most of the CPU.
2) The select method is very CPU friendly. It is also the way
microsecond sleep is implemented in xmms and alsa (xmms_usleep, and
doSleep in alsa)
XMMS's code:
unsigned long usec...
<CODE>
struct timeval tv;
tv.tv_sec = usec / 1000000;
usec -= tv.tv_sec * 1000000;
tv.tv_usec = usec;
select(0, NULL, NULL, NULL, &tv);
</CODE>
It's pretty stable for time periods of ~1 msec and above.
In the end I think we'll implement some sort of combination of all the 3
solutions including the kernel HZ value (thanks Gilad, the link was
great!). Since the delay doesn't change often, we have the freedom to
decide which of the 3 functions is best during runtime, and select it.
Hope this will help others.
Ami
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]