Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0 - CPU/GPU utilization behavior  (Read 6981 times)

0 Members and 1 Guest are viewing this topic.

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
SFML 2.0 - CPU/GPU utilization behavior
« on: January 23, 2012, 12:07:13 pm »
Hi,

Since I started using SFML 2.0 I sometimes, randomly occurring experienced this strange behavior:
When I am testing performance and removing FPS limits I usually have a constant frame rate (lets say 100FPS), and most of the time it keeps going constantly for several minutes (as long as the program was running).
Some other times however, after some time has passed from executing the program (pretty random, sometimes after 5 seconds, other times after a minute) the frame rate suddenly multiplies by 3-4, and after this random event is triggered, the frame rate stays that high. It remains like that even if I restart the game (not by closing the application, but inside the game reloading every file, reinitializing and restarting everything).

This random occurence seems to be independent of the code (running the same executable, this performance boost might or might not get triggered)

I have tried to investigate what might be going on by running a process manager and GPU-Z for GPU load, and this is what I have found out:

During normal performance, I have a ~60% CPU Load, so full load on one core (I have dual core) ,a bit on the other, and 6-8% on the GPU.

After this performance boost is triggered and framerate jumped to 3-4x the CPU Load goes to around 30-35% (huge drop considering the great frame rate increase) and the GPU load goes up to ~35%.

Feels like initially the CPU is doing everything, and after a while, triggered by something, the GPU goes "alright, let me help you out with that", and takes the load off :) (and gives a huge performance boost)

I have no idea what causes this, but I would very much like to be in control of it, as if I could always rely on this increased performance it would make things easier.

I am running Win7 x64, nVidia 8800GTS, intel core2 duo CPU, not sure if relevant.

Please let me know if you have an idea of what could be causing this.

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 - CPU/GPU utilization behavior
« Reply #1 on: January 23, 2012, 12:44:04 pm »
I have no idea, sorry. But it's most likely caused by the driver, not by SFML.

So what you can do is to test other OpenGL apps, that don't use SFML, and see if it happens too.
Laurent Gomila - SFML developer

tobybear

  • Newbie
  • *
  • Posts: 27
    • View Profile
SFML 2.0 - CPU/GPU utilization behavior
« Reply #2 on: January 23, 2012, 01:19:07 pm »
Very strange!
Could be that something is not cached in the GPU or driver, so that the CPU has to send the data again and again. And maybe after some misses the driver decides to activate/increase the cache. Just guessing though :)

As Laurent said, I hardly think this is SFMLs fault, but probably the driver from the graphic card or something else on your system. Have you updated to the latest driver version?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SFML 2.0 - CPU/GPU utilization behavior
« Reply #3 on: January 23, 2012, 09:48:38 pm »
My teacher calls it "Warming up the Cache" :P

No but it probably is that initially that Windows is prioritizing some other process over yours, but since yours application is demanding more and more resources it goes "Alright, you can take over some more time instead". Since even if you have dual core, you will only use one if you have one thread. So if you are using a "little" on the next core, it's not something your doing, that's for sure. Also if you don't have any sleeps in your own code, then if you are not maxing out a core, that means you are waiting for driver calls to finish.

It could also be that it takes the driver that long time to cache everything that you are drawing or whatever optimizations ATI/Nvidia can come up with.

It could also be a combination of them both :)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
SFML 2.0 - CPU/GPU utilization behavior
« Reply #4 on: January 23, 2012, 10:59:24 pm »
Thanks for the responses,

I have just updated my nVidia driver, but it doesn't make any difference.
I am not too familiar with how exactly the GPU cache operates, but it doesn't seem to be like something "normal", since in most cases when this GPU overtake performance boost kicks in, it happens within 3-5 seconds from execution, and other times I am running it for minutes, and it doesn't happen (while a cpu core is running on full load, and the frame rate drops below 60).

This project I am working on was converted from SDL to SFML2.0, and it seems like that currently I get better performance on the SDL build. I have tested the CPU and GPU load on the SDL build, and with that the CPU load is around ~35% (in contrast to SFML's 60%+ without the GPU kicking in) and the GPU load is ~25-30% (in contrast to SFML's below 10% without the GPU kicking in). When this thing is triggered in SFML, the performance is much better on the SFML build than the SDL one.

So I am assuming that this thing that sometimes kicks in, sometimes it doesn't is something that should always happen by default.

I will try running it on another computer when I get the chance, see if this is specific to mine.

EDIT:
The reason this bothers me so much, is that I am trying to make my program get 60FPS, and for that I always have to adjust/optimize the particles, that take most of the resources, yet I know that with this thing getting triggered, the frame rate doesn't fall below even 200.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SFML 2.0 - CPU/GPU utilization behavior
« Reply #5 on: January 23, 2012, 11:24:23 pm »
You do know that SDL can also use DirectX as a backend? Though that doesn't explain the problem.

The only thing I can say is that you probably have something in the background fighting for the graphic card at the same time or something. Can you do automatic tests? That you hard code in a specific behavior in the application and measure the time there. I.E no matter what that the application will always behave the same. If it acts exactly the same and you get a repeatable performance. Then I am afraid it's in your code sir ;)

If the above case is true then you are facing alternating CPU and GPU bound bottlenecks.

If it's not that, then I rest it on that you have something else running that is using the graphics card.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
SFML 2.0 - CPU/GPU utilization behavior
« Reply #6 on: January 23, 2012, 11:25:30 pm »
It's something with Nvidia's graphic card drivers and OpenGL. Having some issues too (Win7 x64; Geforce GTX 295; latest drivers), but these are different and I'm still not sure why this happens. I only know it's not my code, cause other people's programs written with SFML2 show the same thing.

First time I run a SFML2 program after booting Windows, I get very low FPS, something like 3-10 fps max. After ~20-30 seconds this goes away and everything runs at full speed. Don't ask me how/why this happens.

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
SFML 2.0 - CPU/GPU utilization behavior
« Reply #7 on: January 23, 2012, 11:58:47 pm »
Quote from: "Groogy"
You do know that SDL can also use DirectX as a backend? Though that doesn't explain the problem.

The only thing I can say is that you probably have something in the background fighting for the graphic card at the same time or something. Can you do automatic tests? That you hard code in a specific behavior in the application and measure the time there. I.E no matter what that the application will always behave the same. If it acts exactly the same and you get a repeatable performance. Then I am afraid it's in your code sir ;)

If the above case is true then you are facing alternating CPU and GPU bound bottlenecks.

If it's not that, then I rest it on that you have something else running that is using the graphics card.


Thanks for the reply,

The GPU load while I'm not running my program is 0-1%, so I don't think it would need to fight for GPU time. Even if it would, every time I run the SDL build (I am not sure if it uses DirectX or what) it puts ~30% load on the GPU and ~35% on CPU. Regardless of what backend it uses, it would also have to fight for GPU time if something running in the background would hijack the GPU.

To make sure it's not something in my code I will compile one of the SFML1.6 demos in 2.0 (I really doubt it though, I made a very small, simple program when I was first learning SFML2.0 and it happens to that too)