Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: [ANNOUNCE] vdr-softdevice-0.0.7pre2



On Wed, Aug 04, 2004 at 10:56:01PM +0200, Stefan Lucke wrote:
> On Mittwoch, 4. August 2004 22:20, Carsten Koch wrote:
> > Stefan Lucke wrote:
> 
> [ .. ]
> > >>		    usleep(2100);
> > 
> > IIRC, the kernel timer has a resolution of 10 ms on Linux/i386,
> > so anything between usleep(1) and usleep(10000) should be the
> > same, right?
> 
> I was thinking on this mail:
> http://www.linuxtv.org/mailinglists/vdr/2004/06-2004/msg00446.html
> 
> > In particular, usleep(1000) and usleep(2100) should have the
> > same effect.
> 
> Someone mentioned that sleeps < 2ms will be executed in a tight loop in
> kernel 2.6 based systems.

The glibc function usleep(3) uses the system call nanosleep(2)
and now simply read the manual page of nanosleep(2), section
BUGS:

       The current implementation of nanosleep is  based  on  the
       normal  kernel  timer mechanism, which has a resolution of
       1/HZ s (i.e, 10 ms on Linux/i386 and 1 ms on Linux/Alpha).
       Therefore, nanosleep pauses always for at least the speci­
       fied time, however it can take up to  10  ms  longer  than
       specified  until  the  process becomes runnable again. For
       the same reason, the value returned in case of a delivered
       signal  in  *rem  is  usually  rounded  to the next larger
       multiple of 1/HZ s.

       As some applications  require  much  more  precise  pauses
       (e.g.,  in  order to control some time-critical hardware),
       nanosleep is also capable of short high-precision  pauses.
       If  the process is scheduled under a real-time policy like
       SCHED_FIFO or SCHED_RR, then pauses of up to 2 ms will  be
       performed as busy waits with microsecond precision.

...

In other words ... usleep(1 ... 2000) do _not_ trigger the scheduler
to get other thread/processes at work, for this a simple sched_yield(2)
or pthread_yield(no man page) should be used.


             Werner

-- 
AC3 loop through sound card http://bitstreamout.sourceforge.net/
Howto http://www.vdr-portal.de/board/thread.php?threadid=1958
------------------------------------------------------------------
 "Having a smoking section in a restaurant is like having
         a  peeing section in a swimming pool." -- Edward Burr




Home | Main Index | Thread Index