[Lazarus] How to program with time in milliseconds?

Henry Vermaak henry.vermaak at gmail.com
Tue May 13 12:00:04 CEST 2014


On Tue, May 13, 2014 at 09:51:39AM +0200, Michael Schnell wrote:
> On 05/12/2014 10:37 PM, Henry Vermaak wrote:
> >On linux, glibc (and others) will route gettimeofday() (and
> >clock_gettime() for certain clock IDs) via vDSO and no syscall
> >will be called, so it's very fast. I don't think the fpc rtl does
> >this, though?
> 
> I checked with X86 32 Bit Linux: you are right.

This doesn't happen on x86 for me (with Debian stable, at least).  I
can't find the implementation in glibc, either.

> e.g. http://x86.renejeschke.de/html/file_module_x86_id_277.html
> 
> talks about the ASM instruction "RDPMC":
> 
> >When in protected or virtual 8086 mode, the performance-monitoring
> >counters enabled (PCE) flag in register CR4 restricts the use of
> >the RDPMC instruction as follows. When the PCE flag is set, the
> >RDPMC instruction can be executed at any privilege level; when the
> >flag is clear, the instruction can only be executed at privilege
> >level 0.
> 
> Hence, I don't know if accessing the " performance-monitoring
> counter" this is possible / viable in the fpc RTL.

If you really want to use the performance counters, you'll have to use
the perf subsystem.

This doesn't have anything to do with vDSO, though.  The standard
library doesn't use any assembler to read these registers.  It calls
into a page that the kernel makes available to userspace that contains
certain functions where the overhead of a syscall is deemed
excessive/undesirable.  This kernel code will then read the time (using
HPET/TSC to get nanoseconds):

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/x86/vdso/vclock_gettime.c

Henry




More information about the Lazarus mailing list