Received: by 10.223.185.116 with SMTP id b49csp3525693wrg; Mon, 19 Feb 2018 01:18:00 -0800 (PST) X-Google-Smtp-Source: AH8x226riuLasRDmLwf0ojZw+hLAo8HVmHxbhKVOo0amCtOoI2DM3+6orjxYC4bw7M+yw/pJn1jZ X-Received: by 10.99.177.13 with SMTP id r13mr11789798pgf.312.1519031880813; Mon, 19 Feb 2018 01:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519031880; cv=none; d=google.com; s=arc-20160816; b=S0jFP/Bw3WJBQ/A2vOe4fSUPTxRh8FWa4ZvNpDv+TYHWlmgP4P8yiYZm1tNHua6jzE bPCe6V9mnKx/7uE5O2K5Tm+sd1MJlcXJZHQNDbBsrvJ4X0VXtRBj20hERFnsY4Vy8od9 dodnMZKgxoU6NJrRIZkkwW9R0KTRR+uL7l+lGlEc7ZZTBfzuhizTlUOmbShKbNjXOQI/ oT+99iU3FJ3EXa0fN7joVZMHpFCRMzhRQ/E6yRwf5G66t41qEwPywj9iZj38T5XFyFnj SpUKDx0JP9LcnBngoRKcgD8NiH1JNSfEBcAvALUKJpkG4LiXiCF1WJhpnDfgh4HNJLVG B3lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=h8WEpc8N20uI2+U2DGzDZPMriEiJX+9qwsiDq/461Ow=; b=yOe/wz1viEfFykrokhxzOISu6Bc60J4p2GviiudCtDJhCyjju0Xthxh8FPDwcZvqYU f55dH12KRGSv90GWb2cnFVtBtt+xj6Yz3HLvb3M3c+Xrj6gCMxZ9cCse/FvvgXWRX3Qy 6Gy4Ss/zmjsyeK9wPv/79GkKHV2R4NBv0ElHyN3a/i36cx5fHCbeuJdtA7hkRjkJv6zz iVINOUD3WOiEGqaV9NEYxtIv3GnkLdDmxMv2iESSPkds2pi+72sO+n+nCZoJHkWCCM8g hbHi4PeNET+Hay3WC7zWgvlynePRF/Ob7aA0bYClXfkeUOJ77gvwBkaBCQiQh8xivtUp 10YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NIE/VdN+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 201si4968902pge.119.2018.02.19.01.17.45; Mon, 19 Feb 2018 01:18:00 -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=pass header.i=@gmail.com header.s=20161025 header.b=NIE/VdN+; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752120AbeBSJQL (ORCPT + 99 others); Mon, 19 Feb 2018 04:16:11 -0500 Received: from mail-lf0-f41.google.com ([209.85.215.41]:41120 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751866AbeBSJQJ (ORCPT ); Mon, 19 Feb 2018 04:16:09 -0500 Received: by mail-lf0-f41.google.com with SMTP id f136so12073067lff.8; Mon, 19 Feb 2018 01:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=h8WEpc8N20uI2+U2DGzDZPMriEiJX+9qwsiDq/461Ow=; b=NIE/VdN+2l0iGpLg72YdTXE4qW6n9zo8H7KyHWs7OC16k9eCkuCaS/N4rCeU9FSO+K C72E72NK0DgnPf3lxXZlDIh3WW+U/k+2/xM2BAorV4lyzZvJWUopUJ9RS517S59qbqDZ /d7QzwpCApSe/Z5Tlsmkr6//yGt1IvM5EBclVKpb83pFzLgccohd5iAbI3vULmp7FwFe Vmfivm5uGjzEOuJTJiSZdnH+2s1hmde5GyzM1hhSLH79Q/U488fVtu135/UFy+UF+PSX lc3RyfyafDXmlnkTgYXmZEXXK1ja7ud0ZFkU6oObHzRGwa70QuLi7Ec05VohdbJO7AG9 vzMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=h8WEpc8N20uI2+U2DGzDZPMriEiJX+9qwsiDq/461Ow=; b=pSOqN+S2owf1sR5JrXyqoiJfihi1X68cjEZhHnI1nJ0qKHut2nAoXLVsANuMM6JW1C 2BkM3xKSeHYoneINrjp5Je42ylaesvNNV4u5TMkX+QZMmiQdQvdSdCRr/t26yS6dhOQM SFRhUyqTnqZ9P5Vq1AzGW86OMhlrClUfJP7Wg3tmYREuNLOMaAlfScr6BJJ7ZA4L0noM UIcdgdqpdr6bZGTa061pCvTl8NzzYmLj8Am1XfD5gwnI30eFQrqn580hss2Tpn/Djqdj 3FSn9/zjxmHshB4UhStC+TivbjC0xhXeJGeMSlYYFeeHgJiXmHh/eKYsWpZ1xh20pJ68 mANg== X-Gm-Message-State: APf1xPDbbl9GsKWJuStOKetgXzukUAEusoXB1x0kFbpAy1gozJd5hXR4 HRZ2ThSO5M/GQC0nbEI2/3S7BQ4gw4E= X-Received: by 10.46.14.10 with SMTP id 10mr3684101ljo.64.1519031767186; Mon, 19 Feb 2018 01:16:07 -0800 (PST) Received: from [192.168.1.10] ([185.9.184.158]) by smtp.gmail.com with ESMTPSA id o28sm1740296lfc.63.2018.02.19.01.16.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 01:16:06 -0800 (PST) Subject: Re: 500 ms delay in time saved into RTC To: Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, Alessandro Zummo , Alexandre Belloni , rtc-linux@googlegroups.com, util-linux@vger.kernel.org References: <30ae185f-28c9-54f1-2884-4ee7801b130e@gmail.com> <34f50661-85f5-eb46-3ff7-45f0c2bb5960@prevas.dk> From: Igor Plyatov Message-ID: Date: Mon, 19 Feb 2018 12:16:04 +0300 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: <34f50661-85f5-eb46-3ff7-45f0c2bb5960@prevas.dk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dear Rasmus, thank you very much for explanation! I have set "RTC_SET_DELAY_SECS = 0.0" in hwclock.c and got acceptable result. It wonder why such critical function does not implemented on kernel level in RTC driver? It is very strange to rely on specific HW in user space SW. Best wishes. -- Igor Plyatov > 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