CPU overload ?

Started by
3 comments, last by wil_ 14 years, 5 months ago
Hi all, I am developping a small 3d game just using openGL library and sent it to a friend so that he gives me his opinion. I was surprised to hear his CPU was blocked at 100% when running my app, since it's never more than 20% on my PC. What could it mean ? Is there a way I can emulate a smaller config on my PC to see how it looks like ? Shall I try to make my main loop fps-independent (I use a simple "while(1) render();" style loop), would it allow the CPU to rest a bit ? thanks for any suggestions !
Advertisement
Your PC is probably multi-core (at least quad-core, maybe more) so even if you've got one thread running at 100%, that's only 1 core out of many, and so only 25% of your "total" CPU is being used. When you run that same program on a single-core computer, that one thread takes up the whole of that one core, and hence 100%.

In general, you don't want your application to "sleep" when you're trying to render frames as fast as possible. This is expected behaviour.
When your game is running it's most likely the only application the user is looking at, so using 100% CPU is okay. You have no benefit from stalling, and the scheduler will ensure that other background processes gets some CPU time too. So don't worry to much about it.

On the other hand, when your game window looses focus, because the user presses alt+tab or in some other way changes to another window, you might consider playing nice and throttle down. Something like
while( true ) {    if( has_focus ) {        // do logic        // render    } else {        sleep( 1000 ); // pick some suitable interval    }}
That way other apps will still be responsive, even if your game is running in the background.
Quote:Original post by Codeka
Your PC is probably multi-core (at least quad-core, maybe more) so even if you've got one thread running at 100%, that's only 1 core out of many, and so only 25% of your "total" CPU is being used. When you run that same program on a single-core computer, that one thread takes up the whole of that one core, and hence 100%.

In general, you don't want your application to "sleep" when you're trying to render frames as fast as possible. This is expected behaviour.


Most of the time a game shouldn't aim to render frames as fast as possible though, most simple games can run fine on less than 5% of what a modern cpu has to offer so there is no need to let it waste alot of energy. (laptops owners and enviromentalists will thank you).
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Thank you all for your replies, I think I will use a sleep statement because it is not such a big application, it runs in a small window so I'm not surptised if the player opens some other apps at the same time.
What bothers me most is that my friend told me he couldn't move the 3D character on his PC, and when I asked his specs it appears his cpu frequency is bigger and is video card newer. Well, maybe he's making fun of me..

This topic is closed to new replies.

Advertisement