Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 541874 - sys-apps/util-linux-2.26: hwclock ignores --utc
Summary: sys-apps/util-linux-2.26: hwclock ignores --utc
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-02 10:27 UTC by Vladimir
Modified: 2015-03-04 22:16 UTC (History)
0 users

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


Attachments
kernel config (config-3.19.0-gentoo,83.66 KB, text/plain)
2015-03-04 09:35 UTC, Vladimir
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir 2015-03-02 10:27:48 UTC
After a recent upgrade to sys-apps/util-linux-2.26 the system time is incorrectly set from the hardware clock during the system start. I store the time in UTC in hardware clock, and clearly see the words like

"Setting system time from hardware [UTC]"

during the system start, however the time is incorrectly set.

I tried to run 'hwclock -s --utc' by hand, but it actually ignored the difference between UTC and by TimeZone.

Reproducible: Always
Comment 1 SpanKY gentoo-dev 2015-03-04 06:46:10 UTC
seems to be working for me:
# export LC_ALL=C
# hwclock --version
hwclock from util-linux 2.26

# date; strace -eioctl hwclock -w --localtime
Wed Mar  4 01:39:35 EST 2015
ioctl(3, RTC_SET_TIME, {tm_sec=36, tm_min=39, tm_hour=1, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0

# date --utc; strace -eioctl hwclock -w --utc
Wed Mar  4 06:39:45 UTC 2015
ioctl(3, RTC_SET_TIME, {tm_sec=46, tm_min=39, tm_hour=6, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0

# date --utc; hwclock -w --utc; strace -eioctl hwclock -s --utc
Wed Mar  4 06:40:46 UTC 2015
ioctl(3, RTC_RD_TIME, {tm_sec=48, tm_min=40, tm_hour=6, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0

# date; hwclock -w --localtime; strace -eioctl hwclock -s --localtime
Wed Mar  4 01:41:10 EST 2015
ioctl(3, RTC_RD_TIME, {tm_sec=12, tm_min=41, tm_hour=1, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0

to be clear, the --utc/--localtime flags do not cause hwclock mangle the data it reads from the RTC.  the RTC has no notion of timezones, just time.  so when it holds the value like "01:41:10", that means it literally has the numbers hour=1 minute=41 second=10.  the --utc/--localtime flags tell hwclock whether that is "01:41:10 UTC" or "01:41:10 EST" (in my case).  once it has that precise timestamp, it then adjusts/syncs the value to the system clock as it expects.

please attach your kernel config and /etc/conf.d/hwclock file as well as run the example commands i have above
Comment 2 Vladimir 2015-03-04 09:35:13 UTC
Created attachment 398014 [details]
kernel config

(In reply to SpanKY from comment #1)
> 
> please attach your kernel config and /etc/conf.d/hwclock file as well as run
> the example commands i have above
Here is the result of the examples you suggested:

# strace -eioctl hwclock -w --localtime
ioctl(3, PHN_SET_REGS or RTC_UIE_ON, 0) = 0
ioctl(3, PHN_NOT_OH or RTC_UIE_OFF, 0)  = 0
ioctl(3, RTC_RD_TIME, {tm_sec=23, tm_min=10, tm_hour=9, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
ioctl(3, RTC_SET_TIME, {tm_sec=5, tm_min=10, tm_hour=11, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
+++ exited with 0 +++

# date --utc; strace -eioctl hwclock -w --utc
Wed Mar  4 09:10:47 UTC 2015
ioctl(3, PHN_SET_REGS or RTC_UIE_ON, 0) = 0
ioctl(3, PHN_NOT_OH or RTC_UIE_OFF, 0)  = 0
ioctl(3, RTC_RD_TIME, {tm_sec=48, tm_min=10, tm_hour=11, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
ioctl(3, RTC_SET_TIME, {tm_sec=48, tm_min=10, tm_hour=9, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
+++ exited with 0 +++

# date --utc; hwclock -w --utc; strace -eioctl hwclock -s --utc
Wed Mar  4 09:11:54 UTC 2015
ioctl(3, PHN_SET_REGS or RTC_UIE_ON, 0) = 0
ioctl(3, PHN_NOT_OH or RTC_UIE_OFF, 0)  = 0
ioctl(3, RTC_RD_TIME, {tm_sec=56, tm_min=11, tm_hour=9, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
+++ exited with 0 +++

# date; hwclock -w --localtime; strace -eioctl hwclock -s --localtime
Wed Mar  4 11:13:10 EET 2015
ioctl(3, PHN_SET_REGS or RTC_UIE_ON, 0) = 0
ioctl(3, PHN_NOT_OH or RTC_UIE_OFF, 0)  = 0
ioctl(3, RTC_RD_TIME, {tm_sec=12, tm_min=13, tm_hour=11, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
+++ exited with 0 +++



I also noticed that when I run

# date --utc; hwclock --show; strace -eioctl hwclock -w --utc; hwclock --show
Wed Mar  4 09:31:26 UTC 2015
Wed Mar  4 11:31:26 2015  .671098 seconds
ioctl(3, PHN_SET_REGS or RTC_UIE_ON, 0) = 0
ioctl(3, PHN_NOT_OH or RTC_UIE_OFF, 0)  = 0
ioctl(3, RTC_RD_TIME, {tm_sec=28, tm_min=31, tm_hour=9, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
ioctl(3, RTC_SET_TIME, {tm_sec=28, tm_min=31, tm_hour=9, tm_mday=4, tm_mon=2, tm_year=115, ...}) = 0
+++ exited with 0 +++
Wed Mar  4 11:31:28 2015  .479182 seconds

the time shown by 'hwclock --show' is the sabe before and after the setting, although the strace shows the correct numbers.

Here is the config:

# cat /etc/conf.d/hwclock 
# Set CLOCK to "UTC" if your Hardware Clock is set to UTC (also known as
# Greenwich Mean Time).  If that clock is set to the local time, then
# set CLOCK to "local".  Note that if you dual boot with Windows, then
# you should set it to "local".
clock="UTC"

# 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.
# However, you can set this to "NO" if you are running a modern kernel
# and using NTP to synchronize your system clock.
clock_hctosys="YES"

# If you do not want to set the hardware clock to the current system
# time (software clock) during shutdown, set this to no.
clock_systohc="YES"

# If you wish to pass any other arguments to hwclock during bootup,
# you may do so here. Alpha users may wish to use --arc or --srm here.
clock_args=""
Comment 3 SpanKY gentoo-dev 2015-03-04 17:03:08 UTC
(In reply to Vladimir from comment #2)

--show always localizes the timestamp (this is documented by the manpage).  the reason this works is that hwclock, when you use -w, will update /etc/adjtime with details like the timezone, and --show will automatically read that.

you can force the issue by doing:
  hwclock --show --noadjfile --localtime
  hwclock --show --noadjfile --utc

your kernel config has:
  CONFIG_RTC_HCTOSYS=y

so why do you also have in your /etc/conf.d/hwclock:
  clock_hctosys="YES"
Comment 4 Vladimir 2015-03-04 21:11:53 UTC
(In reply to SpanKY from comment #3)
> your kernel config has:
>   CONFIG_RTC_HCTOSYS=y
> 
> so why do you also have in your /etc/conf.d/hwclock:
>   clock_hctosys="YES"
I don't know. Perhaps, I set the one in /etc/conf.d/hwclock long time ago, when it was absent in kernel config. Shouldn't I have both? May it be the cause of my problem?
Comment 5 SpanKY gentoo-dev 2015-03-04 22:16:29 UTC
(In reply to Vladimir from comment #4)

the kernel option didn't always exist.  it's somewhat newish at this point.  at the very least, it's adding overhead to your system and just slowing down boot.

could you try turning off the clock_hctosys and clock_systohc options in your conf.d and see what happens ?