LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-04-2004, 03:40 PM   #1
monkeyman2000
Member
 
Registered: Oct 2003
Posts: 68

Rep: Reputation: 15
System clock is slow


Hi,

I am using Debian / knoppix 3.4 on a laptop. Linux kernel 2.4.26.

My Hardware Clock is accurate. My System Time syncs to the (correct) Hardware Clock setting when I start the computer, but then quickly starts losing time. The System Time seems to be about 15 minutes slower by the end of the day.

Again, the Hardware Clock (time kept by CMOS) is OK. It is the System Time (kep t by the kernel) that is wrong.

Why is this happening? How can I get the kernel to keep accurate time?

Thank you for any help you can provide.
 
Old 09-04-2004, 04:04 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
this is confusing cause as i understand it the kernel uses time stamp counter (hardware)
not real-time clock (software) so there are no interupts thus no latency ????????
this should mean the clock should be rock solid.
what kind of cpu is this ????
 
Old 09-04-2004, 07:33 PM   #3
monkeyman2000
Member
 
Registered: Oct 2003
Posts: 68

Original Poster
Rep: Reputation: 15
The CPU is a Pentium III. Not sure what difference that would make.

To demonstrate that the System Time is indeed slower than the Hardware Clock:

$ hwclock --show
Sat Sep 4 19:29:43 2004 -0.006329 seconds
$ date
Sat Sep 4 19:26:21 EDT 2004
$

The Hardware Clock is accurate. How can I get the system time to be as well?

Thanks for any help anyone can provide.
 
Old 09-04-2004, 10:45 PM   #4
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 61
The only suggestion I have is to set up a Cron Job that runs the command
Code:
 0 * * * *   "/sbin/hwclock --hctosys
This will run every hour, but is obvously only a bandaid, and you would be best to find the cause of the problem

I hope this helps
--Ian
 
Old 09-05-2004, 10:19 AM   #5
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally posted by IBall
The only suggestion I have is to set up a Cron Job that runs the command
Code:
 0 * * * *   "/sbin/hwclock --hctosys
This will run every hour, but is obvously only a bandaid, and you would be best to find the cause of the problem

I hope this helps
--Ian
Or get really accurate time and setup a similiar cron to get the time from an ntp server.
 
Old 09-05-2004, 06:00 PM   #6
monkeyman2000
Member
 
Registered: Oct 2003
Posts: 68

Original Poster
Rep: Reputation: 15
Solved problem with adjtimex

I beleive I have solved the problem. The System Time is calibrated with a program called adjtimex, which I didnt have installed.

After installing adjtimex, I have configured it to run in the startup scripts and calibrated it to adjust the System Time to run at the correct speed. See man adjtimex(8) for details.

This is the right solution; the kernel now keeps correct time. Syncing hourly to the hardware clock would have been a poor solution; the time would have been inaccurate betwen syncs, and in addition it is bad form to change the System Time in a running system as this can cause problems with other processes running on the system.

Using ntpd was not an option in this case since the machine is only intermitantly connected to the net.
 
Old 09-05-2004, 06:12 PM   #7
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Re: Solved problem with adjtimex

Quote:
Originally posted by monkeyman2000
Using ntpd was not an option in this case since the machine is only intermitantly connected to the net.
Be smart, write a script to check for internet connectivity, if its there, make it sync up with the ntp server, if not, then don't..
 
Old 09-05-2004, 06:28 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
On some notebooks the clock won't play nice with apm
enabled ... my machine had erratic timing, too, until I
switched from APM to ACPI.



Cheers,
Tink
 
Old 09-09-2004, 01:34 AM   #9
aeruzcar
Member
 
Registered: Jul 2003
Location: Santiago, Chile
Distribution: Gentoo
Posts: 282

Rep: Reputation: 30
another good program for keeping the system clock at the right time is rdate
maybe you could check it up
 
Old 09-11-2004, 03:51 PM   #10
monkeyman2000
Member
 
Registered: Oct 2003
Posts: 68

Original Poster
Rep: Reputation: 15
update on system time problems

Hi,

Thanks for the various suggestions. Just wanted to update the thread with the latest on my System Time issues.

Using adjtimex, I was able to set up the kernel's time variables more accurately. This has got system time to be much more accurate... now it's off by usually 8-10 seconds a day rather than 8-10 minutes.

I haven't been able to get it to run more accurately than that; the remaining variance seems to be irreguar, sometimes fast sometimes slow. Also note that adjtimex --compare produces wildly innaccurate and inconsisten results on my system. These problems may be due to apmd, which I am running (I use apm because acpi caused more serious problems on my system). Some other people seem to think it could be the battery monitor application. Some more information on laptop time problems under linux is discussed here:

http://tinyurl.com/6t5nl

Setting up ntpd and a script to run it when possible as trickykid suggested might be the best solution for the remaining innaccuracy. I may work on this when I have more time. Really though, if apmd is at fault the program should be fixed.
 
Old 09-11-2004, 06:11 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Did you consider/evaluate the apm vs acpi possibility?


Cheers,
Tink
 
Old 09-12-2004, 12:40 AM   #12
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
Quote:
Originally posted by monkeyman2000
The CPU is a Pentium III. Not sure what difference that would make.

the interplay between kernel and cpu is all the difference there is

Time-stamp counter measures cpu cycles and not "time". For example, two hundred million cycles on a 200 MHz processor is equivalent to one second of real time, while the same number of cycles on a 400 MHz processor is only one-half second of real time. Thus faster proccessor has finer grained time accuracy
access is through model specific registers.. Intel started making it available for programmers
Intel chips have 2 registers AMD chips have 4 some cyrix chips dont do RDTSC some do even as they all identify themselves to the kernel as i686 each chip is handled differently and |o| sometimes the kernel has buggs. (i can't believe i said that)
from the kernel mailing list concerning this subject:
Some web pages say "Works Best with IE 4.0"
Linux will have to say "Works Best with Intel Inside!".
add to this mix the fact that linux people generally are running kernels compiled specifically to run on intel cpus manufactured in 1980 for some strange reason.

If the processor does not have Time-stamp counter available then the kernel will have to use interupts that can well -- get interupted.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow system clock in a notebook cedar Linux - General 4 03-30-2005 04:24 AM
System clock is slow Hcman Linux - Hardware 6 10-21-2003 10:43 PM
System clock is fast AND slow.... cbjhawks Linux - Hardware 1 09-10-2003 04:24 PM
System clock is fast AND slow.... cbjhawks Linux - Software 2 09-10-2003 04:03 PM
system clock is hideously slow - ntpd refuses to fix it elconde Linux - General 1 02-21-2003 01:07 PM


All times are GMT -5. The time now is 08:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration