Skip to contentSkip to conversation

System clock speed too high - 2.6.3 kernel

PATCH New Joris van Rantwijk 3 participants 7 messages May 25, 2004 – May 27, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hello,

Quoted 5 lines · Praedor Atrebates

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)

#2 lore raw
Quoted 18 lines · Joris van Rantwijk
Quoted 5 lines · Praedor Atrebates

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.

Quoted 4 lines

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

#3 lore raw
In reply to Joris van Rantwijk
Quoted 4 lines · Joris van Rantwijk

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

#4 lore raw
Quoted 7 lines · john stultz
Quoted 3 lines · Joris van Rantwijk

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

arch/i386/kernel/timers/timer_pm.c renamed from arch/i386/kernel/timers/timer_pm.orig.c +38 -0
@@ -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)
#5 lore raw
Quoted 15 lines · Joris van Rantwijk
Quoted 7 lines · john stultz
Quoted 3 lines · Joris van Rantwijk

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

Quoted 3 lines

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.

Quoted 8 lines

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.

Quoted 4 lines

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

#6 lore raw

PATCH 1/1 2.6.6 Validate PM-Timer rate at boot time

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.

arch/i386/kernel/timers/timer_pm.c renamed from arch/i386/kernel/timers/timer_pm.orig.c +38 -0
@@ -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)
#7 lore raw
In reply to Joris van Rantwijk
Quoted 23 lines · Joris van Rantwijk
Quoted 9 lines · john stultz
Quoted 3 lines · Joris van Rantwijk

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.

Quoted 8 lines

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.

Signature · 3 lines
   -bill davidsen ([email protected])
"The secret to procrastination is to put things off until the
 last possible moment - but no longer"  -me