Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Mar 2010 08:30:23 +1100
From:      Peter Jeremy <peterjeremy@acm.org>
To:        Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= <des@des.no>
Cc:        freebsd-hackers@FreeBSD.org, Andriy Gapon <avg@icyb.net.ua>
Subject:   Re: periodically save current time to time-of-day hardware
Message-ID:  <20100326213022.GD32799@server.vk2pj.dyndns.org>
In-Reply-To: <86vdcj82qx.fsf@ds4.des.no>
References:  <4BACC791.70502@icyb.net.ua> <86zl1v84vy.fsf@ds4.des.no> <4BACD88E.2040803@icyb.net.ua> <86vdcj82qx.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <des@des.no> wrote:
>Andriy Gapon <avg@icyb.net.ua> writes:
>> Dag-Erling Sm=F8rgrav <des@des.no> writes:
>> > Andriy Gapon <avg@icyb.net.ua> 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100326213022.GD32799>