2003-05-20 17:22:18

by David Balazic

[permalink] [raw]
Subject: Wrong clock initialization

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 ?


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


2003-05-20 17:57:38

by George Anzinger

[permalink] [raw]
Subject: Re: Wrong clock initialization

David Balazic wrote:
> 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 ?

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 :).

>
>

--
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

2003-05-20 17:55:53

by David D. Hagood

[permalink] [raw]
Subject: Re: Wrong clock initialization

David Balazic wrote:

> 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.


2003-05-20 18:05:28

by Michael Buesch

[permalink] [raw]
Subject: Re: Wrong clock initialization

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

On Tuesday 20 May 2003 19:34, David Balazic wrote:
> 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 ?

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-----

2003-05-20 18:13:33

by David Balazic

[permalink] [raw]
Subject: Re: Wrong clock initialization

Michael Buesch wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 20 May 2003 19:34, David Balazic wrote:
> > 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 ?
>
> 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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

2003-05-20 18:15:29

by David Balazic

[permalink] [raw]
Subject: Re: Wrong clock initialization

george anzinger wrote:
>
> David Balazic wrote:
> > 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 ?
>
> 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.

>
> 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 :).


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

2003-05-20 20:03:58

by Jan Harkes

[permalink] [raw]
Subject: Re: Wrong clock initialization

On Tue, May 20, 2003 at 07:34:55PM +0200, David Balazic wrote:
> 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.

> 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

2003-05-20 20:09:32

by George Anzinger

[permalink] [raw]
Subject: Re: Wrong clock initialization

David Balazic wrote:
> george anzinger wrote:
>
>>David Balazic wrote:
>>
>>>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 ?
>>
>>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.
>
>
>>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 :).
>
>
>

--
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

2003-05-21 11:25:47

by Jesse Pollard

[permalink] [raw]
Subject: Re: Wrong clock initialization

On Tuesday 20 May 2003 12:34, David Balazic wrote:
> 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 ?

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.

2003-05-21 16:47:55

by Jerry Cooperstein

[permalink] [raw]
Subject: Re: Wrong clock initialization

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/
======================================================================



On Tue, May 20, 2003 at 07:34:55PM +0200, David Balazic wrote:
> 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 ?
>
>
> --
> 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/