[SDL] Timer accuracy

David Olofson david.olofson at reologica.se
Mon Sep 16 09:06:01 PDT 2002


On Monday 16 September 2002 17:21, Latimerius wrote:
> On Mon, Sep 16, 2002 at 04:37:42PM +0200, David Olofson wrote:
> > On Monday 16 September 2002 12:35, Latimerius wrote:
> > > On Mon, Sep 16, 2002 at 10:20:47AM +0200, David Olofson wrote:
> > > > However, very few operating systems support timers that can wake
> > > > up threads, send signals or something like that, with better than
> > > > 10 ms accuracy. This is because of OS scheduler design, and on
> > > > some platforms, there isn't much to do about it. The scheduler
> > > > checks software timers at 100 Hz, and that's it.
> > >
> > > Won't rising of HZ in the Linux kernel help timer accuracy?
> >
> > Well, it *should* increase the resolution of "wake up/signal" style
> > timers, but as gettimeofday() normally uses the TSC when available,
> > that's still theoretically accurate down to the ns range. (Not sure
> > what accuracy the interface actually allows.)
>
> The interface allows for microseconds iirc (struct timeval::tv_usec)
> and at least on Linux/i386 microsecond resolution is actually used.

Right - and I guess you should get close even without a TSC, since main 
board hardware timers are also independent of the OS and scheduler. 
Should always be quite a bit better than 1 ms, I think.


> But is gettimeofday() useful for timers?

No. (Unless you're into busy-waiting hacks, while(...) yield(); looping 
and that sort of stuff, that is.)


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'




More information about the SDL mailing list