CPU Time in XNA

Started by
5 comments, last by iEat_Babies 12 years, 8 months ago
I'm playing with Game Studio 4.0 following along in a book and I notice when I run this simple app one of the CPU's is pegged at 100%. I turn on vsync by setting SynchronizeWithVerticalRetrace to true and I'm still running 100% CPU. So I count the updates, draws and time the updates, draws and app time. I get 1385 draws and 1389 updates in 23.652s getting just short of 59 fps as I would expect. I'm taking about 0.1ms to draw a frame and 0.02ms to update it though. Sure, I have two real cores and four pretend ones, but I would rather not heat the cpu needlessly.

How do I get XNA, Game Studio, whomever is responsible from chewing up CPU needlessly?
Keys to success: Ability, ambition and opportunity.
Advertisement

I'm playing with Game Studio 4.0 following along in a book and I notice when I run this simple app one of the CPU's is pegged at 100%. I turn on vsync by setting SynchronizeWithVerticalRetrace to true and I'm still running 100% CPU. So I count the updates, draws and time the updates, draws and app time. I get 1385 draws and 1389 updates in 23.652s getting just short of 59 fps as I would expect. I'm taking about 0.1ms to draw a frame and 0.02ms to update it though. Sure, I have two real cores and four pretend ones, but I would rather not heat the cpu needlessly.

How do I get XNA, Game Studio, whomever is responsible from chewing up CPU needlessly?


I personally dont know much at all about XNA, but most games are designed to use 100% of the CPU. I assume that XNA would be the same.
Chances are you have code in the draw function that is doing lots of cpu intensive calculation. move it into the update method, and avoid doing calculation in draw(). This should lower cpu use, if it is still high maybe your pc or graphics card is underpowered to run the program? Can you paste source?

Chances are you have code in the draw function that is doing lots of cpu intensive calculation. move it into the update method, and avoid doing calculation in draw(). This should lower cpu use, if it is still high maybe your pc or graphics card is underpowered to run the program? Can you paste source?


The draw function is using 0.1ms per frame. The update function is using 0.02ms per frame. The GPU is running at about 2%-3% utilization. Only about 0.6% of the time the application is running is spent in my code. Yes, traditionally you said CPU utilization didn't matter, frame rate did. That was before 130W worth of CPU and 600W worth of GPU's. Burning CPU needlessly takes on a quite literal meaning.
Keys to success: Ability, ambition and opportunity.

I'm playing with Game Studio 4.0 following along in a book and I notice when I run this simple app one of the CPU's is pegged at 100%. I turn on vsync by setting SynchronizeWithVerticalRetrace to true and I'm still running 100% CPU. So I count the updates, draws and time the updates, draws and app time. I get 1385 draws and 1389 updates in 23.652s getting just short of 59 fps as I would expect. I'm taking about 0.1ms to draw a frame and 0.02ms to update it though. Sure, I have two real cores and four pretend ones, but I would rather not heat the cpu needlessly.

How do I get XNA, Game Studio, whomever is responsible from chewing up CPU needlessly?


How do you calculate all the information ? total draws and updates, how much it takes to draw and how long o update , how you did that?
Muhammad Kashif Shabbir

I'm playing with Game Studio 4.0 following along in a book and I notice when I run this simple app one of the CPU's is pegged at 100%. I turn on vsync by setting SynchronizeWithVerticalRetrace to true and I'm still running 100% CPU. So I count the updates, draws and time the updates, draws and app time. I get 1385 draws and 1389 updates in 23.652s getting just short of 59 fps as I would expect. I'm taking about 0.1ms to draw a frame and 0.02ms to update it though. Sure, I have two real cores and four pretend ones, but I would rather not heat the cpu needlessly.

How do I get XNA, Game Studio, whomever is responsible from chewing up CPU needlessly?


I noticed this too, one of my cores on my CPU would be close or at 100% even though the game was hardly doing anything. Also I noticed that when I played Terraria, which uses XNA, I would also get 100%-ish usage on one of my cores. So then I googled the problem and a few other people mentioned that this was happening to them, but no fix though. So I just accepted it and knew it would probably run just fine on other computers, hah.

Edit: This doesn't happen when playing XNA games on the windows phone ( Edit 2: emulator), though.

[quote name='LilBudyWizer' timestamp='1311567499' post='4839843']
I'm playing with Game Studio 4.0 following along in a book and I notice when I run this simple app one of the CPU's is pegged at 100%. I turn on vsync by setting SynchronizeWithVerticalRetrace to true and I'm still running 100% CPU. So I count the updates, draws and time the updates, draws and app time. I get 1385 draws and 1389 updates in 23.652s getting just short of 59 fps as I would expect. I'm taking about 0.1ms to draw a frame and 0.02ms to update it though. Sure, I have two real cores and four pretend ones, but I would rather not heat the cpu needlessly.

How do I get XNA, Game Studio, whomever is responsible from chewing up CPU needlessly?


I noticed this too, one of my cores on my CPU would be close or at 100% even though the game was hardly doing anything. Also I noticed that when I played Terraria, which uses XNA, I would also get 100%-ish usage on one of my cores. So then I googled the problem and a few other people mentioned that this was happening to them, but no fix though. So I just accepted it and knew it would probably run just fine on other computers, hah.

Edit: This doesn't happen when playing XNA games for the windows phone, though.
[/quote]


I just read an article about power usage on the Windows Phone. There is this section that applies to what you are discussing:


[color="#333333"][font="Arial"]On Windows or Xbox, battery life is irrelevant. The machine has a certain amount of power available, and you might as well use all of it. If your Update and Draw methods take less than 1/60 second to execute, that means you are wasting processing power that could be used to add more funky effects.[/font]
[color="#333333"]
[color="#333333"][font="Arial"]Pedantic readers may wish to point out that battery life does matter for Windows laptops. True, but there's not much you can do about it. If a Windows game has spare CPU cycles the XNA Framework just busy-waits until the next tick time. We have to do that because the Windows task scheduler has a rather coarse time granularity. If we put the CPU to sleep, there is no guarantee it will wake up exactly when we want. So on Windows, if you add sleep calls in the interests of power efficiency, you can no longer guarantee a steady framerate.
[/font]
[color="#333333"][font="Arial"]Not so on Zune, which has the ability to sleep for tiny and exact periods of time. So on Zune, if your game uses fixed timestep mode and Update plus Draw finish in less than the allotted time, the framework works out when the next tick is due, then puts the CPU to sleep for exactly the right period. In other words, the less work your code does, the less battery it will use.[/font][/quote]

Here is a link for the whole article:
http://blogs.msdn.co...efficiency.aspx


This topic is closed to new replies.

Advertisement