From: Dave Winchell <dwinchell@virtualiron.com>
To: Keir Fraser <keir.fraser@eu.citrix.com>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
"dan.magenheimer@oracle.com" <dan.magenheimer@oracle.com>,
"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
Dave Winchell <dwinchell@virtualiron.com>,
Ian Pratt <Ian.Pratt@eu.citrix.com>
Subject: Fix for get_s_time()
Date: Mon, 21 Apr 2008 16:32:19 -0400 [thread overview]
Message-ID: <480CF9D3.3090305@virtualiron.com> (raw)
In-Reply-To: <C432AA0A.16E43%keir.fraser@eu.citrix.com>
[-- Attachment #1: Type: text/plain, Size: 933 bytes --]
Keir,
In my work on layering hpet on get_s_time, I found a problem
in get_s_time and related code. Because of the problem I was getting
large jumps in the offset between local time and ntp time.
These jumps were on the order of many seconds.
The issue is the race between local_time_calibration() executing
on one processor and platform_time_calibration() on another.
I have included a patch which addresses the race in
local_time_calibration(), cpu_frequency_change(), and
init_percpu_time().
I'm giving you this ahead of the hpet work as it affects all users
of get_s_time().
I'm confident of the fix in local_time_calibration() as I had failures there
before the fix and no failures after. The other two I'm less confident
in, so check
my work closely there.
On the hpet over get_s_time() front, this fix allows me to get .0014% error.
This is very close to the error going to the hardware hpet each time.
Regards,
Dave
[-- Attachment #2: p.time.c.4.21 --]
[-- Type: text/plain, Size: 2830 bytes --]
diff -r a38a41de0800 xen/arch/x86/time.c
--- a/xen/arch/x86/time.c Wed Apr 16 16:42:47 2008 +0100
+++ b/xen/arch/x86/time.c Mon Apr 21 15:19:37 2008 -0400
@@ -530,6 +530,16 @@ static s_time_t read_platform_stime(void
return stime;
}
+static s_time_t read_platform_stime_locked(void)
+{
+ u64 count;
+ s_time_t stime;
+
+ count = plt_count64 + ((plt_src.read_counter() - plt_count) & plt_mask);
+ stime = __read_platform_stime(count);
+
+ return stime;
+}
static void platform_time_calibration(void)
{
@@ -749,6 +759,7 @@ int cpu_frequency_change(u64 freq)
{
struct cpu_time *t = &this_cpu(cpu_time);
u64 curr_tsc;
+ unsigned long flags;
/* Sanity check: CPU frequency allegedly dropping below 1MHz? */
if ( freq < 1000000u )
@@ -758,15 +769,15 @@ int cpu_frequency_change(u64 freq)
return -EINVAL;
}
- local_irq_disable();
+ spin_lock_irqsave(&platform_timer_lock, flags);
rdtscll(curr_tsc);
t->local_tsc_stamp = curr_tsc;
- t->stime_master_stamp = read_platform_stime();
+ t->stime_master_stamp = read_platform_stime_locked();
/* TSC-extrapolated time may be bogus after frequency change. */
/*t->stime_local_stamp = get_s_time();*/
t->stime_local_stamp = t->stime_master_stamp;
set_time_scale(&t->tsc_scale, freq);
- local_irq_enable();
+ spin_unlock_irqrestore(&platform_timer_lock, flags);
/* A full epoch should pass before we check for deviation. */
set_timer(&t->calibration_timer, NOW() + EPOCH);
@@ -830,16 +841,18 @@ static void local_time_calibration(void
/* The overall calibration scale multiplier. */
u32 calibration_mul_frac;
+ unsigned long flags;
+
prev_tsc = t->local_tsc_stamp;
prev_local_stime = t->stime_local_stamp;
prev_master_stime = t->stime_master_stamp;
/* Disable IRQs to get 'instantaneous' current timestamps. */
- local_irq_disable();
+ spin_lock_irqsave(&platform_timer_lock, flags);
rdtscll(curr_tsc);
curr_local_stime = get_s_time();
- curr_master_stime = read_platform_stime();
- local_irq_enable();
+ curr_master_stime = read_platform_stime_locked();
+ spin_unlock_irqrestore(&platform_timer_lock, flags);
#if 0
printk("PRE%d: tsc=%"PRIu64" stime=%"PRIu64" master=%"PRIu64"\n",
@@ -944,10 +957,10 @@ void init_percpu_time(void)
unsigned long flags;
s_time_t now;
- local_irq_save(flags);
+ spin_lock_irqsave(&platform_timer_lock, flags);
rdtscll(t->local_tsc_stamp);
- now = !plt_src.read_counter ? 0 : read_platform_stime();
- local_irq_restore(flags);
+ now = !plt_src.read_counter ? 0 : read_platform_stime_locked();
+ spin_unlock_irqrestore(&platform_timer_lock, flags);
t->stime_master_stamp = now;
t->stime_local_stamp = now;
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2008-04-21 20:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <47FFC37A.4060402@virtualiron.com>
2008-04-11 21:20 ` System time monotonicity Keir Fraser
2008-04-11 21:41 ` Keir Fraser
2008-04-11 22:58 ` Dave Winchell
2008-04-12 7:09 ` Keir Fraser
2008-04-21 19:26 ` Dan Magenheimer
2008-04-21 19:31 ` Keir Fraser
2008-04-21 20:32 ` Dave Winchell [this message]
2008-04-21 22:55 ` Fix for get_s_time() Keir Fraser
2008-04-21 23:10 ` Keir Fraser
2008-04-22 14:09 ` Dave Winchell
2008-04-24 16:04 ` Dave Winchell
2008-04-24 16:37 ` Keir Fraser
2008-04-24 18:32 ` Dave Winchell
2008-04-25 19:48 ` Dave Winchell
2008-04-25 21:03 ` Dan Magenheimer
2008-04-26 1:54 ` Dave Winchell
2008-04-28 17:39 ` Dan Magenheimer
2008-04-28 18:09 ` Dave Winchell
2008-04-28 18:40 ` Dave Winchell
2008-04-29 7:14 ` Keir Fraser
2008-04-29 14:21 ` Dave Winchell
2008-04-28 20:11 ` Dan Magenheimer
2008-04-28 21:29 ` Dave Winchell
2008-04-11 22:22 ` System time monotonicity Dan Magenheimer
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=480CF9D3.3090305@virtualiron.com \
--to=dwinchell@virtualiron.com \
--cc=Ian.Pratt@eu.citrix.com \
--cc=dan.magenheimer@oracle.com \
--cc=keir.fraser@eu.citrix.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.