xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: annie li <annie.li@oracle.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: Dan Magenheimer <dan.magenheimer@oracle.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Kurt Hackel <Kurt.Hackel@oracle.com>,
	young zhang <young.zhang.free@gmail.com>,
	"Zhang, Yang Z" <yang.z.zhang@intel.com>
Subject: Re: [PATCH] hvm: Correct RTC time offset update error due to tm->tm_year
Date: Thu, 23 Feb 2012 22:52:43 +0800	[thread overview]
Message-ID: <4F4652BB.4020809@oracle.com> (raw)
In-Reply-To: <1329919132.8557.2.camel@zakaz.uk.xensource.com>

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



On 2012-2-22 21:58, Ian Campbell wrote:
>
> Yes, this looks plausible to me (although I'm no expert on this code).
> Something similar happens in rtc_next_second. 
>
> Perhaps it would be better to add a function or macro to do the
> conversion, such that it is somewhat self documenting? Or at least make
> the 1900 a #define with a suitable name.
>   
I changed the 1900 to a macro and added a new function get_year. The new 
patch is attached.

Thanks
Annie

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

# HG changeset patch
# Parent f2543f449a49b8979becbf6888e009973427089a
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>

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	Thu Feb 23 18:21:19 2012 +0800
@@ -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 )
                 {

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

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

  parent reply	other threads:[~2012-02-23 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-02-23 15:17                 ` annie li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F4652BB.4020809@oracle.com \
    --to=annie.li@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Kurt.Hackel@oracle.com \
    --cc=dan.magenheimer@oracle.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=yang.z.zhang@intel.com \
    --cc=young.zhang.free@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).