public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Karel Zak <kzak@redhat.com>
Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Igor Plyatov <plyatov@gmail.com>,
	linux-kernel@vger.kernel.org,
	Alessandro Zummo <a.zummo@towertech.it>,
	rtc-linux@googlegroups.com, util-linux@vger.kernel.org,
	J William Piggott <elseifthen@gmx.com>
Subject: Re: 500 ms delay in time saved into RTC
Date: Sun, 25 Feb 2018 01:34:58 +0100	[thread overview]
Message-ID: <20180225003458.GB19904@piout.net> (raw)
In-Reply-To: <20180219110328.n7yjorinjm3xxckr@ws.net.home>

Hi,

On 19/02/2018 at 12:03:28 +0100, Karel Zak wrote:
> On Mon, Feb 19, 2018 at 08:11:05AM +0100, Rasmus Villemoes wrote:
> > It's because util-linux's hwclock still assumes the world is x86. See
> > this comment in the util-linux source code:
> > 
> >         /*
> >          * The Hardware Clock can only be set to any integer time plus one
> >          * half second.  The integer time is required because there is no
> >          * interface to set or get a fractional second.  The additional half
> >          * second is because the Hardware Clock updates to the following
> >          * second precisely 500 ms (not 1 second!) after you release the
> >          * divider reset (after setting the new time) - see description of
> >          * DV2, DV1, DV0 in Register A in the MC146818A data sheet (and note
> > 
> > So if hwclock is asked to --systohc at time 01:02:03.x, it waits until
> > the time is 01:02:03.5 to set the rtc to 01:02:03, or if that has
> > already passed, waits until  01:02:04.5 and sets it to 01:02:04.
> > 
> > On our ARM BSP we patch util-linux to have the "implicit fractional
> > part" configurable, and trying to upstream something like that has been
> > on my todo-list for quite a while. See
> > 
> > https://raw.githubusercontent.com/oe-lite/base/master/recipes/util-linux/util-linux-2.29/hwclock-tweak-delay.patch
> > 
> > for the patch we currently use (on top of that, we change the 0.5
> > initializer to 0.0 to avoid having to always pass the --delay argument).
> > Incidentally, it seems we're on the same util-linux version, so you
> > should be able to try out that patch and see if it works for you.
> 
> Would be possible to somehow detect what is the right default setting for
> --delay? I mean for example detect architecture / clock HW, etc.
> 
> I have no problem with --delay, but it's tuning for advanced users and
> HW specific stuff. It would be nice to have something more portable.
> 

This is what I'm using to synchronize the RTC to the system time:

https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-sync.c

With sane RTCs, it manages to do so with a good precision, 10µs on a
pcf85363 connected to a sama5d4 xplained, 96µs on my PC.

It can still be improved and doesn't handle RTCs in localtime.

I'm planning to integrate that in hwclock at some point i(hopefully
soon) but I didn't have the time to dive too much in the code yet.

-- 
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com

      parent reply	other threads:[~2018-02-25  0:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19  6:40 500 ms delay in time saved into RTC Igor Plyatov
2018-02-19  7:11 ` Rasmus Villemoes
2018-02-19  9:16   ` Igor Plyatov
2018-02-19 10:07     ` Alexandre Belloni
2018-02-19 10:37       ` Rasmus Villemoes
2018-02-19 11:03   ` Karel Zak
2018-02-19 11:31     ` Igor Plyatov
2018-02-25  0:34     ` Alexandre Belloni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180225003458.GB19904@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=elseifthen@gmx.com \
    --cc=kzak@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=plyatov@gmail.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=rtc-linux@googlegroups.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox