Re: pause/resume timer



On Mon, 20 Oct 2003, Johannes [utf-8] WeiÃ?l wrote:

On 2003-10-20 23:07:10, G Hasse wrote:
Timers is a very operating system dependent thing.

Layers above the operating system tries to give a uniform
access to some concepts.

Hmm ... that's bad. I have to write a physical simulation
in school, and need a very precise and portable timer ...

Now we should move this out from gtk-app-devel

That is precicely why there is *different* operating system.
Some is good at timers, some is good att threads and some
is good at real-time behaviour. If you whant a very accurate
timer you must look for an operatingsystem that support this
feature. BUT!

Note that on X86 processors there is a 64 bit CPU clock
register. This can be read both from user and kernel space
(in most operating system).

On Linux you include <asm/msr.h> and use two macros

rdtsc(low,high);  - reads the 64 bit register into two
                    32-bit words.
or
rdtscl(low);      - This reads just the lower half.

Then you need to know the system clock frequency to determin
the runtime.

In Linux there is also a hardware independent version

#include <linux/timex.h>
cycles_t get_cycles(void)

Read more about

FreeBSD: man clocks ...

The TSC clock (64-bit register) on fifth-generation or later x86 systems.
This is a real clock with a frequency that is equivalent to the number of
cycles per second of the CPU(s).  Its frequency can be found using the
sysctl machdep.tsc_freq.  It is used to interpolate between values of the
scheduling clock.  It is only available to applications in a purely
machine-dependent manner.


Göran Hasse

----------------------------------------------------------------
Göran Hasse            email: gh raditex se     Tel: 08-6949270
Raditex AB             http://www.raditex.se    Fax: 08-4420570
Sickla Alle 7, 1tr                              Mob: 070-5530148
131 34  NACKA, SWEDEN






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]