Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 405861 - sys-apps/openrc has misleading comment about clock_hctosys in /etc/conf.d/hwclock
Summary: sys-apps/openrc has misleading comment about clock_hctosys in /etc/conf.d/hwc...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal trivial (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: openrc-0.10
  Show dependency tree
 
Reported: 2012-02-26 08:32 UTC by Ian Abbott
Modified: 2012-03-02 17:09 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Abbott 2012-02-26 08:32:51 UTC
The comment about clock_hctosys in /etc/conf.d/hwclock says you do not need to set it to "YES" if you are running a modern kernel with CONFIG_RTC_HCTOSYS set to y. This is misleading if the hardware clock is set to local time as the kernel CONFIG_RTC_HCTOSYS option assumes the hardware clock is set to UTC.

It would be less misleading if the sentence read as follows:

# You do not need this if you are running a modern kernel with CONFIG_RTC_HCTOSYS set to y AND your Hardware Clock is set to UTC.


Reproducible: Always
Comment 1 William Hubbs gentoo-dev 2012-02-27 17:26:03 UTC
I looked at the documentation in make menuconfig for the
CONFIG_RTC_HCTOSYS option, but I do not see any statement there about
the kernel assuming any particular timezone setting for the RTC.

Where are you getting the idea that the kernel expects UTC?

Thanks,

William
Comment 2 Ian Abbott 2012-02-27 18:03:28 UTC
(In reply to comment #1)
> Where are you getting the idea that the kernel expects UTC?

Because timezones are a user-space thing that the kernel knows nothing about.  There is no kernel configuration option or kernel command-line parameter to tell the kernel what the RTC offset from UTC is (and for good reason!).
Comment 3 Ian Abbott 2012-02-27 18:27:07 UTC
Also, see the description of CONFIG_RTC_HCTOSYS_DEVICE which says the device should record time in UTC.


If the RTC is set to local time, the kernel's system time will be wrong until the hwclock init script sets it. I wonder what happens when resuming from suspend-to-disk? Does the hwclock script get run after resume, or will the system time remain wrong in that case? Now I'm worried!
Comment 4 William Hubbs gentoo-dev 2012-02-27 19:19:30 UTC
(In reply to comment #3)
> Also, see the description of CONFIG_RTC_HCTOSYS_DEVICE which says the device
> should record time in UTC.

This is what I needed to see. I'm wondering if we should also assume clock="UTC" if clock_hctosys="YES"?

> If the RTC is set to local time, the kernel's system time will be wrong until
> the hwclock init script sets it. I wonder what happens when resuming from
> suspend-to-disk? Does the hwclock script get run after resume, or will the
> system time remain wrong in that case? Now I'm worried!

I can't really answer that, but if there is an issue with suspend/resume I'm not sure this bug is the place for it since we are just dealing with the hwclock script.
Comment 5 Ian Abbott 2012-02-27 19:42:26 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > Also, see the description of CONFIG_RTC_HCTOSYS_DEVICE which says the device
> > should record time in UTC.
> 
> This is what I needed to see. I'm wondering if we should also assume
> clock="UTC" if clock_hctosys="YES"?

No, because on a Windows dual-boot system you'd want to set clock="local" and clock_hctosys="YES". Windows traditionally assumes the hardware clock is local time. Although some versions of Windows have registry hacks to allow the hardware clock to be set to UTC, these hacks don't work properly on all versions of Windows.

> > If the RTC is set to local time, the kernel's system time will be wrong until
> > the hwclock init script sets it. I wonder what happens when resuming from
> > suspend-to-disk? Does the hwclock script get run after resume, or will the
> > system time remain wrong in that case? Now I'm worried!
> 
> I can't really answer that, but if there is an issue with suspend/resume I'm
> not sure this bug is the place for it since we are just dealing with the
> hwclock script.

Agreed, it's unrelated.  I just thought I'd mention it in passing!
Comment 6 Ian Abbott 2012-02-27 19:51:01 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > I can't really answer that, but if there is an issue with suspend/resume I'm
> > not sure this bug is the place for it since we are just dealing with the
> > hwclock script.
> 
> Agreed, it's unrelated.  I just thought I'd mention it in passing!

Although I do think it would be useful if the /etc/init.d/hwclock script had a "restore()" action as it already has a "save()" action.  These actions could be usefully called during suspend/resume.
Comment 7 William Hubbs gentoo-dev 2012-02-27 20:09:37 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > I can't really answer that, but if there is an issue with suspend/resume I'm
> > > not sure this bug is the place for it since we are just dealing with the
> > > hwclock script.
> > 
> > Agreed, it's unrelated.  I just thought I'd mention it in passing!
> 
> Although I do think it would be useful if the /etc/init.d/hwclock script had a
> "restore()" action as it already has a "save()" action.  These actions could be
> usefully called during suspend/resume.

Possibly, but that is still another bug. :-)
Comment 8 William Hubbs gentoo-dev 2012-02-27 20:15:48 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > Also, see the description of CONFIG_RTC_HCTOSYS_DEVICE which says the device
> > > should record time in UTC.
> > 
> > This is what I needed to see. I'm wondering if we should also assume
> > clock="UTC" if clock_hctosys="YES"?
> 
> No, because on a Windows dual-boot system you'd want to set clock="local" and
> clock_hctosys="YES". Windows traditionally assumes the hardware clock is local
> time. Although some versions of Windows have registry hacks to allow the
> hardware clock to be set to UTC, these hacks don't work properly on all
> versions of Windows.

Based on the requirement you pointed out above regarding CONFIG_RTC_SYSTOHC_DEVICE being set to UTC, I would recommend using clock_systohc="NO" in this situation. clock="local" and clock_systohc="yes" seem to be mutually exclusive to me.

What am I missing?
Comment 9 Ian Abbott 2012-02-28 10:33:47 UTC
(In reply to comment #8)
> Based on the requirement you pointed out above regarding
> CONFIG_RTC_SYSTOHC_DEVICE being set to UTC, I would recommend using
> clock_systohc="NO" in this situation. clock="local" and clock_systohc="yes"
> seem to be mutually exclusive to me.
> 
> What am I missing?

I assume you meant CONFIG_RTC_HCTOSYS_DEVICE and clock_hctosys in the above.

Setting clock="local" and clock_hctosys="YES" tells /etc/init.d/hwclock to set the system time using the local time stored in the hardware clock.  System time is always assumed to be UTC even if it has been set incorrectly.

If you have CONFIG_RTC_HCTOSYS configured in the kernel as well, it would read the hardware clock and set the system clock to the same time assuming it is UTC.  If the hardware clock is actually set to local time, the system time will be wrong by the difference between local time and UTC.

When hwclock init script is started with the config parameters clock="local", clock_hctosys="YES" it will run the binary /sbin/hwclock as follows:

  hwclock --hctosys --localtime

This will read the hardware clock, convert it from local time to UTC, and set the system time.  The result is that the system time will be set to roughly the correct time, depending on how accurately the hardware clock was set to local time in the first place.

Of course there are well known problems with setting the hardware clock to local time involving ambiguities around DST transitions which may require the time to be adjusted by an hour manually twice a year, but that's the price you pay for Windows compatibility!
Comment 10 William Hubbs gentoo-dev 2012-02-28 17:49:12 UTC
(In reply to comment #9)
> Setting clock="local" and clock_hctosys="YES" tells /etc/init.d/hwclock to
> set the system time using the local time stored in the hardware clock. 
> System time is always assumed to be UTC even if it has been set incorrectly.
> 
> If you have CONFIG_RTC_HCTOSYS configured in the kernel as well, it would
> read the hardware clock and set the system clock to the same time assuming
> it is UTC.  If the hardware clock is actually set to local time, the system
> time will be wrong by the difference between local time and UTC.
> 
> When hwclock init script is started with the config parameters
> clock="local", clock_hctosys="YES" it will run the binary /sbin/hwclock as
> follows:
> 
>   hwclock --hctosys --localtime
> 
> This will read the hardware clock, convert it from local time to UTC, and
> set the system time.  The result is that the system time will be set to
> roughly the correct time, depending on how accurately the hardware clock was
> set to local time in the first place.

Ah, so what we have is if CONFIG_RTC_HCTOSYS=y is set in the kernel, clock_hctosys should be "no", correct?

If that is the case, would it make more sense to change the hwclock script so that clock_hctosys should have the same setting as CONFIG_RTC_HCTOSYS?
Comment 11 Ian Abbott 2012-02-29 10:10:13 UTC
(In reply to comment #10)
> Ah, so what we have is if CONFIG_RTC_HCTOSYS=y is set in the kernel,
> clock_hctosys should be "no", correct?

If CONFIG_RTC_HCTOSYS=y and the RTC device is set to local time, the kernel will at least initialize the system time to within a few hours of what it should be (the difference between UTC and local time).  That's going to be closer to real time than whatever default initial system time the kernel would otherwise set.

So there is some benefit in having both CONFIG_RTC_HCTOSYS=y and clock_hctosys=y

> If that is the case, would it make more sense to change the hwclock script
> so that clock_hctosys should have the same setting as CONFIG_RTC_HCTOSYS?

I'd rather they were independent for the reason given above.  Besides, the hwclock script might not be able to determine the CONFIG_RTC_HCTOSYS setting of the running kernel.
Comment 12 William Hubbs gentoo-dev 2012-02-29 15:43:35 UTC
How do you feel about the following change to /etc/conf.d/hwclock?
I think this makes it a bit more clear what the hwclock script is doing.

diff --git a/conf.d/hwclock b/conf.d/hwclock
index 230d81d..78ee7fa 100644
--- a/conf.d/hwclock
+++ b/conf.d/hwclock
@@ -4,9 +4,11 @@
 # you should set it to "local".
 clock="UTC"
 
-# If you want to set the system time to the current hardware clock
-# during bootup, then say "YES" here. You do not need this if you are
-# running a modern kernel with CONFIG_RTC_HCTOSYS set to y.
+# If you want the hwclock script to set the system time (software clock)
+# to match the current hardware clock during bootup, leave this
+# commented out.
+# You should set this to "NO", however, if you are running a modern
+# kernel with CONFIG_RTC_HCTOSYS set to y.
 #clock_hctosys="YES"
 
 # If you do not want to set the hardware clock to the current system
Comment 13 Ian Abbott 2012-03-01 11:03:30 UTC
(In reply to comment #12)
> How do you feel about the following change to /etc/conf.d/hwclock?
> I think this makes it a bit more clear what the hwclock script is doing.
> 
> +# You should set this to "NO", however, if you are running a modern
> +# kernel with CONFIG_RTC_HCTOSYS set to y.

I would change that last sentence to:

# You should set this to "NO", however, if you are running a modern
# kernel with CONFIG_RTC_HCTOSYS set to y and your hardware clock is
# set to UTC.

because you'd always want clock_hctosys set to "YES" (the default) if your hardware clock is set to local time.
Comment 14 William Hubbs gentoo-dev 2012-03-01 18:45:11 UTC
(In reply to comment #13)
> (In reply to comment #12)
> > How do you feel about the following change to /etc/conf.d/hwclock?
> > I think this makes it a bit more clear what the hwclock script is doing.
> > 
> > +# You should set this to "NO", however, if you are running a modern
> > +# kernel with CONFIG_RTC_HCTOSYS set to y.
> 
> I would change that last sentence to:
> 
> # You should set this to "NO", however, if you are running a modern
> # kernel with CONFIG_RTC_HCTOSYS set to y and your hardware clock is
> # set to UTC.
> 
> because you'd always want clock_hctosys set to "YES" (the default) if your
> hardware clock is set to local time.

In other words, the following is invalid in /etc/conf.d/hwclock:

clock="local"
clock_hctosys="no"

Correct?
Comment 15 Ian Abbott 2012-03-02 10:13:13 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > because you'd always want clock_hctosys set to "YES" (the default) if your
> > hardware clock is set to local time.
> 
> In other words, the following is invalid in /etc/conf.d/hwclock:
> 
> clock="local"
> clock_hctosys="no"
> 
> Correct?

Unwise, but maybe some crazy person has some reason to do that!
Comment 16 William Hubbs gentoo-dev 2012-03-02 17:07:49 UTC
This is fixed in commit 0fa164d.