LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Re: System clock speed too high - 2.6.3 kernel
       [not found] <1E4zj-77w-69@gated-at.bofh.it>
@ 2004-05-25  9:22 ` Joris van Rantwijk
  2004-05-25 20:53   ` john stultz
  2004-05-25 20:58   ` john stultz
  0 siblings, 2 replies; 7+ messages in thread
From: Joris van Rantwijk @ 2004-05-25  9:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Dominik Brodowski

Hello,

On Fri, 26 Mar 2004, Praedor Atrebates wrote:
> I have Mandrake 10.0, kernel-2.6.3-7mdk installed, on an IBM Thinkpad 1412
> laptop, celeron 366, 512MB RAM.  I am finding that my system clock is ticking
> away at a rate of about 3:1 vs reality, ie, I count ~3 seconds on the system
> clock for every 1 real second.  I am running ntpd but this is unable to keep
> up with the rate of system clock passage.

I have the same problem with kernel 2.6.6, only in my case the speed is
exactly doubled (not 3:1). Saying "clock=tsc" at boot time solves this
perfectly.

My mainboard is Asus P5A (4 years old) with ALi M1541 chipset.
Linux detects a PM-Timer at port 0xec08. I measured the counting rate
of this port (while safely running with clock=tsc) and it comes out at
about 7159155 ticks per second. The rate expected by
arch/i386/kernel/timer/timer_pm.c is 3579545 ticks per second, so this
explains the double speed very nicely.

Perhaps this should be documented in the kernel config info.
If there are many systems with this problem, then calibrating the PM timer
against the PIT timer at boot time (possibly rejecting invalid rates)
might be an option.

Bye,
  Joris.

Some information from dmesg:
ACPI: RSDP (v000 ASUS                                      ) @ 0x000f81d0
ACPI: RSDT (v001 ASUS   P5A      0x58582e32 MSFT 0x31313031) @ 0x07ffc000
ACPI: FADT (v001 ASUS   P5A      0x58582e32 MSFT 0x31313031) @ 0x07ffc080
ACPI: BOOT (v001 ASUS   P5A      0x58582e32 MSFT 0x31313031) @ 0x07ffc040
ACPI: DSDT (v001   ASUS P5A      0x00001000 MSFT 0x01000001) @ 0x00000000
ACPI: PM-Timer IO Port: 0xec08

Some information from lspci:
00:00.0 Host bridge: Acer Laboratories Inc. [ALi] M1541 (rev 04)
00:01.0 PCI bridge: Acer Laboratories Inc. [ALi] M5243 (rev 04)
00:02.0 USB Controller: Acer Laboratories Inc. [ALi] M5237 USB (rev 03)
00:03.0 Bridge: Acer Laboratories Inc. [ALi] M7101 PMU
00:07.0 ISA bridge: Acer Laboratories Inc. [ALi] M1533 PCI to ISA Bridge [Aladdin IV] (rev c3)
00:09.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8029(AS)
00:0f.0 IDE interface: Acer Laboratories Inc. [ALi] M5229 IDE (rev c1)
01:00.0 VGA compatible controller: nVidia Corporation Riva TnT [NV04] (rev 04)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: System clock speed too high - 2.6.3 kernel
  2004-05-25  9:22 ` System clock speed too high - 2.6.3 kernel Joris van Rantwijk
@ 2004-05-25 20:53   ` john stultz
  2004-05-25 20:58   ` john stultz
  1 sibling, 0 replies; 7+ messages in thread
From: john stultz @ 2004-05-25 20:53 UTC (permalink / raw)
  To: Joris van Rantwijk; +Cc: lkml, Dominik Brodowski

