[clug] Any Timers Faster than 10ms?

David Gibson david at gibson.dropbear.id.au
Wed Nov 26 11:08:19 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?

If nothing else you'll get milliseconds of delay when the kernel
decides to schedule away from you, so if that hapepned during your
100s of microseconds of wait, I guess you'd be screwed.  So at the
very least I think you'll need to run this as a real-time process, so
you don't get pre-empted when you're not expecting it.

Your best bet for the actual timing may be simply to spin in userspace
- what CPU are you running on, I think a lot of them have
user-accessible timing registers which you could poll to create an
accurate delay loop.  It's pretty wasteful, but if these 100us waits
aren't too frequent, it might be workable.

David Gibson			| For every complex problem there is a
david at gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.

More information about the linux mailing list