[Lazarus] How to program with time in milliseconds?

Michael Van Canneyt michael at freepascal.org
Thu May 15 11:18:17 CEST 2014



On Thu, 15 May 2014, Michael Schnell wrote:

> On 05/15/2014 09:51 AM, Michael Van Canneyt wrote:
>> 
>> 
>>> 
>>> Of course in the end I need something that works for any CPU and OS.
>> 
>> There is nothing. EpikTimer pretends to fill this gap, but it does not.
> Yep.
>
> If necessary I could try to do something myself (i.e. an improved version of 
> fpgettimeofday), with alternative {$if -ed implementations for different 
> settings of the arch and OS settings. But thoroughly testing this seems like 
> a nightmare.
>
>> 
>> Don't get me wrong: I have nothing against the epiktimer, but it is 
>> presented as some super cross-platform solution (or so I perceive it).
>> 
>> Which is simply not correct. Unless you use the i386 version of the 
>> compiler, it is not better than using now().
> In fact in Linux it does call fpgettimeofday() (or did I install an old 
> version ? )
>> 
>>> 
>>> At best, fpgettimeofday itself should be improved (maybe using 
>>> "Performance counter" register if the Arch allows for or vDSO if the OS 
>>> allows for).
>> 
>> FYI: fpgettimeofday is a direct kernel call, there is nothing to improve.
>> 
> I do know (I did ASM stepping), but it does not need to stay that way. (Or 
> maybe there is a platform independent function in the RTL that is used to 
> delegate to fpgettimeofday)

It needs to stay that way, that is what the function is for: 
expose the POSIX GetTimeOfDay call. It is an official API and need not be changed.

>
> If the arch and OS allows for it could work differently (e.g. use vDSO or use 
> a performance counter register, adding value calculated an initializing 
> action.

fpGetTimeOfDay is used to implement Now(). This should not be changed.

For timers and whatnot, the fpgettimeofday call is simply not suitable. 
It is an incredibly slow call, and needs to be replaced with something else.
get_clock() seems to be the way to go. 
vSDO is a very specific linux mechanism; I would recommend against it.

Michael.




More information about the Lazarus mailing list