On Tue, 2004-05-25 at 02:22, Joris van Rantwijk wrote:
> On Fri, 26 Mar 2004, Praedor Atrebates wrote:
> > I have Mandrake 10.0, kernel-2.6.3-7mdk installed, on an IBM Thinkpad 1412
> > laptop, celeron 366, 512MB RAM.  I am finding that my system clock is ticking
> > away at a rate of about 3:1 vs reality, ie, I count ~3 seconds on the system
> > clock for every 1 real second.  I am running ntpd but this is unable to keep
> > up with the rate of system clock passage.
> 
> I have the same problem with kernel 2.6.6, only in my case the speed is
> exactly doubled (not 3:1). Saying "clock=tsc" at boot time solves this
> perfectly.
> 
> My mainboard is Asus P5A (4 years old) with ALi M1541 chipset.
> Linux detects a PM-Timer at port 0xec08. I measured the counting rate
> of this port (while safely running with clock=tsc) and it comes out at
> about 7159155 ticks per second. The rate expected by
> arch/i386/kernel/timer/timer_pm.c is 3579545 ticks per second, so this
> explains the double speed very nicely.
> 
> Perhaps this should be documented in the kernel config info.
> If there are many systems with this problem, then calibrating the PM timer
> against the PIT timer at boot time (possibly rejecting invalid rates)
> might be an option.

Check out bugme bug #2375. Some systems have ACPI PM timers that run too
fast. Running w/ "clock=tsc" is the proper workaround, but we need to
blacklist such systems from using it. If you could add dmidecode output
to the bug, I'll add your system to the list. 

http://bugme.osdl.org/show_bug.cgi?id=2375

thanks
-john



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: System clock speed too high - 2.6.3 kernel
  2004-05-25  9:22 ` System clock speed too high - 2.6.3 kernel Joris van Rantwijk
  2004-05-25 20:53   ` john stultz
@ 2004-05-25 20:58   ` john stultz
  2004-05-26 22:43     ` Joris van Rantwijk
  1 sibling, 1 reply; 7+ messages in thread
From: john stultz @ 2004-05-25 20:58 UTC (permalink / raw)
  To: Joris van Rantwijk; +Cc: lkml, Dominik Brodowski

On Tue, 2004-05-25 at 02:22, Joris van Rantwijk wrote:
> Perhaps this should be documented in the kernel config info.
> If there are many systems with this problem, then calibrating the PM timer
> against the PIT timer at boot time (possibly rejecting invalid rates)
> might be an option.

Also your point above is a good one. We probably should do a sanity
check to make sure we're getting a reasonable frequency (however then
we'll probably start having troubles w/ systems that have broken PITs ;)

I'll put it on my todo list, but if you'd like to take a swing at ti and
beat me to the implementation, I wouldn't complain.

thanks
-john



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: System clock speed too high - 2.6.3 kernel
  2004-05-25 20:58   ` john stultz
@ 2004-05-26 22:43     ` Joris van Rantwijk
  2004-05-26 23:08       ` john stultz
  2004-05-27 13:32       ` System clock speed too high - 2.6.3 kernel Bill Davidsen
  0 siblings, 2 replies; 7+ messages in thread
From: Joris van Rantwijk @ 2004-05-26 22:43 UTC (permalink / raw)
  To: john stultz; +Cc: lkml


On Tue, 25 May 2004, john stultz wrote:
> On Tue, 2004-05-25 at 02:22, Joris van Rantwijk wrote:
> > If there are many systems with this problem, then calibrating the PM timer
> > against the PIT timer at boot time (possibly rejecting invalid rates)
> > might be an option.

> I'll put it on my todo list, but if you'd like to take a swing at ti and
> beat me to the implementation, I wouldn't complain.

Sounds fair. I tried something and it even seems to work here.
My dmesg now says:
  PM-Timer running at invalid rate: 199% of normal - aborting.
  Detected 400.816 MHz processor.
  Using tsc for high-res timesource

Hmm, I think I'm enjoying this :-)
My patch is included below and also submitted at the Kernel Bugzilla
thing. I would appreciate it if someone else could also test it a bit.

