/* Recent absolute time of day */
struct timeval recent_time;
-static struct timeval last_recent_time;
/* Relative time, since startup */
static struct timeval relative_time;
-static struct timeval relative_time_base;
-/* init flag */
-static unsigned short timers_inited;
static struct hash *cpu_record = NULL;
+ (a.tv_usec - b.tv_usec));
}
-#if !defined(HAVE_CLOCK_MONOTONIC) && !defined(__APPLE__)
-static void
-quagga_gettimeofday_relative_adjust (void)
-{
- struct timeval diff;
- if (timeval_cmp (recent_time, last_recent_time) < 0)
- {
- relative_time.tv_sec++;
- relative_time.tv_usec = 0;
- }
- else
- {
- diff = timeval_subtract (recent_time, last_recent_time);
- relative_time.tv_sec += diff.tv_sec;
- relative_time.tv_usec += diff.tv_usec;
- relative_time = timeval_adjust (relative_time);
- }
- last_recent_time = recent_time;
-}
-#endif /* !HAVE_CLOCK_MONOTONIC && !__APPLE__ */
-
/* gettimeofday wrapper, to keep recent_time updated */
static int
quagga_gettimeofday (struct timeval *tv)
if (!(ret = gettimeofday (&recent_time, NULL)))
{
- /* init... */
- if (!timers_inited)
- {
- relative_time_base = last_recent_time = recent_time;
- timers_inited = 1;
- }
/* avoid copy if user passed recent_time pointer.. */
if (tv != &recent_time)
*tv = recent_time;
return 0;
}
#else /* !HAVE_CLOCK_MONOTONIC && !__APPLE__ */
- if (!(ret = quagga_gettimeofday (&recent_time)))
- quagga_gettimeofday_relative_adjust();
+#error no monotonic clock on this system
#endif /* HAVE_CLOCK_MONOTONIC */
if (tv)
return ret;
}
-/* Get absolute time stamp, but in terms of the internal timer
- * Could be wrong, but at least won't go back.
- */
-static void
-quagga_real_stabilised (struct timeval *tv)
-{
- *tv = relative_time_base;
- tv->tv_sec += relative_time.tv_sec;
- tv->tv_usec += relative_time.tv_usec;
- *tv = timeval_adjust (*tv);
-}
-
/* Exported Quagga timestamp function.
* Modelled on POSIX clock_gettime.
*/
{
switch (clkid)
{
- case QUAGGA_CLK_REALTIME:
- return quagga_gettimeofday (tv);
case QUAGGA_CLK_MONOTONIC:
return quagga_get_relative (tv);
- case QUAGGA_CLK_REALTIME_STABILISED:
- quagga_real_stabilised (tv);
- return 0;
default:
errno = EINVAL;
return -1;
return tv.tv_sec;
}
-/* time_t value in terms of stabilised absolute time.
- * replacement for POSIX time()
- */
-time_t
-quagga_time (time_t *t)
-{
- struct timeval tv;
- quagga_real_stabilised (&tv);
- if (t)
- *t = tv.tv_sec;
- return tv.tv_sec;
-}
-
/* Public export of recent_relative_time by value */
struct timeval
recent_relative_time (void)
/* Clocks supported by Quagga */
enum quagga_clkid {
- QUAGGA_CLK_REALTIME = 0, /* ala gettimeofday() */
- QUAGGA_CLK_MONOTONIC, /* monotonic, against an indeterminate base */
- QUAGGA_CLK_REALTIME_STABILISED, /* like realtime, but non-decrementing */
+ QUAGGA_CLK_MONOTONIC = 1, /* monotonic, against an indeterminate base */
};
/* Struct timeval's tv_usec one second value. */
*/
extern int quagga_gettime (enum quagga_clkid, struct timeval *);
extern time_t quagga_monotime (void);
-extern time_t quagga_time (time_t *);
/* Returns elapsed real (wall clock) time. */
extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,