On 2010-Mar-26 17:30:14 +0100, Dag-Erling Smørgrav <d...@des.no> wrote:
>Andriy Gapon <a...@icyb.net.ua> writes:
>> Dag-Erling Smørgrav <d...@des.no> writes:
>> > Andriy Gapon <a...@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 == 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 = 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().

-- 
Peter Jeremy

Attachment: pgpKIlf9OHHpi.pgp
Description: PGP signature

Reply via email to