Received: by 10.223.185.116 with SMTP id b49csp2302809wrg; Sat, 24 Feb 2018 16:37:15 -0800 (PST) X-Google-Smtp-Source: AH8x226NLJseT4UT5N54bme3yc+xFOPZCcHhKA/sgeKLQx5xsGbxAgjXBn+YdTIvvtCFwGMw4GdC X-Received: by 10.99.183.5 with SMTP id t5mr5083472pgf.416.1519519034989; Sat, 24 Feb 2018 16:37:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519519034; cv=none; d=google.com; s=arc-20160816; b=U4uHr2KiXlv7rJTMg4nKBUoJempNhTCghCMsyb1iNEZcbGtb/OqBt4XeIud0n7lQGQ nFEKCR6mIiBMGZc3ewDwC9HmwJ+vnpwihNEnYeHTFRQnAdRlU0G08E3ZvG0siP7OWnJ9 /Vgqx/+cy+qwTEXtEiuRVcO9SlAFqqTX5j71JJYmM54iFkc0b8hGK67y27RIlsNHPHFM jepbKDOYU8RcIhznzOpg+v4kapGEwOw44g5lYASLHye2a4sJXJNNL/t/aOwWpKqvTop+ WYtgUVQVuX2LkbbTf//YqxWimI5w6fswlCwWm896fOJiI3DIWzssiobzf+8CLmiSs4NI SzEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=HMaGNZBsFbRCygzpv84ne4EY0oY6QDEGE/piv9NoFl0=; b=dcwt8rmDc33+JuZOMajunGRfXyNA4LD1g/+sdOunbODavlaRQ4tfYdeK9EHHRI3keY zwLJw0hYRL3Fj07ZDlXen2RapdME4w5pPWRhX7qAuzcKBx78rXwSjVwQt159BdDeZ6uo 1y1UARPIvK9dA6n+cu9K8tc8c8xwzC2PExuEO5mYi4YOVGiu4681qcql7gh1MjLcW5ZI nlY6JpQjB/QISA7NHonBI5JRe6Sagl0WC+4rvZXryDGzGlV878ZP8O9ssz3h7vbSRzSH jdwCRlwDeGqOZV6ePEXhtR7xjsDo0BDk3pfkLJ8AIyI5XGiHXJBC3dnQ6/jHBtHOf4hZ 2ZEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si3573898pge.307.2018.02.24.16.36.31; Sat, 24 Feb 2018 16:37:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751568AbeBYAfB (ORCPT + 99 others); Sat, 24 Feb 2018 19:35:01 -0500 Received: from mail.bootlin.com ([62.4.15.54]:51317 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751500AbeBYAfA (ORCPT ); Sat, 24 Feb 2018 19:35:00 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 70D1D20849; Sun, 25 Feb 2018 01:34:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 1784A20379; Sun, 25 Feb 2018 01:34:57 +0100 (CET) Date: Sun, 25 Feb 2018 01:34:58 +0100 From: Alexandre Belloni To: Karel Zak Cc: Rasmus Villemoes , Igor Plyatov , linux-kernel@vger.kernel.org, Alessandro Zummo , rtc-linux@googlegroups.com, util-linux@vger.kernel.org, J William Piggott Subject: Re: 500 ms delay in time saved into RTC Message-ID: <20180225003458.GB19904@piout.net> References: <30ae185f-28c9-54f1-2884-4ee7801b130e@gmail.com> <34f50661-85f5-eb46-3ff7-45f0c2bb5960@prevas.dk> <20180219110328.n7yjorinjm3xxckr@ws.net.home> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180219110328.n7yjorinjm3xxckr@ws.net.home> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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