LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   System clock is slow (https://www.linuxquestions.org/questions/linux-general-1/system-clock-is-slow-226640/)

monkeyman2000 09-04-2004 02:40 PM

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.

foo_bar_foo 09-04-2004 03:04 PM

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

monkeyman2000 09-04-2004 06:33 PM

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.

IBall 09-04-2004 09:45 PM

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

trickykid 09-05-2004 09:19 AM

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

monkeyman2000 09-05-2004 05:00 PM

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.

trickykid 09-05-2004 05:12 PM

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

Tinkster 09-05-2004 05:28 PM

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

aeruzcar 09-09-2004 12:34 AM

another good program for keeping the system clock at the right time is rdate
maybe you could check it up

monkeyman2000 09-11-2004 02:51 PM

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.

Tinkster 09-11-2004 05:11 PM

Did you consider/evaluate the apm vs acpi possibility?


Cheers,
Tink

foo_bar_foo 09-11-2004 11:40 PM

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.


All times are GMT -5. The time now is 09:51 AM.