* What is the precision of usleep ?
@ 2001-04-20 18:05 Marcus Ramos
2001-04-22 10:47 ` george anzinger
0 siblings, 1 reply; 3+ messages in thread
From: Marcus Ramos @ 2001-04-20 18:05 UTC (permalink / raw)
To: linux-kernel
Hello,
I am using usleep in an application under RH7 kernel 2.4.2. However,
when I bring its argument down to 20 miliseconds (20.000 microseconds)
or less, this seems to be ignored by the function (or the machine's hw
timer), which behaves as if 20 ms where its lowest acceptable value. How
can I measure the precision of usleep in my box ? I am currently using
an Dell GX110 PIII 866 MHz.
Thanks in advance.
Marcus.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: What is the precision of usleep ?
2001-04-20 18:05 What is the precision of usleep ? Marcus Ramos
@ 2001-04-22 10:47 ` george anzinger
2001-04-23 16:20 ` george anzinger
0 siblings, 1 reply; 3+ messages in thread
From: george anzinger @ 2001-04-22 10:47 UTC (permalink / raw)
To: Marcus Ramos; +Cc: linux-kernel
Marcus Ramos wrote:
>
> Hello,
>
> I am using usleep in an application under RH7 kernel 2.4.2. However,
> when I bring its argument down to 20 miliseconds (20.000 microseconds)
> or less, this seems to be ignored by the function (or the machine's hw
> timer), which behaves as if 20 ms where its lowest acceptable value. How
> can I measure the precision of usleep in my box ? I am currently using
> an Dell GX110 PIII 866 MHz.
>
> Thanks in advance.
> Marcus.
Well, first, your issue is resolution, not precision. Current
resolution on most all timers is 1/HZ. So this should get a min.
nanosleep of 10 ms.
So, could someone explain this line from sys_nanosleep() (
kernel/timer.c):
expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
It seems to me this should just be:
expire = timespec_to_jiffies(&t)
timespec_to_jiffies(&t) seems to do all the needed resolution round up
and such. Since || is logical, this seems to always add 1, except if
the requested value is 0. The net result is you always get 1 extra
jiffie (unless you ask for zero, in which case you get a timer that will
expire next tick (thru the wonders of add_timer).
George
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: What is the precision of usleep ?
2001-04-22 10:47 ` george anzinger
@ 2001-04-23 16:20 ` george anzinger
0 siblings, 0 replies; 3+ messages in thread
From: george anzinger @ 2001-04-23 16:20 UTC (permalink / raw)
To: Marcus Ramos, linux-kernel
george anzinger wrote:
>
> Marcus Ramos wrote:
> >
> > Hello,
> >
> > I am using usleep in an application under RH7 kernel 2.4.2. However,
> > when I bring its argument down to 20 miliseconds (20.000 microseconds)
> > or less, this seems to be ignored by the function (or the machine's hw
> > timer), which behaves as if 20 ms where its lowest acceptable value. How
> > can I measure the precision of usleep in my box ? I am currently using
> > an Dell GX110 PIII 866 MHz.
> >
> > Thanks in advance.
> > Marcus.
>
> Well, first, your issue is resolution, not precision. Current
> resolution on most all timers is 1/HZ. So this should get a min.
> nanosleep of 10 ms.
>
> So, could someone explain this line from sys_nanosleep() (
> kernel/timer.c):
>
> expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
>
> It seems to me this should just be:
>
> expire = timespec_to_jiffies(&t)
>
Oh darn! Must NOT do posts at 4AM!
The standard says nanosleep MUST wait at LEAST the requested time.
Since we are dealing with a 1/HZ time resolution (tick) the actual time
waited MUST fall between 10 and 20 ms. Depending on if your code is
synced to the system clock or not you may see times closer to one end of
this range. If you are not synced to the clock the average wait should
be about 15 ms. (Note, locking to the clock in some way is relatively
hard to get away from. After all this is the same clock that is used
for time slicing.)
George
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-04-23 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-20 18:05 What is the precision of usleep ? Marcus Ramos
2001-04-22 10:47 ` george anzinger
2001-04-23 16:20 ` george anzinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox