My clock starts running out of sync in Ubuntu which doesn't happen in Windows. The problem is that it just starts losing time after a moment of syncing it with an NTP server, that means the clock is broken.

So How can I make the system use the hardware clock instead(I tried adjtimex).

To clarify... you think that your internal clock is /more/ accurate than using NTP? Or are you suggesting that NTP is broken on your system? Windows uses time.windows.com or something similar to sync its clock, whereas Ubuntu doens't ship with NTP enabled, so it's more likely that you actually /want/ to enable NTP on Ubuntu? Maybe?
–
ScaineMar 19 '11 at 19:57

1

No. NTP is fine, but the clock is broken in Ubuntu. When you choose to disable time sync in windows, it just keeps working, but when you either install NTP or or manually enter the time, the clock starts to get delays. For instance, the time here is 08:38 AM, in Ubuntu, however, it is 07:59 AM. If I log in NOW to Windows, I will get something very close to 08:38 which means that windows is taking time from a source(Time servers disabled) that Ubuntu fails to use.
–
Reda LazriMar 20 '11 at 7:39

Just a stab, do you have the correct timezone set?
–
theTuxRacerApr 19 '11 at 7:29

What happened when you tried adjtimex? I use it and it works very well on most machines, though on some the rate offset changes suddenly every once in a while. Though in my experience, the adjtimexconfig program usually gets the initial adjustment wrong. I just use ntpdate to manually tweak the FREQ and TICK values in /etc/default/adjtimex I can get it to stay within a few seconds for weeks, without ntp or ntpdate.
–
nealmcbApr 29 '11 at 19:32

@nealmcb: I wasn't sure adjtimex would help me, that's why I didn't test it a lot, I did one thing with it, I updated using ntpdate and then sent that time to the bios' clock, it worked but it couldn't keep it for a long time.
–
Reda LazriApr 30 '11 at 15:06

3 Answers
3

By default, Ubuntu only sets the time when a network interface comes up. It does this with a small piece of the "ntp" system: ntpdate. If your machine stays connected and keeps running for days or weeks, even the best internal clock will eventually go out of sync.
Ubuntu also doesn't try to adjust your internal clock by default, and it sounds like your clock is badly adjusted. The real time clock (hardware clock) in most systems is also not very good over the long term.

So if you want better time, I can recommend two options:

Install the full "ntp" package to get the Network Time Protocol, which regularly looks at Internet time servers and keeps your clock within milliseconds of the right time. See some good instructions here: Install NTP.... You can also install it from the Ubuntu Software Center. This is easy and typically pretty foolproof, if your machine is usually on the Internet and doesn't have really nasty firewalls cutting off ntp.

Manually adjust the frequency of your internal clock, using the adjtimex package. Actually, when you install adjtimex, it runs adjtimexconfig which sets values in /etc/default/adjtimex. But it does so quickly using the hardware clock, and in my experience the results are usually somewhere between bad and terrible. Some machines are hard to tune well, but I've had good luck with most of my machines by doing the manual calculation necessary to figure out the right FREQ and TICK values to put in /etc/default/adjtimex. To go this route, start by installing adjtimex via Applications/Ubuntu Software Center. To figure out manual settings for FREQ and TICK, see the nice calculator at Tuning with adjtimex as an alternative to running ntpd. That page also notes that your choice of "clocksource" can affect how accurate your clock is. The hpet (High Precision Event Timer) seems more accurate than the tsc (Time Stamp Counter).

I'm not sure things work the way you're describing. I.e., there are no "software" clock process/application which either uses BIOS clock or an ntp server and which can be "broken" in Ubuntu but working in Windows. In any case the info you see on the screen comes from BIOS clock.

If NTP server is enabled, the data coming from it is used to adjust the BIOS/hardware clock, and, when the hardware clock is thought to be "incorrect", NTP daemon adjusts time gradually in small increments instead of setting it straight away. This is done to avoid sudden "jumps" in system time which may cause all sorts of trouble (i.e. an event which happens after some other event but at earlier time).

Which perfectly explains the behaviour you're seeing - as soon as the "correct" data comes from the NTP server, the daemon starts gradually adjusting your system time.

I think your timezone/daylight saving time may be set incorrectly. Another possibility may be that Ubuntu expects the BIOS clock to be set to UTC time while Windows sets the clock in your local timezone, which results in Ubuntu thinking your system clock are late/early by your GMT offset