[quagga-dev 7813] Re: [PATCH] lib: fix monotonic clock for relative time

Sogabe Takashi sogabe at iij.ad.jp
Wed Mar 3 01:12:15 GMT 2010


We observed following problem.
  - ospfd can't advertise as-external routes after one hour uptime

Embedded (NetBSD) system which have RTC, clock_gettime(CLOCK_MONOTONIC,)
might returns large value (e.g. current date).

For example, in ospf_refresher_register_lsa(), result of quagga_time()
is zero because quagga_real_stabilised() calculates overflowed data,
then timeval_adjust() changes negative timeouts to 0.

(2010/03/02 21:29), Joakim Tjernlund wrote:
>>
> ospfd uses quagga_time(); quagga_get_relative() shoud not assume
> that clock_gettime(CLOCK_MONOTONIC,) returns uptime since last
> boot.
> 
>> This does not quite make sense to me. You can't use quagga_get_relative()
>> as an absolute time. You can only use it to calc the difference
>> between two calls so it does not matter where time starts.
> 
>> Did this patch fix anything for you? If so I suspect the caller is misusing
>> relative time.
> 
> ---
>  lib/thread.c |   12 ++++++++++--
>  1 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/thread.c b/lib/thread.c
> index e89af54..018ea2d 100644
> --- a/lib/thread.c
> +++ b/lib/thread.c
> @@ -36,6 +36,9 @@ static struct timeval last_recent_time;
>  /* Relative time, since startup */
>  static struct timeval relative_time;
>  static struct timeval relative_time_base;
> +#ifdef HAVE_CLOCK_MONOTONIC
> +static struct timespec monotonic_time_base;
> +#endif /* HAVE_CLOCK_MONOTONIC */
>  /* init flag */
>  static unsigned short timers_inited;
> 
> @@ -128,6 +131,9 @@ quagga_gettimeofday (struct timeval *tv)
>        if (!timers_inited)
>          {
>            relative_time_base = last_recent_time = recent_time;
> +#ifdef HAVE_CLOCK_MONOTONIC
> +          clock_gettime (CLOCK_MONOTONIC, &monotonic_time_base);
> +#endif /* HAVE_CLOCK_MONOTONIC */
>            timers_inited = 1;
>          }
>        /* avoid copy if user passed recent_time pointer.. */
> @@ -148,8 +154,10 @@ quagga_get_relative (struct timeval *tv)
>      struct timespec tp;
>      if (!(ret = clock_gettime (CLOCK_MONOTONIC, &tp)))
>        {
> -        relative_time.tv_sec = tp.tv_sec;
> -        relative_time.tv_usec = tp.tv_nsec / 1000;
> +        relative_time.tv_sec = tp.tv_sec - monotonic_time_base.tv_sec;
> +        relative_time.tv_usec = (tp.tv_nsec -
> +                                 monotonic_time_base.tv_nsec) / 1000;
> +        relative_time = timeval_adjust (relative_time);
>        }
>    }
>  #else /* !HAVE_CLOCK_MONOTONIC */


-- 
Takashi Sogabe <sogabe at iij.ad.jp>



More information about the Quagga-dev mailing list