iprog.com

How to work around slow clock drift in a Xen domU

I have a Xen 3.2.1 server and the guests (domU’s), after a few months of uptime, are all behind about 45 seconds. Interestingly, the dom0’s clock is fine.

It seems that the hypervisor’s clock is what’s off as all the guests are off by the same amount. A reboot would likely fix it, but what fun is that?

There are a few ways to solve this. Most commonly, it’s recommended to tell each domU to manage its own clock. This necessitates the use of ntpd or the regular use of ntpdate in each domU though and seems like gross overkill for such a slow drift.

It is possible, however, to enable domU clock management briefly, reset the clock using ntpdate, and then return to Xen-based clock management.

To do just that, first move to domU clock management:

echo 1 > /proc/sys/xen/independent_wallclock

Then reset the time:

ntpdate -b pool.ntp.org

Lastly, return to Xen clock management:

echo 0 > /proc/sys/xen/independent_wallclock

This does have to be run on each domU. Perhaps there’s some way to actually reset the hypervisor’s time (which is where I suspect the problem lies—shutting the domU down and recreating it didn’t fix the time). If you know how to do so, leave a comment.

It would be pretty easy to add this to cron—even once per week would be enough in my case.

tags: xen, domu, clock

by Khabi

Have had this same problem. In my case when this happens you can get the DomUs back in sync by running ntpdate then running hwclock —systohc AND hwclock —hctosys on the Dom0.

I know it seems dumb to sync the system clock to the hardware and then back, but somehow this seems to fix the time on the domUs.

by tm

Thanks for the tip. It does sound a bit strange, but I’ll certainly give it a shot.

—t

by Nakarti

Well it isn’t dumb because that’s what the system does during a reboot. It syncs system to hardware, assuming the system time may have changed, (especially with NTP or other manual/dst changes) before shutdown, then reads its new time from the hardware clock on bootup.