High resolution sleep (Linux)

Hendrik van Rooyen mail at microcorp.co.za
Sun May 6 04:15:26 EDT 2007


 "Tim Roberts" <ti.. at pr...o.com> wrote"

> Consider what you're asking here.  The operating system can only age the
> timer list and re-evaluate process ready states when a process goes into
> kernel mode, either by releasing the CPU or hitting the end of its time
> slice.  In order to know that a process has reached the end of its time
> slice, it has to be interrupted by something, typically the timer
> interrupt.

Yes

> 
> In order to provide 10us sleep resolution, the timer interrupt would have
> to fire every 10us.

Not necessarily. see below

>  The overhead of handling the timer interrupt and
> rescheduling that often is quite significant.

Yes

It is also possible to keep the timer list sorted by "expiry date",
and to reprogram the timer to interrupt at the next expiry time
to give arbitrary resolution, instead of implementing a regular 'tick'.
But this also adds overhead and its a PITA to do efficiently, 
using a linked list of "next interrupt time".   So its not normally 
done unless you *really* need it.  Its easier to make a free 
running hardware counter and to read it and do the sums 
yourself, hogging the processor, if you need such fine resolution.

Ten microseconds is not much time - Speed of light is about 
one foot per nanosecond, so that gives ten thousand feet of
travel for a radio wave - less than two miles, or about three
kilometres.

A rifle bullet can travel at around 5000 feet per second.
In ten microseconds it moves six tenths of an inch.
A vehicle at 300 Km/h (about 187 MPH) will not move
as much as a millimetre in that time.

OTOH - if you are trying to make a software radar system to
pick up intruders in your back yard, then ten microseconds
is a hopelessly long time...

- Hendrik





More information about the Python-list mailing list