[clug] Any Timers Faster than 10ms?

Martijn van Oosterhout kleptog at svana.org
Wed Nov 26 10:30:32 EST 2003


On Wed, Nov 26, 2003 at 09:55:56AM +1100, Carter, Michael wrote:
> Hi all,

> I'm trying to write some software for Linux that has some pretty accurate
> timing requirements. I know that in userspace you can get timers to wake
> up processes, but this seems to only be with a granularity of about 10ms,
> which is apparently how often there is a timer interrupt on IRQ0. However,
> what I'd really like is to be able to perform a task, sleep for a few
> hundred microseconds, and then perform another task. Are there any more
> accurate timers available in the kernel? Perhaps a timer exisits in an
> ordinary i386 architecture that can offer interrupts at a faster rate? Can
> I use gettimeofday() in anything other than a busy wait?

There is nanosleep() but like you say, I don't know the granularity. When
the kernel intends to sleep for such short periods, it tends to busy wait.
Basically a little loop which reads the TSC on the chip and waits until a
certain number of cycles has passed. This needs to be calibrated to the chip
speed but that value is somewhere in /proc IIRC.

Hope this helps,
-- 
Martijn van Oosterhout   <kleptog at svana.org>   http://svana.org/kleptog/
> "All that is needed for the forces of evil to triumph is for enough good
> men to do nothing." - Edmond Burke
> "The penalty good people pay for not being interested in politics is to be
> governed by people worse than themselves." - Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.samba.org/archive/linux/attachments/20031126/7d31851a/attachment.bin


More information about the linux mailing list