lathoub's picture

High CPU usage on some demo's (Win7, 64bit)

Project:The Open Toolkit library
Version:1.0.0-rc1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:confirmed
Description

Hello,

Some demo's in the samples stack have a very high CPU usage (Win 7, 64bit - GeForce 9600M GT)
Eg the "Threaded Rendering" in OpenTK examples from the The Open Toolkit Sample Browser indicates 95% CPU usage, just spinning a cube.
The same for "Simple GLControl Game Loop" with CPU usage around 50%.

"Simple GLControl" and "Multiple GLCOntrols" show almost no CPU usage.
"OpenGL 3.0" example from the OpenGL samples also shows very little CPU usage.

What could be causing the high CPU usage? (Multi threading?)

Thanks for looking into this.
Bart

Hardware:
1) Macbook Pro, Windows 7 64bit, nVidia GeForce 9600M GT


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Status:open» confirmed

Thanks for the bug report, I am cleaning up the samples for RC2 to fix issues such as these. The cause of the high CPU usage will become obvious if you consider how a game loop works in its most simple form:

while (true)
{
    Update();
    Render();
    SwapBuffers();
}

By default, this will all CPU time of one core (which translates into 100% for a single-core CPU, 50% for a dual-core, etc). To reduce CPU usage, you can either add a call to System.Threading.Thread.Sleep() after SwapBuffers or enable VSync. On the other hand, samples that don't use a game loop (like SimpleGLControl and Multiple GLControls) don't need this: like regular GUIs they spend most of their time waiting for a Paint message to arrive.

lathoub's picture

#2

Thanks for the reaction Fiddler.
Indeed, i forced the VSync to 'On' in de driver of my video card, and the CPU usage of the game loops drops practically to zero.

But not so with the Threaded Rendering sample, both CPU are at almost 100% just to spin a cube around. The Multithreading Test with 2 windows has a CPU usage of 50% on both CPU's. If i close 1 window, CPU on 1 CPU drops to 30%, the other remains at 50%.

Is this behaviour you are also seeing?
I have not noticed this before (on Vista), until i switched to Windows 7 64bit. I tried switching off Aero, but that does not change the CPU usage.
Same results on a i7 with a Quadro 5600 (1 CPU at 100%, 2 at 50% and 1 at 30%), this on a Windows 7 32bit

Can someone test this on XP and see if they get the same result?

Thanks
Bart

the Fiddler's picture

#3

Quote:

But not so with the Threaded Rendering sample, both CPU are at almost 100% just to spin a cube around.

That is because we have two rendering loops, an empty one spinning at 100% (on the main GameWindow thread) and a second one drawing the cube(*) (with vsync disabled, IIRC, which means it is also spinning at 100%). In short, this is a programming "error" (or oversight, depending on your point of view).

Quote:

Can someone test this on XP and see if they get the same result?

While I don't have a native XP installation anymore, I am seeing similar behavior on Linux (Ubuntu 9.10, amd64 ). I'm cleaning up and documenting the samples as time permits, will check Multithreading Test in due time.

(*) in SVN this has been replaced by a much better sample, I was starting to grow tired of cubes!