Received: by 10.223.185.116 with SMTP id b49csp3589676wrg; Mon, 19 Feb 2018 02:38:32 -0800 (PST) X-Google-Smtp-Source: AH8x224Pf57mKXpJAd5WvHXx5HeBanVJ0sGSCpVAzyvOpSTULo1BnifwnN96lHjAnAk+Mkc5BQYq X-Received: by 10.99.96.77 with SMTP id u74mr12120573pgb.453.1519036712541; Mon, 19 Feb 2018 02:38:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519036712; cv=none; d=google.com; s=arc-20160816; b=Gt24JIfJSrAy5M6sB/pcPlyHM45vs0xnIJORV0CtCjK6B6fRE2CnzXzxVz23yVgvbB 11QhePs7s6HQVVWhRQdBIqX7UUkaZvhehPKcTR8vHMqKDAY5kGsnmfkzQhEegp8n7kNT WLmS/TC+CBnRoj2mAlNQ8ODNK2i0HBa1Cakj3/tzy8C4jVm30+43ct9IY38T35ZxtkEM mL3m281ppBGAfWNxU0P0Yw/xVLXQez0quWoDrS/pCL9mM7svBvKN1r0111pcy16IsPuZ zqAa03q2N30QRvXJnkra3sKjna0AjT8h0yXKuUrIx+BlT5MiM1hmMF+y9Sp9JziKHsTq eflQ== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=Jm/tssJ6rhhj7daxclvVo9sgif6o7wSibee5efUddAQ=; b=RaNQPavn5m3QawT0c4qwOul4e2tEcdNanHxTgpyEsuBSvZ77xyrWfcjZ++ExTxyNbY E/ERlW2z87PE3MjFSf8d/a7S3DWSw6qYF4EBOY/G5S1A0H0z/Y1Dd1A5kFLIoDdmd2Ol ncXyY8s+2sjTetkKubhbrJgViOlJpVXksdK1fqOtieKVZFBd5hZauIXnpMw0Un8BPr0A Z1Hg5kn8UQzz/xdbXAKK07noTEfOzU0+nWNQXttpR9y2EwM156acP+QWPv4xB6oSdfTB 5qjYODwoX/M5ZwRbiuqlXd4z/l4gNBOjRCC1+3Uh7Zx8y+yckCpmB0NRxnD5VRAa0Phf jgNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport1 header.b=AD3rPoAk; 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 e18si7445647pfi.130.2018.02.19.02.38.17; Mon, 19 Feb 2018 02:38:32 -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=ironport1 header.b=AD3rPoAk; 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 S1752516AbeBSKhk (ORCPT + 99 others); Mon, 19 Feb 2018 05:37:40 -0500 Received: from mail01.prevas.se ([62.95.78.3]:1867 "EHLO mail01.prevas.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322AbeBSKhj (ORCPT ); Mon, 19 Feb 2018 05:37:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=2297; q=dns/txt; s=ironport1; t=1519036658; x=1550572658; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=9WHIj+NKPvFpYIhjOYTfSmZWm1zu8QoXvIUvTQ3lk6Q=; b=AD3rPoAkq8XmglnIZiOkPBer/4flQWqtCmyLngw66xaN88R03iY6wBbR DnmDBITjZI1M0dASLO3ISFKnS11s8xUBtphhPHYi2UwuR23uvG/Aso331 G+GtFqyx64KU+yyqdLMso7MOaDO+79qYvleKqdHRjEahsa8gkE4n1QdTt g=; X-IronPort-AV: E=Sophos;i="5.46,534,1511823600"; d="scan'208";a="3264749" Received: from vmprevas4.prevas.se (HELO smtp.prevas.se) ([172.16.8.104]) by ironport1.prevas.se with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2018 11:37:37 +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 11:37:37 +0100 Subject: Re: 500 ms delay in time saved into RTC To: Alexandre Belloni , Igor Plyatov CC: , Alessandro Zummo , , References: <30ae185f-28c9-54f1-2884-4ee7801b130e@gmail.com> <34f50661-85f5-eb46-3ff7-45f0c2bb5960@prevas.dk> <20180219100754.GL14177@piout.net> From: Rasmus Villemoes Message-ID: <33e30f44-c774-1130-0461-4b48a58f9c4a@prevas.dk> Date: Mon, 19 Feb 2018 11:37:36 +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: <20180219100754.GL14177@piout.net> 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 11:07, Alexandre Belloni wrote: > On 19/02/2018 at 12:16:04 +0300, Igor Plyatov wrote: >> 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. >> > > Because of the way the API is designed, handling the MC146818A oddity is > not possible in the driver (i.e. 50% of the time, it will be too late > to handle it). Well, I suppose one could implement an ioctl that would not actually take a struct rtctime from userspace but simply use the current value of clock_realtime (which is what 99% of rtc_set_times are using anyway), and doing it as accurately as possible (which requires implementations in each driver) - i.e., have the kernel do the appropriate sleeping which is currently done in userspace: a generic implementation of that ioctl would sleep until clock_realtime is a whole second, while the x86 driver could sleep until a .5 second. Sure, clock_realtime can jump or get adjusted while we sleep, and we can oversleep for all kinds of reasons, but the kernel is in a much better position to do the sleeping and knowing when to attempt the rtc setting than userspace. Said ioctl could also take an integer offset to apply to the clock_realtime value to support setting the rtc to some non-UTC timezone. > You can use busybox hwclock which has the x86 insanity commented out: > https://git.busybox.net/busybox/tree/util-linux/hwclock.c No, the code that is commented out is code that would actually try to do the rtc setting at a whole (system clock) second, which is what one wants on non-x86. It is apparently commented out because aiming for a whole second is not the right thing to do on some platforms (i.e., x86). So the current busybox code, on rtcs which set the fractional part to 0, end up discarding (losing) some uniformly distributed number from [0,1] instead of consistently .5 seconds. Also, AFAIR, the busybox code which implements the --hctosys doesn't do anything to do it right after the rtc has incremented, losing another [0, 1] uniformly. Rasmus