Received: by 10.223.185.116 with SMTP id b49csp3435228wrg; Sun, 18 Feb 2018 23:12:57 -0800 (PST) X-Google-Smtp-Source: AH8x224w+pR2hayU59QYA0V0fhdwhUQ0QgkFo5L6GBcAZI64SrnC9X36887UOI3QVS30peL7Kw6K X-Received: by 10.101.97.139 with SMTP id c11mr1914904pgv.443.1519024377084; Sun, 18 Feb 2018 23:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519024377; cv=none; d=google.com; s=arc-20160816; b=B1Qy4qDVy/F7OTPCL0SYx7oibOLckCZrUdiuoKlbkZhXM0B/MY8FhO+N6jOKngk9r1 Tn13kggkoNSoqtfWi9bMqHv+Gp0U0YGq3SM8H4ROvqsefYiY/YKwGXJzupyMBpWJ2EjH zwSZit4SMqzLp9qUFdg6+bNDh5jPDQFdUVTQ82EMjhsP6jtaEdgqgmYGv+teHX+F8xba MM7Edlu0687OFF3SbpJxoAYJa6BZjq1vEfGy3Mzir6jCk94VrB4oD1fwMz4Ob/kNk8eW EavCQOIDPtbbk6fNUK7zpiW7oyZP1zS8WbcRJGN3fgtJhWcnHmlc3kR3+dDJKkM/+JXF hW7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:cc:from:references:to:subject:dkim-signature :arc-authentication-results; bh=SfryVeL7qOLgJegkytRv7WrvHWrJv46Pw2jh2oKa7xY=; b=bBKx4kpNOv8/YQCK+kox4qUTBpH3qvkpv+zR5EktWuEneYLUAtJntgQqzqU4EmXsmX OalpK2XjOReGshihpfKjI95PGaBjtHeqkjhAKzlHxopWIuUZZASCjXd5dv0odoSn/Yn9 rpdL95p0rP+mlIIoouSq1SUETC3rms2ql3kMPNnW0eUo2OUwRogcuaiU5CippjH2lAhI c8hBOpMBF8BlBa4yP8OXFX6gxi3Kq2gtqQwwPtKM9OSUgOxGGbtrbNAWYDDeovihNDUE RcvW7Xmw54mneuttnLgCh7m11CF9POjhLmgEVp/K99TOSJT7hdJ61h3yakno7gotSohr Ur/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport2 header.b=jqFnSOZd; 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 b185si3141448pga.370.2018.02.18.23.12.43; Sun, 18 Feb 2018 23:12:57 -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; dkim=fail header.i=@prevas.dk header.s=ironport2 header.b=jqFnSOZd; 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 S1751926AbeBSHLJ (ORCPT + 99 others); Mon, 19 Feb 2018 02:11:09 -0500 Received: from mail02.prevas.se ([62.95.78.10]:10711 "EHLO mail02.prevas.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751854AbeBSHLH (ORCPT ); Mon, 19 Feb 2018 02:11:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=2865; q=dns/txt; s=ironport2; t=1519024267; x=1550560267; h=subject:to:references:from:cc:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=dfsTdreIuH0FYYVuCSFDBOFEUmMLf/88n+XT6R1tfxw=; b=jqFnSOZd2ISv4tKd6sRAubfNMRx5bNfytwd6q01ds3UC8I69UO/OHwZ1 dlJvuxoU1BaF43U6URh9cN/do+ZuwbqV/lYDKKvNPQ03OaBrA71KdiSPs zceDMDG+t/3nyzCodvq1Oqom8ONk3eSKJZLAXhdHWz3oNOucwLESZGDpR E=; X-IronPort-AV: E=Sophos;i="5.46,534,1511823600"; d="scan'208";a="3084906" Received: from vmprevas4.prevas.se (HELO smtp.prevas.se) ([172.16.8.104]) by ironport2.prevas.se with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2018 08:11:05 +0100 Received: from [172.16.11.22] (172.16.8.31) by smtp.prevas.se (172.16.8.104) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 19 Feb 2018 08:11:05 +0100 Subject: Re: 500 ms delay in time saved into RTC To: Igor Plyatov , , Alessandro Zummo , Alexandre Belloni , References: <30ae185f-28c9-54f1-2884-4ee7801b130e@gmail.com> From: Rasmus Villemoes CC: Message-ID: <34f50661-85f5-eb46-3ff7-45f0c2bb5960@prevas.dk> Date: Mon, 19 Feb 2018 08:11:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <30ae185f-28c9-54f1-2884-4ee7801b130e@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.8.31] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-02-19 07:40, Igor Plyatov wrote: > Hi! > > I have board based on AT91SAM9G20 (ARM926EJ-S CPU), Linux-4.9.36 kernel > and RTC chip DS1340 (rtc-ds1307.c driver). > > RTC chip connected by means of I2C-bus, without HW IRQ line connected. > > Kernel configured to not use embedded functions for time getting at > startup and saving at shutdown: > CONFIG_RTC_CLASS=y > # CONFIG_RTC_HCTOSYS is not set > # CONFIG_RTC_SYSTOHC is not set > CONFIG_RTC_INTF_DEV_UIE_EMUL=y > CONFIG_RTC_DRV_DS1307=y > CONFIG_RTC_DRV_DS1307_CENTURY=y > > The hwclock utility is from util-linux-2.29.1. > > The OS does not have external time synchronization sources like NTP, PTP > or else. > > Generally I need to achieve error within +-20 ms when RTC's time copied > into OS or back from OS into RTC. > > I have made measurements during startup and shutdown of OS and have > found 500 ms delay introduced into RTC's time, when "hwclock --utc > --systohc" executed. > > Logical analyzer show to me I2C-bus transactions and PPS signal > generated by Linux. And I see 500 ms delay is between of rising edge of > PPS signal (start of OS second) and moment when time saved into RTC. > > Please explain, why this happens? Is this due to absence of IRQ line for > RTC or due to a bug in the hwclock, or kernel bug or I have missed > something else? cc += util-linux@vger.kernel.org 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. Rasmus