[linux-audio-dev] gettimeofday() realtime safe?

Lee Revell rlrevell at joe-job.com
Thu Apr 21 14:28:28 UTC 2005


On Thu, 2005-04-21 at 11:28 +0200, David Olofson wrote:
> On Thursday 21 April 2005 07.45, Jack O'Quin wrote:
> [...]
> > > Is calling gettimeofday this many times in the realtime thread a
> > > wise idea?
> > 
> > How often?  Once per MIDI event?  That should be OK, I suppose.
> 
> I did a quick hack for testing some custom hardware on an embedded 
> system, where I just polled gettimeofday() to get some code to run at 
> 10 kHz. (Didn't care about the occasional stalls - which were very 
> few anyway, as this was the only process actually doing anything at 
> the time.) That is, a bunch of gettimeofday() calls for each loop, 
> times 10 kHz. Worked just fine.
> 
> This was on a 300 MHz low power Pentium clone, which has about 10-15% 
> of the power of a 1 GHz P-III CPU. I'm not even sure if Linux is 
> using RDTSC for gettimeofday() on this thing...

Yes, Linux implements gettimeofday via rdtsc() on x86.   I think it may
use the ACPI PM timer under some conditions also.  Which is why if you
can get away with just using rdtsc directly for timing it's better than
gettimeofday.

Lee




More information about the Linux-audio-dev mailing list