[Lazarus] How to program with time in milliseconds?
Mark Morgan Lloyd
markMLl.lazarus at telemetry.co.uk
Tue May 13 10:45:07 CEST 2014
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.
>
> e.g. http://x86.renejeschke.de/html/file_module_x86_id_277.html
>
> talks about the ASM instruction "RDPMC":
That's hardly surprising, since the various processor ID etc. registers
were available in real mode.
>> 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.
There's an obvious pitfall there: a poor implementation might /think/
that it's directly accessing the counters when in actual fact it's being
virtualised or fixed up by a signal handler. There's debate elsewhere
about inadvertently relying on the OS to fix up e.g. alignment errors,
with a vast performance hit being suggested for e.g. Solaris if poor
coding practice forces the OS to straighten things out.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the Lazarus
mailing list