Limiting CPU Usage

Limiting CPU Usage

Post by Michael » Thu, 26 Jun 2003 17:44:59



Hi all,

is there a simple way to limit the CPU Usage of an OpenGL Application
other than downscaling the redraw time?

greets Michael

 
 
 

Limiting CPU Usage

Post by Rasmus Christian Kaa » Thu, 26 Jun 2003 18:40:17


Quote:> is there a simple way to limit the CPU Usage of an OpenGL Application
> other than downscaling the redraw time?

If you're using windows then you can release cpu-time by using the Sleep
functions from win32 api.

 
 
 

Limiting CPU Usage

Post by Tetsu » Thu, 26 Jun 2003 19:02:27


It was 25-06-2003 10:40 when Rasmus Christian Kaae said :

Quote:>> is there a simple way to limit the CPU Usage of an OpenGL Application
>> other than downscaling the redraw time?

> If you're using windows then you can release cpu-time by using the Sleep
> functions from win32 api.

Same for Linux I think, by using sleep(long) in a forked process
('thread').. Although I might be wrong.

--
Tetsuo

 
 
 

Limiting CPU Usage

Post by j » Thu, 26 Jun 2003 19:32:36


hej,

also on w32, you can SetPriority
see msdn docs
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmis...
setpriority_method_in_class_win32_process.asp
--
-------------------------------------------------------------
  please tear the sticker off my eddress before use
-------------------------------------------------------------


Quote:> > is there a simple way to limit the CPU Usage of an OpenGL Application
> > other than downscaling the redraw time?

> If you're using windows then you can release cpu-time by using the Sleep
> functions from win32 api.

 
 
 

Limiting CPU Usage

Post by Rob » Thu, 26 Jun 2003 20:32:38



> Hi all,

> is there a simple way to limit the CPU Usage of an OpenGL Application
> other than downscaling the redraw time?

Hang the redraw off a timer and tune it for your usage.

Don't do any drawing when the window is inconised or covered.

rob.

 
 
 

Limiting CPU Usage

Post by Espen Ruud Schult » Fri, 27 Jun 2003 09:42:51



Quote:>>> is there a simple way to limit the CPU Usage of an OpenGL Application
>>> other than downscaling the redraw time?

>> If you're using windows then you can release cpu-time by using the Sleep
>> functions from win32 api.
> hej,

> also on w32, you can SetPriority
> see msdn docs

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmis...

Quote:> setpriority_method_in_class_win32_process.asp

But, consider this.

If you want to limit cpu usage becasue you want to give more cpu time to
other processes, then changing priority is THE way to do it.  Windows will
simply cut back on cpu time for your program, and give more to the other
ones...

However, if you want to limit cpu usage to slow down the program for
whatever reason I can't think of, then changing priority is NOT the way to
do it.  This is becasue if there are no other programs to use cpu time, then
your program will run at full throttle no matter how low priority your
program has...

, Espen

 
 
 

Limiting CPU Usage

Post by Andy Bolstridg » Sat, 28 Jun 2003 02:19:29






> >>> is there a simple way to limit the CPU Usage of an OpenGL Application
> >>> other than downscaling the redraw time?

> >> If you're using windows then you can release cpu-time by using the
Sleep
> >> functions from win32 api.
> > hej,

> > also on w32, you can SetPriority
> > see msdn docs

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmis...

Quote:> > setpriority_method_in_class_win32_process.asp

> But, consider this.

> If you want to limit cpu usage becasue you want to give more cpu time to
> other processes, then changing priority is THE way to do it.  Windows will
> simply cut back on cpu time for your program, and give more to the other
> ones...

that's not 100% true. the task scheduler runs a round-robin schedule of all
tasks that want to run, with the highest priority. If none of them want to
run, then the set with the next highest priority run, and so on.

This means that if you turn your app's priority to 'low' say, it will only
ever run if there are *no* other apps of a higher priority that want to run.

