xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hvm: Correct RTC time offset update error due to tm->tm_year
@ 2012-02-20  7:19 ANNIE LI
  2012-02-20 14:53 ` Zhang, Yang Z
  0 siblings, 1 reply; 11+ messages in thread
From: ANNIE LI @ 2012-02-20  7:19 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com
  Cc: Kurt Hackel, Dan Magenheimer, Konrad Rzeszutek Wilk

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

Hi

In rtc_set_time, mktime is called to calculate seconds since 1970/01/01, 
input parameters of mktime are required to be in normal date format. 
Such as: year=1980, mon=12, day=31, hour=23, min=59, sec=59. However, 
the current input parameter of mktime is tm->tm_year, and it is the 
number of years since 1900. (For example, if current time is 2012/12/31, 
and tm->tm_year is 112). This is not suitable for requirement of mktime. 
So I think tm->tm_year should be changed to tm->tm_year+1900 when 
calling mktime. Please check the patch attached.

Thanks,
Annie

[-- Attachment #2: rtc-timeoffset.patch --]
[-- Type: text/plain, Size: 1329 bytes --]

# HG changeset patch
# Parent f2543f449a49b8979becbf6888e009973427089a
hvm: correct RTC time offset update error due to tm->tm_year

mktime requires input year in normal date format, i.e. 1980. So it is necessary
to change tm->tm_year to tm->tm_year+1900. Otherwise, the calculation result
of mktime is incorrect.

Signed-off-by: Annie Li <annie.li@oracle.com>

diff -r f2543f449a49 xen/arch/x86/hvm/rtc.c
--- a/xen/arch/x86/hvm/rtc.c	Mon Feb 13 17:57:47 2012 +0000
+++ b/xen/arch/x86/hvm/rtc.c	Mon Feb 20 14:39:00 2012 +0800
@@ -165,7 +165,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(tm->tm_year + 1900, 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 +179,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(tm->tm_year + 1900, 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 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-02-23 15:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-20  7:19 [PATCH] hvm: Correct RTC time offset update error due to tm->tm_year ANNIE LI
2012-02-20 14:53 ` Zhang, Yang Z
2012-02-20 15:04   ` young zhang
2012-02-20 23:54     ` Zhang, Yang Z
2012-02-21  2:31       ` ANNIE LI
2012-02-22 11:05         ` Ian Campbell
2012-02-22 13:10           ` annie li
2012-02-22 13:58             ` Ian Campbell
2012-02-22 14:35               ` annie li
2012-02-23 14:52               ` annie li
2012-02-23 15:17                 ` annie li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).