Rafał’s random comments – programming, IT, other

June 12, 2008

adjtime() and synchronizing time in linux kernel

Filed under: idea,linux — limcore @ 3:37 pm

Time problem

My main board clock is really broken – running too slow. Ntpd network time synchronizer tries to fix it, but the drift is so big (10 second per hour) that linux kernel can not adjust the time using adjtime(). Adjtime usually is good, because it applies the time change gradually.

The only thing that works for me is settimeofday() which is not as good because then time “jumps” instead gradually change to correct time, distrubing movies playback and lots of other stuff.

So, I would like adjtime() to be able to adjust the time gradually but FASTER, to work for really broken hardware clocks.

Also, time ntpd program could be smart enought to see that the time difference is really bad, and could start using settimeofday as ntpdate does… I reported this originally as ubuntu bug in ntp.

Details – example

During 2 hours 20 minutes my clock drifted by 20.2 sec; So 0.0024 sec/sec time drift.

During 1 minute adjtime() makes kernel fix the drift by 0.03 sec. So, 0.0005 sec/sec time adjust.

Therefore kernel time adjust is too slow to compensate for time drifting of my hardware clock.

Solution

The correct solution seems to be to add another syscall that tells kernel how fast should the time be adjusted.

In lib C currently we have:
int adjtime(delta, olddelta);
and my idea is:

int adjtime_speed(
delta, speed, olddelta, oldspeed)

Then, programs like ntpd would observe the time drift, and issue orders to apply the correction faster.

Also, for clocks that are just slower in a linear/constant way, it would be nice to add:
int time_set_drift(double constant_drift);
time_set_drift(0); // normal clock
time_set_drift(0.001); // clock that always losts 1 second per 1000 seconds
etc.
Then ntp deamon would first observe how system clock reacts to adjust commands, and if a constant drift is discovered and messured, kernel would be told how to fix it.
That way the correction would work even if system is offline and ntpd doesnt work normally.

Any comments are appreciated 🙂  Is this worth implementing? Any hints which kernel files to look at?
Anyone had similar problems?

Advertisements

1 Comment »

  1. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=475959
    http://lxr.linux.no/linux+v2.6.25.6/arch/x86/Kconfig#L421

    HPET is ON in my ubuntu’s kernel (amd64, 64bit, smp)
    Still this may be source to look into when possibly patching kernel

    Comment by limcore — June 12, 2008 @ 5:22 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: