We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 496 - SDL_delay is a cpu hog
Summary: SDL_delay is a cpu hog
Status: RESOLVED WORKSFORME
Alias: None
Product: SDL
Classification: Unclassified
Component: timer (show other bugs)
Version: 1.2.12
Hardware: x86 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-28 19:44 UTC by Sylvain Bougerel
Modified: 2009-09-13 15:33 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Bougerel 2007-09-28 19:44:12 UTC
I understand that the goal of SDL_Delay is to decrease CPU load. But it doesn't work on my machine.

I have seen many similar comments on the net, but no bug was posted. Apparently for Windows users, the function works, but for my Linux box, no matter what delay I pass as a parameter to SDL_Delay, it just tops my CPU usage to 100%.

I've read some thread where some people argue that it's normal, but I am writting a very simple tetris-clone (as a practice) on my laptop, and it's a problem to have a CPU heating up just for a tetris game.
Comment 1 Sylvain Bougerel 2007-09-28 21:33:04 UTC
Hi,

I just realized that there is a small range of values that doesn't hog the CPU: from 33 to 41 milliseconds exactly; 41 resulting in the lowest CPU usage (~4%); 33 the highest CPU usage (~60%).

Outside this range, CPU usage is at 100%. I get the feeling that these values depend on my machine. Is there a way to make this portable to other machines (including windows platforms)?
Comment 2 Sam Lantinga 2007-12-29 12:39:02 UTC
Have you tried inserting debug output to see what's going on?  If you want, I can log in and see if I can help debug this.  Please send me e-mail directly at slouken@libsdl.org if you would like me to check it out on your system.
Comment 3 Ryan C. Gordon 2008-01-02 13:07:22 UTC
I have a suspicion that this happens with the CK kernel patches. We saw similar things in the Call of Duty 4 and Unreal Tournament 3 dedicated servers; they should use around 0% CPU when no one is playing on the box, but the CK patches were running at around 75% CPU for this idle state. My guess is that it decides to "idle" a process when waiting on i/o, but just reschedules the process immediately if there's nothing to do and it's otherwise sleeping...it probably results in better performance (that is, lower latency) at the cost of cooking the CPU more.

This is just a guess, though.

--ryan.

Comment 4 Ryan C. Gordon 2009-09-13 15:33:49 UTC
Resolving bug as WORKSFORME...I'm sticking with my guess that it was a CK scheduler.

--ryan.