[alsa-devel] need help with io plugin programming: how to add delay ?
broonie at opensource.wolfsonmicro.com
Wed Dec 23 18:40:10 CET 2009
On Wed, Dec 23, 2009 at 06:08:06PM +0100, Stefan Schoenleitner wrote:
> However, right now I found out that there seems to be no way
> to execute *anything* each 20ms +/- 1ms.
> So far I tried
> * nanosleep()
> * pthread_cond_timed_wait()
> * usleep()
> I'm looking forward to try
> * HPET
> * RTC
> * setitimer()
> * alsa timers ?
> * anything else ?
I'd be somewhat surprised if any of them do any better to be honest. A
brief glance at the AT91 RTC drivers suggests they don't implement any
sort of high resolution tick, HPET is an x86 thing and the others are
likely to be implemented in terms of the same underlying constructs as
the things you've tried already.
> I don't understand why all the function I have tried
> so far have microsecond or even nanosecond precision and in the
> end I'm off not for some nano- or microseconds, but for a full 15ms !
> This is really bad :(
These APIs are all standards based ones. The time units they use are
deliberately chosen to be much smaller than might have realistically
been used on systems when they were specified to allow room for systems
with highly accurate timers that might come along, but they're all
specified in terms of a minimum requested delay rather than a guaranteed
Much of the timing in Linux is based of HZ, which is often set quite low
for power reasons. As well as the scheduler it's probably also worth
asking the AT91 port people how to get the best out of the hardware. It
may be that some work is needed to hook the port into the kernel time
framework to better use the capabilities of the hardware, for example.
More information about the Alsa-devel