Do I need Delay(1) on AMD?

BlitzMax Forums/BlitzMax Programming/Do I need Delay(1) on AMD?

Grey Alien(Posted 2006) [#1]
It was brought to my attention with Easter Bonus and now my new Game Framework demo that if you bring up task manager in full-screen mode, the CPU useage is 100% (ish) on AMDs and only 50%(ish) on Pentiums (well on my Hyperthreading P4 3.2GHz anyway). This may mean that windows struggles to do background tasks and could be causing/accentuating and stuttering problems on smooth moving graphics. Someone a while ago suggested using Delay(1) in the main loop.

So does anyone have more info about this, and is delay(1) enough? It seems a bit lame to have to give up 1ms per frame, esp if someone is running at 100Hz, you only have 10Ms to play with per frame! Maybe there is a neater way to do this?

Also is there a way to detect if the CPU is AMD not Intel and only switch the delay on for AMD CPUs?

Here's my framework demo to test how it affects your CPU useage in full-screen mode http://www.greyaliengames.com/aotmg/aotmg.zip (3.93Mb)

I'd really appreciate any feedback people can offer, thanks in advance.


Robert Cummings(Posted 2006) [#2]
use delay 1000


Yan(Posted 2006) [#3]
I not sure if it's a help or a hindrance, but my CPU usage peaks at about 40% when running your framework demo (v4).


Grey Alien(Posted 2006) [#4]
OEJ: Is that a joke?

Ian: hmm, thanks, I didn't get reports of that maxing out the CPU though. Did you press A in full-screen mode to turn on the Anti-lag fix? Did that change the CPU useage?


Dreamora(Posted 2006) [#5]
In fact its the P4 having the problem, not the AMD one :-) Blitz Products don't support HT, so only 50% of the P4 is used, as Blitz does not know of the existance of the full processor (HT are 1 core as well with a virtual cpu ... which simply means: you need a twice as fast HT processor to get the same resultas non HT if you are using any Blitz, unless HT is disabled in bios)


Damien Sturdy(Posted 2006) [#6]
I need "Delay 1" in most of my projects- the sound struggles otherwise.

I've not had any problems with your stuff though Grey...


Robert Cummings(Posted 2006) [#7]
Yes it was a little joke.

The problem you're having I think, is an illusion. The intel processor has two virtual processors. It isn't multiple core but hyperthreaded intels have two virtual ones to the system. Could this be why?

I have a dual core so my results are meaningless to you.


Grey Alien(Posted 2006) [#8]
hmm OK so only half my CPU use is reported, I did suspect this. OK, but Daz has said the music pauses in my demo and he gets stutters, he has an AMD and I thought it might be that. I KNOW my timing is cool, it's just hardware and OS stuff I'm battling against now.


Yan(Posted 2006) [#9]
DOH!...You said full screen mode...Yeah, 100% CPU usage here too.

Sorry about that. :o/


Grey Alien(Posted 2006) [#10]
s'OK. I like to double check stuff but there is a thin line between that and offending someone who has already done it correctly. So did A have any effect or not? Anyway looks like we've figured out that really all CPUs *should* show 100% unless they hyperthread. Wonder what dual cores show, any ideas?


Dreamora(Posted 2006) [#11]
To get around the 100% usage:
Switch to event based programming, using timers and the input events. You don't need MaxGUI to use events (just if that is a reason not to try it with it :-) )

Using delay is nice, but it has its drawbacks due to the full app blockage.


Grey Alien(Posted 2006) [#12]
hmm, not sure I want to use timers at all, that will screw up everything. But I understand what you are getting at.


Yan(Posted 2006) [#13]
I like to double check stuff but there is a thin line between that and offending someone who has already done it correctly. So did A have any effect or not?
Hmm...I'm not sure how I'm supposed take that?

In light of my mistake, I didn't see that my results would be any different to the ones you already had, and therefore, relevant.

Anyway...

Enabling or disabling the lag fix had no effect on CPU usage in windowed or full screen mode.


smilertoo(Posted 2006) [#14]
the hyperthreading is a gimmick thats being dropped anyway, it didnt really give 2x speed, it let things runs smoother and a bit faster if the processes were different.


Dreamora(Posted 2006) [#15]
If you use timer + event based, this is not the same like waittimer.

But you can call rendering time based (as if you would do it by time differences). The main difference on that approach is, that if nothing happens and nothing has to be rendered, then the program has 0% cpu usage! (and if you do it intelligently, you will get up to 300k mainloop runs at 60FPS and that on a 1,5ghz with radeon 9700) *ok not much going on, but just to show the difference we are talking of here*

Side effect of this technique is as well, that you don't have the so called mouse lag problem which just happens because of 300+ frames actually drawed although its totally pointless (just wastes a lot of cpu time with rendering instead of a more dynamic world)


Grey Alien(Posted 2006) [#16]
Ian: I wasn't trying to say anything about you, hope you didn't take offence. I was just saying I like to double check, but in my experience, some people don't like being asked to double check, esp. when they think they've done it correctly anway. You DID double check and got back to me which is great thanks. Shame the test made no difference. Oh well.


Kuron(Posted 2006) [#17]
It was brought to my attention with Easter Bonus
FWIW, In B+, when using "graphics mode", whether windowed or full-screen, it is best to still use the event stuff to keep your game from hogging the CPU.


Grey Alien(Posted 2006) [#18]
Thing is, if you are going to make an action game that scrolls every frame, and redraws everything that's moving, it's going to hog a lot anyway. But I guess you are saying that any gaps at all can be used by windows then. Regretably, my whole game structure is NOT using events, just a loop doing logic, input (KeyDown, MouseHit etc) and drawing.


boomboom(Posted 2006) [#19]
[edit - removed. Sorry I am insanely Tired]


Yan(Posted 2006) [#20]
Hehe...No probs GA, the most innocent of remarks can be easily interpreted in the wrong way. It's the nature of text only communication. :o)


Grey Alien(Posted 2006) [#21]
Ian: yeah I know it can make you quite paranoid at times.


TomToad(Posted 2006) [#22]
With VSync off, the app used about 95% of the CPU. With VSync on, I use about 2%. pressing A makes no noticable difference. CPU is an AMD XP2400+


FlameDuck(Posted 2006) [#23]
Regretably, my whole game structure is NOT using events, just a loop doing logic, input (KeyDown, MouseHit etc) and drawing.
You may want to rethink that. Event/Hook based programming is more difficult, but it is the 'correct' way to go, seeing as it's the one that's most 'modern OS' friendly.


Grey Alien(Posted 2006) [#24]
Thanks for the info TomToad. "A" is not programmed into this demo which is why it did nothing :-)

you may want to rethink that
Yeah, seems like a bummer though, sigh, we'll see.