Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running idle still costs 30-50% of cpu #137

Closed
villermen opened this issue Jun 17, 2014 · 7 comments
Closed

Running idle still costs 30-50% of cpu #137

villermen opened this issue Jun 17, 2014 · 7 comments

Comments

@villermen
Copy link

I'm clueless as to why a GameWindow uses 30-50% of the CPU when it's just running (having created a simple project that just creates a gamewindow and runs it without parameters.). After doing a few profiler tests I've noticed that System.ni.dll takes up 20% of all the GameWindow.Run samples and another 20% inside of GameWindow.DispatchUpdateAndRenderFrame (64%). This is just findings, and might not have anything to do with it but I'm still curious as to what this is and why it's gobbling up so much CPU.

This relates to my 'Game Engine of sorts' having trouble running smoothly at 100 updates per second and using up to 100% of my 4th core while running idle. Again while profiling System.ni.dll and DispatchUpdateAnRenderFrame seem to be the bottlenecks (this leaves very little room for logic). Also ProcessEvents and especially readbit from keyboards seem to take way more cpu time than needed (but this might be a fault on my part).

Is there anything I am doing wrong here? (Do I not grasp how to use a GameWindow?)

I am on Windows 8.1 64x (32-bit exe) with an i5 at 4x2.79GHz by the way, if that changes anything.

@thefiddler
Copy link
Contributor

GameWindow.Run() without parameters instructs the window to run as fast as possible. This is only useful if you are implementing your own timing scheme and do not want OpenTK to interfere.

If you wish to release CPU time back to the operating system, what you should do instead is:

using (var gw = new GameWindow())
{
    gw.VSync = VSyncMode.Adaptive;
    gw.RenderFrame += (sender, e) =>
    {
        gw.SwapBuffers();
        Thread.Sleep(1);
    };
    gw.Run(60);
}

This will run GameWindow with 60 UpdateFrame events per second and a variable number of RenderFrame events per second (up to the refresh rate of your monitor.) You can use an OpenGL timer query to measure your GPU performance and adjust (or even skip) Thread.Sleep(1) (however note that Sleep(1) may sleep between 10-20 ms, depending on the operating system.)

@winterhell
Copy link
Contributor

When running with empty window, GL.Clear(), SwapBuffer() and Thread.Sleep(1):
VsyncMode.On and VsyncMode.Adaptive cause 33-66% CPU usage on 3 core i5 2500K.(1 core disabled)
VsyncMode.Off reduces CPU usage to 0%.
This is on both GameWindow.Run() and GameWindow.Run(60);

Windows 7 64-bit , GeForce GTX 650, drivers are from this summer. OpenTK 1.1.4.
Tried the above code as well, gave the same result.
Is this a bug, and if not what is the procedure if we want to limit the framerate to a certain cap without occupying the CPU?

@Frassle
Copy link
Contributor

Frassle commented Oct 29, 2014

Looks like this might be an nVidia thing http://stackoverflow.com/questions/21925313/100-cpu-utilization-when-using-vsync-opengl.

Suggestion is that while it says it's using 50% cpu it's actually yeilding control so if something else want to use the CPU it will be able to and the driver will end up at close to 0%.

@stadnitchii
Copy link

I have the same issue, video link: https://www.youtube.com/watch?v=hJf3bTR0Zqo

@mellinoe
Copy link

@Raptor2277 Did you read the discussion above?

@stadnitchii
Copy link

@mellione Yes, I've tried all the things mentioned above. Still the same result.

@varon
Copy link
Member

varon commented Mar 22, 2017

There was a LONG discussion of this in #472

While this may not be EXACTLY the same thing, I'd argue that it's essentially a non-issue.

Most games are going to want to run as fast as possible, and don't particularly mind about potentially maxing out one core.
If they really did care, they'd probably need to implement their own timing anyway, as concluded in #472, which would resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants