Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » cpu fps etc...

This thread is locked; no one can reply to it. rss feed Print
 1   2 
cpu fps etc...
Goalie Ca
Member #2,579
July 2002
avatar

He must be referring to the fact that people assume volatile is atomic. That is it reads, processes, and writes back.

I think of Volatile as the (sort of) opposite of "register". That is, this is not to be cached in a register. Write-through!!! Read too!

-------------
Bah weep granah weep nini bong!

bamccaig
Member #7,536
July 2006
avatar

Thanks, Goalie Ca! My raw Allegro timer example uses approximately 20% CPU. The modified version implementing pthreads/semaphores is using 3-5% CPU. :D

** EDIT **

I may have spoken too soon. The 20% CPU usage was seen on another system. My home system is actually using a very similar amount of CPU with raw Allegro timers... :-/

Thomas Fjellstrom
Member #476
June 2000
avatar

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

I may have spoken too soon. The 20% CPU usage was seen on another system. My home system is actually using a very similar amount of CPU with raw Allegro timers... :-/

rest() will vary from system to system. It is dependant on the operating system scheduler. It may even vary from session to session. Might vary if you run it in win2k instead of vista.

I also wonder about pthread performance on windows. Windows does not have native posix threading. Windows threads will have to be "Wrapped" in order to have the necessary behaviour.

I can take my code and run it on a junker linux system and it will use < 1%.

-------------
Bah weep granah weep nini bong!

Kitty Cat
Member #2,815
October 2002
avatar

BTW, is there a way to do this without relying on an Allegro timer? It's just that if you're trying to move away from a while(waiting) rest(1); loop, that's basically what Allegro's timers do. Though the timer thread does attempt to use precise resting, and calculating the rest time 'til it needs to wake up next, it still won't get any more accurate than 75 to 100 fps (since once it goes to sleep, the thread won't wake up again for about 10ms, which maxes you out at 100 tics per second; and if you're trying for 100fps, then you're not getting any better than a rest(1) anyway.. or worse, rest past the intended wakeup time causing an additional 10ms delay; then add the overhead of the callback loop itself, plus other timers trying to run..).

Obviously there'd be no portable way to do it, but I think having the system interrupt and call into your process at specific intervals to do a simple sem_post wouldn't be too hard to wrap.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Goalie Ca
Member #2,579
July 2002
avatar

Hmm.. that's good food for thought. I would have thought the allegro timers would use the underlying operating system ones (eg: windows highperformance timer). Granted.. none are "real-time" but they are pretty accurate nonetheless.

Allegro is in desperate need of threading tools and primitives. Not to be the devil here but SDL has a built-in pthread-like interface. Allegro5 better hurry up. DNF depends on it! I think DOS support is the real problem here holding a lot of this stuff back. Please correct me if i'm wrong.

-------------
Bah weep granah weep nini bong!

Thomas Fjellstrom
Member #476
June 2000
avatar

Allegro has an internal cross platform'ish api.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

I would have thought the allegro timers would use the underlying operating system ones (eg: windows highperformance timer). Granted.. none are "real-time" but they are pretty accurate nonetheless.

They do use the high-precision timing methods when possible, but the granularity of the sleep method is the problem. Whether it tries to sleep 1 nanosecond* or one millisecond, the thread will stay down until it gets a timeslice again, which would be in about 10ms. Having the system interrupt your process on time would be the only way to break that.

(*) Sometimes nanosleep will actually busy wait on really small rest values (a few nanoseconds) depending on the system configuration.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Goalie Ca
Member #2,579
July 2002
avatar

So i've gone ahead and wrote a windows/linux/mac timer file that doesn't use allegro. The *nix one uses real-time posix extensions and the windows one uses the multimedia timer set to 1ms accuracy. Both use a semaphore mechanism to wake/sleep.

I've posted it here.
http://www.allegro.cc/forums/thread/594745

edit: no need for windows pthread anymore. THe windows version uses windows own locking mechanism.

-------------
Bah weep granah weep nini bong!

Evert
Member #794
November 2000
avatar

Quote:

I think DOS support is the real problem here holding a lot of this stuff back. Please correct me if i'm wrong.

At your service.
Allegro 5 doesn't have DOS support, unless someone comes along and wants to do the work to try to fit it in somehow.

 1   2 


Go to: