struct timex and Linux adjtimex()

Konstantin Belousov kostikbel at gmail.com
Thu Dec 3 20:06:11 UTC 2020


On Thu, Dec 03, 2020 at 09:17:36AM -0800, Cy Schubert wrote:
> In message <60612.1606991186 at critter.freebsd.dk>, "Poul-Henning Kamp" 
> writes:
> > --------
> > Konstantin Belousov writes:
> > > On Thu, Dec 03, 2020 at 10:17:51AM +0000, Poul-Henning Kamp wrote:
> > > > --------
> > > > Konstantin Belousov writes:
> > > > 
> > > > > 1. Implement new syscall, which would take extended struct timex.
> > > > >    ntp_adjtimex() perhaps should be kept for backward compatibility.
> > > > >    [It does not matter where struct timeval is placed in the updated
> > > > >    struct timex, see below].
> > > > 
> > > > That would break all ports with timekeeping software.
> > > Why ?
> >
> > Last I looked they all had "#ifdef FreeBSD use ntp_adjtim()", so if
> > you rename it to ntp_adjtimex() you break them.
> 
> There was no discussion about renaming ntp_adjtime() to ntp_adjtimex(). 
> ntp_adjtime() would remain. A new adjtimex() would be added.
As discussed, we should stay with ntp_adjtime(), it seems.
Libc may provide adjtimex() as an alias if this makes some porting easier.

BTW, I can code the syscall and compat layers, if this would make thinks
easier for everybody.  I can do the addition of the actual flag if you
describe the semantic in more details.

I see the description of ADJ_SETOFFSET in the Linux adjtimex(2) man page:

       ADJ_SETOFFSET (since Linux 2.6.39)
              Add  buf.time  to  the current time.  If buf.status includes the
              ADJ_NANO  flag,  then  buf.time.tv_usec  is  interpreted  as   a
              nanosecond value; otherwise it is interpreted as microseconds.

              The  value  of  buf.time  is  the sum of its two fields, but the
              field buf.time.tv_usec must always be nonnegative.  The  follow‐
              ing  example  shows  how  to normalize a timeval with nanosecond
              resolution.

                   while (buf.time.tv_usec < 0) {
                       buf.time.tv_sec  -= 1;
                       buf.time.tv_usec += 1000000000;
                   }

I do not quite understand the context and internal meaning of the second
paragraph, though.  Kernel should not allow negative tv_usec as the input
parameter, right ?

> 
> >
> > I see no problem having a #define to alias timex() to ntp_adjtime(),
> > but I doubt it would make life easier for anybody.  (I think we used
> > to have that and it got GC'ed.)
> >
> > *If* we want to do this, the right way is to extend struct timex and
> > let ntpadjtime(2) handle the new modes.
> >
> > -- 
> > Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> > phk at FreeBSD.ORG         | TCP/IP since RFC 956
> > FreeBSD committer       | BSD since 4.3-tahoe    
> > Never attribute to malice what can adequately be explained by incompetence.
> 
> 
> -- 
> Cheers,
> Cy Schubert <Cy.Schubert at cschubert.com>
> FreeBSD UNIX:  <cy at FreeBSD.org>   Web:  https://FreeBSD.org
> NTP:           <cy at nwtime.org>    Web:  https://nwtime.org
> 
> 	The need of the many outweighs the greed of the few.
> 


More information about the freebsd-arch mailing list