Re: Can't sleep less than 20 ms

Bernd Paysan (bernd.paysan@gmx.de)
Mon, 05 Jul 1999 11:51:49 +0200


Rogier Wolff wrote:
> Clock interrupts + + + + +
> App is waken up: * * * *
> app calls usleep (9000) ^ ^ ^ ^
>
> it will only sleep for 2ms before getting woken. And the manual states
> that the sleep will be -=* at least *=- the number of microseconds
> requested, and that you should always be prepared to be woken a little
> later due to scheduling overhead or other tasks running.

I hate to cite it, but people should read the manpage before they
implement something. The manpage of select is quite clear about what the
timeout means:

"timeout is an upper bound on the amount of time elapsed
before select returns."

Thus select should return *before* timeout expires. Well, it doesn't
need to return if the process is descheduled, or if it takes more time
to calculate the result than timeout was set to, but IMHO select should
not wait at all for timeout between 0 and 10 ms, wait for up to 10 ms
for a timeout between 10 and 20 ms*... or even better, incorporate the
microsecond patch which allows a much finer grain for requested
timeouts, at the cost of a less accurate clock (or uses the processor's
timer register if available).

*) more correct would be to look if there is a timer interrupt before
the expire time, and schedule the wakeup at that timer interrupt. Thus
if the next timer interrupt is due in 2 ms, a 2 ms timeout is ok to
sleep for.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/