diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-09-17 16:59:21 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-09-17 16:59:21 +0100 |
commit | a541d50bffb48c13dd6776f3d75c189af8c24b3d (patch) | |
tree | 499ea3478381422288ea619d1575a9266dab15b4 /xen/arch/x86/hvm/pmtimer.c | |
parent | 453bfd468f1f1db8764b8f282c375852dc1c77ab (diff) | |
download | xen-a541d50bffb48c13dd6776f3d75c189af8c24b3d.tar.gz xen-a541d50bffb48c13dd6776f3d75c189af8c24b3d.tar.bz2 xen-a541d50bffb48c13dd6776f3d75c189af8c24b3d.zip |
hvm pmtimer: correct pmtimer accuracy
Several seconds of backward time drift per minute can be seen on a
RHEL6 HVM guest by switching the clocksource to 'acpi_pm' and then
running gettimeofday() in a loop. This is due to the accumulation
of small inaccuracies that are caused by shifting out the lower 32
bits when pmt_update_time() computes 'tmr_val'.
The patch makes sure that the lower 32 bits of the computed value
are not lost. They are saved in a new field 'not_accounted' in the
PMTState structure and are accounted the next time pmt_update_time()
is called.
From: Ulrich Obergfell <uobergfe@redhat.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Diffstat (limited to 'xen/arch/x86/hvm/pmtimer.c')
-rw-r--r-- | xen/arch/x86/hvm/pmtimer.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/xen/arch/x86/hvm/pmtimer.c b/xen/arch/x86/hvm/pmtimer.c index 48fe26ac87..1b9ab7ba18 100644 --- a/xen/arch/x86/hvm/pmtimer.c +++ b/xen/arch/x86/hvm/pmtimer.c @@ -83,14 +83,16 @@ void hvm_acpi_sleep_button(struct domain *d) * since the last time we did that. */ static void pmt_update_time(PMTState *s) { - uint64_t curr_gtime; + uint64_t curr_gtime, tmp; uint32_t msb = s->pm.tmr_val & TMR_VAL_MSB; ASSERT(spin_is_locked(&s->lock)); /* Update the timer */ curr_gtime = hvm_get_guest_time(s->vcpu); - s->pm.tmr_val += ((curr_gtime - s->last_gtime) * s->scale) >> 32; + tmp = ((curr_gtime - s->last_gtime) * s->scale) + s->not_accounted; + s->not_accounted = (uint32_t)tmp; + s->pm.tmr_val += tmp >> 32; s->pm.tmr_val &= TMR_VAL_MASK; s->last_gtime = curr_gtime; @@ -257,6 +259,7 @@ static int pmtimer_load(struct domain *d, hvm_domain_context_t *h) /* Calculate future counter values from now. */ s->last_gtime = hvm_get_guest_time(s->vcpu); + s->not_accounted = 0; /* Set the SCI state from the registers */ pmt_update_sci(s); @@ -276,6 +279,7 @@ void pmtimer_init(struct vcpu *v) spin_lock_init(&s->lock); s->scale = ((uint64_t)FREQUENCE_PMTIMER << 32) / SYSTEM_TIME_HZ; + s->not_accounted = 0; s->vcpu = v; /* Intercept port I/O (need two handlers because PM1a_CNT is between |