Yesterday, I ran into a (hopefully) completely seperate issue with the
timer. This happened before I even started messing with the kernel and
while running with "clock=tsc". The kernel suddenly logged:
  Losing too many ticks!
  TSC cannot be used as a timesource
   ...
  Falling back to a sane timesource now.

And from that point on my system clock was running at about one third of
normal speed. The fallback timesource is just the PIT timer, so it seems
that my PIT had spontaneously dropped speed (thereby also causing the lost
ticks). Anyone else seen this before ?

Bye,
  Joris.

Patch: Verify PMTMR rate against PIT Ch2 at boot time before using it
Against: linux-2.6.6

--- linux-2.6.6/arch/i386/kernel/timers/timer_pm.orig.c	Sun Apr  4 05:36:18 2004
+++ linux-2.6.6/arch/i386/kernel/timers/timer_pm.c	Thu May 27 00:11:22 2004
@@ -19,10 +19,18 @@
 #include <asm/timer.h>
 #include <asm/smp.h>
 #include <asm/io.h>
 #include <asm/arch_hooks.h>

+#include <linux/timex.h>
+#include "mach_timer.h"
+
+/* Number of PMTMR ticks expected during calibration run */
+#define PMTMR_TICKS_PER_SEC 3579545
+#define PMTMR_EXPECTED_RATE \
+  ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
+

 /* The I/O port the PMTMR resides at.
  * The location is detected during setup_arch(),
  * in arch/i386/acpi/boot.c */
 u32 pmtmr_ioport = 0;
@@ -55,10 +63,37 @@

 	/* mask the output to 24 bits */
 	return v2 & ACPI_PM_MASK;
 }

+
+/*
+ * Some boards have the PMTMR running way too fast. We check
+ * the PMTMR rate against PIT channel 2 to catch these cases.
+ */
+static int verify_pmtmr_rate(void)
+{
+	u32 value1, value2;
+	unsigned long count, delta;
+
+	mach_prepare_counter();
+	value1 = read_pmtmr();
+	mach_countup(&count);
+	value2 = read_pmtmr();
+	delta = (value2 - value1) & ACPI_PM_MASK;
+
+	/* Check that the PMTMR delta is within 5% of what we expect */
+	if (delta < (PMTMR_EXPECTED_RATE * 19) / 20 ||
+	    delta > (PMTMR_EXPECTED_RATE * 21) / 20) {
+		printk(KERN_INFO "PM-Timer running at invalid rate: %lu%% of normal - aborting.\n", 100UL * delta / PMTMR_EXPECTED_RATE);
+		return -1;
+	}
+
+	return 0;
+}
+
+
 static int init_pmtmr(char* override)
 {
 	u32 value1, value2;
 	unsigned int i;

@@ -87,10 +122,13 @@
 	}
 	printk(KERN_INFO "PM-Timer had no reasonable result: 0x%#x - aborting.\n", value1);
 	return -ENODEV;

 pm_good:
+	if (verify_pmtmr_rate() != 0)
+		return -ENODEV;
+
 	init_cpu_khz();
 	return 0;
 }

 static inline u32 cyc2us(u32 cycles)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: System clock speed too high - 2.6.3 kernel
  2004-05-26 22:43     ` Joris van Rantwijk
@ 2004-05-26 23:08       ` john stultz
  2004-05-27 21:35         ` [PATCH] 2.6.6 Validate PM-Timer rate at boot time Joris van Rantwijk
  2004-05-27 13:32       ` System clock speed too high - 2.6.3 kernel Bill Davidsen
  1 sibling, 1 reply; 7+ messages in thread
From: john stultz @ 2004-05-26 23:08 UTC (permalink / raw)
  To: Joris van Rantwijk; +Cc: lkml, Dominik Brodowski

