From: Tim Deegan Subject: Re: Time Skewing on Windows XP Date: Thu, 14 Mar 2013 16:24:47 +0000 Message-ID: <20130314162447.GC5174@ocelot.phlegethon.org> References: <513EB1BC.9050803@amd.com> <513EEF5102000078000C4C89@nat28.tlf.novell.com> <5141E9CB.9020608@amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="envbJBWh7q8WU6mo" Return-path: Content-Disposition: inline In-Reply-To: <5141E9CB.9020608@amd.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Suravee Suthikulanit Cc: George.Dunlap@eu.citrix.com, Jan Beulich , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org --envbJBWh7q8WU6mo Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline At 10:16 -0500 on 14 Mar (1363256187), Suravee Suthikulanit wrote: > On 3/12/2013 3:03 AM, Jan Beulich wrote: > > >While I recall respective reports, the issue should not be present > >on current -unstable, so if you do have observations like this they > >will need investigation. > > Jan, > > I finally traced the issue back to the patch that this first happened. > This bug started in the patch : > > H86/HVM: assorted RTC emulation adjustment (w/ git commit id > 620d5dad54008e40798c4a0c4322aef274c36fa3) > > I believe there are some issues with the changes in rtc_ioport_read in the > arch/x86/hvm/rtc.c > and in the pt_update_irq(). Yes, it looks like the new call to rtc_timer_update() will reset the RTC timer every time RTC_C is read, even if it's already running. So each second will start from the last read of RTC_C, not the start of the last second. The attached patch makes the drift better, but doesn't fix it entirely. I'm not sure that it's the best approach though - it seems like in the common case we shouldn't be restarting the timer at all. Tim. --envbJBWh7q8WU6mo Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename=x diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c index c1e09d8..e9aa81a 100644 --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -80,7 +80,7 @@ void rtc_periodic_interrupt(void *opaque) * RTC_RATE_SELECT settings */ static void rtc_timer_update(RTCState *s) { - int period_code, period; + int period_code, period, delta; struct vcpu *v = vrtc_vcpu(s); ASSERT(spin_is_locked(&s->lock)); @@ -98,7 +98,8 @@ static void rtc_timer_update(RTCState *s) { period = 1 << (period_code - 1); /* period in 32 Khz cycles */ period = DIV_ROUND(period * 1000000000ULL, 32768); /* in ns */ - create_periodic_time(v, &s->pt, period, period, RTC_IRQ, NULL, s); + delta = period - ((NOW() - s->start_time) % period); + create_periodic_time(v, &s->pt, delta, period, RTC_IRQ, NULL, s); break; } /* fall through */ @@ -740,6 +741,7 @@ void rtc_init(struct domain *d) s->hw.cmos_data[RTC_REG_D] = RTC_VRT; s->current_tm = gmtime(get_localtime(d)); + s->start_time = NOW(); rtc_copy_date(s); diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h index c75297b..d6155b8 100644 --- a/xen/include/asm-x86/hvm/vpt.h +++ b/xen/include/asm-x86/hvm/vpt.h @@ -105,7 +105,7 @@ typedef struct RTCState { /* RTC's idea of the current time */ struct tm current_tm; /* second update */ - int64_t next_second_time; + s_time_t start_time; struct periodic_time pt; /* update-ended timer */ struct timer update_timer; --envbJBWh7q8WU6mo Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --envbJBWh7q8WU6mo--