Skip to contentSkip to conversation

timer fixes for 2.6.27

GIT PULL Thomas Gleixner 2 participants 2 messages Sep 6, 2008

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest timers-fixes-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git timers-fixes-for-linus

This is a rather large update that late in the rc cycle, but it's all really important bugfixes around the timers/timekeeping code.

The C1E idle support (added in .27) made some long standing bugs in the timers code more prominent and I spent almost two weeks now going through the code with a fine comb, creating debug patches and tracking down the last (and for me most embarrassing) bug in the hpet code along with a new workaround for hardware bugs^Wfeatures in ATI HPETs which need a readback of the compare value _before_ reading the count register to verify that we did not miss the event.

The patches are confirmed by various testers and close a couple of entries in the regression list [BZ #11145 #11191 #11279] and some other related bug reports.

Also passed in -tip testing on a broad range of x86 boxes.

I thought about disabling C1E for .27, but the bugs are real and affect non C1E systems as well. So fixing them is better than hiding them and hope they wont trigger.

The timekeeping patches vs. acpi_pm and ntp were collected and tested by Andrew and have been in -mm for some time.

Thanks,

tglx

------------------>
Dominik Brodowski (2):
clocksource, acpi_pm.c: use proper read function also in errata mode clocksource, acpi_pm.c: check for monotonicity

Maciej W. Rozycki (1):
ntp: fix calculation of the next jiffie to trigger RTC sync

Thomas Gleixner (8):
clockevents: prevent endless loop in periodic broadcast handler
clockevents: enforce reprogram in oneshot setup
clockevents: prevent multiple init/shutdown
clockevents: prevent endless loop lockup
HPET: make minimum reprogramming delta useful
clockevents: broadcast fixup possible waiters
x86: HPET fix moronic 32/64bit thinko
x86: HPET: read back compare register before reading counter

Venkatesh Pallipadi (1):
clockevents: prevent clockevent event_handler ending up handler_noop

 arch/x86/kernel/hpet.c        |   19 +++++++---
 drivers/clocksource/acpi_pm.c |   54 +++++++++++++++++-----------
 include/linux/clockchips.h    |    2 +
 kernel/time/clockevents.c     |    3 +-
 kernel/time/ntp.c             |    2 +-
 kernel/time/tick-broadcast.c  |   78 ++++++++++++++++++++++++++++++----------
 kernel/time/tick-common.c     |    1 +
 kernel/time/tick-internal.h   |    2 +
 kernel/time/tick-oneshot.c    |   46 +++++++++++++++++++++---
 9 files changed, 151 insertions(+), 56 deletions(-)
arch/x86/kernel/hpet.c +13 -6
index 59fd3b6..73deaff 100644
@@ -210,8 +210,8 @@ static void hpet_legacy_clockevent_register(void)
 	/* Calculate the min / max delta */
 	hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF,
 							   &hpet_clockevent);
-	hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
-							   &hpet_clockevent);
+	/* 5 usec minimum reprogramming delta. */
+	hpet_clockevent.min_delta_ns = 5000;
 
 	/*
 	 * Start hpet with the boot cpu mask and make it
@@ -270,15 +270,22 @@ static void hpet_legacy_set_mode(enum clock_event_mode mode,
 }
 
 static int hpet_legacy_next_event(unsigned long delta,
-			   struct clock_event_device *evt)
+				  struct clock_event_device *evt)
 {
-	unsigned long cnt;
+	u32 cnt;
 
 	cnt = hpet_readl(HPET_COUNTER);
-	cnt += delta;
+	cnt += (u32) delta;
 	hpet_writel(cnt, HPET_T0_CMP);
 
-	return ((long)(hpet_readl(HPET_COUNTER) - cnt ) > 0) ? -ETIME : 0;
+	/*
+	 * We need to read back the CMP register to make sure that
+	 * what we wrote hit the chip before we compare it to the
+	 * counter.
+	 */
+	WARN_ON((u32)hpet_readl(HPET_T0_CMP) != cnt);
+
+	return (s32)((u32)hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0;
 }
 
 /*
drivers/clocksource/acpi_pm.c +33 -21

86 lines not on this page · raw message

include/linux/clockchips.h +2 -0
index c33b0dc..ed3a5d4 100644
@@ -127,6 +127,8 @@ extern int clockevents_register_notifier(struct notifier_block *nb);
 extern int clockevents_program_event(struct clock_event_device *dev,
 				     ktime_t expires, ktime_t now);
 
+extern void clockevents_handle_noop(struct clock_event_device *dev);
+
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void clockevents_notify(unsigned long reason, void *arg);
 #else
kernel/time/clockevents.c +1 -2
index 3d1e3e1..1876b52 100644
@@ -177,7 +177,7 @@ void clockevents_register_device(struct clock_event_device *dev)
 /*
  * Noop handler when we shut down an event device
  */
-static void clockevents_handle_noop(struct clock_event_device *dev)
+void clockevents_handle_noop(struct clock_event_device *dev)
 {
 }
 
@@ -199,7 +199,6 @@ void clockevents_exchange_device(struct clock_event_device *old,
 	 * released list and do a notify add later.
 	 */
 	if (old) {
-		old->event_handler = clockevents_handle_noop;
 		clockevents_set_mode(old, CLOCK_EVT_MODE_UNUSED);
 		list_del(&old->list);
 		list_add(&old->list, &clockevents_released);
kernel/time/ntp.c +1 -1
index 5125ddd..1ad46f3 100644
@@ -245,7 +245,7 @@ static void sync_cmos_clock(unsigned long dummy)
 	if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2)
 		fail = update_persistent_clock(now);
 
-	next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec;
+	next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2);
 	if (next.tv_nsec <= 0)
 		next.tv_nsec += NSEC_PER_SEC;
 
