[Openais] changing gettimeofday to times
Fabien THOMAS
fabien.thomas at netasq.com
Mon Nov 20 06:30:12 PST 2006
under darwin:
clock_get_time
The clock_get_time function returns the current time kept by a clock.
The value returned is a monotonically increasing value (unless
tampered with via the clock_set_time function).
> under my previous mail i incorrectly stated that clock_gettime is
> unavailable under Darwin and FreeBSD:
> it exist under FreeBSD with CLOCK_MONOTONIC.
>
> steven do you need a clock that can be converted to time of day ?
>
> Le 20 nov. 06 à 13:38, Alejandro López a écrit :
>
>> Hi Steven,
>>
>> on Solaris you can use the function posix clock_gettime():
>>
>> Realtime Library Functions clock_settime(3RT)
>>
>> NAME
>> clock_settime, clock_gettime, clock_getres - high-resolution
>> clock operations
>>
>> SYNOPSIS
>> cc [ flag... ] file... -lrt [ library... ]
>> #include <time.h>
>>
>> int clock_gettime(clockid_t clock_id, struct timespec *tp);
>>
>>
>> with clock_id CLOCK_HIGHRES:
>>
>> A clock_id of CLOCK_HIGHRES represents the non-adjustable,
>> high-resolution clock for the system. For this clock, the
>> value returned by clock_gettime(3RT) represents the amount
>> of time (in seconds and nanoseconds) since some arbitrary
>> time in the past; it is not correlated in any way to the
>> time of day, and thus is not subject to resetting or
>> drifting by way of adjtime(2), ntp_adjtime(2),
>> settimeofday(3C), or clock_settime(). The time source for
>> this clock is the same as that for gethrtime(3C).
>>
>>
>> This function is also available on linux but the clock_id is
>> CLOCK_MONOTONIC.
>>
>>
>>
>>
>>
>> Or you could use the Solaris-specific gethrtime():
>>
>>
>> Standard C Library Functions gethrtime(3C)
>>
>>
>>
>> NAME
>> gethrtime, gethrvtime - get high resolution time
>>
>> SYNOPSIS
>> #include <sys/time.h>
>>
>> hrtime_t gethrtime(void);
>>
>> hrtime_t gethrvtime(void);
>>
>> DESCRIPTION
>> The gethrtime() function returns the current high-resolution
>> real time. Time is expressed as nanoseconds since some arbi-
>> trary time in the past; it is not correlated in any way to
>> the time of day, and thus is not subject to resetting or
>> drifting by way of adjtime(2) or settimeofday(3C). The hi-
>> res timer is ideally suited to performance measurement
>> tasks, where cheap, accurate interval timing is required.
>>
>> The gethrvtime() function returns the current high-
>> resolution LWP virtual time, expressed as total nanoseconds
>> of execution time.
>>
>> The gethrtime() and gethrvtime() functions both return an
>> hrtime_t, which is a 64-bit (long long) signed integer.
>>
>>
>>
>>
>> Hope this helps.
>> Alejandro.
>>
>>
>>
>> Steven Dake wrote:
>>> If the system time is changed while openais is running the timing
>>> system
>>> gets all out of wack. This is because gettimeofday returns the
>>> current
>>> time, instead of the number of msec since boot and is used in the
>>> tlist
>>> code.
>>>
>>> There is a mechanism to determine the number of msec since boot
>>> which
>>> appears to be portable. The posix API is "times" which returns the
>>> number of clock ticks since system boot.
>>>
>>> The Linux man page says times returns a time value from some time
>>> in the
>>> past but on linux this is the system boot time.
>>>
>>> On BSD or Solaris, is this also the case? I don't have the man
>>> pages to
>>> check these systems and would like a portable solution. The other
>>> possibility is getitimer and setitimer or the posix timer_gettime
>>> absolute time but I think these posix APIs are not supported on all
>>> platforms.
>>>
>>> Regards
>>> -steve
>>>
>>> _______________________________________________
>>> Openais mailing list
>>> Openais at lists.osdl.org
>>> https://lists.osdl.org/mailman/listinfo/openais
>> _______________________________________________
>> Openais mailing list
>> Openais at lists.osdl.org
>> https://lists.osdl.org/mailman/listinfo/openais
>
>
> _______________________________________________
> Openais mailing list
> Openais at lists.osdl.org
> https://lists.osdl.org/mailman/listinfo/openais
>
More information about the Openais
mailing list