bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: systime() vs gettimeofday()


From: Andrew J. Schorr
Subject: Re: systime() vs gettimeofday()
Date: Tue, 2 Jan 2024 12:55:07 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Jan 02, 2024 at 12:49:33PM -0500, Andrew J. Schorr wrote:
> Hi,
> 
> On Tue, Jan 02, 2024 at 03:46:05PM +0100, Andreas Schwab wrote:
> > On Jan 02 2024, Andrew J. Schorr wrote:
> > 
> > > The awk gettimeofday() call should simply map to the gettimeofday()
> > > system call, and systime() maps to time().
> > 
> > The gettimeofday and time functions use different time sources with
> > differing precision, so they may move to the next second at slightly
> > different points.
> 
> Is this on Linux? I'm no expert on this, but in the kernel source
> lib/vdso/gettimeofday.c, I see this:
> 
> __cvdso_gettimeofday_data:
>                 if (do_hres(&vd[CS_HRES_COARSE], CLOCK_REALTIME, &ts))
>                         return gettimeofday_fallback(tv, tz);
> 
>                 tv->tv_sec = ts.tv_sec;
>                 tv->tv_usec = (u32)ts.tv_nsec / NSEC_PER_USEC;
> 
> __cvdso_time_data:
>         t = READ_ONCE(vd[CS_HRES_COARSE].basetime[CLOCK_REALTIME].sec);
> 
> This looks to me as if it's the same source. But maybe I'm looking in the
> wrong place or misunderstanding.

I suppose we could eliminate the uncertainty by reimplementing
both systime() and gettimeofday() to use the same underlying API
(either gettimeofday or clock_gettime(CLOCK_REALTIME)), but
I imagine this would result in portability issues for the
systime() call.

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]