kernel/time/tick-broadcast.c +58 -20

126 lines not on this page · raw message

kernel/time/tick-common.c +1 -0
index 80c4336..c477719 100644
@@ -161,6 +161,7 @@ static void tick_setup_device(struct tick_device *td,
 	} else {
 		handler = td->evtdev->event_handler;
 		next_event = td->evtdev->next_event;
+		td->evtdev->event_handler = clockevents_handle_noop;
 	}
 
 	td->evtdev = newdev;
kernel/time/tick-internal.h +2 -0
index f13f2b7..0ffc291 100644
@@ -17,6 +17,8 @@ extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_setup_oneshot(struct clock_event_device *newdev,
 			       void (*handler)(struct clock_event_device *),
 			       ktime_t nextevt);
+extern int tick_dev_program_event(struct clock_event_device *dev,
+				  ktime_t expires, int force);
 extern int tick_program_event(ktime_t expires, int force);
 extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
kernel/time/tick-oneshot.c +40 -6

71 lines not on this page · raw message

#1 lore raw

Hi,

2008/9/6 Thomas Gleixner <[email protected]>:

Quoted 3 lines

Dominik Brodowski (2):
[...]
clocksource, acpi_pm.c: check for monotonicity

I made some comments about this patch which were never answered:

    http://lkml.org/lkml/2008/8/23/28

Not sure whether this was because they were irrelevant or overlooked. Just to make sure, I replicate them below:

Quoted 61 lines
drivers/clocksource/acpi_pm.c +9 -17
index 5ca1d80..4eee533 100644
@@ -21,6 +21,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/delay.h>
 #include <asm/io.h>
 
 /*
@@ -151,13 +152,13 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_LE,
 */
 static int verify_pmtmr_rate(void)
 {
-       u32 value1, value2;
+       cycle_t value1, value2;
       unsigned long count, delta;
 
       mach_prepare_counter();
-       value1 = read_pmtmr();
+       value1 = clocksource_acpi_pm.read();
       mach_countup(&count);
-       value2 = read_pmtmr();
+       value2 = clocksource_acpi_pm.read();
       delta = (value2 - value1) & ACPI_PM_MASK;
 
       /* Check that the PMTMR delta is within 5% of what we expect */
@@ -175,10 +176,13 @@ static int verify_pmtmr_rate(void)
 #define verify_pmtmr_rate() (0)
 #endif
 
+/* Number of monotonicity checks to perform during initialization */
+#define ACPI_PM_MONOTONICITY_CHECKS 10
+
 static int __init init_acpi_pm_clocksource(void)
 {
-       u32 value1, value2;
-       unsigned int i;
+       cycle_t value1, value2;
+       unsigned int i, j, good = 0;
 
       if (!pmtmr_ioport)
               return -ENODEV;
@@ -187,24 +191,32 @@ static int __init init_acpi_pm_clocksource(void)
                                               clocksource_acpi_pm.shift);
 
       /* "verify" this timing source: */
-       value1 = read_pmtmr();
-       for (i = 0; i < 10000; i++) {
-               value2 = read_pmtmr();
-               if (value2 == value1)
-                       continue;
-               if (value2 > value1)
-                       goto pm_good;
-               if ((value2 < value1) && ((value2) < 0xFFF))
-                       goto pm_good;
-               printk(KERN_INFO "PM-Timer had inconsistent results:"
-                       " 0x%#x, 0x%#x - aborting.\n", value1, value2);
-               return -EINVAL;

drivers/clocksource/acpi_pm.c static int __init init_acpi_pm_clocksource(void) · line 203

Quoted 10 lines
drivers/clocksource/acpi_pm.c +10 -0
+       for (j = 0; j < ACPI_PM_MONOTONICITY_CHECKS; j++) {
+               value1 = clocksource_acpi_pm.read();
+               for (i = 0; i < 10000; i++) {
+                       value2 = clocksource_acpi_pm.read();
+                       if (value2 == value1)
+                               continue;
+                       if (value2 > value1)
+                               good++;
+                               break;
+                       if ((value2 < value1) && ((value2) < 0xFFF))

The brackets arout value2 are not needed and look strange.

drivers/clocksource/acpi_pm.c static int __init init_acpi_pm_clocksource(void) · line 211

Quoted 8 lines
drivers/clocksource/acpi_pm.c +8 -0
+                               good++;
+                               break;
+                       printk(KERN_INFO "PM-Timer had inconsistent results:"
+                              " 0x%#llx, 0x%#llx - aborting.\n",
+                              value1, value2);
+                       return -EINVAL;
+               }
+               udelay(300 * i);

300*10000 microseconds seems like a long time to me. Is this the intended maximal delay?

drivers/clocksource/acpi_pm.c static int __init init_acpi_pm_clocksource(void) · line 217

Quoted 6 lines
drivers/clocksource/acpi_pm.c +6 -0
+       }
+
+       if (good != ACPI_PM_MONOTONICITY_CHECKS) {
+               printk(KERN_INFO "PM-Timer failed consistency check "
+                      " (0x%#llx) - aborting.\n", value1);
+               return -ENODEV;

If the inner loop runs out once, you alreay know that you will later abort here. Maybe move the check directly after the inner loop to avoid the additional delay (10*10000*300 microseconds = 30 seconds) in case of failure?

drivers/clocksource/acpi_pm.c static int __init init_acpi_pm_clocksource(void) · line 221

Quoted 8 lines
drivers/clocksource/acpi_pm.c +0 -4
       }
-       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;

I hope this helps,
Jochen

Signature · 1 line
http://seehuhn.de/