[Lazarus] Epiktimer elapsed = negative value
Giuliano Colla
giuliano.colla at fastwebnet.it
Mon Jul 7 11:58:04 CEST 2014
Il 07/07/2014 11:28, Michael Schnell ha scritto:
> Moreover:
>
> Even if the CPU's hardware tick counter is used, in a multi-CPU
> system, each CPU might have it's own counter and those are not
> guaranteed to be in sync. as the OS might move the program from one
> CPU to the other, this method does not seem to be safe, either.
>
I don't know Epiktimer implementation, but I have some experience about
Linux timers, because I've implemented several "real time" schedulers on
top of Linux kernel.
The POSIX clock_gettime() function provides a parameter to specify which
timer should be used. From clock_gettime man page:
> clock_gettime returns the current timespec value of tp for the
> specific
> clock, which_clock. The values that clockid_t currently
> supports for
> POSIX.1b timers, as defined in include/linux/time.h, are:
>
> CLOCK_REALTIME
> Systemwide realtime clock.
>
> CLOCK_MONOTONIC
> Represents monotonic time. Cannot be set.
>
> CLOCK_PROCESS_CPUTIME_ID
> High resolution per-process timer.
>
> CLOCK_THREAD_CPUTIME_ID
> Thread-specific timer.
>
> CLOCK_REALTIME_HR
> High resolution version of CLOCK_REALTIME.
>
> CLOCK_MONOTONIC_HR
> High resolution version of CLOCK_MONOTONIC.
>
In my C code a simple function like this:
> struct timespec curr_time () {
> struct timespec ts;
> if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
> handle_error("clock_gettime");
> return (ts);
> }
always return correct time. Pascal code should bind to the proper libc
function. Maybe CLOCK_MONOTONIC or CLOCK_MONOTONIC_HR is even safer.
Giuliano
More information about the Lazarus
mailing list