Hi Arne,

> But that also
> implies it is the other way round on other platforms. The update_time 
> function is
> called in multiple critical places. Do we have any idea about this?

On Linux with glibc's implementation both time() and gettimeofday() results in 
the same clock_gettime() call over VDSO 
(https://man7.org/linux/man-pages/man7/vdso.7.html).
On FreeBSD (and so), same if VDSO is used both time() and gettimeofday() will 
use clock_gettime too with even additional "tv->tv_usec = 0" for time().
So, on most of architectures there will be no difference after replacing time() 
to gettimeofday() except. asm commands for moving 32/64bit tv_usec, it'll be 
not visible.
On some acrhs/systems where VDSO is not supported - same syscall will happen.

> I remember
> vaguely that the default gettimeofday in FreeBSD is more accurate than the
> Linux variant (involves a kernel call) but you can request a version similar 
> to the
> Linux one by some flag (reading from a shared readonly memory page that is
> read only).

As for clock drifting, it maybe feasible to use clock_gettime() with 
CLOCK_MONOTONIC and get rid of homegrown time adj code at all -> returned time 
will always be monotonic by design.
At least on supported platforms (!_WIN32).

--
Best Regards, Vladislav Grishenko

> -----Original Message-----
> From: Arne Schwabe <a...@rfc2549.org>
> Sent: Tuesday, September 22, 2020 1:41 PM
> To: Vladislav Grishenko <themi...@yandex-team.ru>; openvpn-
> de...@lists.sourceforge.net
> Subject: Re: [Openvpn-devel] [PATCH] Fix update_time() and
> openvpn_gettimeofday()
> 
> 
> > --- a/src/openvpn/otime.h
> > +++ b/src/openvpn/otime.h
> > @@ -78,13 +78,9 @@ openvpn_gettimeofday(struct timeval *tv, void *tz)
> > static inline void
> >  update_time(void)
> >  {
> > -#ifdef _WIN32
> > -    /* on _WIN32, gettimeofday is faster than time(NULL) */
> > +    /* can't use time(NULL), now_usec needs to be updated */
> >      struct timeval tv;
> >      openvpn_gettimeofday(&tv, NULL);
> > -#else
> > -    update_now(time(NULL));
> > -#endif
> >  }
> >
> >  #else /* !TIME_BACKTRACK_PROTECTION */
> >
> 
> I am hesitant about this change, it mentions that gettimeofday is faster on
> Windows than time(NULL) and we prefer it there for this reason. But that also
> implies it is the other way round on other platforms. The update_time 
> function is
> called in multiple critical places. Do we have any idea about this? I remember
> vaguely that the default gettimeofday in FreeBSD is more accurate than the
> Linux variant (involves a kernel call) but you can request a version similar 
> to the
> Linux one by some flag (reading from a shared readonly memory page that is
> read only).
> 
> Arne




_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to