On Wed, 2004-05-26 at 15:43, Joris van Rantwijk wrote:
> On Tue, 25 May 2004, john stultz wrote:
> > On Tue, 2004-05-25 at 02:22, Joris van Rantwijk wrote:
> > > If there are many systems with this problem, then calibrating the PM timer
> > > against the PIT timer at boot time (possibly rejecting invalid rates)
> > > might be an option.
> 
> > I'll put it on my todo list, but if you'd like to take a swing at ti and
> > beat me to the implementation, I wouldn't complain.
> 
> Sounds fair. I tried something and it even seems to work here.
> My dmesg now says:
>   PM-Timer running at invalid rate: 199% of normal - aborting.
>   Detected 400.816 MHz processor.
>   Using tsc for high-res timesource
> 
> Hmm, I think I'm enjoying this :-)
> My patch is included below and also submitted at the Kernel Bugzilla
> thing. I would appreciate it if someone else could also test it a bit.

As I said in the bugzilla bug, it looks good to me. I'm going to test it
on my box to make sure it works properly on normal systems, so I'll send
you the results. 

> Yesterday, I ran into a (hopefully) completely seperate issue with the
> timer. This happened before I even started messing with the kernel and
> while running with "clock=tsc". The kernel suddenly logged:
>   Losing too many ticks!
>   TSC cannot be used as a timesource
>    ...
>   Falling back to a sane timesource now.
> 
> And from that point on my system clock was running at about one third of
> normal speed. The fallback timesource is just the PIT timer, so it seems
> that my PIT had spontaneously dropped speed (thereby also causing the lost
> ticks). Anyone else seen this before ?

I've seen that occasionally, but normally due to cpufreq changes. Any
clue what else was happening on your system when it occurred? (heavy
disk load, etc?)

thanks
-john


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: System clock speed too high - 2.6.3 kernel
  2004-05-26 22:43     ` Joris van Rantwijk
  2004-05-26 23:08       ` john stultz
@ 2004-05-27 13:32       ` Bill Davidsen
  1 sibling, 0 replies; 7+ messages in thread
From: Bill Davidsen @ 2004-05-27 13:32 UTC (permalink / raw)
  To: Joris van Rantwijk; +Cc: john stultz, lkml

Joris van Rantwijk wrote:
> On Tue, 25 May 2004, john stultz wrote:
> 
>>On Tue, 2004-05-25 at 02:22, Joris van Rantwijk wrote:
>>
>>>If there are many systems with this problem, then calibrating the PM timer
>>>against the PIT timer at boot time (possibly rejecting invalid rates)
>>>might be an option.
> 
> 
>>I'll put it on my todo list, but if you'd like to take a swing at ti and
>>beat me to the implementation, I wouldn't complain.
> 
> 
> Sounds fair. I tried something and it even seems to work here.
> My dmesg now says:
>   PM-Timer running at invalid rate: 199% of normal - aborting.
>   Detected 400.816 MHz processor.
>   Using tsc for high-res timesource
> 
> Hmm, I think I'm enjoying this :-)
> My patch is included below and also submitted at the Kernel Bugzilla
> thing. I would appreciate it if someone else could also test it a bit.
> 
> Yesterday, I ran into a (hopefully) completely seperate issue with the
> timer. This happened before I even started messing with the kernel and
> while running with "clock=tsc". The kernel suddenly logged:
>   Losing too many ticks!
>   TSC cannot be used as a timesource
>    ...
>   Falling back to a sane timesource now.
> 

Have to say that since adding clock=tsc my test systems are all keeping 
perfect time (ntpd running) which has not been the case since I started 
using test kernels about 2.5.38.

You do seem to have an issue with the pit.

-- 
    -bill davidsen (davidsen@tmr.com)
"The secret to procrastination is to put things off until the
  last possible moment - but no longer"  -me

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] 2.6.6 Validate PM-Timer rate at boot time
  2004-05-26 23:08       ` john stultz
