From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 26 21:30:36 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 89794106566C for ; Fri, 26 Mar 2010 21:30:36 +0000 (UTC) (envelope-from peterjeremy@acm.org) Received: from mail36.syd.optusnet.com.au (mail36.syd.optusnet.com.au [211.29.133.76]) by mx1.freebsd.org (Postfix) with ESMTP id 15FC58FC0C for ; Fri, 26 Mar 2010 21:30:35 +0000 (UTC) Received: from server.vk2pj.dyndns.org (c122-106-253-149.belrs3.nsw.optusnet.com.au [122.106.253.149]) by mail36.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o2QLUQRO030701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 27 Mar 2010 08:30:28 +1100 X-Bogosity: Ham, spamicity=0.000000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.3/8.14.3) with ESMTP id o2QLUOgG077869; Sat, 27 Mar 2010 08:30:24 +1100 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.3/8.14.3/Submit) id o2QLUNrU077868; Sat, 27 Mar 2010 08:30:23 +1100 (EST) (envelope-from peter) Date: Sat, 27 Mar 2010 08:30:23 +1100 From: Peter Jeremy To: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= Message-ID: <20100326213022.GD32799@server.vk2pj.dyndns.org> References: <4BACC791.70502@icyb.net.ua> <86zl1v84vy.fsf@ds4.des.no> <4BACD88E.2040803@icyb.net.ua> <86vdcj82qx.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6WlEvdN9Dv0WHSBl" Content-Disposition: inline In-Reply-To: <86vdcj82qx.fsf@ds4.des.no> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.20 (2009-06-14) X-CMAE-Score: 0 Cc: freebsd-hackers@FreeBSD.org, Andriy Gapon Subject: Re: periodically save current time to time-of-day hardware X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Mar 2010 21:30:36 -0000 --6WlEvdN9Dv0WHSBl Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2010-Mar-26 17:30:14 +0100, Dag-Erling Sm=F8rgrav wrote: >Andriy Gapon writes: >> Dag-Erling Sm=F8rgrav writes: >> > Andriy Gapon writes: >> > > Also, I am aware that the period should be configurable (sysctl). >> > Why? >> Because there would always be someone who would want a different value :) >> > Although I can see an argument for a sysctl to turn it on or off. >> Good idea. > >You can combine the two - P =3D=3D 0 means "don't save", P > 0 means "save >every P minutes". > >> > IIRC, Linux saves the clock at shutdown, and every 11 minutes if and >> > only if the system clock is synchronized to an external reference. At least some versions of Linux also save a RTC drift approximation and "last set" timestamp whenever the RTC is updated. This allows the kernel to better set the system clock from the RTC at boot (ie, our inittodr()). The downside is that this needs to store 8-16 bytes of state somewhere non-volatile. Linux does this using an external program and a file - but finding a location for a regularly updated file that is read very early in the rc.d sequence might be problematic. >> I know how to add a shutdown hook (event handler), but I don't know how = to check >> if time synchronization is taking place. > >adjtime() / adjtimex() sets a flag. I'm not sure if (or how) the flag >is cleared when synchronization stops (i.e. /etc/rc.d/ntpd stop); >perhaps the simplest solution is to set a T =3D monotime() every time >adjtime() is called, and check that monotime() - (T * 60) < (P * 60). It's not especially important how regularly the RTC is updated, just that it _is_ updated. This suggests that an alternative approach would be for adjtime() / ntp_adjtime() to directly call resettodr() if it's more than P minutes since resettodr() was last called. As a general comment, whilst resettodr() needs to be serialised, there is no need for it to block. If thread B wants to call resettodr() whilst thread A is doing so, thread B can just skip the call because calling resettodr() twice in quick succession has no benefit. This means the serialisation can be a simple atomic_readandclear_int(). --=20 Peter Jeremy --6WlEvdN9Dv0WHSBl Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAkutJ24ACgkQ/opHv/APuIdbWQCgtz5xPTFoNDTx+3Kz7LxVdEPf ZpsAn3LP6UpQYzxu/L68GZzojlmiaNmg =T2iL -----END PGP SIGNATURE----- --6WlEvdN9Dv0WHSBl--