I thought the OP wanted to run his OpenGL (I assume GLUT) apps so they used
no cpu when they had nothing to do, which generally means changing lgut so
it only processes events when there is an event to process, and sleeps the
rest of the time, with maybe a timed event that kicks in periodically.
I know how to do this using SDL, and Win32 events, but not Glut. However,
that's my assumption of what the OP wanted.

Cheers.

 
 
 

Limiting CPU Usage

Post by Rob » Sat, 28 Jun 2003 18:40:18







> > >>> is there a simple way to limit the CPU Usage of an OpenGL Application
> > >>> other than downscaling the redraw time?

> > >> If you're using windows then you can release cpu-time by using the
> Sleep
> > >> functions from win32 api.
> > > hej,

> > > also on w32, you can SetPriority
> > > see msdn docs

<snippage>>

Quote:> I thought the OP wanted to run his OpenGL (I assume GLUT) apps so they used
> no cpu when they had nothing to do, which generally means changing lgut so
> it only processes events when there is an event to process, and sleeps the
> rest of the time,

But that is what an event based system does! no events, nothing happens.
It depends what you are defining as "nothing to do".

Quote:> with maybe a timed event that kicks in periodically.
> I know how to do this using SDL, and Win32 events, but not Glut. However,
> that's my assumption of what the OP wanted.

Set up a timer, and in the timer function, check for "nothing to do"
in your terms. I assume that if e.g. in a game, there has been no
movement etc etc, then the frame to "redisplay" would in fact be the
same as the current frame, and therefore there is no need to redisplay.

So, pseudo-code could be:

        mytimer()
        {
          do we need to update?
          yes
           glutPostRedisplay()
          reset timer   // note, timers are "one-shot"
        }

mind you, all sorts of problems might occur ...

perhaps using the timer to give a "required framerate" might be OK.

In the end it all rather depends on the application ...

Rob.

 
 
 

Limiting CPU Usage

Post by Alex Mizrah » Sun, 29 Jun 2003 04:07:40


Hello, Michael!
You wrote  on 25 Jun 2003 01:44:59 -0700:

 MG> is there a simple way to limit the CPU Usage of an OpenGL
 MG> Application other than downscaling the redraw time?

i was trying to develop opengl program that will do it's task in
background(3d desktop wallpaper for example), and i think i have good
results - i have ~5% cpu load on simple enough scenes(and a lot of this goes
on handing of overlapping windows), with quite smooth animation.

best schema i found is such:
rendering is performed in response to WM_PAINT messages(OnDraw/OnPaint
handlers)

messages are send by separate thread, that also ensures that there is always
some time given to the system:

 while(!ai3d->wanna_die) {
  while(!(ai3d->wanna_die || !ai3d->GetUpdateRect(0)))
   Sleep(3);
  if (ai3d->wanna_die) return 0;
  ResetEvent(ai3d->renderwaitevent);
  //ai3d->RedrawWindow(0,0,RDW_INTERNALPAINT);
  ai3d->Invalidate(0); //that sends WM_PAINT
  WaitForSingleObject(ai3d->renderwaitevent,INFINITE);
  Sleep(6);
 }
 return 0;

and btw, dont forget to turn vsync on.

With best regards, Alex Mizrahi aka killer_storm.

 
 
 

1. O2 High Cpu usage with lossless jpeg

Hi,
  I'm trying to playback high quality 1.0, lossless?, jpeg movies. I
have a process to display the data and another to read the compressed
frames and decompress them with dmic. The read and decompress process at
times uses 65% of the cpu on high quality movies (9MB/second) and about
30% with lower quality movies (3.5MB/second). I think alot of this time
is system as opposed to user time. This cpu usage seems high to me, does
anyone know why? Any ideas on how to reduce this?

Thanks,
Dave

2. More wacom intuos questions. Sorry!

3. PS7 pegs CPU usage at 100%

4. Delphi with SGI OpenGL/Mesa

5. PS6: 70 % CPU Usage for Cursor in Texttool ?!

6. Battletech

7. CPU USAGE

8. Pour me a glass of plug-in

9. CPU usage in openGL application

10. Minimizing CPU/bus usage

11. CPU usage while rendering?

12. Maxed-out cpu usage