SDL_Delay() granularity

Is SDL_Delay() on Linux limited to a granularity of 10 ms? I could have
sworn that previously I was able to ask for and get delays of less than
10 ms, but playing with testgl.c I observe that the delay is always 10,
20, … ms. Is my memory playing up again?

Gib–

Gib Bogle @Gib_Bogle
1/44 Arthur St Tel: (64-9) 525-6878
Ellerslie, N.Z. Fax: (64-9) 525-6878

Is SDL_Delay() on Linux limited to a granularity of 10 ms? I could have
sworn that previously I was able to ask for and get delays of less than
10 ms, but playing with testgl.c I observe that the delay is always 10,
20, … ms. Is my memory playing up again?

10 is the minimum, without the aid of a Real Time kernel. Don’t use
SDL_Delay in loops that need to pause for explicit amounts of time, since
even without the 10 ms minimum, you aren’t guaranteed to get an exact
amount…well, with preemptive multitasking you aren’t anyhow, but if you
only need to delay for a few milliseconds, hog the CPU in a busy-loop and
keep checking the current time until you have waited as long as you like.

–ryan.

Do other operating systems like Win32 also have this 10 ms minimum?On Thu, 2002-07-11 at 07:31, Ryan C. Gordon wrote:

10 is the minimum, without the aid of a Real Time kernel. Don’t use
SDL_Delay in loops that need to pause for explicit amounts of time, since
even without the 10 ms minimum, you aren’t guaranteed to get an exact
amount…well, with preemptive multitasking you aren’t anyhow, but if you
only need to delay for a few milliseconds, hog the CPU in a busy-loop and
keep checking the current time until you have waited as long as you like.

10ms is the minimum scheduler timeslice on x86 Linux. This means that if
your process gives up control – or has it taken away by the OS – it’ll be
at least 10ms before you get it back. On Alpha Linux, it’s around 1ms. This
actually may change on intel in the next kernel release, which’ll make
things nice. http://lwn.net/Articles/4228/.

Anyway, the way to cope with this is to SDL_Delay(0) to release to the
scheduler periodically without specifically requesting a pause, and make
your loop timing independent of this delay. If you don’t do this, the
scheduler will see your process as a CPU hog and and schedule you away
anyway, but at times when you weren’t expecting it.On Thu, Jul 11, 2002 at 05:21:04PM +1200, Gib Bogle wrote:

Is SDL_Delay() on Linux limited to a granularity of 10 ms? I could have
sworn that previously I was able to ask for and get delays of less than
10 ms, but playing with testgl.c I observe that the delay is always 10,
20, … ms. Is my memory playing up again?


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/

According to something I just read on the Linux kernel mailing list, Win2k
(at least) has a 10ms timer that can adjust itself on the fly down to 1ms –
but you can’t count on it being that small.On Thu, Jul 11, 2002 at 12:31:56PM +0200, Hongli Lai wrote:

Do other operating systems like Win32 also have this 10 ms minimum?


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/