Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-05

High performance Linux timer

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Does anybody know if there is a Linux (or generic Unix) high performance timer API available. Something like the Win32 API QueryPerformanceCounter()?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 5 lines
I once implemented a high precision timer on linux, but I don't remember how I did it. Look at the code here: http://wiki.lazarus.freepascal.org/EpikTimer

Thanks, I'll have a look at the code for more details. From the wiki, it sounds like there might be some issues EpikTimer implementation though.

* .... Timestamp Counter.
* Pentium IV 3,2Mhz on Windows and Linux with great precision (~ 3,220,000,000 ticks per second)

Timestamp counter from the CPU (assuming we are speaking of RDTSC) is susceptible to many issue. eg: A Intel P4 3.2Mhz does not always produce 3,220,000,000 ticks per second. Powersaving features like SpeedStep, Hibernate etc all affect the CPU clock speed. Also on a multi-core system, not all cores are guaranteed to run at the same clock speed.

Above information was gathered from the WikiPedia article. http://en.wikipedia.org/wiki/Rdtsc

Anybody know what Win32's QueryPerformanceCounter() uses internally to get a stable timer? Or is QueryPerformanceCounter also susceptible to powersaving features?

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Vladimir Zhirov
to Graeme Geldenhuys: Does anybody know if there is a Linux (or generic Unix) high performance timer API…

Hi,

Graeme Geldenhuys wrote
Does anybody know if there is a Linux (or generic Unix) high performance timer API available. Something like the Win32 API QueryPerformanceCounter()?

Graeme, maybe this link will help:
http://www.gamedev.net/community/forums/topic.asp?topic_id=127700

There are some functions mentioned there in addition to RDTSC:
- gettimeofday
- clock_gettime
- ftime

Anybody know what Win32's QueryPerformanceCounter() uses internally to get a stable timer? Or is QueryPerformanceCounter also susceptible to powersaving features?

I found an article named "Beware of QueryPerformanceCounter()" on http://www.virtualdub.org/blog/pivot/entry.php?id=106 that gives some information about this function.
It will not answer your questions directly, but may be useful.

Regards, Vladimir

Reply by email

Felipe Monteiro de Carvalho
to Graeme Geldenhuys: Thanks, I'll have a look at the code for more details. From the wiki, it sounds like…
Graeme Geldenhuys wrote
Timestamp counter from the CPU (assuming we are speaking of RDTSC) is susceptible to many issue...

Read the line just bellow the one you just quoted:

* Nanosecond resolution is supported on Intel Pentium versions with a Timestamp Counter. * Microsecond system clock is the default timebase. <<<

The default timebase doesn't use the hardware directly.

Felipe Monteiro de Carvalho

Reply by email