[quagga-dev 8644] Re: proposed change for uptime output in bgp_dump_routes_func, bgp_dump.c

Stephen Hemminger shemminger at vyatta.com
Tue Apr 5 16:40:35 BST 2011


On Tue, 5 Apr 2011 14:04:02 +0100
"'Chris Hall'" <chris.hall.list at highwayman.com> wrote:

> John Kemp wrote (on 09-Dec-2010 at 20:21):
> ...
> > We've been running as noted below for 2 weeks on a number of
> > collectors.  This method works well.
> > MONOTONIC time should not be written into the MRT files or printed
> > on the vty.  This fixes that problem.
> 
> I think this misunderstands what HAVE_CLOCK_MONOTONIC means...
> 
> ...the bgp_clock() function introduced by commit 6595788...09be calls:
> quagga_gettime(QUAGGA_CLK_MONOTONIC, ...), which will:
> 
>   - if HAVE_CLOCK_MONOTONIC: return clock_gettime(CLOCK_MONOTONIC,
> ....)
>     ie: use the system provided monotonic clock.
> 
>   - otherwise: return some manufactured monotonic clock.
> 
>     (I see that this is based on gettimeofday() -- there is a better
>      approach, using times() -- but that is another story.)
> 
> So, whether or not clock_gettime(CLOCK_MONOTONIC, ....) is supported
> (which is what HAVE_CLOCK_MONOTONIC means):
> 
>   time(NULL) - (bgp_clock() - info->uptime);
> 
> is required to get a Wall Clock time.
> 
> I believe CLOCK_MONOTONIC is POSIX 2001 -- but was optional up to
> POSIX 2008 -- so I wonder how many systems still do not
> HAVE_CLOCK_MONOTONIC, so this may not matter a damn.
> 
> Thinking about it... the problem is that if the system wall clock is
> adjusted between some past event and now, that creates two versions of
> the time of that event: (1) the time the wall clock said, at the time;
> (2) the time the wall clock says now, less how long ago the event
> occurred.  The current code is now using (2).  Both are "wrong" in
> different ways: (1) is (presumably) wrong because the clock was wrong
> at the time; (2) is wrong because it does not match any wall clock
> times recorded at the time (eg log entries).  There doesn't seem to be
> a good way of choosing which of these is the less wrong.
> 
> FWIW: I suggest a further function:
> 
>   time_t bgp_wall_clock(time_t mono)
>   {
>      return time(NULL) - (bgp_clock() - mono) ;
>   }
> 
> next to bgp_clock() -- where suitable comment can remind the reader
> WTH this all means :-)
> 
> Chris
> 
> > bgpd/bgp_dump.c: bgp_dump_routes_func
> > 
> > +   time_t tbuf;
> > 
> >             /* Originated */
> > + #ifdef HAVE_CLOCK_MONOTONIC
> > +           tbuf = time(NULL) - (bgp_clock() - info->uptime);
> > +           stream_putl (obuf, tbuf);
> > + #else
> >             stream_putl (obuf, info->uptime);
> > + #endif /* HAVE_CLOCK_MONOTONIC */
> > 
> > 
> > bgpd/bgp_route.c: route_vty_out_detail
> > 
> > +   time_t tbuf;
> > 
> >       /* Line 7 display Uptime */
> > +#ifdef HAVE_CLOCK_MONOTONIC
> > +      tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
> > +      vty_out (vty, "      Last update: %s", ctime(&tbuf));
> > +#else
> >       vty_out (vty, "      Last update: %s", ctime(&binfo->uptime));
> > +#endif /* HAVE_CLOCK_MONOTONIC */
> 

On Linux, the proper clock to use is the newish CLOCK_MONOTONIC_RAW

       CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
              Similar to CLOCK_MONOTONIC, but provides access to a  raw  hard‐
              ware-based time that is not subject to NTP adjustments.



-- 



More information about the Quagga-dev mailing list