aboutsummaryrefslogtreecommitdiffstats
path: root/xen/arch/x86/hvm/rtc.c
diff options
context:
space:
mode:
authorAnnie Li <annie.li@oracle.com>2012-03-01 16:29:59 +0000
committerAnnie Li <annie.li@oracle.com>2012-03-01 16:29:59 +0000
commitd9659850fbf929bed0b302323bf9465cd68492b9 (patch)
tree47897a6ffb03a85af8da03b7d4f63ba377426b35 /xen/arch/x86/hvm/rtc.c
parentca92c5098f0d841ef937c56f0a34a86a87cd6437 (diff)
downloadxen-d9659850fbf929bed0b302323bf9465cd68492b9.tar.gz
xen-d9659850fbf929bed0b302323bf9465cd68492b9.tar.bz2
xen-d9659850fbf929bed0b302323bf9465cd68492b9.zip
hvm: correct RTC time offset update error due to tm->tm_year
tm->tm_year in rtc.c is year number offsetting from 1900. So it is necessary to add the offset 1900 when calling mktime funtion in Xen. Otherwise, the calculation result of mktime is incorrect. Signed-off-by: Annie Li <annie.li@oracle.com> Committed-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/arch/x86/hvm/rtc.c')
-rw-r--r--xen/arch/x86/hvm/rtc.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c
index 81a74a33c6..e1139da89f 100644
--- a/xen/arch/x86/hvm/rtc.c
+++ b/xen/arch/x86/hvm/rtc.c
@@ -33,6 +33,8 @@
#define vrtc_domain(x) (container_of((x), struct domain, \
arch.hvm_domain.pl_time.vrtc))
#define vrtc_vcpu(x) (pt_global_vcpu_target(vrtc_domain(x)))
+#define epoch_year 1900
+#define get_year(x) (x + epoch_year)
static void rtc_periodic_cb(struct vcpu *v, void *opaque)
{
@@ -165,7 +167,7 @@ static void rtc_set_time(RTCState *s)
ASSERT(spin_is_locked(&s->lock));
- before = mktime(tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+ before = mktime(get_year(tm->tm_year), tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
tm->tm_sec = from_bcd(s, s->hw.cmos_data[RTC_SECONDS]);
@@ -179,7 +181,7 @@ static void rtc_set_time(RTCState *s)
tm->tm_mon = from_bcd(s, s->hw.cmos_data[RTC_MONTH]) - 1;
tm->tm_year = from_bcd(s, s->hw.cmos_data[RTC_YEAR]) + 100;
- after = mktime(tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+ after = mktime(get_year(tm->tm_year), tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
/* We use the guest's setting of the RTC to define the local-time
@@ -257,7 +259,7 @@ static void rtc_next_second(RTCState *s)
if ( (unsigned)tm->tm_wday >= 7 )
tm->tm_wday = 0;
days_in_month = get_days_in_month(tm->tm_mon,
- tm->tm_year + 1900);
+ get_year(tm->tm_year));
tm->tm_mday++;
if ( tm->tm_mday < 1 )
{