@ 2004-05-27 21:35         ` Joris van Rantwijk
  0 siblings, 0 replies; 7+ messages in thread
From: Joris van Rantwijk @ 2004-05-27 21:35 UTC (permalink / raw)
  To: akpm; +Cc: lkml, john stultz, Dominik Brodowski


The patch below adds a check to the PM-Timer initialization code.
It validates the PM-Timer rate against PIT channel 2 and rejects
the PM-Timer if its rate is not withing 5% of the expected number.

Rationale:
The PMTMR timers of certain (older) mainboards are running at invalid
rates, often much faster than the rate expected by the PM-Timer code.
This causes the system clock to run much too fast.
See also http://bugme.osdl.org/show_bug.cgi?id=2375

Possible workarounds are disabling the PM-Timer in the kernel config
or disabling the PM-Timer at boot time through the "clock=tsc" parameter.
However, we believe it is more user friendly to automatically validate
the PM-Timer rate at boot time before using it as the system time source.

Patch is against linux 2.6.6.
Tested by me (with broken timer) and John Stultz (with good timer)
and believed to be ok.
Please consider applying.

Bye,
  Joris.

--- linux-2.6.6/arch/i386/kernel/timers/timer_pm.orig.c	Sun Apr  4 05:36:18 2004
+++ linux-2.6.6/arch/i386/kernel/timers/timer_pm.c	Thu May 27 00:11:22 2004
@@ -19,10 +19,18 @@
 #include <asm/timer.h>
 #include <asm/smp.h>
 #include <asm/io.h>
 #include <asm/arch_hooks.h>

+#include <linux/timex.h>
+#include "mach_timer.h"
+
+/* Number of PMTMR ticks expected during calibration run */
+#define PMTMR_TICKS_PER_SEC 3579545
+#define PMTMR_EXPECTED_RATE \
+  ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
+

 /* The I/O port the PMTMR resides at.
  * The location is detected during setup_arch(),
  * in arch/i386/acpi/boot.c */
 u32 pmtmr_ioport = 0;
@@ -55,10 +63,37 @@

 	/* mask the output to 24 bits */
 	return v2 & ACPI_PM_MASK;
 }

+
+/*
+ * Some boards have the PMTMR running way too fast. We check
+ * the PMTMR rate against PIT channel 2 to catch these cases.
+ */
+static int verify_pmtmr_rate(void)
+{
+	u32 value1, value2;
+	unsigned long count, delta;
+
+	mach_prepare_counter();
+	value1 = read_pmtmr();
+	mach_countup(&count);
+	value2 = read_pmtmr();
+	delta = (value2 - value1) & ACPI_PM_MASK;
+
+	/* Check that the PMTMR delta is within 5% of what we expect */
+	if (delta < (PMTMR_EXPECTED_RATE * 19) / 20 ||
+	    delta > (PMTMR_EXPECTED_RATE * 21) / 20) {
+		printk(KERN_INFO "PM-Timer running at invalid rate: %lu%% of normal - aborting.\n", 100UL * delta / PMTMR_EXPECTED_RATE);
+		return -1;
+	}
+
+	return 0;
+}
+
+
 static int init_pmtmr(char* override)
 {
 	u32 value1, value2;
 	unsigned int i;

@@ -87,10 +122,13 @@
 	}
 	printk(KERN_INFO "PM-Timer had no reasonable result: 0x%#x - aborting.\n", value1);
 	return -ENODEV;

 pm_good:
+	if (verify_pmtmr_rate() != 0)
+		return -ENODEV;
+
 	init_cpu_khz();
 	return 0;
 }

 static inline u32 cyc2us(u32 cycles)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-27 21:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1E4zj-77w-69@gated-at.bofh.it>
2004-05-25  9:22 ` System clock speed too high - 2.6.3 kernel Joris van Rantwijk
2004-05-25 20:53   ` john stultz
2004-05-25 20:58   ` john stultz
2004-05-26 22:43     ` Joris van Rantwijk
2004-05-26 23:08       ` john stultz
2004-05-27 21:35         ` [PATCH] 2.6.6 Validate PM-Timer rate at boot time Joris van Rantwijk
2004-05-27 13:32       ` System clock speed too high - 2.6.3 kernel Bill Davidsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).