FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu Kernel Team

LinkBack Thread Tools
Old 03-10-2010, 06:30 PM
Chase Douglas
Default Switch to jiffies for native_sched_clock() when TSC warps

I took a look at the x86 code handling the clock to see what could be done
about the TSC warping coming out of resume on some of the newer processors. The
code includes a built-in fallback path that uses the jiffies count instead of
the TSC register if "notsc" is used on the command line. This patch merely sets
this option at runtime if two TSC time stamps differ by more than 6 years.

I'm sending this here first because I've not touched clocking code before. I'm
not sure whether this is a feasible approach, and I would like feedback. Note
that the TSC warping hasn't caused any noticeable issues beyond triggering some
oops messages, so even if there's some skew in the switch from TSC to jiffies
it should hopefully not cause too much of an issue.

The only truly negative outcome I foresee is that the clock won't be stable on
a single CPU. Programs needing accurate clock timing can pin themselves to a
single CPU in order to get TSC time stamps that are monotonic and accurate (The
TSC register is per cpu, and there may be skew between CPUs). However, if the
TSC has warped we are beyond that point anyways. If you have a warping
processor you should run with notsc if you care about accuracy, even though
precision would be reduced.

kernel-team mailing list
Old 03-10-2010, 06:30 PM
Chase Douglas
Default Switch to jiffies for native_sched_clock() when TSC warps

Some newer x86 processors (seen on core 2 duo, arrandale) warp their TSC
registers after a suspend. It is believed that a microcode fix may be a
solution, but for now we should work around the issue.

This change adds an upper bound on the difference between TSC readings. It
should be very generous (multiple year difference) so as to only catch TSC
warping which appears to generate timestamps many years in the future.
When a warp is found, usage of the TSC for timing is disabled. The
kernel falls back to using the jiffies counter, which is not as precise
but should be accurate.

Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
arch/x86/kernel/tsc.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 597683a..3e2921d 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -43,7 +43,9 @@ static int tsc_clocksource_reliable;
u64 native_sched_clock(void)
u64 this_offset;
+ static u64 prev_offset;

* Fall back to jiffies if there's no TSC available:
* ( But note that we still use it if the TSC is marked
@@ -60,6 +62,19 @@ u64 native_sched_clock(void)
/* read the Time Stamp Counter: */

+ /*
+ * if new time stamp is many years later, assume warping and disable
+ * TSC usage:
+ */
+ if (__cycles_2_ns(this_offset - prev_offset) > 0x100000000000000
+ && prev_offset) {
+ printk(KERN_WARNING "TSC warped, using jiffies
+ tsc_disabled = 1;
+ goto jiffies;
+ }
+ prev_offset = this_offset;
/* return the value in ns */
return __cycles_2_ns(this_offset);

kernel-team mailing list

Thread Tools

All times are GMT. The time now is 11:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org