From owner-freebsd-arch@freebsd.org Thu Dec 3 10:05:31 2020 Return-Path: Delivered-To: freebsd-arch@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 909884A19C9 for ; Thu, 3 Dec 2020 10:05:31 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cms0V531rz3LQL for ; Thu, 3 Dec 2020 10:05:30 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 0B3A546P032054 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 3 Dec 2020 12:05:07 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 0B3A546P032054 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 0B3A54SZ032053; Thu, 3 Dec 2020 12:05:04 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 3 Dec 2020 12:05:04 +0200 From: Konstantin Belousov To: Cy Schubert Cc: freebsd-arch@freebsd.org Subject: Re: struct timex and Linux adjtimex() Message-ID: References: <202012030523.0B35NsG7003810@slippy.cwsent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202012030523.0B35NsG7003810@slippy.cwsent.com> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4Cms0V531rz3LQL X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[2001:470:d5e7:1::1:from]; R_SPF_SOFTFAIL(0.00)[~all]; SPAMHAUS_ZRD(0.00)[2001:470:d5e7:1::1:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-arch]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2020 10:05:31 -0000 On Wed, Dec 02, 2020 at 09:23:54PM -0800, Cy Schubert wrote: > An NTP developer at approached me about the prospect of a system call to > add or subtract time from the system clock, returning the current time > after the update. The two options were: > > 1. A new syscall, similar to clock_settime() and clock_gettime() that > adds/subtracts the delta, in a struct timespec, via a call to > kern_clock_settime(). Then atomically returns the current time as if > clock_gettime() was immediately called. > > 2. His colleague didn't think this was appropriate for their needs. He > wants a FreeBSD implementation of the Linux adjtimex() syscall. > > Though non-standard option 1 is least intrusive on existing applications. > > Option 2, implement the Linux adjtimex(): > > 1. The Linux adjtimex() appears to be a re-implementation of ntp_adjtime() > with the addition of ADJ_SETOFFSET. > > 2. ADJ_SETOFFSET adds or subtracts the time specified in a struct timeval > within the timex struct. Unfortunately the FreeBSD timex struct contains no > timeval. To implement this would require versioned symbols to maintain > backward compatiblity. There are two options, as far as I see: 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]. 2. Extend existing struct timex with struct timeval at the end of the structure, but do not require it for any mode except when ADJ_SETOFFSET is specified in modes. In other words, syscall should copyin legacy struct timex, and if ADJ_SETOFFSET is set, copying struct timeval from the address right after timex. IMO option 1 is relatively simple and low overhead. Option 2 is just more work for a little gain. If you go the route 1, please add some padding at the end of extended struct timex so potential future modifications do not require a new syscall. Add me to the review anyway. NB. compat32 for ntp_adjtime(2) seems to be completely broken. It is probably a good moment to fix old syscall, since you would need to implement compat32 shims for the new one anyway. > > Up for discussion is: > > 1. Are we, FreeBSD, interested in implementing the Linux adjtimex() > syscall? (I would take on the task to author it should we feel this is a > worthwhile project. OTOH I prefer not to spend the time working on this if > the community feels otherwise.) > > 2. From a cursory scan through the tree it appears that ntp is the only > internal consumer of struct timex. There are probably others in ports and > other third party software such as openntpd and chrony. A versioned symbol > should satisfy old applications which might use the previous timex struct. > > Are we interested in the Linux adjtimex(2) for FreeBSD? > > > -- > Cheers, > Cy Schubert > FreeBSD UNIX: Web: https://FreeBSD.org > NTP: Web: https://nwtime.org > > The need of the many outweighs the greed of the few. > > > _______________________________________________ > freebsd-arch@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-arch > To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"