Sign in to follow this  
LilBudyWizer

CPU Time in XNA

Recommended Posts

LilBudyWizer    491
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?

Share this post


Link to post
Share on other sites
taliesinnz    231
[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?
[/quote]

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.

Share this post


Link to post
Share on other sites
braindigitalis    18902
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?

Share this post


Link to post
Share on other sites
LilBudyWizer    491
[quote name='braindigitalis' timestamp='1311589514' post='4839930']
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?
[/quote]

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.

Share this post


Link to post
Share on other sites
yaKashif    99
[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?
[/quote]

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?

Share this post


Link to post
Share on other sites
beatlefan    198
[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?
[/quote]

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.

Share this post


Link to post
Share on other sites
iEat_Babies    102
[quote name='beatlefan' timestamp='1312056930' post='4842623']
[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?
[/quote]

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:

[quote]
[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]
[color="#333333"] [/color]
[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]
[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 [url="http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx"]fixed timestep mode[/url] 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][/color][/quote]

Here is a link for the whole article:
[url="http://blogs.msdn.com/b/shawnhar/archive/2008/12/02/zune-battery-efficiency.aspx"]http://blogs.msdn.co...efficiency.aspx[/url]


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this