Re: sleep() API behaves differently in Linux 2.4 and Linux 2.6



On 2007-02-28, bizhan.gholikhamseh@xxxxxxxxx <bizhan.gholikhamseh@xxxxxxxxx> wrote:

I have a simple program utilizing "sleep()" api to sleep 3
msec periodically.

No, you don't. You have a program that uses select() api to
sleep at least 3ms periodically.

I measured the time difference before calling the api and
after it returns back.

The same application behaves differently running on Linux 2.4
and 2.6 In Linux 2.6.11, it takes about 3 msec, and running on
Linux 2.4.20 it takes about 10 msec.

The default system timer tick on 2.4 kernels was 10ms. With a
10ms tick, 10ms is the minimum amount of time you can sleep.

On 2.6, most systems use a 1ms or 4ms timer tick. The system
on which you tested must have been configured for 1ms. Some
2.6 systems might still be configured for 10ms.

Unfortunately, the man page for select() is incorrect. timeout
is not an upper bound on the the amount of time elapsed before
select() returns (as is stated on the man page).

timeout is actually a lower bound on the maximimum time slept
in the case where the selected events do not occur and the
system call is not interrupted. In that case the amount of
time slept will be a multiple of the system tick time that is
greater than or equal to the specified timeout. On a busy
system it could be many ticks larger than the specified
timeout.

Expecting it to be precisely 3ms is futile.

--
Grant Edwards grante Yow! PUNK ROCK!! DISCO
at DUCK!! BIRTH CONTROL!!
visi.com
.



Relevant Pages

  • Re: question about thread scheduling
    ... I doubt you will need to mess with the system tick to get what ... I will try what you suggested, the reason that I didn't use the sleep ... If the NN run in a different thread as the control loop ... Sleepputs your thread to sleep for 3 timer ticks and ...
    (microsoft.public.windowsce.platbuilder)
  • Re: nanosleep returning early
    ... most of the sleep time. ... best known approximation to the, er, real time, but most other times are ... Adding 1 to the tick ... nanosleep(), because they get in sync with clock interrupts. ...
    (freebsd-current)
  • I urge you to have a Lyme Western Blot...
    ... sleep in the middle of whatever she is doing. ... I have two places on my leg that get sore at times. ... uncontrollable sleeping. ... Your leg discomfort is not secondary to a tick bite that occurred 20 ...
    (sci.med.diseases.lyme)
  • Re: semTake .. millisecond/microsecond waits
    ... The semTake would return on a timeout between a min of 0 and a max of 0.0166666... ... Since you can't know how far away the next clock tick is, the time that you actually get for the timeout can always be just less than 1 tick of what you asked. ... With the default system clock rate of 60 hz, this will timeout after a minimum of 0.100 and a max of 0.116666... ...
    (comp.os.vxworks)
  • Re: question about thread scheduling
    ... If the solution with Sleep, SleepTillTick and GetTickCount does not work for you and you are using normal CEPC, you can also take a look at http://msdn2.microsoft.com/en-us/library/ms836797.aspx which is an old technical article, but will give you a good idea on how to achieve what you want. ... I doubt you will need to mess with the system tick to get what you want though. ... If the NN run in a different thread as the control loop ... Sleepputs your thread to sleep for 3 timer ticks and ...
    (microsoft.public.windowsce.platbuilder)