Skip to contentSkip to conversation

Wrong clock initialization

DISCUSSION David Balazic 7 participants 10 messages May 20, 2003 – May 21, 2003

lore
Share & tools
lore
#0 lore raw

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

Signature · 6 lines
David Balazic
--------------
"Be excellent to each other." - Bill S. Preston, Esq., & "Ted" Theodore
Logan
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
#1 lore raw
Quoted 2 lines · David Balazic

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

I run my clocks in UTC - the MS approach of keeping the system clock in local time (and having to change it twice a year, or when I'm travelling, or....) is too much of a pain in the ass.

#2 lore raw
In reply to David Balazic
Quoted 11 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

Quoted 8 lines

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

During shut down my system "says" it is setting the CMOS clock from the kernel clock. I would expect this to correct the problem. Is this a distro thing?

In any case, this would seem to make the problem go away after the first shutdown (if you don't dual boot with something other than Linux :).

Quoted 2 lines
Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#3 lore raw
Quoted 17 lines · george anzinger
Quoted 15 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

Quoted 8 lines
Quoted 4 lines

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

During shut down my system "says" it is setting the CMOS clock from the kernel clock. I would expect this to correct the problem. Is this a distro thing?

The time is properly converted first to be localtime, if your CMOS is localtime. So this does not fix anything.

Quoted 3 lines

In any case, this would seem to make the problem go away after the first shutdown (if you don't dual boot with something other than Linux :).

Signature · 6 lines
David Balazic
--------------
"Be excellent to each other." - Bill S. Preston, Esq., & "Ted" Theodore
Logan
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
#4 lore raw
Quoted 24 lines · David Balazic
Quoted 22 lines · george anzinger
Quoted 19 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

Quoted 7 lines
Quoted 3 lines

During shut down my system "says" it is setting the CMOS clock from the kernel clock. I would expect this to correct the problem. Is this a distro thing?

The time is properly converted first to be localtime, if your CMOS is localtime. So this does not fix anything.

Ouch! That is a real disconnect. Time to fix something.

Quoted 7 lines
Quoted 4 lines

In any case, this would seem to make the problem go away after the first shutdown (if you don't dual boot with something other than Linux :).

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#5 lore raw
In reply to David Balazic

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 11 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

Quoted 8 lines

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

Why don't you simply set your CMOS clock to UTC?

- --
Regards Michael Büsch
http://www.8ung.at/tuxsoft
20:16:51 up 4:12, 2 users, load average: 1.00, 1.07, 1.24

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+ynFooxoigfggmSgRAopWAJ0YOxEJ5jA3sfNhDwbSHmM5Z2nJQACcDxad +25XjbOyOGRKYUMtdQtv6mI=
=jE5A
-----END PGP SIGNATURE-----

#6 lore raw
Quoted 20 lines · Michael Buesch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 15 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

Quoted 6 lines
Quoted 4 lines

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

Why don't you simply set your CMOS clock to UTC?

Because certain other operating systems that expect localtime would then have problems.

--------------
"Be excellent to each other." - Bill S. Preston, Esq., & "Ted" Theodore Logan
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

#7 lore raw
In reply to David Balazic
Quoted 2 lines · David Balazic

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

I thought everybody used the CMOS clock in UTC, which means that the kernel doesn't have to know anything about nasty little details related to timezones, daylight savings time and such. Localtime is just a presentation issue.

Quoted 10 lines

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

All your disks are typically still mounted readonly and no important applications are running except for perhaps an fsck /dev/root between the time the system is booted and the clock is fixed up. So it really doesn't matter whether your clock is off by a couple of hours for a couple of seconds (a minute?) during boot.

Jan

#8 lore raw
In reply to David Balazic
Quoted 11 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

Quoted 8 lines

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

I strongly recommend running in UTC.

1. the system can then move between time zones without additional complexity
2. conversion errors during localtime -> system time don't occur
3. your clock doesn't get blown during system->localtime during shutdown (assuming you save system time...)
4. if you operate in a daylight saving time area, you won't get your clock blowin by variations in time depending on when you reboot.

#9 lore raw
In reply to David Balazic

This is not directly a kernel problem. I developed this after a glibc upgrade. The problem is most distros (such as redhat) make a symbolic link

/etc/localtime -> /usr/share/zoneinfo/America/Los_Angeles

or whatever your timezone is. On some of my systems, /usr/share is on a disk partition that is not mounted at the time the link is needed during initialization; the system then defaults to UTC. As a result, each time you boot up your system loses a time equal to the difference between UTC and your local time zone.

To fix this, just make sure /etc/localtime is actually a file on the root filesystem, not a link to a possibly unmounted filesystem. Just copy the one pointed to by the link.

I have systems with the same partition/mount layout which have no problem, so I don't know why some systems get confused. So far I have only seen this on laptops.

======================================================================
Jerry Cooperstein, Senior Consultant, <[email protected]> Axian, Inc., Software Consulting and Training 4800 SW Griffith Dr., Ste. 202, Beaverton, OR 97005 USA
http://www.axian.com/
======================================================================

Quoted 33 lines · David Balazic

Hi!

When the kernel is booted ( ia32 version at least ) , it reads the time from from the hardware CMOS clock , _assumes_ it is in UTC and set the system time to it.

As almost nobody runs their clock in UTC, this means that the system is running on wrong time until some userspace tool corrects it.

This can lead to situtation when time goes backwards :

timezone is 2hours east of UTC.
UTC time : 20:00
local time : 22:00

System time between boot and userspace fix : 22:00UTC System time after fix : 20:00UTC

Comments ?

Signature · 11 lines
David Balazic
--------------
"Be excellent to each other." - Bill S. Preston, Esq., & "Ted" Theodore
Logan
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/