[Openais] changing gettimeofday to times
Alejandro López
Alejandro.Lopez at Sun.COM
Mon Nov 20 04:38:33 PST 2006
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_MONOTONI=
C.
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2950 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.linux-foundation.org/pipermail/openais/attachments/20061=
120/47902300/smime-0001.bin
More information about the Openais
mailing list