mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: Andy Pfiffer <andyp@osdl.org>
Cc: Andreas Haumer <andreas@xss.co.at>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: 2.5.72: wall-clock time advancing too rapidly?
Date: 20 Jun 2003 17:07:52 -0700	[thread overview]
Message-ID: <1056154072.1027.13.camel@w-jstultz2.beaverton.ibm.com> (raw)
In-Reply-To: <1056151705.1162.114.camel@andyp.pdx.osdl.net>

Alright, I've got a first pass at a patch that might solve this. 

This patch detects if we have 100 consecutive interrupts that find lost
ticks. If that occurs, we assume that the TSC is changing frequency and
we fall back to the PIT for a time source (equiv to booting w/
clock=pit). 

I'd like to see this well tested as I don't want to prematurely disable
the TSC if lost ticks is just doing its job, but I also want to catch
speedstep cpus before folks notice time going out of control. So the #
of consecutive interrupts may need adjusting. 

thanks
-john

This patch can also be found under bugme bug #827
http://bugme.osdl.org/show_bug.cgi?id=827

diff -Nru a/arch/i386/kernel/timers/timer.c b/arch/i386/kernel/timers/timer.c
--- a/arch/i386/kernel/timers/timer.c	Fri Jun 20 16:56:05 2003
+++ b/arch/i386/kernel/timers/timer.c	Fri Jun 20 16:56:05 2003
@@ -29,6 +29,16 @@
 }
 __setup("clock=", clock_setup);
 
+
+/* The chosen timesource has been found to be bad. 
+ * Fall back to a known good timesource (the PIT)
+ */
+extern struct timer_opts *timer;
+void clock_fallback(void)
+{
+	timer = &timer_pit;	
+}
+
 /* iterates through the list of timers, returning the first 
  * one that initializes successfully.
  */
diff -Nru a/arch/i386/kernel/timers/timer_tsc.c b/arch/i386/kernel/timers/timer_tsc.c
--- a/arch/i386/kernel/timers/timer_tsc.c	Fri Jun 20 16:56:05 2003
+++ b/arch/i386/kernel/timers/timer_tsc.c	Fri Jun 20 16:56:05 2003
@@ -124,6 +124,7 @@
 	int countmp;
 	static int count1 = 0;
 	unsigned long long this_offset, last_offset;
+	static int lost_count = 0;
 	
 	write_lock(&monotonic_lock);
 	last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
@@ -178,9 +179,19 @@
 	delta += delay_at_last_interrupt;
 	lost = delta/(1000000/HZ);
 	delay = delta%(1000000/HZ);
-	if (lost >= 2)
+	if (lost >= 2) {
 		jiffies += lost-1;
 
+		/* sanity check to ensure we're not always loosing ticks */
+		if (lost_count++ > 100) {
+			printk("Loosing too many ticks!\n");
+			printk("TSC cannot be used as a timesource."
+					" (Are you running with SpeedStep?)\n");
+			printk("Falling back to a sane timesource.\n");
+			clock_fallback();
+		}
+	} else
+		lost_count = 0;
 	/* update the monotonic base value */
 	this_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
 	monotonic_base += cycles_2_ns(this_offset - last_offset);






  parent reply	other threads:[~2003-06-21  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-19 16:10 Andy Pfiffer
2003-06-19 21:30 ` john stultz
2003-06-20 14:01   ` Wiktor Wodecki
2003-06-20 18:09     ` john stultz
2003-06-20 15:02   ` Andreas Haumer
2003-06-20 23:28     ` Andy Pfiffer
2003-06-20 23:31       ` john stultz
2003-06-21  0:07       ` john stultz [this message]
2003-06-24  0:16         ` 2.5.7[23]: " Andy Pfiffer
2003-06-24  0:37           ` john stultz
2003-06-24 16:09             ` Andy Pfiffer

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=1056154072.1027.13.camel@w-jstultz2.beaverton.ibm.com \
    --to=johnstul@us.ibm.com \
    --cc=andreas@xss.co.at \
    --cc=andyp@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®