|
This thread is locked; no one can reply to it. |
1
2
|
cpu fps etc... |
Goalie Ca
Member #2,579
July 2002
|
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! ------------- |
bamccaig
Member #7,536
July 2006
|
Thanks, Goalie Ca! My raw Allegro timer example uses approximately 20% CPU. The modified version implementing pthreads/semaphores is using 3-5% CPU. ** 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... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Thomas Fjellstrom
Member #476
June 2000
|
Also, see this: http://kerneltrap.org/Linux/Volatile_Superstition -- |
Goalie Ca
Member #2,579
July 2002
|
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%. ------------- |
Kitty Cat
Member #2,815
October 2002
|
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. -- |
Goalie Ca
Member #2,579
July 2002
|
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. ------------- |
Thomas Fjellstrom
Member #476
June 2000
|
Allegro has an internal cross platform'ish api. -- |
Kitty Cat
Member #2,815
October 2002
|
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. -- |
Goalie Ca
Member #2,579
July 2002
|
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. edit: no need for windows pthread anymore. THe windows version uses windows own locking mechanism. ------------- |
Evert
Member #794
November 2000
|
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. |
|
1
2
|