100% CPU usage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

100% CPU usage

Post by Midnight »

Ok I understand Irrlicht updates like every second or something.

It's a rendering engine it makes sense.

But my menu only requires the GUI be updated every so often and even without a scene manager implimented it still uses 100% of the available cpu to update the GUI. (or at least I think thats whats happening)

So the question is, how can i reduce the cpu usage?
Guest

Post by Guest »

my irrlicht applications only use 50%-56% cpu usage. i guess you cannot turn it off.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

well how to you obtain that?

I have a 2.4 pentium with exact stats as yourself almost.


unless your gpu is pci and helps your cpu.. how do you do that? lol
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

in winblows only, put a short Sleep() in your main loop.
I dunno what the equivelant in linux is though
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

thanks I knew it was something like that.

couldn't seem to find anything on google.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

thanks that worked AWSOME.. the frames per second have gone down 1/3 but the cpu usage drop is Dramatic it's using 0% cpu when idle and thats with direct x 9 and the 3d background... other then the fps drop I see no reason not to do it this way.
MBA
Posts: 4
Joined: Tue Jul 26, 2005 9:46 am

Post by MBA »

hi

just for completenes, the equivalent to the windows Sleep() on a *nix system is the usleep().
The sleep() defined in unistd.h has only seconds precision while the usleep() takes a msec argument. The highest precision is about 10 msec dependent on the granularity of the linux scheduler. When performing a usleep your process is rescheduled and the Linux scheduler (for the x86 architecture) usually takes at least about 10-30 milliseconds before it returns control to your process.

best regards
mba
Andreas
Posts: 166
Joined: Sun Oct 31, 2004 7:15 am
Location: Münster / Germany
Contact:

Post by Andreas »

I think the disadvantage of using a sleep is, that the game will run slow on less powerfull machines. :?

Or is there a way to determine the sleep argument (i.e. sleep for 1, 2, 3,... seconds) depending on the CPU speed??
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

so let me get this straight usleep() works on both windows and linux?

so it's good to use this instead?
luckymutt
Posts: 453
Joined: Sun Mar 06, 2005 11:56 pm
Location: C-Ville

Post by luckymutt »

put a short Sleep() in your main loop.
is there a parameter that goes with this? expressed in time(ms) or something?

when its running at 400+ fps to begin with, I don't see how a 30% drop in the frame rate would be a big deal.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

thanks MBA... I'll push it one further with a half-arsed preprocessor macro then :)

Code: Select all

#ifdef LINUX
#include <unistd.h>
#define Sleep(x) usleep(x)
#else
#include <windows.h>
#endif
luckymutt- yes, it's "Sleep(time_in_ms)". Andreas, see this thread for frame limiting info http://irrlicht.sourceforge.net/phpBB2/ ... php?t=8246
MBA
Posts: 4
Joined: Tue Jul 26, 2005 9:46 am

Post by MBA »

so let me get this straight usleep() works on both windows and linux?
so it's good to use this instead?
The unistd.h defines standard routines used in a unix environment, and it contains unix specific code. You probably wouldn't use it on a windows machine.


"Do not #include <unistd.h> as it contains UNIX-specific definitions. At the very least, check with your Windows environment before using functions or constants from <unistd.h>."

From:
http://www.opengl.org/resources/tutoria ... de389.html


But you would use it when doing something portable like the portable-macro bitplane was suggesting
Fred

Post by Fred »

How many ms are you sleeping?
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

#ifdef LINUX
#include <unistd.h>
#define Sleep(x) usleep(x)
#endif
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif


so then would this be proper?

I'm sleeping Sleep(50); for the menu which is only GUI (no 3d not even a scene manager)

and I'm sleeping Sleep(10); for the Guice application to reduce the lag to a minimum where the menu has a touch of lag but really it doesn't seem to hurt anything and reduce cpu to almost nothing.

I have another question will it lag more on a slower system then my own?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

sleep(0) is commonly used in threading models. What it does for a thread is drops the cswitch which allows other threads to start running.
Image
Post Reply