From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>,
Igor Plyatov <plyatov@gmail.com>
Cc: <linux-kernel@vger.kernel.org>,
Alessandro Zummo <a.zummo@towertech.it>,
<rtc-linux@googlegroups.com>, <util-linux@vger.kernel.org>
Subject: Re: 500 ms delay in time saved into RTC
Date: Mon, 19 Feb 2018 11:37:36 +0100 [thread overview]
Message-ID: <33e30f44-c774-1130-0461-4b48a58f9c4a@prevas.dk> (raw)
In-Reply-To: <20180219100754.GL14177@piout.net>
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
next prev parent reply other threads:[~2018-02-19 10:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-19 6:40 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 [this message]
2018-02-19 11:03 ` Karel Zak
2018-02-19 11:31 ` Igor Plyatov
2018-02-25 0:34 ` Alexandre Belloni
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=33e30f44-c774-1130-0461-4b48a58f9c4a@prevas.dk \
--to=rasmus.villemoes@prevas.dk \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@free-electrons.com \
--cc=linux-kernel@vger.kernel.org \
--cc=plyatov@gmail.com \
--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
all inboxes | Powered by JetHome®