Personal tools
You are here: Home Linux Xen Clock offset issue with Xen domU guests

Clock offset issue with Xen domU guests

— filed under:

Guests failed to have the correct date & time.

This issue came up when installing Xen v4.1.2 on Fedora 16 with Linux 3.1.1-2.fc16.x86_64. It was unclear as to what the issue was until I saw the message 'RTC configured in localtime' in the log. Windows guests didn't have an issue with this, whereas the CentOS v5.x and CentOS 6.x guests did.

The dom0 host is configured with NTP and the domU hosts are configured to use the wallclock (/proc/sys/xen/independent_wallclock=0). Also worth noting is that although the CentOS v5.x guests with the Xen kernel support the 'independent_wallclock' setting, the paravirtualised ops (pv_ops) kernel with CentOS v6.x doesn't have this setting.

Summary

Somehow the real time clock (RTC) was setup for localtime. Use 'hwclock' to set the time to UTC and flag that the time is stored as UTC. Verify that the RTC is set to UTC with the correct date & time.

# hwclock -w --utc --debug

Links

 

Appendices

Note: The timezone in the information below is for NZST during summer, which is +13 hours ahead of UTC.

Proof of the issue

The last RTC message shows the RTC is using locatime. It should be using UTC.

$ dmesg | grep -i RTC
[    0.064994] RTC time: 11:08:27, date: 11/21/11
[    1.207456] rtc_cmos 00:08: RTC can wake from S4
[    1.207852] rtc_cmos 00:08: rtc core: registered rtc_cmos as rtc0
[    1.208112] rtc0: alarms up to one year, y3k, 114 bytes nvram
[    1.215407] rtc_cmos 00:08: setting system clock to 2011-11-21 11:08:28 UTC (1321873708)
[   23.784283] systemd[1]: RTC configured in localtime, applying delta of 780 minutes to system time.

Display RTC

Correct RTC settings after setting the clock

# hwclock --debug
hwclock from util-linux 2.20.1
Using /dev interface to clock.
Last drift adjustment done at 1321829459 seconds after 1969
Last calibration done at 1321829459 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2011/11/20 22:59:32
Hw clock time : 2011/11/20 22:59:32 = 1321829972 seconds since 1969
Mon 21 Nov 2011 11:59:32 AM NZDT  -0.560935 seconds

Set RTC

Set the RTC with the current UTC time.

# hwclock -w --utc --debug
hwclock from util-linux 2.20.1
Using /dev interface to clock.
Last drift adjustment done at 1321829459 seconds after 1969
Last calibration done at 1321829459 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2011/11/20 23:00:21
Hw clock time : 2011/11/20 23:00:21 = 1321830021 seconds since 1969
Time elapsed since reference time has been 0.016426 seconds.
Delaying further to reach the new time.
Setting Hardware Clock to 23:00:21 = 1321830021 seconds since 1969
ioctl(RTC_SET_TIME) was successful.
Not adjusting drift factor because it has been less than a day since the last calibration.

CentOS v5.x guest clocksource

The CentOS v5.x Xen kernel has a 'jiffies' clock source.

# grep . /sys/devices/system/clocksource/clocksource0/*
/sys/devices/system/clocksource/clocksource0/available_clocksource:jiffies
/sys/devices/system/clocksource/clocksource0/current_clocksource:jiffies

CentOS v6.x guest clocksource

The CentOS v6.x paravirtualised ops kernel has a 'xen' clock source.

$ grep . /sys/devices/system/clocksource/clocksource0/*
/sys/devices/system/clocksource/clocksource0/available_clocksource:xen
/sys/devices/system/clocksource/clocksource0/current_clocksource:xen

Fixed dmesg entries

The next boot confirms the RTC clock is set to UTC.

# dmesg | grep -i rtc
[    0.065994] RTC time: 23:08:54, date: 11/20/11
[    1.224367] rtc_cmos 00:08: RTC can wake from S4
[    1.224741] rtc_cmos 00:08: rtc core: registered rtc_cmos as rtc0
[    1.224999] rtc0: alarms up to one year, y3k, 114 bytes nvram
[    1.232615] rtc_cmos 00:08: setting system clock to 2011-11-20 23:08:55 UTC (1321830535)
Document Actions